summaryrefslogtreecommitdiff
path: root/Lib/glob.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-11-09 23:12:07 +0200
committerSerhiy Storchaka <storchaka@gmail.com>2015-11-09 23:12:07 +0200
commit735b790fed417c797d68d031c75a005a5e6dfc52 (patch)
tree694e2ffdeba0ceafda4d7e4da39c486bc1d71ad4 /Lib/glob.py
parentf9827ea61859c6fb3fdac1e5a364d87bd4237622 (diff)
downloadcpython-git-735b790fed417c797d68d031c75a005a5e6dfc52.tar.gz
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 56d670419a..d674289318 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):