Use mv_file for single-file moves - #2099
Conversation
|
I feel this might have been done - perhaps only for async? Or perhaps in a PR that hasn't been merged? Please check. |
|
Thanks for flagging this. I checked current This draft is the sync counterpart: file-only moves go through the new default |
| source_is_str = isinstance(path1, str) | ||
| paths1 = self.expand_path( | ||
| path1, recursive=recursive, maxdepth=maxdepth, **kwargs | ||
| ) | ||
| if source_is_str and (not recursive or maxdepth is not None): | ||
| # Non-recursive glob does not move directories | ||
| paths1 = [p for p in paths1 if not (trailing_sep(p) or self.isdir(p))] | ||
| if not paths1: | ||
| # Preserve the existing error behavior for directory moves | ||
| # that are not recursive. | ||
| self.copy( | ||
| path1, | ||
| path2, | ||
| recursive=recursive, | ||
| maxdepth=maxdepth, | ||
| on_error="raise", | ||
| ) | ||
| self.rm(path1, recursive=recursive) | ||
| return | ||
|
|
||
| source_is_file = len(paths1) == 1 | ||
| dest_is_dir = isinstance(path2, str) and ( | ||
| trailing_sep(path2) or self.isdir(path2) | ||
| ) | ||
|
|
||
| exists = source_is_str and ( | ||
| (has_magic(path1) and source_is_file) | ||
| or (not has_magic(path1) and dest_is_dir and not trailing_sep(path1)) | ||
| ) | ||
| paths2 = other_paths( | ||
| paths1, | ||
| path2, | ||
| exists=exists, | ||
| flatten=not source_is_str, | ||
| ) |
There was a problem hiding this comment.
Is this identical code to what it seen in the cp method?
Fixes #2017
Summary
mv_fileimplementation that preserves the existing copy/delete behaviormv_fileso filesystems can provide an atomic overrideValidation
ruff format fsspec/spec.py fsspec/implementations/tests/test_memory.pyruff check fsspec/spec.py fsspec/implementations/tests/test_memory.pypytest fsspec/implementations/tests/test_memory.py -qpytest fsspec/tests/abstract/mv.py -qgit diff --checkPrepared with AI assistance; I reviewed the implementation and validation output.