diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-01-06 19:16:19 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-01-06 19:16:19 (GMT) |
commit | 0a08d7a09537b2ccfc93c5a81bd36cf5f1b1e92d (patch) | |
tree | 21e3d955272e135012cccdd18bc909b088da8c34 /Lib/shutil.py | |
parent | deec7566ae4905ec4b61495bbeb06adaa98f70ef (diff) | |
download | cpython-0a08d7a09537b2ccfc93c5a81bd36cf5f1b1e92d.zip cpython-0a08d7a09537b2ccfc93c5a81bd36cf5f1b1e92d.tar.gz cpython-0a08d7a09537b2ccfc93c5a81bd36cf5f1b1e92d.tar.bz2 |
Issue #9993: When the source and destination are on different filesystems,
and the source is a symlink, shutil.move() now recreates a symlink on the
destination instead of copying the file contents.
Patch by Jonathan Niehof and Hynek Schlawack.
Diffstat (limited to 'Lib/shutil.py')
-rw-r--r-- | Lib/shutil.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py index 95bebb8..5f69fb7 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -356,7 +356,10 @@ def move(src, dst): overwritten depending on os.rename() semantics. If the destination is on our current filesystem, then rename() is used. - Otherwise, src is copied to the destination and then removed. + Otherwise, src is copied to the destination and then removed. Symlinks are + recreated under the new name if os.rename() fails because of cross + filesystem renames. + A lot more could be done here... A look at a mv.c shows a lot of the issues this implementation glosses over. @@ -375,7 +378,11 @@ def move(src, dst): try: os.rename(src, real_dst) except OSError: - if os.path.isdir(src): + if os.path.islink(src): + linkto = os.readlink(src) + os.symlink(linkto, real_dst) + os.unlink(src) + elif os.path.isdir(src): if _destinsrc(src, dst): raise Error("Cannot move a directory '%s' into itself '%s'." % (src, dst)) copytree(src, real_dst, symlinks=True) |