Repository navigation
Create Drive directories in mkdir and makedirs - #409
Conversation
shcheklein
left a comment
There was a problem hiding this comment.
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).
shcheklein
left a comment
There was a problem hiding this comment.
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.
|
Directory creation now uses the path resolver from #408. It handles named mounts, exact-case matches and multiple folder IDs once. 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. |
|
Uploads and copies now report Downstream, dvc-gdrive calls Creating a configured named mount still requires mounting an existing ancestor. Empty-folder removal is implemented separately in #414. |
There was a problem hiding this comment.
🟡 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
# Conflicts: # pydrive2/fs/spec.py
# Conflicts: # pydrive2/fs/spec.py

Fixes #349. This PR builds on #408.
PyDrive2 inherited fsspec's no-op directory creation methods.
mkdirandmakedirsnow 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.