Skip to content

fix: Revert doublestar v4 update#5434

Merged
kalleep merged 1 commit intomainfrom
revert-5148-kalleep/doublestar-v4
Feb 4, 2026
Merged

fix: Revert doublestar v4 update#5434
kalleep merged 1 commit intomainfrom
revert-5148-kalleep/doublestar-v4

Conversation

@kalleep
Copy link
Contributor

@kalleep kalleep commented Feb 4, 2026

Reverts #5148

Discovered that updating to v4 introduces regression on windows around case sensitivity for paths. So we need to revert and look into that before updating.

@kalleep kalleep requested a review from a team as a code owner February 4, 2026 13:27
@kalleep kalleep added the backport/v1.13 Backport to release/v1.13 label Feb 4, 2026
@kalleep kalleep changed the title Revert "fix: Update to use doublestar v4" fix: Revert doublestar v4 update Feb 4, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2026

🔍 Dependency Review

github.com/bmatcuk/doublestar/v4 v4.9.1 → github.com/bmatcuk/doublestar v1.3.4 — ⚠️ Needs Review

Summary:

  • This PR replaces the v4 module with the legacy v1 module and updates call sites accordingly.
  • v4 and v1 have breaking API differences. The PR has already changed:
    • FilepathGlob(...)Glob(...)
    • import path github.com/bmatcuk/doublestar/v4github.com/bmatcuk/doublestar
  • One subtle but important behavioral difference to double-check is path separator normalization (especially on Windows) for exclude patterns and possibly for glob patterns.

Why review is needed:

  • v4 introduced an explicitly named FilepathGlob (filepath/OS-specific semantics). In v1, the equivalent is Glob.
  • Both versions expose PathMatch, but pattern/name separator handling differs if your pattern strings use forward slashes while the OS path separator is backslash (Windows). The current PR removes filepath.FromSlash(...) normalization around exclude patterns; that can change matching semantics on Windows.

Recommended code adjustments to preserve behavior:

  • Keep normalizing exclude patterns to the OS path separator before calling PathMatch, as was done before. This avoids mismatches when config-supplied patterns use / on Windows.

Code changes:

  1. internal/component/local/file_match/watch.go
