diff options
author | Guido van Rossum <guido@dropbox.com> | 2016-01-07 18:58:20 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@dropbox.com> | 2016-01-07 18:58:20 (GMT) |
commit | 8355bd7f66029708c9a1d4145314b0654c81ea48 (patch) | |
tree | 35759aa9f9cfb3293411d079a8400c70db448e2f /Lib | |
parent | bd15bae45afd5d7361eb4cd0ca7df210fe8aaa2d (diff) | |
parent | c3a8272705f26499d522ddda8ef0f07f8efcee40 (diff) | |
download | cpython-8355bd7f66029708c9a1d4145314b0654c81ea48.zip cpython-8355bd7f66029708c9a1d4145314b0654c81ea48.tar.gz cpython-8355bd7f66029708c9a1d4145314b0654c81ea48.tar.bz2 |
Add another try/except PermissionError to avoid depending on listdir order. Fix issues #24120 and #26012. (Merge 3.5->3.6)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/pathlib.py | 13 | ||||
-rw-r--r-- | Lib/test/test_pathlib.py | 16 |
2 files changed, 16 insertions, 13 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py index a1e0a82..bbac773 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -539,11 +539,14 @@ class _RecursiveWildcardSelector(_Selector): def _iterate_directories(self, parent_path, is_dir, listdir): yield parent_path - for name in listdir(parent_path): - path = parent_path._make_child_relpath(name) - if is_dir(path) and not path.is_symlink(): - for p in self._iterate_directories(path, is_dir, listdir): - yield p + try: + for name in listdir(parent_path): + path = parent_path._make_child_relpath(name) + if is_dir(path) and not path.is_symlink(): + 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): try: diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py index bfdafe3..8e1b545 100644 --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -1236,7 +1236,7 @@ class _BasePathTest(object): # | |-- dirD # | | `-- fileD # | `-- fileC - # |-- dirE + # |-- dirE # No permissions # |-- fileA # |-- linkA -> fileA # `-- linkB -> dirB @@ -1453,13 +1453,13 @@ class _BasePathTest(object): p = P(BASE) it = p.rglob("fileA") self.assertIsInstance(it, collections.Iterator) - # XXX cannot test because of symlink loops in the test setup - #_check(it, ["fileA"]) - #_check(p.rglob("fileB"), ["dirB/fileB"]) - #_check(p.rglob("*/fileA"), [""]) - #_check(p.rglob("*/fileB"), ["dirB/fileB"]) - #_check(p.rglob("file*"), ["fileA", "dirB/fileB"]) - # No symlink loops here + _check(it, ["fileA"]) + _check(p.rglob("fileB"), ["dirB/fileB"]) + _check(p.rglob("*/fileA"), []) + _check(p.rglob("*/fileB"), ["dirB/fileB", "dirB/linkD/fileB", + "linkB/fileB", "dirA/linkC/fileB"]) + _check(p.rglob("file*"), ["fileA", "dirB/fileB", + "dirC/fileC", "dirC/dirD/fileD"]) p = P(BASE, "dirC") _check(p.rglob("file*"), ["dirC/fileC", "dirC/dirD/fileD"]) _check(p.rglob("*/*"), ["dirC/dirD/fileD"]) |