Repository navigation
Make recursive get, put and copy work for folders - #424
Conversation
Each test moves a small tree with a nested file and an empty folder. They fail today: get_file, put_file and cp_file treat a folder as a file. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
fsspec calls these for every entry of a recursive get, put or copy and expects a folder entry to create the folder. A file transfer makes the same requests as before: get_file and cp_file read the folder flag from the path lookup they already make. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
Copying a directory to root still raises a filename-required error because destination validation runs before source classification; folder handling and the corresponding test need updating.
1 open issue
What changed in this PR
This PR makes GDriveFileSystem handle directory entries during fsspec’s recursive uploads, downloads, and copies.
Changes:
- Create destination folders instead of attempting file transfers for directory entries.
- Reuse path lookup information to identify folders, with cached metadata for bare-ID roots.
- Add integration tests for nested files, empty folders, and downloads by Drive ID.
| File | Description |
|---|---|
pydrive2/test/test_fs.py |
Adds recursive transfer and bare-ID download tests. |
pydrive2/fs/spec.py |
Adds folder detection and directory handling to transfer methods. |
Review effort: Balanced
shcheklein
left a comment
There was a problem hiding this comment.
The core approach (reading the folder flag from _lookup_path so file transfers don't incur extra Drive requests) fits DirectoryCache nicely. Left a few inline comments covering three edge cases (cp_file targeting the root, trashed bare root IDs in _lookup_item, and missing local parent dirs in get_file) plus offline unit test coverage.
- A trashed bare ID raises FileNotFoundError in get_file and cp_file. - cp_file accepts a folder copied onto the filesystem root. - get_file creates the missing local parent folders. - Offline tests cover the folder branches and their request counts. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

fs.get,fs.putandfs.copywithrecursive=Truefail on the first folder they meet:fsspec calls
get_file,put_fileandcp_filefor every entry of the tree, folders included, and expects each one to create the folder. The three overrides inGDriveFileSystemtreated a folder as a file.Changes
put_filecreates the Drive folder when the local path is a directory.get_filecreates the local directory andcp_filecreates the destination folder when the source is a Drive folder. Both read this from the path lookup they already make, so a file transfer makes the same requests as before.get_filecreates the missing local parent folders, as fsspec's ownget_filedoes. Without this,fs.get(source, target, recursive=True, maxdepth=2)and a glob download into a new directory failed withFileNotFoundError.fs.copy("root/source/", "root", recursive=True). Copying a file there still requires a filename, now after one lookup of the source.get_fileorcp_fileof the root itself asks Drive once whether that ID is a folder. The answer is cached. A trashed ID raisesFileNotFoundError, asinfo()already does.Validation
get_fileandcp_filestill make 2 requests per file. Recursivegetmakes 2,003, the same as callingget_filefor each path thatfind()returns.🤖 Generated with Claude Code