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,13 +276,9 @@ class FSOperations(Operations):
def rename(self,old,new):
old = old.decode(NATIVE_ENCODING)
new = new.decode(NATIVE_ENCODING)
if issamedir(old,new):
try:
self.fs.rename(old,new)
except ResourceInvalidError:
pass
else:
return None
except FSError:
if self.fs.isdir(old):
self.fs.movedir(old,new)
else:
......
......@@ -388,9 +388,6 @@ class MemoryFS(FS):
@synchronize
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]
dir_entry = self._get_dir_entry(src)
......
......@@ -200,8 +200,6 @@ class MountFS(FS):
@synchronize
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)
fs2, mount_path2, delegate_path2 = self._delegate(dst)
......
......@@ -158,8 +158,6 @@ class MultiFS(FS):
@synchronize
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:
if fs.exists(src):
fs.rename(src, dst)
......
......@@ -140,8 +140,6 @@ class OSFS(FS):
@convert_os_errors
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_dst = self.getsyspath(dst)
os.rename(path_src, path_dst)
......
......@@ -394,8 +394,6 @@ class S3FS(FS):
def rename(self,src,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'
self.move(src,dst)
......
......@@ -251,8 +251,6 @@ class SFTPFS(FS):
@convert_os_errors
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)
ndst = self._normpath(dst)
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