-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Incorrect shutil.copytree() behaviour with symlinks #91205
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
Comments
shutil.copytree incorrectly does not copy symlink contents if called The wrong behaviour can be reproduced like this: $ tree
.
└── a
├── a.txt
└── b
└── a.txt -> ../a.txt
$ python3 -c "import shutil;shutil.copytree('a/b', 'c', symlinks=False, ignore_dangling_symlinks=True)" As a result directoy c will be created but it will remain empty. |
This comment was marked as outdated.
This comment was marked as outdated.
This still seems to be an issue even though the underlying PR was closed. Even though |
The issue is still present in Python 3.12.5 and must be fixed since copied data with enabled option symlinks=False and ignore_dangling_symlinks=True misses all resolved symbolic links file contents. |
Fix in shutil _copytree could look like: linkPath = linkto if os.path.isabs(linkto) else os.path.join(os.path.dirname(srcname), linkto)
# ignore dangling symlink if the flag is on
if not os.path.exists(linkPath) and ignore_dangling_symlinks: |
@hugovk since you closed my duplicate: may I ask when this fix will finally go into Python 3.12 or 3.13? It is annoying to always fix the one line for each new python release to get the correct behavior. Thanks upfront! |
Hello! The linked PR was closed before merge:
If it's still a problem, someone needs to submit a PR first, then we can merge that into main/3.14, and then we can backport it to 3.12 and 3.13, and it would go out in the subsequent releases. So there's currently no timeline on a fix. Are you interested in creating a PR to fix it, with tests? |
Hi @hugovk , thanks for the reply - since I am not familiar with the working style I would prefer the experts doing it. |
I'm not planning on working on the fix, but this is the ticket for it. |
Hi all, |
…nore_dangling_symlinks=True.
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:
Linked PRs
The text was updated successfully, but these errors were encountered: