bpo-35332: shutil.rmtree(ignore_errors=True) doesn't handle os.close()

When *ignore_errors* is True, the shutil.rmtree() function now
ignores errors when calling os.close().
This commit is contained in:
Zackery Spytz 2020-12-14 09:29:22 -07:00
parent 674fa0a740
commit 4b620b13b7
2 changed files with 10 additions and 2 deletions

View File

@ -667,7 +667,10 @@ def _rmtree_safe_fd(topfd, path, onerror):
except OSError:
onerror(os.path.islink, fullname, sys.exc_info())
finally:
os.close(dirfd)
try:
os.close(dirfd)
except OSError:
onerror(os.close, fullname, sys.exc_info())
else:
try:
os.unlink(entry.name, dir_fd=topfd)
@ -727,7 +730,10 @@ def rmtree(path, ignore_errors=False, onerror=None):
except OSError:
onerror(os.path.islink, path, sys.exc_info())
finally:
os.close(fd)
try:
os.close(fd)
except OSError:
onerror(os.close, path, sys.exc_info())
else:
try:
if _rmtree_islink(path):

View File

@ -0,0 +1,2 @@
The :func:`shutil.rmtree` function now ignores errors when calling
:func:`os.close` when *ignore_errors* is ``True``.