Skip to content

SMB: implement cp_file instead of overriding copy - #2558

Open
atishay-kasliwal wants to merge 1 commit into
fsspec:masterfrom
atishay-kasliwal:fix/smb-copy-cp-file
Open

atishay-kasliwal wants to merge 1 commit into
fsspec:masterfrom
atishay-kasliwal:fix/smb-copy-cp-file

Conversation

@atishay-kasliwal

Copy link
Copy Markdown

Fixes #2557.

SMBFileSystem.copy passed every keyword argument to smbclient.copyfile, so fs.copy(a, b, recursive=False) failed with TypeError: get_smb_tree() got an unexpected keyword argument 'recursive'. Folders and lists of paths never got expanded either.

This takes the approach suggested in the issue. The copy override is replaced with cp_file, which still copies on the server with smbclient.copyfile, and the generic copy handles recursive, maxdepth, on_error and lists. cp_file creates the target folder when the source is a folder, like LocalFileSystem.cp_file does.

test_copy covers a single file with recursive=False, a recursive folder copy, and a list of paths. I ran the SMB tests against Samba 4 on port 9999 with the same user and share as the docker fixture. All 9 pass, and without the change test_copy fails with the TypeError above.

The copy override passed every keyword argument on to smbclient.copyfile, so recursive=False from the generic signature raised a TypeError, and folders and lists of paths were never expanded. cp_file keeps the server-side copy and lets the generic copy handle recursive, maxdepth and on_error.
@lexingtonhibiki

Copy link
Copy Markdown
Contributor

The recursive/list support is useful. I found one backward-compatibility case at 22d2a4d: the old SMB override treated a scalar source as a literal name. The generic implementation now treats brackets in that same name as a glob.

With /home/report[1].txt containing literal and /home/report1.txt containing match, I called fs.copy("/home/report[1].txt", "/home/out.txt") on the exact base and head. The base passed the literal path to copyfile and wrote out.txt. The head instead passed report1.txt → out.txt/report1.txt. With auto_mkdir=False and a fresh destination that fails; with auto_mkdir=True it creates the directory and copies the matching sibling successfully. If only the bracket-named file exists, the head raises before calling copyfile. A plain scalar name works on both; the head's explicit source/destination lists and intentional glob controls also work.

I used the real fsspec copy/expansion code with a filesystem-backed smbclient double, not a second Samba run. Could we add a scalar bracket-name test alongside the new cases? Preserving an existing literal file before falling back to glob expansion would keep the old call working while still allowing intentional patterns when there is no literal match.

@atishay-kasliwal

Copy link
Copy Markdown
Author

Thanks for checking. That's how the generic copy treats a source name, so SMB now matches the other backends. With the same two files, the memory filesystem copies report1.txt into out.txt/, and file fails the same way when out.txt/ doesn't exist. I'd rather keep SMB consistent with them than special-case literal names here, but I can add a literal-first check if the maintainers want to keep the old SMB behavior.

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.

SMBFileSystem.copy passes recursive on to smbclient

2 participants