Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-91205: fix bug in shutil.copytree with relative links and ignore_dangling_symlinks=True#132984

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
duaneg wants to merge3 commits intopython:main
base:main
Choose a base branch
Loading
fromduaneg:gh-91205

Conversation

duaneg
Copy link
Contributor

@duanegduaneg commentedApr 26, 2025
edited by bedevere-appbot
Loading

Fix bug whereshutil.copytree was skipping copying the contents of symbolic links to relative paths when theignore_dangling_symlinks flag was set.

picnixz
picnixz previously requested changesApr 26, 2025
# if the link is not to an absolute path it is relative to
# the source (see gh-91205)
if not os.path.isabs(linkto):
linkto = os.path.join(os.path.dirname(srcname), linkto)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The original patch usedos.path.normpath. Do we need it? Also, shouldn't we retest whetherlinkto is a symlink or not? if not, please also add a test

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I don't think we should usenormpath: it does a string replacement which can change the meaning if symbolic links are involved, which I think would be a bug if it can happen. If itdoesn't change the meaning then it shouldn't matter, since we just use the result in one place immediately after, to check whether it exists or not.

We don't need to check whether the result is a link: it may or may not be, but is correctly handled either way by the following code.os.path.exists will return false if it is a dangling link (and we will either skip it or carry on and raise an error depending onignore_dangling_symlinks). Note that absolute symbolic links are handled the same way, so if this was necessary they would already be broken.

Having said that, good point about testing: AFAICT this case is not currently under test. I'll add a few levels of valid links-to-links to the new test case and expandtest_copytree_dangling_symlinks to test dangling links-to-links.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

expand test_copytree_dangling_symlinks to test dangling links-to-links.

Let's do it in a separate test function. It's easier to debug. Namely, one test for flat links and one test for multiple links. What about circular links? (are they allowed actually? namely l1 -> l2 -> l1?)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Let's do it in a separate test function. It's easier to debug. Namely, one test for flat links and one test for multiple links.

Sure thing, will do.

What about circular links? (are they allowed actually? namely l1 -> l2 -> l1?)

Good question. As it happens, they are treated exactly like dangling links for the purposes of this method, sinceos.path.exists will returnFalse for them. I.e. ifsymlinks=True they will be recreated as symbolic links (and it doesn't matter that they are circular), otherwise they will be skipped or cause an error depending if theignore_dangling_symlinks flag is true or false, respectively.

Naturally this means they are also affected by this bug. E.g. if the symlink target is a relative path that happens to exist relative to theworking directory the code will think they are valid and then fail when it tries to copy their content.

@bedevere-app
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phraseI have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@duanegduaneg requested a review frompicnixzApril 26, 2025 22:31
@picnixzpicnixz removed their request for reviewMay 9, 2025 09:49
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@picnixzpicnixzpicnixz left review comments

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@duaneg@picnixz

[8]ページ先頭

©2009-2025 Movatter.jp