[New-bugs-announce] [issue26791] shutil.move fails to move symlink (Invalid cross-device link)
report at bugs.python.org
Sun Apr 17 12:58:17 EDT 2016
New submission from Renato Alves:
I'm not really sure if this is a new issue but digging through the bug reports from the past I couldn't find an answer.
There's http://bugs.python.org/issue1438480 but this seems to be a different issue.
I also found http://bugs.python.org/issue9993 that addressed problems with symlinks but didn't correct the behavior reported here.
The problem can be visualized with the following code.
Code fails on python 2.7 as well as python 3.4+. Not tested in python <2.7 and <3.4.
TMPDIR = "/tmp/tmpdir"
TESTLINK = "test_dir"
if not os.path.isdir(TMPDIR):
if not os.path.islink(TESTLINK):
When executed it gives me:
% python3 test.py
Traceback (most recent call last):
File "test.py", line 14, in <module>
File "/usr/lib64/python3.4/shutil.py", line 516, in move
OSError: [Errno 18] Invalid cross-device link: 'test_dir' -> '/tmp/tmpdir'
This happens because /tmp is:
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noatime,nodiratime)
In the past the recommendation to handle this problem was to stop using os.rename and use shutil.move instead.
This was even discussed in a bug report - http://bugs.python.org/issue14848
If one searches for this exception there's plenty of advice  in the same direction.
However, given that shutil.move uses os.rename internally, the problem returns.
On the other end doing the equivalent action in the shell with 'mv' works fine.
 - http://stackoverflow.com/a/15300474
 - https://mail.python.org/pipermail/python-list/2005-February/342892.html
 - http://www.thecodingforums.com/threads/errno-18-invalid-cross-device-link-using-os-rename.341597/
 - https://github.com/pypa/pip/issues/103
components: Library (Lib)
title: shutil.move fails to move symlink (Invalid cross-device link)
versions: Python 3.4
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce