gh-116401: Fix blocking os.fwalk() and shutil.rmtree() on opening a named pipe (GH-116421)

This commit is contained in:
Serhiy Storchaka 2024-03-13 11:40:28 +02:00 committed by GitHub
parent 8332e85b2f
commit aa7bcf284f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 113 additions and 8 deletions

View file

@ -681,7 +681,7 @@ def _rmtree_safe_fd(topfd, path, onexc):
continue
if is_dir:
try:
dirfd = os.open(entry.name, os.O_RDONLY, dir_fd=topfd)
dirfd = os.open(entry.name, os.O_RDONLY | os.O_NONBLOCK, dir_fd=topfd)
dirfd_closed = False
except FileNotFoundError:
continue
@ -786,7 +786,7 @@ def rmtree(path, ignore_errors=False, onerror=None, *, onexc=None, dir_fd=None):
onexc(os.lstat, path, err)
return
try:
fd = os.open(path, os.O_RDONLY, dir_fd=dir_fd)
fd = os.open(path, os.O_RDONLY | os.O_NONBLOCK, dir_fd=dir_fd)
fd_closed = False
except OSError as err:
onexc(os.open, path, err)