Skip to content

Create Drive directories in mkdir and makedirs - #409

Merged
shcheklein merged 30 commits into
mainfrom
fix/fs-create-directories
Nov 26, 2026
Merged

shcheklein merged 30 commits into
mainfrom
fix/fs-create-directories

Conversation

@shcheklein

@shcheklein shcheklein commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Fixes #349. This PR builds on #408.

PyDrive2 inherited fsspec's no-op directory creation methods. mkdir and makedirs now create real Drive folders and use the resolver from #408 to identify missing components, existing folders, and blocking files. Bare folder-ID mounts also check their Drive, MIME type and trash status.

Tests cover create_parents, exist_ok, duplicate names, shared drives and concurrent invalidation. They require one lookup and one create per missing component and zero requests for an already cached directory. A live Drive test verifies an empty nested directory from a fresh filesystem instance.

@shcheklein shcheklein left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-generated review of ae0d8572fbc4e3b35707c9ad19616388aa9b21b8.

Scope is well-bounded for #349, and the request-level + live tests are concise. Main findings inline: walking top-down from root misses self.base / cached ancestors (adding extra Drive calls for nested mounts like dvc-gdrive), relying on _get_cached_item_ids right after _get_remote_item_ids as a folder-vs-file side-channel will race once #408 lands, and not base makes an uncached self.info() call on every root-level makedirs(..., exist_ok=True).

Comment thread pydrive2/fs/spec.py Resolved
Comment thread pydrive2/fs/spec.py Resolved
Comment thread pydrive2/fs/spec.py Resolved
Comment thread pydrive2/fs/spec.py Resolved
@shcheklein
shcheklein changed the base branch from main to fix/fs-directory-cache-invalidation November 22, 2026 07:02

@shcheklein shcheklein left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-generated re-review of adb4a5cac8b6fb2611e927855fbbb622b9618bc7 (from scratch).

The bottom-up ancestor walk (missing), direct _named_items folder filtering (removing the cache side-channel), and _mount_directory_ids() filtering are all much cleaner and resolve the earlier issues.

Two remaining things flagged inline: an unlocked read/write race on self._directory_ids / root_cache["root_is_directory"], and duplication between root_is_directory here and _root_location in #411.

Comment thread pydrive2/fs/spec.py Resolved
Comment thread pydrive2/fs/spec.py Resolved
@shcheklein

Copy link
Copy Markdown
Member Author

Directory creation now uses the path resolver from #408. It handles named mounts, exact-case matches and multiple folder IDs once. mkdir and makedirs apply the creation rules for missing parents, a blocking file and exist_ok to those results.

The request tests still require one lookup and one create per missing folder, zero requests for an already cached folder, and one lookup when a file blocks creation at a named mount. This PR continues to target #408.

@shcheklein

Copy link
Copy Markdown
Member Author

Uploads and copies now report NotADirectoryError when a file blocks the parent. Explicit mkdir on that file still reports FileExistsError. The new tests check both the exception and that no Drive mutation occurs. Bare-ID mkdir and makedirs refresh the root’s trash status; named cached directories still take zero requests to reuse. The freshness check also contributes the shared-drive routing information for subsequent listings.

Downstream, dvc-gdrive calls makedirs(parent) before streaming an upload. Its preflight therefore reports FileExistsError for a file at that exact parent path. I verified that it sent one lookup and no mutation. On a normal warm hash prefix, the DVC upload took only its upload session request and body PUT.

Creating a configured named mount still requires mounting an existing ancestor. Empty-folder removal is implemented separately in #414.

shcheklein added a commit that referenced this pull request Nov 25, 2026
shcheklein added a commit that referenced this pull request Nov 25, 2026
@shcheklein
shcheklein requested a balanced review from Copilot November 25, 2026 21:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Root validation is skipped for descendant paths, allowing folder creation under regular-file or trashed-folder mounts instead of raising the expected errors.

1 open issue
What changed in this PR

Implements real Google Drive directory creation through fsspec’s mkdir and makedirs, addressing #349 using the resolver and cache infrastructure from #408.

Changes:

  • Adds folder creation with parent-creation controls and existing-path handling.
  • Adds root metadata caching and validation for bare folder-ID mounts.
  • Expands unit and live tests for empty directories, shared drives, blocking files, and cache invalidation.
File Description
pydrive2/​test/​test_fs.py Verifies empty directories from a fresh filesystem and uses public directory-creation methods.
pydrive2/​test/​test_fs_unit.py Covers creation semantics, mount validation, request counts, and concurrent invalidation.
pydrive2/​fs/​spec.py Implements directory creation and refreshable root metadata handling.

Review effort: Balanced

Comment thread pydrive2/fs/spec.py Resolved
shcheklein added a commit that referenced this pull request Nov 25, 2026
# Conflicts:
#	pydrive2/fs/spec.py
@shcheklein
shcheklein requested a balanced review from Copilot November 25, 2026 21:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A trashed or missing mount leaves cached descendants valid, allowing subsequent directory checks to succeed after the mount has been observed as invalid.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread pydrive2/fs/spec.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

When a mount is observed as trashed or missing, cached child IDs and mount_checked remain intact, allowing later makedirs and exists calls to incorrectly treat invalid paths as valid.

1 open issue

Review effort: Balanced

Base automatically changed from fix/fs-directory-cache-invalidation to main November 26, 2026 01:11
shcheklein added a commit that referenced this pull request Nov 26, 2026
# Conflicts:
#	pydrive2/fs/spec.py
shcheklein added a commit that referenced this pull request Nov 26, 2026
@shcheklein shcheklein self-assigned this Nov 26, 2026
@shcheklein
shcheklein merged commit 4cf129e into main Nov 26, 2026
27 checks passed
@shcheklein
shcheklein deleted the fix/fs-create-directories branch November 26, 2026 23:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fs.makedirs() fails unless you put a file in the folder (shared drive)

2 participants