-   matches, err := doublestar.Glob(w.getPath())
+   matches, err := doublestar.Glob(w.getPath())
    if err != nil {
        return nil, err
    }
    exclude := w.getExcludePath()
    for _, m := range matches {
        if exclude != "" {
-           if match, _ := doublestar.PathMatch(exclude, m); match {
+           // Normalize exclude to OS-specific separators to preserve previous behavior
+           if match, _ := doublestar.PathMatch(filepath.FromSlash(exclude), m); match {
                continue
            }
        }
  1. internal/component/loki/source/file/resolver.go
-           matches, err := doublestar.Glob(targetPath)
+           matches, err := doublestar.Glob(targetPath)
            if err != nil {
                level.Error(s.logger).Log("msg", "failed to resolve target", "error", err)
                continue
            }

            for _, m := range matches {
                if exclude != "" {
-                   if match, _ := doublestar.PathMatch(exclude, m); match {
+                   // Normalize exclude to OS-specific separators to preserve previous behavior
+                   if match, _ := doublestar.PathMatch(filepath.FromSlash(exclude), m); match {
                        continue
                    }
                }

Optional hardening (only if your config patterns use forward slashes on Windows):

  • If targets are user-configured with / separators, also normalize the glob pattern before calling Glob:
- matches, err := doublestar.Glob(targetPath)
+ matches, err := doublestar.Glob(filepath.FromSlash(targetPath))

Only apply this if you do accept /-separated patterns on Windows. If your config already provides OS-native separators, keep as-is.

Behavioral notes to verify with tests:

  • Exclusion patterns on Windows still work as before when given with / separators (the normalization above preserves this).
  • Recursive matching over ** and hidden files remains consistent with your expectations. v1 and v4 share doublestar semantics for these primitives for simple use cases like yours, but validate with a couple of representative patterns.
  • You are no longer using any v4-only APIs (e.g., fs.FS-based globbing, option structs). Your code does not reference those, so this looks fine.

Evidence and references:

  • v4 introduced an explicitly OS-aware FilepathGlob(...) API; v1 provides Glob(...) for file system globbing and PathMatch(...) for pattern checks. The code changes in this

🔍 Dependency Review

github.com/bmatcuk/doublestar/v4 v4.9.1 → github.com/bmatcuk/doublestar v1.3.4 — ⚠️ Needs Review

Summary:

  • This PR replaces the v4 module with the legacy v1 module and updates imports and some calls.
  • v4 and v1 differ in API names and path-separator semantics. The changes in this PR switch:
    • FilepathGlob(...) (v4) → Glob(...) (v1)
    • PathMatch(filepath.FromSlash(exclude), ...) (v4) → PathMatch(exclude, ...) (v1) in two places.
  • To maintain existing behavior across platforms (especially Windows), the matching calls should be adjusted to use the OS-aware matcher in v1 and keep pattern normalization.

Why this needs review:

  • In v1.3.x:
    • Glob(pattern) behaves like filepath.Glob, i.e., it is OS/path-separator aware.
    • Match(pattern, name) behaves like filepath.Match (OS-aware) with doublestar’s ** support.
    • PathMatch(pattern, name) behaves like path.Match (POSIX ‘/’ separator) with doublestar’s ** support.
  • In v4, you used FilepathGlob (explicitly OS-aware) and paired it with PathMatch(filepath.FromSlash(exclude), m). After moving to v1, continuing to use PathMatch without normalization changes semantics on non-POSIX systems because PathMatch in v1 uses POSIX-style ‘/’ separators.
  • To preserve behavior when excluding OS-native paths returned by Glob, use Match (OS-aware) and normalize the pattern (if your configs supply forward slashes).

Required code changes (to preserve existing behavior):

  1. internal/component/local/file_match/watch.go
-   matches, err := doublestar.Glob(w.getPath())
+   matches, err := doublestar.Glob(w.getPath())
    if err != nil {
        return nil, err
    }
    exclude := w.getExcludePath()
    for _, m := range matches {
        if exclude != "" {
-           if match, _ := doublestar.PathMatch(exclude, m); match {
+           // Use OS-aware match and normalize pattern to OS separators
+           if match, _ := doublestar.Match(filepath.FromSlash(exclude), m); match {
                continue
            }
        }
  1. internal/component/loki/source/file/resolver.go
-           matches, err := doublestar.Glob(targetPath)
+           matches, err := doublestar.Glob(targetPath)
            if err != nil {
                level.Error(s.logger).Log("msg", "failed to resolve target", "error", err)
                continue
            }

            for _, m := range matches {
                if exclude != "" {
-                   if match, _ := doublestar.PathMatch(exclude, m); match {
+                   // Use OS-aware match and normalize pattern to OS separators
+                   if match, _ := doublestar.Match(filepath.FromSlash(exclude), m); match {
                        continue
                    }
                }

Optional hardening (only if your configuration allows forward-slash patterns on Windows):

  • Normalize targetPath before globbing:
- matches, err := doublestar.Glob(targetPath)
+ matches, err := doublestar.Glob(filepath.FromSlash(targetPath))

Behavior to verify with tests:

  • Exclusion patterns supplied with forward slashes continue to exclude matches on Windows.
  • Recursive patterns using ** resolve the same set of files as before.
  • No use of v4-only APIs (e.g., fs.FS-based globbing/options) remains in the codebase.

Relevant API differences (v1.3.x vs v4):

  • v1.3.x provides:
    • func Glob(pattern string) ([]string, error) — OS-aware globbing (like filepath.Glob) with **.
    • func Match(pattern, name string) (bool, error) — OS-aware matching (like filepath.Match) with **.
    • func PathMatch(pattern, name string) (bool, error) — POSIX ‘/’ matching (like path.Match) with **.
  • v4 introduced FilepathGlob(...) and additional fs/options APIs that are not available in v1. Your code does not use those, so no additional changes are required beyond the matching semantics above.

Notes

  • Both github.com/bmatcuk/doublestar (v1) and github.com/bmatcuk/doublestar/v4 (v4) now appear in the workspace (v4 as indirect). Consider consolidating to a single major version to reduce ambiguity and binary size if possible.

@kalleep kalleep merged commit 0925795 into main Feb 4, 2026
53 of 54 checks passed
@kalleep kalleep deleted the revert-5148-kalleep/doublestar-v4 branch February 4, 2026 13:52
grafana-alloybot bot pushed a commit that referenced this pull request Feb 4, 2026
Reverts #5148

Discovered that updating to v4 introduces regression on windows around
case sensitivity for paths. So we need to revert and look into that
before updating.

(cherry picked from commit 0925795)
kalleep added a commit that referenced this pull request Feb 4, 2026
## Backport of #5434

This PR backports #5434 to release/v1.13.

### Original PR Author
@kalleep

### Description
Reverts #5148

Discovered that updating to v4 introduces regression on windows around
case sensitivity for paths. So we need to revert and look into that
before updating.



---
*This backport was created automatically.*

Co-authored-by: Karl Persson <23356117+kalleep@users.noreply.github.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

backport/v1.13 Backport to release/v1.13 frozen-due-to-age

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants