diff --git a/.chloggen/fix-stanza-finder-windows.yaml b/.chloggen/fix-stanza-finder-windows.yaml new file mode 100644 index 000000000000..6c783f36324a --- /dev/null +++ b/.chloggen/fix-stanza-finder-windows.yaml @@ -0,0 +1,11 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: pkg/stanza + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Fix support of include/exclude patterns with "\" separators on Windows. + +# One or more tracking issues related to the change +issues: [14754] diff --git a/pkg/stanza/fileconsumer/finder.go b/pkg/stanza/fileconsumer/finder.go index b7ac16508035..17600f36fbb8 100644 --- a/pkg/stanza/fileconsumer/finder.go +++ b/pkg/stanza/fileconsumer/finder.go @@ -15,9 +15,6 @@ package fileconsumer // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/fileconsumer" import ( - "os" - "path/filepath" - "github.com/bmatcuk/doublestar/v4" ) @@ -30,14 +27,11 @@ type Finder struct { func (f Finder) FindFiles() []string { all := make([]string, 0, len(f.Include)) for _, include := range f.Include { - basepath, pattern := doublestar.SplitPattern(include) - fsys := os.DirFS(basepath) - matches, _ := doublestar.Glob(fsys, pattern) // compile error checked in build + matches, _ := doublestar.FilepathGlob(include) // compile error checked in build INCLUDE: for _, match := range matches { for _, exclude := range f.Exclude { - _, pattern = doublestar.SplitPattern(exclude) - if itMatches, _ := doublestar.PathMatch(pattern, match); itMatches { + if itMatches, _ := doublestar.PathMatch(exclude, match); itMatches { continue INCLUDE } } @@ -48,7 +42,7 @@ func (f Finder) FindFiles() []string { } } - all = append(all, filepath.Join(basepath, match)) + all = append(all, match) } } diff --git a/pkg/stanza/fileconsumer/finder_test.go b/pkg/stanza/fileconsumer/finder_test.go index dc4ec8170342..c5b7cfd1b60c 100644 --- a/pkg/stanza/fileconsumer/finder_test.go +++ b/pkg/stanza/fileconsumer/finder_test.go @@ -96,31 +96,31 @@ func TestFinder(t *testing.T) { }, { name: "IncludeMultipleDirectories", - files: []string{"a/1.log", "a/2.log", "b/1.log", "b/2.log"}, - include: []string{"a/*.log", "b/*.log"}, + files: []string{filepath.Join("a", "1.log"), filepath.Join("a", "2.log"), filepath.Join("b", "1.log"), filepath.Join("b", "2.log")}, + include: []string{filepath.Join("a", "*.log"), filepath.Join("b", "*.log")}, exclude: []string{}, - expected: []string{"a/1.log", "a/2.log", "b/1.log", "b/2.log"}, + expected: []string{filepath.Join("a", "1.log"), filepath.Join("a", "2.log"), filepath.Join("b", "1.log"), filepath.Join("b", "2.log")}, }, { name: "IncludeMultipleDirectoriesVaryingDepth", - files: []string{"1.log", "a/1.log", "a/b/1.log", "c/1.log"}, - include: []string{"*.log", "a/*.log", "a/b/*.log", "c/*.log"}, + files: []string{"1.log", filepath.Join("a", "1.log"), filepath.Join("a", "b", "1.log"), filepath.Join("c", "1.log")}, + include: []string{"*.log", filepath.Join("a", "*.log"), filepath.Join("a", "b", "*.log"), filepath.Join("c", "*.log")}, exclude: []string{}, - expected: []string{"1.log", "a/1.log", "a/b/1.log", "c/1.log"}, + expected: []string{"1.log", filepath.Join("a", "1.log"), filepath.Join("a", "b", "1.log"), filepath.Join("c", "1.log")}, }, { name: "DoubleStarSameDepth", - files: []string{"a/1.log", "b/1.log", "c/1.log"}, - include: []string{"**/*.log"}, + files: []string{filepath.Join("a", "1.log"), filepath.Join("b", "1.log"), filepath.Join("c", "1.log")}, + include: []string{filepath.Join("**", "*.log")}, exclude: []string{}, - expected: []string{"a/1.log", "b/1.log", "c/1.log"}, + expected: []string{filepath.Join("a", "1.log"), filepath.Join("b", "1.log"), filepath.Join("c", "1.log")}, }, { name: "DoubleStarVaryingDepth", - files: []string{"1.log", "a/1.log", "a/b/1.log", "c/1.log"}, - include: []string{"**/*.log"}, + files: []string{"1.log", filepath.Join("a", "1.log"), filepath.Join("a", "b", "1.log"), filepath.Join("c", "1.log")}, + include: []string{filepath.Join("**", "*.log")}, exclude: []string{}, - expected: []string{"1.log", "a/1.log", "a/b/1.log", "c/1.log"}, + expected: []string{"1.log", filepath.Join("a", "1.log"), filepath.Join("a", "b", "1.log"), filepath.Join("c", "1.log")}, }, }