Skip to content

fix: Update to use doublestar v4#5148

Merged
kalleep merged 5 commits intomainfrom
kalleep/doublestar-v4
Jan 14, 2026
Merged

fix: Update to use doublestar v4#5148
kalleep merged 5 commits intomainfrom
kalleep/doublestar-v4

Conversation

@kalleep
Copy link
Contributor

@kalleep kalleep commented Dec 19, 2025

PR Description

Update to latest version that supports more complex patterns.

Check Dependency Review and looked through releases. FilepathGlob is a drop in replacement for what we previously used (Glob) so we are fine to update this.

PathMatch had a change in behavior - previously it would accept either / as separator or platform specific separator. As documented in their change we can use filepath.FromSlash too not break this.

Which issue(s) this PR fixes

fixes: #4423

Notes to the Reviewer

PR Checklist

  • Documentation added
  • Tests updated
  • Config converters updated

@kalleep kalleep requested a review from a team as a code owner December 19, 2025 10:02
@github-actions
Copy link
Contributor

github-actions bot commented Dec 19, 2025

🔍 Dependency Review

github.com/bmatcuk/doublestar v1.3.4 → v4.9.1 — ❌ Changes Needed

Summary:

  • This is a major upgrade (v1 → v4) that requires code changes.
  • v4 introduces a new module path and new Filepath* helpers to handle OS-native path separators. To preserve previous behavior in most codebases that work with filesystem paths, you should:
    • Update imports to github.com/bmatcuk/doublestar/v4.
    • Replace doublestar.Glob with doublestar.FilepathGlob.
    • Ensure pattern/name separator semantics are consistent. When matching against OS-native file paths, either:
      • Use doublestar.FilepathMatch(pattern, name), or
      • If using doublestar.PathMatch, normalize the pattern or name so both use the same separator (e.g., filepath.FromSlash(pattern) if the name uses OS-native separators).

Code changes required (examples from this PR):

- import "github.com/bmatcuk/doublestar"
+ import "github.com/bmatcuk/doublestar/v4"
- matches, err := doublestar.Glob(pattern)
+ matches, err := doublestar.FilepathGlob(pattern)
- if match, _ := doublestar.PathMatch(exclude, path) { ... }
+ if match, _ := doublestar.PathMatch(filepath.FromSlash(exclude), path) { ... }

Alternatively, to make intent explicit and avoid manual normalization:

- if match, _ := doublestar.PathMatch(filepath.FromSlash(exclude), path) { ... }
+ if match, _ := doublestar.FilepathMatch(exclude, path) { ... }

Potential additional updates to search for in your codebase:

  • Any remaining usage of:
    • doublestar.Glob → prefer doublestar.FilepathGlob for filesystem paths.
    • doublestar.Match/PathMatch → for filesystem paths, prefer doublestar.FilepathMatch, or normalize separators explicitly as shown above.

Why these changes are needed:

  • v4 is a new module (/v4 import path) with an expanded API. It adds Filepath* variants (e.g., FilepathGlob, FilepathMatch) designed to operate with OS-native separators. Using these preserves the behavior you likely relied on with v1 when dealing with actual filesystem paths and platform-specific separators.

Changelog highlights and references:

  • v2/v3: Module path bumps and internal improvements; no required changes for typical Glob/Match usage.
  • v4: Introduces Filepath* variants and clarifies separator semantics between “path” (forward slash) and “filepath” (OS-native) functions.
    • New functions include:
      • func FilepathGlob(pattern string) ([]string, error)
      • func FilepathMatch(pattern, name string) (bool, error)
    • The v4 module is imported as github.com/bmatcuk/doublestar/v4.

Relevant excerpts (from upstream docs/changelog/readme):

  • v4 adds “Filepath…” functions to mirror Go’s standard library distinctions between path vs filepath semantics, improving cross-platform correctness when matching and globbing filesystem paths.

Additional considerations:

  • If your patterns are user-provided and use forward slashes regardless of OS, you can continue to use non-Filepath variants (e.g., PathMatch) but normalize either the pattern or the candidate path consistently.
  • Verify behavior on Windows, especially for exclude patterns and globbing with “**”, to ensure the intended matches still occur.

Files updated in this PR (good examples):

  • internal/component/local/file_match/watch.go
  • internal/component/loki/source/file/resolver.go

Notes

  • The indirect v1 dependency was removed in submodules (collector/, extension/alloyengine/) and replaced with v4 in the root module as a direct dependency. No other dependency changes were detected.

Copy link
Contributor

@dehaansa dehaansa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should loki.source.file resolver also use FromSlash?

@kalleep kalleep force-pushed the kalleep/doublestar-v4 branch from bc4a747 to 9b38d3f Compare January 12, 2026 08:30
@kalleep kalleep changed the title fix: update to use doublestar v4 fix: Update to use doublestar v4 Jan 12, 2026
@kalleep kalleep requested a review from dehaansa January 12, 2026 09:47
@kalleep kalleep merged commit d8f0b3e into main Jan 14, 2026
47 checks passed
@kalleep kalleep deleted the kalleep/doublestar-v4 branch January 14, 2026 14:33
@grafana-alloybot grafana-alloybot bot mentioned this pull request Jan 14, 2026
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Alloy local.file_match supporting include/exclude multiple path

2 participants