Skip to content

Commit 2e0238a

Browse files
committed
fix copydir hangup
1 parent 0f09731 commit 2e0238a

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

fs/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,10 @@ def copydir(
461461
462462
"""
463463
with self._lock:
464+
_src_path = self.validatepath(src_path)
465+
_dst_path = self.validatepath(dst_path)
466+
if isbase(_src_path, _dst_path):
467+
raise errors.IllegalDestination(dst_path)
464468
if not create and not self.exists(dst_path):
465469
raise errors.ResourceNotFound(dst_path)
466470
if not self.getinfo(src_path).is_dir:

fs/test.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,13 +1874,12 @@ def test_copydir_onto_itself(self):
18741874
self.assert_text("folder/sub/file2.txt", "Hello2")
18751875

18761876
def test_copydir_into_its_own_subfolder(self):
1877-
# folder = self.fs.makedir("folder")
1878-
# folder.writetext("file1.txt", "Hello1")
1879-
# sub = folder.makedir("sub")
1880-
# sub.writetext("file2.txt", "Hello2")
1881-
# with self.assertRaises(errors.IllegalDestination):
1882-
# self.fs.copydir("folder", "folder/sub/")
1883-
pass
1877+
folder = self.fs.makedir("folder")
1878+
folder.writetext("file1.txt", "Hello1")
1879+
sub = folder.makedir("sub")
1880+
sub.writetext("file2.txt", "Hello2")
1881+
with self.assertRaises(errors.IllegalDestination):
1882+
self.fs.copydir("folder", "folder/sub/")
18841883

18851884
def test_movedir(self):
18861885
self.fs.makedirs("foo/bar/baz/egg")

0 commit comments

Comments
 (0)