]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-154307: Fix TemporaryDirectory cleanup on DragonFly BSD (GH-154309) (GH...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 21 Jul 2026 03:54:27 +0000 (05:54 +0200)
committerGitHub <noreply@github.com>
Tue, 21 Jul 2026 03:54:27 +0000 (06:54 +0300)
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 <storchaka@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Lib/tempfile.py
Misc/NEWS.d/next/Library/2026-07-21-01-13-39.gh-issue-154307.UNFKL4.rst [new file with mode: 0644]

index a34e062f8399a037bc9dee8351bfa3ca12a8b85e..6c036d2fd51cb0f0522e47ccbde32c6616d1782e 100644 (file)
@@ -915,7 +915,8 @@ class TemporaryDirectory:
     @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 (file)
index 0000000..fdba0c2
--- /dev/null
@@ -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``.