[issue26791] shutil.move fails to move symlink (Invalid cross-device link)

2021-11-30 Thread Irit Katriel


Irit Katriel  added the comment:

Removing old versions.

--
nosy: +iritkatriel
versions: +Python 3.11 -Python 2.7, Python 3.5, Python 3.6, Python 3.7, Python 
3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26791] shutil.move fails to move symlink (Invalid cross-device link)

2020-08-06 Thread Jeffrey Kintscher


Change by Jeffrey Kintscher :


--
keywords: +patch
pull_requests: +20904
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/21759

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26791] shutil.move fails to move symlink (Invalid cross-device link)

2020-08-06 Thread Jeffrey Kintscher


Change by Jeffrey Kintscher :


--
versions: +Python 3.10, Python 3.7, Python 3.8, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26791] shutil.move fails to move symlink (Invalid cross-device link)

2020-08-06 Thread Jeffrey Kintscher


Jeffrey Kintscher  added the comment:

SilentGhost's analysis is correct.  The provided example code causes the error 
because it is trying to move the symlink into its target when the target is a 
directory. Any cross-device moving issues are unrelated to this example code.  
Here is the relevant code in the master branch:

if os.path.isdir(dst):
if _samefile(src, dst):
# We might be on a case insensitive filesystem,
# perform the rename anyway.
os.rename(src, dst)
return

shutil._samefile() considers the example link and its target to be the same.  
When _samefile() returns False, this code gets executed:

real_dst = os.path.join(dst, _basename(src))

if os.path.exists(real_dst):
raise Error("Destination path '%s' already exists" % real_dst)
try:
os.rename(src, real_dst)
except OSError:
if os.path.islink(src):
linkto = os.readlink(src)
os.symlink(linkto, real_dst)
os.unlink(src)

A simple fix is to check whether src is a symlink when _samefile() returns 
True.  The "Destination path...already exists" error isn't a problem for our 
symlink case because the shell mv command also returns an error.

$ ls -l /tmp/tmpdir/
total 0
lrwxr-xr-x  1 jeff  staff  11 Aug  5 23:36 test_dir -> /tmp/tmpdir
$ mv test_dir /tmp/tmpdir
mv: test_dir and /tmp/tmpdir/test_dir are identical

I will generate a pull request.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26791] shutil.move fails to move symlink (Invalid cross-device link)

2020-07-31 Thread SilentGhost


Change by SilentGhost :


--
nosy:  -SilentGhost

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26791] shutil.move fails to move symlink (Invalid cross-device link)

2020-07-31 Thread Murray Wilson


Murray Wilson  added the comment:

It also happens when moving a file in linux from an xfs filesystem to a NFS 
mounted filesystem.

--
nosy: +Murray Wilson

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26791] shutil.move fails to move symlink (Invalid cross-device link)

2019-06-01 Thread Jeffrey Kintscher


Change by Jeffrey Kintscher :


--
nosy: +Jeffrey.Kintscher

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26791] shutil.move fails to move symlink (Invalid cross-device link)

2016-04-18 Thread SilentGhost

SilentGhost added the comment:

This seems to be only triggered when moving a symlink into its destination. 
Assumption in the code is that when _samefile returns True, it must be due to 
case-insensitive filesystem, rather than this edge case.

--
nosy: +SilentGhost, tarek
type:  -> behavior
versions: +Python 3.6 -Python 3.4

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26791] shutil.move fails to move symlink (Invalid cross-device link)

2016-04-17 Thread Renato Alves

Renato Alves added the comment:

Also related to http://bugs.python.org/issue212317

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26791] shutil.move fails to move symlink (Invalid cross-device link)

2016-04-17 Thread Renato Alves

Changes by Renato Alves :


--
versions: +Python 2.7, Python 3.5

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26791] shutil.move fails to move symlink (Invalid cross-device link)

2016-04-17 Thread Renato Alves

New submission from Renato Alves:

Hi everyone,

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.


import shutil
import os

TMPDIR = "/tmp/tmpdir"
TESTLINK = "test_dir"

if not os.path.isdir(TMPDIR):
os.mkdir(TMPDIR)

if not os.path.islink(TESTLINK):
os.symlink(TMPDIR, TESTLINK)

shutil.move(TESTLINK, TMPDIR)


When executed it gives me:

% python3 test.py
Traceback (most recent call last):
  File "test.py", line 14, in 
shutil.move(TESTLINK, TMPDIR)
  File "/usr/lib64/python3.4/shutil.py", line 516, in move
os.rename(src, dst)
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 [1][2][3][4] 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.


[1] - http://stackoverflow.com/a/15300474
[2] - https://mail.python.org/pipermail/python-list/2005-February/342892.html
[3] - 
http://www.thecodingforums.com/threads/errno-18-invalid-cross-device-link-using-os-rename.341597/
[4] - https://github.com/pypa/pip/issues/103

--
components: Library (Lib)
messages: 263616
nosy: Unode
priority: normal
severity: normal
status: open
title: shutil.move fails to move symlink (Invalid cross-device link)
versions: Python 3.4

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com