Skip to content

Commit

Permalink
copy_structure FS can be of type str
Browse files Browse the repository at this point in the history
  • Loading branch information
tfeldmann committed Aug 2, 2022
1 parent 3bc8691 commit 420998d
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions fs/copy.py
Expand Up @@ -306,14 +306,16 @@ def copy_structure(
dst_root (str): Path to the target root of the tree structure.
"""
_src_root = src_fs.validatepath(src_root)
_dst_root = dst_fs.validatepath(dst_root)
# It's not allowed to copy a structure into itself
if src_fs == dst_fs and isbase(_src_root, _dst_root):
raise IllegalDestination(dst_root)
walker = walker or Walker()
with manage_fs(src_fs) as _src_fs:
with manage_fs(dst_fs, create=True) as _dst_fs:
_src_root = _src_fs.validatepath(src_root)
_dst_root = _dst_fs.validatepath(dst_root)

# It's not allowed to copy a structure into itself
if _src_fs == _dst_fs and isbase(_src_root, _dst_root):
raise IllegalDestination(dst_root)

with _src_fs.lock(), _dst_fs.lock():
_dst_fs.makedirs(_dst_root, recreate=True)
for dir_path in walker.dirs(_src_fs, _src_root):
Expand Down

0 comments on commit 420998d

Please sign in to comment.