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

(cherry picked from commit b2923a61a1)
This commit is contained in:
Serhiy Storchaka 2023-12-07 19:46:30 +02:00 committed by GitHub
parent 5585334d77
commit a18201bff1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 2 deletions

View file

@ -876,9 +876,14 @@ class TemporaryDirectory:
ignore_errors=self._ignore_cleanup_errors)
@classmethod
def _rmtree(cls, name, ignore_errors=False):
def _rmtree(cls, name, ignore_errors=False, repeated=False):
def onerror(func, path, exc_info):
if issubclass(exc_info[0], PermissionError):
if repeated and path == name:
if ignore_errors:
return
raise
try:
if path != name:
_resetperms(_os.path.dirname(path))
@ -911,7 +916,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 issubclass(exc_info[0], FileNotFoundError):