From 6b91d3edc8de8e98a9b8d6f8f671250fa1f87ff6 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 7 Dec 2023 18:32:10 +0200 Subject: [PATCH] gh-87319: Simplify TemporaryDirectory cleanup using os.path.isjunction() (GH-112791) (cherry picked from commit ba18893555bbf69b1da262aaf85d65e4b67e8955) Co-authored-by: Serhiy Storchaka --- Lib/tempfile.py | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/Lib/tempfile.py b/Lib/tempfile.py index 55403ad1faf46d..a85067bea943c2 100644 --- a/Lib/tempfile.py +++ b/Lib/tempfile.py @@ -41,7 +41,6 @@ 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 @@ -900,18 +899,7 @@ def resetperms(path): # 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