diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2020-03-07 18:11:24 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-07 18:11:24 (GMT) |
commit | 928b4dd0edf0022190a8a296c8ea65e7ef55c694 (patch) | |
tree | 3da9f52799baebf08d3bc7589f679650b3b3f776 /Lib/pathlib.py | |
parent | 92b72788ecf2ee5dfac780c7dfb5ee5350fc641d (diff) | |
download | cpython-928b4dd0edf0022190a8a296c8ea65e7ef55c694.zip cpython-928b4dd0edf0022190a8a296c8ea65e7ef55c694.tar.gz cpython-928b4dd0edf0022190a8a296c8ea65e7ef55c694.tar.bz2 |
bpo-38894: Fix pathlib.Path.glob in the presence of symlinks and insufficient permissions (GH-18815)
Co-authored-by: Matt Wozniski <mwozniski@bloomberg.net>
(cherry picked from commit eb7560a73d46800e4ade4a8869139b48e6c92811)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Diffstat (limited to 'Lib/pathlib.py')
-rw-r--r-- | Lib/pathlib.py | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py index 015370a..d188026 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -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): |