Skip to content

Commit e17ca9b

Browse files
authored
Merge pull request #64 from facelessuser/glob-regressions
Fix regression with literal start pattern and multiple patterns in glob
2 parents 9bd55a7 + b0b6950 commit e17ca9b

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

docs/src/markdown/changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 4.3.1
4+
5+
- **FIX**: Regression for root level literal matches in `glob`.
6+
- **FIX**: Bug where `glob` would mistakenly abort if a pattern started with a literal file or directory and could not match a file or directory. This caused subsequent patterns in the chain to not get evaluated.
7+
38
## 4.3.0
49

510
- **NEW**: Add `CASE` flag which allows for case sensitive paths on Linux, macOS, and Windows. Windows drive letters and UNC `//host-name/share-name/` portion are still treated insensitively, but all directories will be treated with case sensitivity.

tests/test_glob.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,8 +1099,8 @@ def test_selflink(self):
10991099
depth += 1
11001100

11011101

1102-
class TestGlobRoot(unittest.TestCase):
1103-
"""Test `glob` at root of mount."""
1102+
class TestGlobPaths(unittest.TestCase):
1103+
"""Test `glob` paths."""
11041104

11051105
def test_root(self):
11061106
"""Test that `glob` translates the root properly."""
@@ -1110,6 +1110,14 @@ def test_root(self):
11101110
# Basically, we should not return an empty set.
11111111
self.assertTrue(len(glob.glob('/*')) > 0)
11121112

1113+
def test_start(self):
1114+
"""Test that starting directory/files are handled properly."""
1115+
1116+
self.assertEqual(
1117+
sorted(['docs', 'wcmatch', 'readme.md']),
1118+
sorted([each.lower() for each in glob.glob(['BAD', 'docs', 'WCMATCH', 'readme.MD'], flags=glob.I)])
1119+
)
1120+
11131121

11141122
class TestDeprecated(unittest.TestCase):
11151123
"""Test deprecated."""

wcmatch/__meta__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,5 +186,5 @@ def parse_version(ver, pre=False):
186186
return Version(major, minor, micro, release, pre, post, dev)
187187

188188

189-
__version_info__ = Version(4, 3, 0, "final")
189+
__version_info__ = Version(4, 3, 1, "final")
190190
__version__ = __version_info__._get_canonical()

wcmatch/glob.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ def _glob(self, curdir, this, rest):
373373
else:
374374
yield path, is_dir
375375

376-
def _get_starting_paths(self, curdir):
376+
def _get_starting_paths(self, curdir, dir_only):
377377
"""
378378
Get the starting location.
379379
@@ -391,7 +391,9 @@ def _get_starting_paths(self, curdir):
391391
dirname = os.path.dirname(fullpath)
392392
if basename:
393393
matcher = self._get_matcher(basename)
394-
results = [(os.path.basename(name), is_dir) for name, is_dir in self._glob_dir(dirname, matcher, self)]
394+
results = [
395+
(os.path.basename(name), is_dir) for name, is_dir in self._glob_dir(dirname, matcher, dir_only)
396+
]
395397

396398
return results
397399

@@ -422,18 +424,14 @@ def glob(self):
422424

423425
# Abort if we cannot find the drive, or if current directory is empty
424426
if not curdir or (this.is_drive and not os.path.lexists(curdir)):
425-
return
427+
continue
426428

427429
# Make sure case matches, but running case insensitive
428430
# on a case sensitive file system may return more than
429431
# one starting location.
430-
results = [(curdir, True)] if this.is_drive else self._get_starting_paths(curdir)
432+
results = [(curdir, True)] if this.is_drive else self._get_starting_paths(curdir, dir_only)
431433
if not results:
432-
if not dir_only:
433-
# There is no directory with this name,
434-
# but we have a file and no directory restriction
435-
yield self.format_path(curdir, False, dir_only)
436-
return
434+
continue
437435

438436
if this.dir_only:
439437
# Glob these directories if they exists

0 commit comments

Comments
 (0)