Skip to content

Commit

Permalink
use validatepath
Browse files Browse the repository at this point in the history
  • Loading branch information
tfeldmann committed Aug 2, 2022
1 parent 9d9dcd6 commit 3bc8691
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
22 changes: 12 additions & 10 deletions fs/base.py
Expand Up @@ -1171,17 +1171,19 @@ def move(self, src_path, dst_path, overwrite=False, preserve_time=False):
``dst_path`` does not exist.
"""
if not overwrite and self.exists(dst_path):
_src_path = self.validatepath(src_path)
_dst_path = self.validatepath(dst_path)
if not overwrite and self.exists(_dst_path):
raise errors.DestinationExists(dst_path)
if self.getinfo(src_path).is_dir:
if self.getinfo(_src_path).is_dir:
raise errors.FileExpected(src_path)
if normpath(src_path) == normpath(dst_path):
if _src_path == _dst_path:
# early exit when moving a file onto itself
return
if self.getmeta().get("supports_rename", False):
try:
src_sys_path = self.getsyspath(src_path)
dst_sys_path = self.getsyspath(dst_path)
src_sys_path = self.getsyspath(_src_path)
dst_sys_path = self.getsyspath(_dst_path)
except errors.NoSysPath: # pragma: no cover
pass
else:
Expand All @@ -1191,15 +1193,15 @@ def move(self, src_path, dst_path, overwrite=False, preserve_time=False):
pass
else:
if preserve_time:
copy_modified_time(self, src_path, self, dst_path)
copy_modified_time(self, _src_path, self, _dst_path)
return
with self._lock:
with self.open(src_path, "rb") as read_file:
with self.open(_src_path, "rb") as read_file:
# FIXME(@althonos): typing complains because open return IO
self.upload(dst_path, read_file) # type: ignore
self.upload(_dst_path, read_file) # type: ignore
if preserve_time:
copy_modified_time(self, src_path, self, dst_path)
self.remove(src_path)
copy_modified_time(self, _src_path, self, _dst_path)
self.remove(_src_path)

def open(
self,
Expand Down
4 changes: 2 additions & 2 deletions fs/copy.py
Expand Up @@ -306,8 +306,8 @@ def copy_structure(
dst_root (str): Path to the target root of the tree structure.
"""
_src_root = abspath(normpath(src_root))
_dst_root = abspath(normpath(dst_root))
_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)
Expand Down

0 comments on commit 3bc8691

Please sign in to comment.