Skip to content

fix: replace substring pattern matching with globset in FileWalker#21

Open
oudeis01 wants to merge 1 commit into
Brainwires:mainfrom
oudeis01:fix/glob-patterns
Open

fix: replace substring pattern matching with globset in FileWalker#21
oudeis01 wants to merge 1 commit into
Brainwires:mainfrom
oudeis01:fix/glob-patterns

Conversation

@oudeis01

Copy link
Copy Markdown

Problem

matches_patterns() used path_str.contains(pattern) to check include and exclude patterns. This treats every pattern as a literal substring, so glob-style inputs like **/vendor/** or **/*.rs never match any real path -- the string "**/vendor/**" is simply not a substring of "project/vendor/foo.c".

The globset crate is already a declared dependency in Cargo.toml but was unused in this module.

Fix

  • Add build_glob_set() to compile patterns into a GlobSet once in with_patterns(), avoiding recompilation on every call to matches_patterns().
  • Rewrite matches_patterns() to match against the path relative to the walk root, so patterns behave correctly regardless of where the root directory sits in the filesystem.
  • Update tests to use proper glob patterns (**/*.rs, **/target/**, etc.) that reflect real-world usage.

Test plan

  • cargo test --lib indexer::file_walker passes (34 tests)
  • Indexing with exclude_patterns: ["**/vendor/**"] correctly skips vendored files
  • Indexing with include_patterns: ["**/*.rs"] correctly includes only Rust files

matches_patterns() used path_str.contains(pattern), treating every
pattern as a literal substring. Patterns like "**/vendor/**" never
matched any path because the string "**/vendor/**" is not a substring
of real file paths, making exclude_patterns effectively broken for
glob-style inputs.

globset is already a declared dependency. This change:
- Adds build_glob_set() to compile patterns into a GlobSet once on
  construction rather than on every call to matches_patterns().
- Rewrites matches_patterns() to match against the path relative to
  the walk root, so patterns behave correctly regardless of where the
  root directory sits in the filesystem.
- Updates tests to use glob-style patterns (e.g. **/*.rs, **/target/**)
  that reflect actual usage.
@Waxolunist

Copy link
Copy Markdown

Please merge. Include and exclude patterns don't work currently

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants