Visitar URL original
gh-157579: Fix race condition in the cleanup of `tempfile.TemporaryDirectory` by StanFromIreland · Pull Request #157580 · python/cpython · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ff74078
Fix `tempfile.TemporaryDirectory` cleanup race condition
StanFromIreland Aug 14, 2026
0fd04ae
Pass descriptors to `onexc` instead of re-walking
StanFromIreland Aug 26, 2026
55c0c1f
Petr's review
StanFromIreland Aug 28, 2026
b4c1865
Add regression check for _rmtree_use_dir_fd=True
encukou Sep 1, 2026
51c9c6a
Avoid infinite recursion if directory removal fails
encukou Sep 1, 2026
bbbb669
Bring back chmod by name (avoid regression); use LBYL
encukou Sep 1, 2026
a9a993e
Bring back chmod(open(nofollow))
encukou Sep 1, 2026
f524182
Add warning for Windows
encukou Sep 1, 2026
d4e5045
Use lstat; check for it
encukou Sep 1, 2026
4a9eb37
Test that cleanup() does not chmod the parent directory
encukou Sep 1, 2026
4a2ab25
Catch OSError on ignore_errors
encukou Sep 1, 2026
99c6f63
Apply suggestion from @StanFromIreland
encukou Sep 8, 2026
ffcf4bb
Match else: to try:, and don't catch AttributeError
encukou Sep 8, 2026
7994121
Use new issue number.
StanFromIreland Sep 15, 2026
10c4541
Merge branch 'main' into tempfile-toctou-2
StanFromIreland Sep 15, 2026
a837624
Add WASI skip
StanFromIreland Sep 15, 2026
4baeeb1
Update Lib/test/test_tempfile.py
StanFromIreland Sep 17, 2026
c12bec3
Revert "Update Lib/test/test_tempfile.py"
StanFromIreland Sep 17, 2026
de46e06
Make dir1 writeable before rename
StanFromIreland Sep 17, 2026
d8aab2b
Add skip for Emscripten
StanFromIreland Sep 22, 2026
9992aae
Fix case
encukou Sep 22, 2026
7568089
Merge branch 'main' into tempfile-toctou-2
encukou Sep 22, 2026
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
Prev Previous commit
Next Next commit
Match else: to try:, and don't catch AttributeError
  • Loading branch information
encukou committed Sep 8, 2026
commit ffcf4bb3068c4cc67fa19e36f9983004bd037784
14 changes: 7 additions & 7 deletions Lib/tempfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,14 @@ def _resetperms_at(name, dir_fd, path):
if _nofollow_mode is not None:
try:
fd = _os.open(name, _nofollow_mode, dir_fd=dir_fd)
except (OSError, AttributeError):
except OSError:
pass
else:
try:
_os.chmod(fd, 0o700)
finally:
_os.close(fd)
return
else:
try:
_os.chmod(fd, 0o700)
finally:
_os.close(fd)
return
# If that did not work, we change by name, which is subject to a race
# condition.
stat = _os.lstat(name, dir_fd=dir_fd)
Expand Down