[3.13] gh-154307: Fix TemporaryDirectory cleanup on DragonFly BSD (GH-154309) (GH-154313)

serhiy-storchaka <[email protected]>
Newsgroups gmane.comp.python.cvs
Message-ID <[email protected]>
https://github.com/python/cpython/commit/b8d315182c54cc2b2fc96d570a648bad0ead0549
commit: b8d315182c54cc2b2fc96d570a648bad0ead0549
branch: 3.13
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-07-21T06:54:11+03:00
summary:

[3.13] gh-154307: Fix TemporaryDirectory cleanup on DragonFly BSD (GH-154309) (GH-154313)

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 1c1088b1da5a7484b7b04e90ccc47aa362e709eb)

Co-authored-by: Serhiy Storchaka <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>

files:
A Misc/NEWS.d/next/Library/2026-07-21-01-13-39.gh-issue-154307.UNFKL4.rst
M Lib/tempfile.py

diff --git a/Lib/tempfile.py b/Lib/tempfile.py
index 609ef4877d18e2c..cc9833125d28164 100644
--- a/Lib/tempfile.py
+++ b/Lib/tempfile.py
@@ -895,7 +895,8 @@ def __init__(self, suffix=None, prefix=None, dir=None,
     @classmethod
     def _rmtree(cls, name, ignore_errors=False, repeated=False):
         def onexc(func, path, exc):
-            if isinstance(exc, PermissionError):
+            # On DragonFly BSD, UF_NOUNLINK removal fails with EISDIR, not EPERM.
+            if isinstance(exc, (PermissionError, IsADirectoryError)):
                 if repeated and path == name:
                     if ignore_errors:
                         return
diff --git a/Misc/NEWS.d/next/Library/2026-07-21-01-13-39.gh-issue-154307.UNFKL4.rst b/Misc/NEWS.d/next/Library/2026-07-21-01-13-39.gh-issue-154307.UNFKL4.rst
new file mode 100644
index 000000000000000..fdba0c2940f0050
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-07-21-01-13-39.gh-issue-154307.UNFKL4.rst
@@ -0,0 +1,3 @@
+Fix :meth:`tempfile.TemporaryDirectory.cleanup` on DragonFly BSD, where removing
+a file with the ``UF_NOUNLINK`` flag failed with ``EISDIR`` instead of
+``EPERM``.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.