mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-38894: Fix pathlib.Path.glob in the presence of symlinks and insufficient permissions (GH-18815)
Co-authored-by: Matt Wozniski <mwozniski@bloomberg.net>
This commit is contained in:
parent
aa450a0364
commit
eb7560a73d
3 changed files with 56 additions and 13 deletions
|
@ -529,23 +529,26 @@ class _WildcardSelector(_Selector):
|
|||
try:
|
||||
entries = list(scandir(parent_path))
|
||||
for entry in entries:
|
||||
entry_is_dir = False
|
||||
try:
|
||||
entry_is_dir = entry.is_dir()
|
||||
except OSError as e:
|
||||
if not _ignore_error(e):
|
||||
raise
|
||||
if not self.dironly or entry_is_dir:
|
||||
name = entry.name
|
||||
if self.match(name):
|
||||
path = parent_path._make_child_relpath(name)
|
||||
for p in self.successor._select_from(path, is_dir, exists, scandir):
|
||||
yield p
|
||||
if self.dironly:
|
||||
try:
|
||||
# "entry.is_dir()" can raise PermissionError
|
||||
# in some cases (see bpo-38894), which is not
|
||||
# among the errors ignored by _ignore_error()
|
||||
if not entry.is_dir():
|
||||
continue
|
||||
except OSError as e:
|
||||
if not _ignore_error(e):
|
||||
raise
|
||||
continue
|
||||
name = entry.name
|
||||
if self.match(name):
|
||||
path = parent_path._make_child_relpath(name)
|
||||
for p in self.successor._select_from(path, is_dir, exists, scandir):
|
||||
yield p
|
||||
except PermissionError:
|
||||
return
|
||||
|
||||
|
||||
|
||||
class _RecursiveWildcardSelector(_Selector):
|
||||
|
||||
def __init__(self, pat, child_parts, flavour):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue