Skip to content

gh-87319: Simplify TemporaryDirectory cleanup using os.path.isjunction() #112791

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

Merged
merged 1 commit into from
Dec 7, 2023

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Dec 6, 2023

Copy link
Contributor

@barneygale barneygale left a comment

Choose a reason for hiding this comment

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

Looks good!

@serhiy-storchaka serhiy-storchaka merged commit ba18893 into python:main Dec 7, 2023
@miss-islington-app
Copy link

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@serhiy-storchaka serhiy-storchaka deleted the tempfile-isjunction branch December 7, 2023 16:32
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Dec 7, 2023
…unction() (pythonGH-112791)

(cherry picked from commit ba18893)

Co-authored-by: Serhiy Storchaka <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Dec 7, 2023

GH-112845 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 only security fixes label Dec 7, 2023
serhiy-storchaka added a commit that referenced this pull request Dec 7, 2023
…junction() (GH-112791) (GH-112845)

(cherry picked from commit ba18893)

Co-authored-by: Serhiy Storchaka <[email protected]>
Comment on lines -903 to +902
try:
st = _os.lstat(path)
except OSError:
if ignore_errors:
return
raise
if (_stat.S_ISLNK(st.st_mode) or
not _stat.S_ISDIR(st.st_mode) or
(hasattr(st, 'st_file_attributes') and
st.st_file_attributes & _stat.FILE_ATTRIBUTE_REPARSE_POINT and
st.st_reparse_tag == _stat.IO_REPARSE_TAG_MOUNT_POINT)
):
if not _os.path.isdir(path) or _os.path.isjunction(path):
Copy link

@proc-2 proc-2 Dec 9, 2023

Choose a reason for hiding this comment

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

I assume "TOCTOU" issues are out-of-scope here (both in the original implementation and the simplified one) since it is perfectly fine to handle any concurrent modification of the current directory with "undefined behaviour"?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is the best that we can do with the current API. I will consider supporting a new error handler interface that accepts dir_fd and the relative path.

aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants