diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-11-09 23:12:28 +0200 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-11-09 23:12:28 +0200 |
commit | 8e43e11be300e6aa16ac37548d0799c27700c16e (patch) | |
tree | 6d1346cfb0b1eee09326c141bae907426422132f /Lib/glob.py | |
parent | d9d002b0ceb1070b538768168743a627262d4895 (diff) | |
parent | 735b790fed417c797d68d031c75a005a5e6dfc52 (diff) | |
download | cpython-git-8e43e11be300e6aa16ac37548d0799c27700c16e.tar.gz |
Issue #25584: Fixed recursive glob() with patterns starting with '**'.
Diffstat (limited to 'Lib/glob.py')
-rw-r--r-- | Lib/glob.py | 13 |
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): |