8000 do not follow links when checking for precise glob match · python/cpython@272c1b4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 272c1b4

Browse files
committed
do not follow links when checking for precise glob match
1 parent be36e06 commit 272c1b4

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

Lib/pathlib.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,8 @@ def __init__(self, name, child_parts, flavour):
422422
def _select_from(self, parent_path, is_dir, exists, scandir):
423423
try:
424424
path = parent_path._make_child_relpath(self.name)
425-
if (is_dir if self.dironly else exists)(path):
425+
if ((self.dironly and is_dir(path)) or \
426+
(not self.dironly and exists(path, follow_symlinks=False))):
426427
for p in self.successor._select_from(path, is_dir, exists, scandir):
427428
yield p
428429
except PermissionError:
@@ -1280,12 +1281,12 @@ def link_to(self, target):
12801281

12811282
# Convenience functions for querying the stat results
12821283

1283-
def exists(self):
1284+
def exists(self, follow_symlinks=True):
12841285
"""
12851286
Whether this path exists.
12861287
"""
12871288
try:
1288-
self.stat()
1289+
self.stat(follow_symlinks=follow_symlinks)
12891290
except OSError as e:
12901291
if not _ignore_error(e):
12911292
raise

Lib/test/test_pathlib.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,6 +1529,7 @@ def test_exists(self):
15291529
self.assertIs(False, P('/xyzzy').exists())
15301530
self.assertIs(False, P(BASE + '\udfff').exists())
15311531
self.assertIs(False, P(BASE + '\x00').exists())
1532+
self.assertIs(False, (p / 'brokenLink').exists())
15321533

15331534
def test_open_common(self):
15341535
p = self.cls(BASE)
@@ -1631,6 +1632,8 @@ def _check(glob, expected):
16311632
_check(p.glob("*/fileB"), ['dirB/fileB'])
16321633
else:
16331634
_check(p.glob("*/fileB"), ['dirB/fileB', 'linkB/fileB'])
1635+
if os_helper.can_symlink():
1636+
_check(p.glob("brokenLink"), ['brokenLink'])
16341637

16351638
def test_rglob_common(self):
16361639
def _check(glob, expected):

0 commit comments

Comments
 (0)
0