Skip to content

Commit 37e2543

Browse files
committed
Avoid copying src other than EXDEV
1 parent 2e3c075 commit 37e2543

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎Lib/shutil.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,9 +943,10 @@ def move(src, dst, copy_function=copy2):
943943
raise Error("Destination path '%s' already exists" % real_dst)
944944
try:
945945
os.rename(src, real_dst)
946-
except OSError:
946+
except OSError as e:
947947
if os.path.islink(src):
948948
linkto = os.readlink(src)
949+
_raise_not_EXDEV(e)
949950
os.symlink(linkto, real_dst)
950951
os.unlink(src)
951952
elif os.path.isdir(src):
@@ -958,10 +959,12 @@ def move(src, dst, copy_function=copy2):
958959
raise PermissionError("Cannot move the non-empty directory "
959960
"'%s': Lacking write permission to '%s'."
960961
% (src, src))
962+
_raise_not_EXDEV(e)
961963
copytree(src, real_dst, copy_function=copy_function,
962964
symlinks=True)
963965
rmtree(src)
964966
else:
967+
_raise_not_EXDEV(e)
965968
copy_function(src, real_dst)
966969
os.unlink(src)
967970
return real_dst

0 commit comments

Comments
 (0)