]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-87319: Simplify TemporaryDirectory cleanup using os.path.isjunction() (GH-112791)
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 7 Dec 2023 16:32:10 +0000 (18:32 +0200)
committerGitHub <noreply@github.com>
Thu, 7 Dec 2023 16:32:10 +0000 (18:32 +0200)
Lib/tempfile.py

index 9a5e7d01c2379b03225d069304cf76da8b11e6dc..4d99f91e1f53b7db4e5127cc84d8d1361bac282a 100644 (file)
@@ -41,7 +41,6 @@ import warnings as _warnings
 import io as _io
 import os as _os
 import shutil as _shutil
-import stat as _stat
 import errno as _errno
 from random import Random as _Random
 import sys as _sys
@@ -909,18 +908,7 @@ class TemporaryDirectory:
                         # raise NotADirectoryError and mask the PermissionError.
                         # So we must re-raise the current PermissionError if
                         # path is not a directory.
-                        try:
-                            st = _os.lstat(path)
-                        except OSError:
-                            if ignore_errors:
-                                return
-                            raise
-                        if (_stat.S_ISLNK(st.st_mode) or
-                            not _stat.S_ISDIR(st.st_mode) or
-                            (hasattr(st, 'st_file_attributes') and
-                             st.st_file_attributes & _stat.FILE_ATTRIBUTE_REPARSE_POINT and
-                             st.st_reparse_tag == _stat.IO_REPARSE_TAG_MOUNT_POINT)
-                        ):
+                        if not _os.path.isdir(path) or _os.path.isjunction(path):
                             if ignore_errors:
                                 return
                             raise