Skip to content

Commit

Permalink
Merge pull request #64 from facelessuser/glob-regressions
Browse files Browse the repository at this point in the history
Fix regression with literal start pattern and multiple patterns in glob
  • Loading branch information
facelessuser authored Aug 21, 2019
2 parents 9bd55a7 + b0b6950 commit e17ca9b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
5 changes: 5 additions & 0 deletions docs/src/markdown/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 4.3.1

- **FIX**: Regression for root level literal matches in `glob`.
- **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.

## 4.3.0

- **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.
Expand Down
12 changes: 10 additions & 2 deletions tests/test_glob.py
Original file line number Diff line number Diff line change
Expand Up @@ -1099,8 +1099,8 @@ def test_selflink(self):
depth += 1


class TestGlobRoot(unittest.TestCase):
"""Test `glob` at root of mount."""
class TestGlobPaths(unittest.TestCase):
"""Test `glob` paths."""

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

def test_start(self):
"""Test that starting directory/files are handled properly."""

self.assertEqual(
sorted(['docs', 'wcmatch', 'readme.md']),
sorted([each.lower() for each in glob.glob(['BAD', 'docs', 'WCMATCH', 'readme.MD'], flags=glob.I)])
)


class TestDeprecated(unittest.TestCase):
"""Test deprecated."""
Expand Down
2 changes: 1 addition & 1 deletion wcmatch/__meta__.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,5 @@ def parse_version(ver, pre=False):
return Version(major, minor, micro, release, pre, post, dev)


__version_info__ = Version(4, 3, 0, "final")
__version_info__ = Version(4, 3, 1, "final")
__version__ = __version_info__._get_canonical()
16 changes: 7 additions & 9 deletions wcmatch/glob.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def _glob(self, curdir, this, rest):
else:
yield path, is_dir

def _get_starting_paths(self, curdir):
def _get_starting_paths(self, curdir, dir_only):
"""
Get the starting location.
Expand All @@ -391,7 +391,9 @@ def _get_starting_paths(self, curdir):
dirname = os.path.dirname(fullpath)
if basename:
matcher = self._get_matcher(basename)
results = [(os.path.basename(name), is_dir) for name, is_dir in self._glob_dir(dirname, matcher, self)]
results = [
(os.path.basename(name), is_dir) for name, is_dir in self._glob_dir(dirname, matcher, dir_only)
]

return results

Expand Down Expand Up @@ -422,18 +424,14 @@ def glob(self):

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

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

if this.dir_only:
# Glob these directories if they exists
Expand Down

0 comments on commit e17ca9b

Please sign in to comment.