summaryrefslogtreecommitdiffstats
path: root/Lib/glob.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-11-09 21:12:07 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-11-09 21:12:07 (GMT)
commit735b790fed417c797d68d031c75a005a5e6dfc52 (patch)
tree694e2ffdeba0ceafda4d7e4da39c486bc1d71ad4 /Lib/glob.py
parentf9827ea61859c6fb3fdac1e5a364d87bd4237622 (diff)
downloadcpython-735b790fed417c797d68d031c75a005a5e6dfc52.zip
cpython-735b790fed417c797d68d031c75a005a5e6dfc52.tar.gz
cpython-735b790fed417c797d68d031c75a005a5e6dfc52.tar.bz2
Issue #25584: Fixed recursive glob() with patterns starting with '**'.
Diffstat (limited to 'Lib/glob.py')
-rw-r--r--Lib/glob.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/Lib/glob.py b/Lib/glob.py
index 56d6704..d674289 100644
--- a/Lib/glob.py
+++ b/Lib/glob.py
@@ -30,6 +30,13 @@ def iglob(pathname, *, recursive=False):
If recursive is true, the pattern '**' will match any files and
zero or more directories and subdirectories.
"""
+ it = _iglob(pathname, recursive)
+ if recursive and _isrecursive(pathname):
+ s = next(it) # skip empty string
+ assert not s
+ return it
+
+def _iglob(pathname, recursive):
dirname, basename = os.path.split(pathname)
if not has_magic(pathname):
if basename:
@@ -50,7 +57,7 @@ def iglob(pathname, *, recursive=False):
# drive or UNC path. Prevent an infinite recursion if a drive or UNC path
# contains magic characters (i.e. r'\\?\C:').
if dirname != pathname and has_magic(dirname):
- dirs = iglob(dirname, recursive=recursive)
+ dirs = _iglob(dirname, recursive)
else:
dirs = [dirname]
if has_magic(basename):
@@ -98,12 +105,10 @@ def glob0(dirname, basename):
def glob2(dirname, pattern):
assert _isrecursive(pattern)
- if dirname:
- yield pattern[:0]
+ yield pattern[:0]
yield from _rlistdir(dirname)
# Recursively yields relative pathnames inside a literal directory.
-
def _rlistdir(dirname):
if not dirname:
if isinstance(dirname, bytes):