]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] GH-87695: Fix OSError from `pathlib.Path.glob()` (GH-104292) (GH-104362)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 10 May 2023 23:19:49 +0000 (16:19 -0700)
committerGitHub <noreply@github.com>
Wed, 10 May 2023 23:19:49 +0000 (23:19 +0000)
Fix issue where `pathlib.Path.glob()` raised `OSError` when it encountered
a symlink to an overly long path.
(cherry picked from commit a33ce66dca57d4c36b1022fdf3b7e322f3203468)

Co-authored-by: Barney Gale <barney.gale@gmail.com>
Lib/pathlib.py
Lib/test/test_pathlib.py
Misc/NEWS.d/next/Library/2023-05-08-15-39-00.gh-issue-87695.f6iO7v.rst [new file with mode: 0644]

index 9d40d88ef5f2e8c767a3c711c4eb6cdbdccc5609..ecb1e8a40d8cf02e7df4723c1db6ab3481470e86 100644 (file)
@@ -388,11 +388,11 @@ class _RecursiveWildcardSelector(_Selector):
             for entry in entries:
                 entry_is_dir = False
                 try:
-                    entry_is_dir = entry.is_dir()
+                    entry_is_dir = entry.is_dir(follow_symlinks=False)
                 except OSError as e:
                     if not _ignore_error(e):
                         raise
-                if entry_is_dir and not entry.is_symlink():
+                if entry_is_dir:
                     path = parent_path._make_child_relpath(entry.name)
                     for p in self._iterate_directories(path, is_dir, scandir):
                         yield p
index 3b88c0848a0448440992b185d71ac99f3c6d3408..bd5170651d534544ebb838dbd8ba5c4f0c076b32 100644 (file)
@@ -1790,6 +1790,15 @@ class _BasePathTest(object):
             subdir.chmod(000)
             self.assertEqual(len(set(base.glob("*"))), 4)
 
+    @os_helper.skip_unless_symlink
+    def test_glob_long_symlink(self):
+        # See gh-87695
+        base = self.cls(BASE) / 'long_symlink'
+        base.mkdir()
+        bad_link = base / 'bad_link'
+        bad_link.symlink_to("bad" * 200)
+        self.assertEqual(sorted(base.glob('**/*')), [bad_link])
+
     def _check_resolve(self, p, expected, strict=True):
         q = p.resolve(strict)
         self.assertEqual(q, expected)
diff --git a/Misc/NEWS.d/next/Library/2023-05-08-15-39-00.gh-issue-87695.f6iO7v.rst b/Misc/NEWS.d/next/Library/2023-05-08-15-39-00.gh-issue-87695.f6iO7v.rst
new file mode 100644 (file)
index 0000000..7b67765
--- /dev/null
@@ -0,0 +1,2 @@
+Fix issue where :meth:`pathlib.Path.glob` raised :exc:`OSError` when it
+encountered a symlink to an overly long path.