From 4d30d9a96c60aa5b0ae650580480215c4499ec0f Mon Sep 17 00:00:00 2001 From: quassy <369996+quassy@users.noreply.github.com> Date: Tue, 7 Feb 2023 19:47:47 +0100 Subject: [PATCH] Fix mixup of paths in put function `put` currently sorts the list of input paths so when they are not in order before already, the don't match their output paths anymore and file names get mixed up. This fixes https://github.com/fsspec/gcsfs/issues/468 --- fsspec/spec.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fsspec/spec.py b/fsspec/spec.py index a58331f8c..769b20a15 100644 --- a/fsspec/spec.py +++ b/fsspec/spec.py @@ -935,7 +935,7 @@ def put(self, lpath, rpath, recursive=False, callback=_DEFAULT_CALLBACK, **kwarg if isinstance(lpath, str): lpath = make_path_posix(lpath) fs = LocalFileSystem() - lpaths = fs.expand_path(lpath, recursive=recursive) + lpaths = fs.expand_path(lpath, recursive=recursive, sort=False) isdir = isinstance(rpath, str) and self.isdir(rpath) rpaths = other_paths( lpaths, @@ -992,7 +992,7 @@ def copy(self, path1, path2, recursive=False, on_error=None, **kwargs): if on_error == "raise": raise - def expand_path(self, path, recursive=False, maxdepth=None): + def expand_path(self, path, recursive=False, maxdepth=None, sort=True): """Turn one or more globs or directories into a list of all matching paths to files or directories.""" if maxdepth is not None and maxdepth < 1: @@ -1026,7 +1026,10 @@ def expand_path(self, path, recursive=False, maxdepth=None): maxdepth = maxdepth if not maxdepth else maxdepth - 1 if not out: raise FileNotFoundError(path) - return list(sorted(out)) + if sort: + return list(sorted(out)) + else: + return list(out) def mv(self, path1, path2, recursive=False, maxdepth=None, **kwargs): """Move file(s) from one location to another"""