Skip to content

Commit 6ef99f6

Browse files
committed
wrapfs does not need checks sprinkled everywhere anymore
1 parent 2668bfc commit 6ef99f6

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

fs/copy.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,14 +306,19 @@ def copy_structure(
306306
dst_root (str): Path to the target root of the tree structure.
307307
308308
"""
309+
_src_root = abspath(normpath(src_root))
310+
_dst_root = abspath(normpath(dst_root))
311+
# It's not allowed to copy a structure into itself
312+
if src_fs == dst_fs and isbase(_src_root, _dst_root):
313+
raise IllegalDestination(dst_root)
309314
walker = walker or Walker()
310315
with manage_fs(src_fs) as _src_fs:
311316
with manage_fs(dst_fs, create=True) as _dst_fs:
312317
with _src_fs.lock(), _dst_fs.lock():
313-
_dst_fs.makedirs(dst_root, recreate=True)
314-
for dir_path in walker.dirs(_src_fs, src_root):
318+
_dst_fs.makedirs(_dst_root, recreate=True)
319+
for dir_path in walker.dirs(_src_fs, _src_root):
315320
_dst_fs.makedir(
316-
combine(dst_root, frombase(src_root, dir_path)), recreate=True
321+
combine(_dst_root, frombase(_src_root, dir_path)), recreate=True
317322
)
318323

319324

fs/wrapfs.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,6 @@ def copydir(self, src_path, dst_path, create=False, preserve_time=False):
281281
_val_src_path = self.validatepath(_src_path)
282282
_val_dst_path = self.validatepath(_dst_path)
283283
with unwrap_errors({_src_path: src_path, _dst_path: dst_path}):
284-
if src_fs == dst_fs and isbase(_val_src_path, _val_dst_path):
285-
raise errors.IllegalDestination(_dst_path)
286284
if not create and not dst_fs.exists(_dst_path):
287285
raise errors.ResourceNotFound(dst_path)
288286
if not src_fs.getinfo(_src_path).is_dir:

0 commit comments

Comments
 (0)