Commit c3a82727 authored by Guido van Rossum's avatar Guido van Rossum

Add another try/except PermissionError to avoid depending on listdir order....

Add another try/except PermissionError to avoid depending on listdir order. Fix issues #24120 and #26012. (Merge 3.4->3.5)
parents 16fb6748 bc9fddaf
...@@ -539,11 +539,14 @@ class _RecursiveWildcardSelector(_Selector): ...@@ -539,11 +539,14 @@ class _RecursiveWildcardSelector(_Selector):
def _iterate_directories(self, parent_path, is_dir, listdir): def _iterate_directories(self, parent_path, is_dir, listdir):
yield parent_path yield parent_path
for name in listdir(parent_path): try:
path = parent_path._make_child_relpath(name) for name in listdir(parent_path):
if is_dir(path) and not path.is_symlink(): path = parent_path._make_child_relpath(name)
for p in self._iterate_directories(path, is_dir, listdir): if is_dir(path) and not path.is_symlink():
yield p for p in self._iterate_directories(path, is_dir, listdir):
yield p
except PermissionError:
return
def _select_from(self, parent_path, is_dir, exists, listdir): def _select_from(self, parent_path, is_dir, exists, listdir):
try: try:
......
...@@ -1236,7 +1236,7 @@ class _BasePathTest(object): ...@@ -1236,7 +1236,7 @@ class _BasePathTest(object):
# | |-- dirD # | |-- dirD
# | | `-- fileD # | | `-- fileD
# | `-- fileC # | `-- fileC
# |-- dirE # |-- dirE # No permissions
# |-- fileA # |-- fileA
# |-- linkA -> fileA # |-- linkA -> fileA
# `-- linkB -> dirB # `-- linkB -> dirB
...@@ -1453,13 +1453,13 @@ class _BasePathTest(object): ...@@ -1453,13 +1453,13 @@ class _BasePathTest(object):
p = P(BASE) p = P(BASE)
it = p.rglob("fileA") it = p.rglob("fileA")
self.assertIsInstance(it, collections.Iterator) self.assertIsInstance(it, collections.Iterator)
# XXX cannot test because of symlink loops in the test setup _check(it, ["fileA"])
#_check(it, ["fileA"]) _check(p.rglob("fileB"), ["dirB/fileB"])
#_check(p.rglob("fileB"), ["dirB/fileB"]) _check(p.rglob("*/fileA"), [])
#_check(p.rglob("*/fileA"), [""]) _check(p.rglob("*/fileB"), ["dirB/fileB", "dirB/linkD/fileB",
#_check(p.rglob("*/fileB"), ["dirB/fileB"]) "linkB/fileB", "dirA/linkC/fileB"])
#_check(p.rglob("file*"), ["fileA", "dirB/fileB"]) _check(p.rglob("file*"), ["fileA", "dirB/fileB",
# No symlink loops here "dirC/fileC", "dirC/dirD/fileD"])
p = P(BASE, "dirC") p = P(BASE, "dirC")
_check(p.rglob("file*"), ["dirC/fileC", "dirC/dirD/fileD"]) _check(p.rglob("file*"), ["dirC/fileC", "dirC/dirD/fileD"])
_check(p.rglob("*/*"), ["dirC/dirD/fileD"]) _check(p.rglob("*/*"), ["dirC/dirD/fileD"])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment