-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
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
gh-87319: Simplify TemporaryDirectory cleanup using os.path.isjunction() #112791
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12. |
…unction() (pythonGH-112791) (cherry picked from commit ba18893) Co-authored-by: Serhiy Storchaka <[email protected]>
GH-112845 is a backport of this pull request to the 3.12 branch. |
…junction() (GH-112791) (GH-112845) (cherry picked from commit ba18893) Co-authored-by: Serhiy Storchaka <[email protected]>
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): |
There was a problem hiding this comment.
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"?
There was a problem hiding this comment.
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.
As suggested by @eryksun in #29940 (comment).