This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Jeffrey.Kintscher
Recipients Jeffrey.Kintscher, Murray Wilson, Unode, tarek
Date 2020-08-06.07:10:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1596697823.61.0.946573401673.issue26791@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2020-08-06 07:10:23Jeffrey.Kintschersetrecipients: + Jeffrey.Kintscher, tarek, Unode, Murray Wilson
2020-08-06 07:10:23Jeffrey.Kintschersetmessageid: <1596697823.61.0.946573401673.issue26791@roundup.psfhosted.org>
2020-08-06 07:10:23Jeffrey.Kintscherlinkissue26791 messages
2020-08-06 07:10:23Jeffrey.Kintschercreate