gh-91133: tempfile.TemporaryDirectory: fix symlink bug in cleanup#99930
gh-91133: tempfile.TemporaryDirectory: fix symlink bug in cleanup#99930serhiy-storchaka merged 15 commits intopython:mainfrom
Conversation
During development, it becomes tiresome to have to manually clean up these files in case of unrelated TemporaryDirectory breakage.
✅ Deploy Preview for python-cpython-preview ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
carljm
left a comment
There was a problem hiding this comment.
This looks to me like a good fix, thanks! A few comments.
Misc/NEWS.d/next/Library/2022-12-01-16-57-44.gh-issue-91133.LKMVCV.rst
Outdated
Show resolved
Hide resolved
This reverts commit d8f50e5.
Co-authored-by: Carl Meyer <[email protected]>
carljm
left a comment
There was a problem hiding this comment.
LGTM modulo one more comment. Thanks!
|
@serhiy-storchaka and @vstinner (as active committers into |
serhiy-storchaka
left a comment
There was a problem hiding this comment.
LGTM, but I prefer to test with real filesystem. Mock tests are too fragile, they depend on implementation details that can be changed.
Lib/tempfile.py
Outdated
|
|
||
| @classmethod | ||
| def _rmtree(cls, name, ignore_errors=False): | ||
| def without_following_symlinks(func, path, *args): |
There was a problem hiding this comment.
I suggest to rename the function to "no_follow_symlinks" or "dont_follow_symlinks".
I dislike this trend to declare nested functions. Can't you move these functions at the module level, just make them private? This function doesn't use name nor ignore_errors.
|
GH-112838 is a backport of this pull request to the 3.12 branch. |
|
Sorry, @kwi-dk and @serhiy-storchaka, I could not cleanly backport this to |
…up (pythonGH-99930) (cherry picked from commit 81c16cd) Co-authored-by: Søren Løvborg <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
|
Sorry, @kwi-dk and @serhiy-storchaka, I could not cleanly backport this to |
|
Sorry, @kwi-dk and @serhiy-storchaka, I could not cleanly backport this to |
|
Sorry, @kwi-dk and @serhiy-storchaka, I could not cleanly backport this to |
…n cleanup (pythonGH-99930) (cherry picked from commit 81c16cd) Co-authored-by: Søren Løvborg <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
|
GH-112839 is a backport of this pull request to the 3.11 branch. |
|
I opened the issue this is fixing. Thank you all for the fix. |
|
GH-112840 is a backport of this pull request to the 3.10 branch. |
…n cleanup (pythonGH-99930) (cherry picked from commit 81c16cd) Co-authored-by: Søren Løvborg <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
|
GH-112842 is a backport of this pull request to the 3.9 branch. |
… cleanup (pythonGH-99930) (cherry picked from commit 81c16cd) Co-authored-by: Søren Løvborg <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
|
GH-112843 is a backport of this pull request to the 3.8 branch. |
… cleanup (pythonGH-99930) (cherry picked from commit 81c16cd) Co-authored-by: Søren Løvborg <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
…nup (GH-99930) (GH-112838) (cherry picked from commit 81c16cd) Co-authored-by: Søren Løvborg <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
…nup (GH-99930) (GH-112839) (cherry picked from commit 81c16cd) Co-authored-by: Søren Løvborg <[email protected]>
|
Thanks @kwi-dk for this fix. Thanks @serhiy-storchaka to taking the lead to update the code and merge the fix! |
…up (GH-99930) (GH-112843) (cherry picked from commit 81c16cd) Co-authored-by: Søren Løvborg <[email protected]>
…up (GH-99930) (GH-112842) (cherry picked from commit 81c16cd) Co-authored-by: Søren Løvborg <[email protected]>
…nup (GH-99930) (GH-112840) (cherry picked from commit 81c16cd) Co-authored-by: Søren Løvborg <[email protected]>
…up (pythonGH-99930) Co-authored-by: Serhiy Storchaka <[email protected]>
…up (pythonGH-99930) Co-authored-by: Serhiy Storchaka <[email protected]>
This PR fixes issue gh-91133, in which
TemporaryDirectory.cleanupcould try to fix permissions when deleting a symlink, but accidentally fix permissions of the target of the symlink instead.(It also changes thetest_flagstest case so it doesn't leave behindNOUNLINKfiles when the test fails, which is just annoying when working on any change to theTemporaryDirectorycode.)Compatibility: There could conceivably be code out there relying on
TemporaryDirectory.cleanupmodifying permissions on files outside the tempdir being cleaned up, which the fixed code will no longer do.