Skip to content

Commit 1e949b8

Browse files
gh-154307: Fix tempfile.TemporaryDirectory cleanup on DragonFly BSD
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. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent c7bbf04 commit 1e949b8

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
@@ -929,7 +929,8 @@ def __init__(self, suffix=None, prefix=None, dir=None,
929929
@classmethod
930930
def _rmtree(cls, name, ignore_errors=False, repeated=False):
931931
def onexc(func, path, exc):
932-
if isinstance(exc, PermissionError):
932+
# On DragonFly BSD, UF_NOUNLINK removal fails with EISDIR, not EPERM.
933+
if isinstance(exc, (PermissionError, IsADirectoryError)):
933934
if repeated and path == name:
934935
if ignore_errors:
935936
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)