mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
[3.12] gh-79325: Fix recursion error in TemporaryDirectory cleanup on Windows (GH-112762) (GH-112847)
(cherry picked from commit b2923a61a1
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
418adf687f
commit
34e9e20cf2
3 changed files with 21 additions and 2 deletions
|
@ -888,9 +888,14 @@ 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):
|
||||
if repeated and path == name:
|
||||
if ignore_errors:
|
||||
return
|
||||
raise
|
||||
|
||||
try:
|
||||
if path != name:
|
||||
_resetperms(_os.path.dirname(path))
|
||||
|
@ -912,7 +917,8 @@ class TemporaryDirectory:
|
|||
if ignore_errors:
|
||||
return
|
||||
raise
|
||||
cls._rmtree(path, ignore_errors=ignore_errors)
|
||||
cls._rmtree(path, ignore_errors=ignore_errors,
|
||||
repeated=(path == name))
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
elif isinstance(exc, FileNotFoundError):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue