Repository navigation
Remove empty Drive folders through fsspec rmdir - #414
shcheklein wants to merge 3 commits into
Conversation
|
The reason I ran dvc-data's checkout directory-cleanup path with the real dvc-gdrive adapter and a simulated Drive. It removed an empty directory and preserved a populated sibling in both trash and permanent-delete modes, at fsspec 2024.2.0 and 2026.9.0. DVC object garbage collection has a separate per-object remove path. Drive's child listing and folder mutation are separate requests, so concurrent writers must be coordinated for this operation. |
There was a problem hiding this comment.
🟡 Changes recommended
The resolver does not check search completeness, so an omitted same-named sibling can cause rmdir to delete a folder at an ambiguous path; completeness validation and a no-mutation regression test are needed.
1 open issue
What changed in this PR
This PR replaces fsspec’s inherited no-op rmdir with Drive folder removal, supporting directory cleanup by callers such as DVC.
Changes:
- Resolves removal targets afresh and checks folder emptiness before trashing or permanently deleting.
- Adds offline request tests and a live Drive test for removal and refusal paths.
- Documents trash behavior and the need to coordinate concurrent writers.
| File | Description |
|---|---|
| pydrive2/test/test_fs.py | Adds live coverage for empty-folder removal and nonempty-parent preservation. |
| pydrive2/test/test_fs_unit.py | Tests resolution, protected roots, pagination, incomplete child listings, and retries. |
| pydrive2/fs/spec.py | Implements rmdir and retry-aware emptiness checks. |
| docs/fsspec.rst | Documents removal semantics and concurrency limitations. |
Review effort: Balanced
| if base: | ||
| # Name duplicates and external renames must be checked before | ||
| # deleting. A cached folder ID alone cannot establish uniqueness. | ||
| match = self._resolve_path(base, _DirectoryCache()) |

PyDrive2 inherited fsspec's empty default implementation of
rmdir, so the call returned successfully without sending a request to Drive. DVC's filesystem wrapper delegates directly to this API, including during directory cleanup. This PR builds on #409 alongside #411.rmdirresolves the current target, refuses ambiguous names and protected roots, and checks the child listing before using the configured trash or permanent-delete operation. Nonempty folders raiseOSError(ENOTEMPTY). Permanent removal includes trashed children in the check. Empty intermediate pages, incomplete searches and retries are covered. As Drive uses separate list and mutation requests, applications should coordinate concurrent writers.Offline request tests verify the target ID, child filters, failure paths and absence of mutations on refusal. A live Drive test checks that a nonempty parent survives and a fresh reader sees the empty child disappear.