]> granicus.if.org Git - python/commitdiff
Add another try/except PermissionError to avoid depending on listdir order. Fix issue...
authorGuido van Rossum <guido@python.org>
Thu, 7 Jan 2016 18:56:36 +0000 (10:56 -0800)
committerGuido van Rossum <guido@python.org>
Thu, 7 Jan 2016 18:56:36 +0000 (10:56 -0800)
Lib/pathlib.py
Lib/test/test_pathlib.py

index 1bd457a4872f37cab465d17233c7be2c8351b5ac..8fef2590b85a4c8435408e27aec564261ec55cdb 100644 (file)
@@ -494,11 +494,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:
index 061c7645f213fc3cb0e790dc917f91fce17cb793..a12af225c8b4f1dbe2391c4d263c83fdd8d86e3b 100644 (file)
@@ -1240,7 +1240,7 @@ class _BasePathTest(object):
     #  |   |-- dirD
     #  |   |   `-- fileD
     #  |   `-- fileC
-    #  |-- dirE
+    #  |-- dirE  # No permissions
     #  |-- fileA
     #  |-- linkA -> fileA
     #  `-- linkB -> dirB
@@ -1396,13 +1396,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"])