FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add another try/except PermissionError to avoid depending on listdir … · python/cpython@c3a8272 · GitHub

Repository navigation

Commit c3a8272

Browse files
committed
Add another try/except PermissionError to avoid depending on listdir order. Fix issues #24120 and #26012. (Merge 3.4->3.5)
2 parents 16fb674 + bc9fdda commit c3a8272

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

‎Lib/pathlib.py‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -539,11 +539,14 @@ def __init__(self, pat, child_parts):
539539

540540
def _iterate_directories(self, parent_path, is_dir, listdir):
541541
yield parent_path
542-
for name in listdir(parent_path):
543-
path = parent_path._make_child_relpath(name)
544-
if is_dir(path) and not path.is_symlink():
545-
for p in self._iterate_directories(path, is_dir, listdir):
546-
yield p
542+
try:
543+
for name in listdir(parent_path):
544+
path = parent_path._make_child_relpath(name)
545+
if is_dir(path) and not path.is_symlink():
546+
for p in self._iterate_directories(path, is_dir, listdir):
547+
yield p
548+
except PermissionError:
549+
return
547550

548551
def _select_from(self, parent_path, is_dir, exists, listdir):
549552
try:

‎Lib/test/test_pathlib.py‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ class _BasePathTest(object):
12361236
# | |-- dirD
12371237
# | | `-- fileD
12381238
# | `-- fileC
1239-
# |-- dirE
1239+
# |-- dirE # No permissions
12401240
# |-- fileA
12411241
# |-- linkA -> fileA
12421242
# `-- linkB -> dirB
@@ -1453,13 +1453,13 @@ def _check(glob, expected):
14531453
p = P(BASE)
14541454
it = p.rglob("fileA")
14551455
self.assertIsInstance(it, collections.Iterator)
1456-
# XXX cannot test because of symlink loops in the test setup
1457-
#_check(it, ["fileA"])
1458-
#_check(p.rglob("fileB"), ["dirB/fileB"])
1459-
#_check(p.rglob("*/fileA"), [""])
1460-
#_check(p.rglob("*/fileB"), ["dirB/fileB"])
1461-
#_check(p.rglob("file*"), ["fileA", "dirB/fileB"])
1462-
# No symlink loops here
1456+
_check(it, ["fileA"])
1457+
_check(p.rglob("fileB"), ["dirB/fileB"])
1458+
_check(p.rglob("*/fileA"), [])
1459+
_check(p.rglob("*/fileB"), ["dirB/fileB", "dirB/linkD/fileB",
1460+
"linkB/fileB", "dirA/linkC/fileB"])
1461+
_check(p.rglob("file*"), ["fileA", "dirB/fileB",
1462+
"dirC/fileC", "dirC/dirD/fileD"])
14631463
p = P(BASE, "dirC")
14641464
_check(p.rglob("file*"), ["dirC/fileC", "dirC/dirD/fileD"])
14651465
_check(p.rglob("*/*"), ["dirC/dirD/fileD"])

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL