Skip to content

Commit 856c811

Browse files
miss-islingtonserhiy-storchakaclaude
authored
[3.14] gh-154307: Fix TemporaryDirectory cleanup on DragonFly BSD (GH-154309) (GH-154312)
On DragonFly BSD, removing a file or directory with the UF_NOUNLINK flag fails with EISDIR (IsADirectoryError) instead of EPERM, so the cleanup did not reset the flags. Handle IsADirectoryError the same as PermissionError. (cherry picked from commit 1c1088b) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 0df683f commit 856c811

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

Lib/tempfile.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,8 @@ def __init__(self, suffix=None, prefix=None, dir=None,
915915
@classmethod
916916
def _rmtree(cls, name, ignore_errors=False, repeated=False):
917917
def onexc(func, path, exc):
918-
if isinstance(exc, PermissionError):
918+
# On DragonFly BSD, UF_NOUNLINK removal fails with EISDIR, not EPERM.
919+
if isinstance(exc, (PermissionError, IsADirectoryError)):
919920
if repeated and path == name:
920921
if ignore_errors:
921922
return
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix :meth:`tempfile.TemporaryDirectory.cleanup` on DragonFly BSD, where removing
2+
a file with the ``UF_NOUNLINK`` flag failed with ``EISDIR`` instead of
3+
``EPERM``.

0 commit comments

Comments
 (0)