update
This commit is contained in:
49
.CondaPkg/env/Lib/tempfile.py
vendored
49
.CondaPkg/env/Lib/tempfile.py
vendored
@@ -269,6 +269,22 @@ def _mkstemp_inner(dir, pre, suf, flags, output_type):
|
||||
raise FileExistsError(_errno.EEXIST,
|
||||
"No usable temporary file name found")
|
||||
|
||||
def _dont_follow_symlinks(func, path, *args):
|
||||
# Pass follow_symlinks=False, unless not supported on this platform.
|
||||
if func in _os.supports_follow_symlinks:
|
||||
func(path, *args, follow_symlinks=False)
|
||||
elif _os.name == 'nt' or not _os.path.islink(path):
|
||||
func(path, *args)
|
||||
|
||||
def _resetperms(path):
|
||||
try:
|
||||
chflags = _os.chflags
|
||||
except AttributeError:
|
||||
pass
|
||||
else:
|
||||
_dont_follow_symlinks(chflags, path, 0)
|
||||
_dont_follow_symlinks(_os.chmod, path, 0o700)
|
||||
|
||||
|
||||
# User visible interfaces.
|
||||
|
||||
@@ -872,26 +888,37 @@ class TemporaryDirectory:
|
||||
ignore_errors=self._ignore_cleanup_errors, delete=self._delete)
|
||||
|
||||
@classmethod
|
||||
def _rmtree(cls, name, ignore_errors=False):
|
||||
def _rmtree(cls, name, ignore_errors=False, repeated=False):
|
||||
def onexc(func, path, exc):
|
||||
if isinstance(exc, PermissionError):
|
||||
def resetperms(path):
|
||||
try:
|
||||
_os.chflags(path, 0)
|
||||
except AttributeError:
|
||||
pass
|
||||
_os.chmod(path, 0o700)
|
||||
if repeated and path == name:
|
||||
if ignore_errors:
|
||||
return
|
||||
raise
|
||||
|
||||
try:
|
||||
if path != name:
|
||||
resetperms(_os.path.dirname(path))
|
||||
resetperms(path)
|
||||
_resetperms(_os.path.dirname(path))
|
||||
_resetperms(path)
|
||||
|
||||
try:
|
||||
_os.unlink(path)
|
||||
# PermissionError is raised on FreeBSD for directories
|
||||
except (IsADirectoryError, PermissionError):
|
||||
except IsADirectoryError:
|
||||
cls._rmtree(path, ignore_errors=ignore_errors)
|
||||
except PermissionError:
|
||||
# The PermissionError handler was originally added for
|
||||
# FreeBSD in directories, but it seems that it is raised
|
||||
# on Windows too.
|
||||
# bpo-43153: Calling _rmtree again may
|
||||
# raise NotADirectoryError and mask the PermissionError.
|
||||
# So we must re-raise the current PermissionError if
|
||||
# path is not a directory.
|
||||
if not _os.path.isdir(path) or _os.path.isjunction(path):
|
||||
if ignore_errors:
|
||||
return
|
||||
raise
|
||||
cls._rmtree(path, ignore_errors=ignore_errors,
|
||||
repeated=(path == name))
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
elif isinstance(exc, FileNotFoundError):
|
||||
|
||||
Reference in New Issue
Block a user