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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions Lib/tempfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import io as _io
import os as _os
import shutil as _shutil
import stat as _stat
import errno as _errno
from random import Random as _Random
import sys as _sys
Expand Down Expand Up @@ -900,18 +899,7 @@ def resetperms(path):
# raise NotADirectoryError and mask the PermissionError.
# So we must re-raise the current PermissionError if
# path is not a directory.
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):
Comment on lines -903 to +902
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.

if ignore_errors:
return
raise
Expand Down