Skip to content

Commit

Permalink
Fix mixup of paths in put function
Browse files Browse the repository at this point in the history
`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 fsspec/gcsfs#468
  • Loading branch information
quassy authored Feb 7, 2023
1 parent 013ea5c commit 4d30d9a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions fsspec/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"""
Expand Down

0 comments on commit 4d30d9a

Please sign in to comment.