[3.12] gh-87319: Simplify TemporaryDirectory cleanup using os.path.isjunction() (GH-112791) (GH-112845)

(cherry picked from commit ba18893555)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Miss Islington (bot) 2023-12-07 18:17:27 +01:00 committed by GitHub
parent 6ceb8aeda5
commit 418adf687f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -41,7 +41,6 @@ import warnings as _warnings
import io as _io import io as _io
import os as _os import os as _os
import shutil as _shutil import shutil as _shutil
import stat as _stat
import errno as _errno import errno as _errno
from random import Random as _Random from random import Random as _Random
import sys as _sys import sys as _sys
@ -909,18 +908,7 @@ class TemporaryDirectory:
# raise NotADirectoryError and mask the PermissionError. # raise NotADirectoryError and mask the PermissionError.
# So we must re-raise the current PermissionError if # So we must re-raise the current PermissionError if
# path is not a directory. # path is not a directory.
try: if not _os.path.isdir(path) or _os.path.isjunction(path):
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 ignore_errors: if ignore_errors:
return return
raise raise