mirror of
https://github.com/python/cpython.git
synced 2025-08-15 22:30:42 +00:00
[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:
parent
5585334d77
commit
a18201bff1
3 changed files with 21 additions and 2 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue