summaryrefslogtreecommitdiffstats
path: root/Lib/pathlib.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-05-21 19:05:08 (GMT)
committerGitHub <noreply@github.com>2019-05-21 19:05:08 (GMT)
commitaea49b18752880e5d0260f16ca7ff2c6dce78515 (patch)
tree9567dc9c0bc6ea7bcf05dd23837e0dadcb1320f4 /Lib/pathlib.py
parent390d88e49c55c15fac7cdf60b649a4b9b15d189b (diff)
downloadcpython-aea49b18752880e5d0260f16ca7ff2c6dce78515.zip
cpython-aea49b18752880e5d0260f16ca7ff2c6dce78515.tar.gz
cpython-aea49b18752880e5d0260f16ca7ff2c6dce78515.tar.bz2
[3.7] bpo-36035: fix Path.rglob for broken links (GH-11988) (GH-13469)
Links creating an infinite symlink loop would raise an exception. (cherry picked from commit d5c120f7eb6f2a9cdab282a5d588afed307a23df) Co-authored-by: Jörg Stucke <joerg.stucke@fkie.fraunhofer.de> https://bugs.python.org/issue36035
Diffstat (limited to 'Lib/pathlib.py')
-rw-r--r--Lib/pathlib.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py
index e6e7181..24437f8 100644
--- a/Lib/pathlib.py
+++ b/Lib/pathlib.py
@@ -7,7 +7,7 @@ import posixpath
import re
import sys
from _collections_abc import Sequence
-from errno import EINVAL, ENOENT, ENOTDIR, EBADF
+from errno import EINVAL, ENOENT, ENOTDIR, EBADF, ELOOP
from operator import attrgetter
from stat import S_ISDIR, S_ISLNK, S_ISREG, S_ISSOCK, S_ISBLK, S_ISCHR, S_ISFIFO
from urllib.parse import quote_from_bytes as urlquote_from_bytes
@@ -35,10 +35,11 @@ __all__ = [
#
# EBADF - guard against macOS `stat` throwing EBADF
-_IGNORED_ERROS = (ENOENT, ENOTDIR, EBADF)
+_IGNORED_ERROS = (ENOENT, ENOTDIR, EBADF, ELOOP)
_IGNORED_WINERRORS = (
21, # ERROR_NOT_READY - drive exists but is not accessible
+ 1921, # ERROR_CANT_RESOLVE_FILENAME - fix for broken symlink pointing to itself
)
def _ignore_error(exception):
@@ -518,7 +519,13 @@ class _WildcardSelector(_Selector):
cf = parent_path._flavour.casefold
entries = list(scandir(parent_path))
for entry in entries:
- if not self.dironly or entry.is_dir():
+ entry_is_dir = False
+ try:
+ entry_is_dir = entry.is_dir()
+ except OSError as e:
+ if not _ignore_error(e):
+ raise
+ if not self.dironly or entry_is_dir:
name = entry.name
casefolded = cf(name)
if self.pat.match(casefolded):