Commit 6525a214 by rfkelly0

FS.rename: remove requirment that src and dst be in the same dir

Most filesystem seem to support moving between different directories, and it's
really inconvenient to have to break out os.rename() to achieve this.
parent 0a533ceb
...@@ -276,17 +276,13 @@ class FSOperations(Operations): ...@@ -276,17 +276,13 @@ class FSOperations(Operations):
def rename(self,old,new): def rename(self,old,new):
old = old.decode(NATIVE_ENCODING) old = old.decode(NATIVE_ENCODING)
new = new.decode(NATIVE_ENCODING) new = new.decode(NATIVE_ENCODING)
if issamedir(old,new): try:
try: self.fs.rename(old,new)
self.fs.rename(old,new) except FSError:
except ResourceInvalidError: if self.fs.isdir(old):
pass self.fs.movedir(old,new)
else: else:
return None self.fs.move(old,new)
if self.fs.isdir(old):
self.fs.movedir(old,new)
else:
self.fs.move(old,new)
@handle_fs_errors @handle_fs_errors
def rmdir(self, path): def rmdir(self, path):
......
...@@ -388,9 +388,6 @@ class MemoryFS(FS): ...@@ -388,9 +388,6 @@ class MemoryFS(FS):
@synchronize @synchronize
def rename(self, src, dst): def rename(self, src, dst):
if not issamedir(src, dst):
raise ValueError("Destination path must the same directory (use the move method for moving to a different directory)")
dst = pathsplit(dst)[-1] dst = pathsplit(dst)[-1]
dir_entry = self._get_dir_entry(src) dir_entry = self._get_dir_entry(src)
......
...@@ -200,8 +200,6 @@ class MountFS(FS): ...@@ -200,8 +200,6 @@ class MountFS(FS):
@synchronize @synchronize
def rename(self, src, dst): def rename(self, src, dst):
if not issamedir(src, dst):
raise ValueError("Destination path must the same directory (use the move method for moving to a different directory)")
fs1, mount_path1, delegate_path1 = self._delegate(src) fs1, mount_path1, delegate_path1 = self._delegate(src)
fs2, mount_path2, delegate_path2 = self._delegate(dst) fs2, mount_path2, delegate_path2 = self._delegate(dst)
......
...@@ -158,8 +158,6 @@ class MultiFS(FS): ...@@ -158,8 +158,6 @@ class MultiFS(FS):
@synchronize @synchronize
def rename(self, src, dst): def rename(self, src, dst):
if not issamedir(src, dst):
raise ValueError("Destination path must the same directory (use the move method for moving to a different directory)")
for fs in self: for fs in self:
if fs.exists(src): if fs.exists(src):
fs.rename(src, dst) fs.rename(src, dst)
......
...@@ -140,8 +140,6 @@ class OSFS(FS): ...@@ -140,8 +140,6 @@ class OSFS(FS):
@convert_os_errors @convert_os_errors
def rename(self, src, dst): def rename(self, src, dst):
if not issamedir(src, dst):
raise ValueError("Destination path must the same directory (use the move method for moving to a different directory)")
path_src = self.getsyspath(src) path_src = self.getsyspath(src)
path_dst = self.getsyspath(dst) path_dst = self.getsyspath(dst)
os.rename(path_src, path_dst) os.rename(path_src, path_dst)
......
...@@ -394,8 +394,6 @@ class S3FS(FS): ...@@ -394,8 +394,6 @@ class S3FS(FS):
def rename(self,src,dst): def rename(self,src,dst):
"""Rename the file at 'src' to 'dst'.""" """Rename the file at 'src' to 'dst'."""
if not issamedir(src,dst):
raise ValueError("Destination path must be in the same directory (use the 'move' method for moving to a different directory)")
# Actually, in S3 'rename' is exactly the same as 'move' # Actually, in S3 'rename' is exactly the same as 'move'
self.move(src,dst) self.move(src,dst)
......
...@@ -251,8 +251,6 @@ class SFTPFS(FS): ...@@ -251,8 +251,6 @@ class SFTPFS(FS):
@convert_os_errors @convert_os_errors
def rename(self,src,dst): def rename(self,src,dst):
if not issamedir(src, dst):
raise ValueError("Destination path must the same directory (use the move method for moving to a different directory)")
nsrc = self._normpath(src) nsrc = self._normpath(src)
ndst = self._normpath(dst) ndst = self._normpath(dst)
try: try:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment