summaryrefslogtreecommitdiff
path: root/Lib/pathlib.py
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2020-03-07 17:53:20 +0000
committerGitHub <noreply@github.com>2020-03-07 17:53:20 +0000
commiteb7560a73d46800e4ade4a8869139b48e6c92811 (patch)
tree25cb909155802b1d27d47d41c41b0b7bd2fd6feb /Lib/pathlib.py
parentaa450a0364b6160be7dd61ec2d378abb0652f014 (diff)
downloadcpython-git-eb7560a73d46800e4ade4a8869139b48e6c92811.tar.gz
bpo-38894: Fix pathlib.Path.glob in the presence of symlinks and insufficient permissions (GH-18815)
Co-authored-by: Matt Wozniski <mwozniski@bloomberg.net>
Diffstat (limited to 'Lib/pathlib.py')
-rw-r--r--Lib/pathlib.py29
1 files changed, 16 insertions, 13 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py
index cfa574af6e..851aabd479 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):