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>
@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
--- /dev/null
+Fix :meth:`tempfile.TemporaryDirectory.cleanup` on DragonFly BSD, where removing
+a file with the ``UF_NOUNLINK`` flag failed with ``EISDIR`` instead of
+``EPERM``.