gh-79325: Fix recursion error in TemporaryDirectory cleanup on Windows (GH-112762)

This commit is contained in:
Serhiy Storchaka
2023-12-07 19:21:36 +02:00
committed by GitHub
parent ba18893555
commit b2923a61a1
3 changed files with 21 additions and 2 deletions

View File

@@ -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):