-
Notifications
You must be signed in to change notification settings - Fork 419
Do nothing for non-recursive copy of empty directory #1254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -939,32 +939,24 @@ def test_cp_get_put_empty_directory(tmpdir, funcname): | |
| # cp/get/put without slash, target directory exists | ||
| assert fs.isdir(target) | ||
| func(empty, target) | ||
| assert fs.find(target, withdirs=True) == [ | ||
| make_path_posix(os.path.join(target, "empty")) | ||
| ] | ||
|
|
||
| fs.rm(target + "/empty", recursive=True) | ||
| assert fs.find(target, withdirs=True) == [] | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is effectively duplicated in the abstract test harness, so it can eventually be removed. But I have fixed it here for the time being. The same applies to the one in |
||
|
|
||
| # cp/get/put with slash, target directory exists | ||
| assert fs.isdir(target) | ||
| func(empty + "/", target) | ||
| assert fs.find(target, withdirs=True) == [] | ||
|
|
||
| fs.rm(target, recursive=True) | ||
| fs.rmdir(target) | ||
|
|
||
| # cp/get/put without slash, target directory doesn't exist | ||
| assert not fs.isdir(target) | ||
| func(empty, target) | ||
| assert fs.isdir(target) | ||
| assert fs.find(target, withdirs=True) == [] | ||
|
|
||
| fs.rm(target, recursive=True) | ||
| assert not fs.isdir(target) | ||
|
|
||
| # cp/get/put with slash, target directory doesn't exist | ||
| assert not fs.isdir(target) | ||
| func(empty + "/", target) | ||
| assert fs.isdir(target) | ||
| assert fs.find(target, withdirs=True) == [] | ||
| assert not fs.isdir(target) | ||
|
|
||
|
|
||
| def test_cp_two_files(tmpdir): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -886,13 +886,21 @@ def get(self, rpath, lpath, recursive=False, callback=_DEFAULT_CALLBACK, **kwarg | |
| trailing_sep_maybe_asterisk, | ||
| ) | ||
|
|
||
| rpaths = self.expand_path(rpath, recursive=recursive) | ||
| if ( | ||
| len(rpaths) == 1 | ||
| and not recursive | ||
| and (trailing_sep(rpaths[0]) or self.isdir(rpaths[0])) | ||
| ): | ||
| # Non-recursive copy of directory does nothing. | ||
| return | ||
| source_is_str = isinstance(rpath, str) | ||
|
|
||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have reordered the code here (and the other 2 functions below) to separate out the handling of |
||
| if isinstance(lpath, str): | ||
| lpath = make_path_posix(lpath) | ||
| rpaths = self.expand_path(rpath, recursive=recursive) | ||
| isdir = isinstance(lpath, str) and ( | ||
| trailing_sep(lpath) or LocalFileSystem().isdir(lpath) | ||
| ) | ||
| source_is_str = isinstance(rpath, str) | ||
| lpaths = other_paths( | ||
| rpaths, | ||
| lpath, | ||
|
|
@@ -942,17 +950,25 @@ def put(self, lpath, rpath, recursive=False, callback=_DEFAULT_CALLBACK, **kwarg | |
| trailing_sep_maybe_asterisk, | ||
| ) | ||
|
|
||
| if isinstance(lpath, str): | ||
| lpath = make_path_posix(lpath) | ||
| fs = LocalFileSystem() | ||
| lpaths = fs.expand_path(lpath, recursive=recursive) | ||
| if ( | ||
| len(lpaths) == 1 | ||
| and not recursive | ||
| and (trailing_sep(lpaths[0]) or self.isdir(lpaths[0])) | ||
| ): | ||
| # Non-recursive copy of directory does nothing. | ||
| return | ||
| source_is_str = isinstance(lpath, str) | ||
|
|
||
| rpath = ( | ||
| self._strip_protocol(rpath) | ||
| if isinstance(rpath, str) | ||
| else [self._strip_protocol(p) for p in rpath] | ||
| ) | ||
| if isinstance(lpath, str): | ||
| lpath = make_path_posix(lpath) | ||
| fs = LocalFileSystem() | ||
| lpaths = fs.expand_path(lpath, recursive=recursive) | ||
| isdir = isinstance(rpath, str) and (trailing_sep(rpath) or self.isdir(rpath)) | ||
| source_is_str = isinstance(lpath, str) | ||
| rpaths = other_paths( | ||
| lpaths, | ||
| rpath, | ||
|
|
@@ -996,8 +1012,16 @@ def copy(self, path1, path2, recursive=False, on_error=None, **kwargs): | |
| on_error = "raise" | ||
|
|
||
| paths = self.expand_path(path1, recursive=recursive) | ||
| isdir = isinstance(path2, str) and (trailing_sep(path2) or self.isdir(path2)) | ||
| if ( | ||
| len(paths) == 1 | ||
| and not recursive | ||
| and (trailing_sep(paths[0]) or self.isdir(paths[0])) | ||
| ): | ||
| # Non-recursive copy of directory does nothing. | ||
| return | ||
| source_is_str = isinstance(path1, str) | ||
|
|
||
| isdir = isinstance(path2, str) and (trailing_sep(path2) or self.isdir(path2)) | ||
| path2 = other_paths( | ||
| paths, | ||
| path2, | ||
|
|
@@ -1019,6 +1043,7 @@ def expand_path(self, path, recursive=False, maxdepth=None, **kwargs): | |
|
|
||
| kwargs are passed to ``glob`` or ``find``, which may in turn call ``ls`` | ||
| """ | ||
|
|
||
| if maxdepth is not None and maxdepth < 1: | ||
| raise ValueError("maxdepth must be at least 1") | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wasn't quite correct before but now is.