-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
shutil.move fails on symlink source #54202
Comments
shutil.move does not behave as I expect when moving a symlink across filesystems. (This is when src itself is a symlink, not when it is a directory tree including symlinks.) -If src is a symlink to file, rather than moving the symlink, it copies the contents of the file Attached patch against the py3k branch adds tests for these cases and adds the expected behaviour, which is to recreate the symlink. (I have encountered this on 2.6 - current SVN; it is probably in 2.5 as well but I have not confirmed.) |
I can confirm that the tests fail before the patch (but if an only if /tmp is a different file system from the one where the build is, see bpo-9999) and pass after the patch. The patch itself looks good to me and does accord better with how 'mv' works. |
I work on the superficially related bpo-12715 (symlinks for shutil). As we try to mimic the POSIX tools and |
Can you update the documentation? |
Éric, here's a quick docs-only patch against current default...does this do the job? |
Thanks for the doc patch, which looks good. I have one question: if a relative symlink is copied, should the resulting symlink be relative too? |
Éric: I think copying a relative symlink should also be relative, and that's the behaviour of this patch. That was the use case that tripped me up with the original behaviour of shutil.move: a relative symlink which was dangling in its original location, but not once moved. (This was, believe it or not, intentional design....) This is also the behaviour when src and dst are on the same filesystem. Basically my intention was to remove the distinction between "same filesystem" and "different filesystem." |
Looks good to me. |
Antoine, would you mind taking this one? |
Ow, I'm sorry for overlooking this. I thought you would take it. By the way, I think this shouldn't be applied to bugfix branches, since it's a behaviour change. |
I took the liberty to fix the tests. Basically I've adapted them to the new mock based cross file system approach (that doesn't depend on luck anymore :)). I also had to add one more I didn't touch the actual code. Tested on OS X and Ubuntu Linux (Oneiric). |
Thanks! I think we also need a doc update for the change in behaviour (with a "versionchanged" tag). |
Oh sorry, I didn't look into the doc patch. I unified both into one patch and added the versionchanged tag and also updated the docstring of shutil.move. |
New changeset 1ea8b7233fd7 by Antoine Pitrou in branch 'default': |
Patch now committed to 3.3. Thank you Jonathan and Hynek! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: