Skip to content

Commit f9cf49f

Browse files
committed
fix wrapfs
1 parent a039bb6 commit f9cf49f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

fs/wrapfs.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from .copy import copy_dir, copy_file
1313
from .error_tools import unwrap_errors
1414
from .info import Info
15-
from .path import abspath, join, normpath
15+
from .path import abspath, isbase, join, normpath
1616

1717
if typing.TYPE_CHECKING:
1818
from typing import (
@@ -267,7 +267,11 @@ def copy(self, src_path, dst_path, overwrite=False, preserve_time=False):
267267
# type: (Text, Text, bool, bool) -> None
268268
src_fs, _src_path = self.delegate_path(src_path)
269269
dst_fs, _dst_path = self.delegate_path(dst_path)
270+
_val_src_path = self.validatepath(_src_path)
271+
_val_dst_path = self.validatepath(_dst_path)
270272
with unwrap_errors({_src_path: src_path, _dst_path: dst_path}):
273+
if src_fs == dst_fs and _val_src_path == _val_dst_path:
274+
raise errors.IllegalDestination(_dst_path)
271275
if not overwrite and dst_fs.exists(_dst_path):
272276
raise errors.DestinationExists(_dst_path)
273277
copy_file(src_fs, _src_path, dst_fs, _dst_path, preserve_time=preserve_time)
@@ -276,7 +280,11 @@ def copydir(self, src_path, dst_path, create=False, preserve_time=False):
276280
# type: (Text, Text, bool, bool) -> None
277281
src_fs, _src_path = self.delegate_path(src_path)
278282
dst_fs, _dst_path = self.delegate_path(dst_path)
283+
_val_src_path = self.validatepath(_src_path)
284+
_val_dst_path = self.validatepath(_dst_path)
279285
with unwrap_errors({_src_path: src_path, _dst_path: dst_path}):
286+
if src_fs == dst_fs and isbase(_val_src_path, _val_dst_path):
287+
raise errors.IllegalDestination(_dst_path)
280288
if not create and not dst_fs.exists(_dst_path):
281289
raise errors.ResourceNotFound(dst_path)
282290
if not src_fs.getinfo(_src_path).is_dir:

0 commit comments

Comments
 (0)