Skip to content

Commit

Permalink
Use FilepathGlob, as it is a built in helper function to mimic the ol…
Browse files Browse the repository at this point in the history
…der behavior
  • Loading branch information
paul1r committed Nov 19, 2024
1 parent b3817d0 commit fa2cf3b
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions clients/pkg/promtail/targets/file/filetarget.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,40 +246,21 @@ func (t *FileTarget) sync() error {
matches = []string{t.path}
} else {
// Gets current list of files to tail.
base, pattern := doublestar.SplitPattern(t.path)
relMatches, err := doublestar.Glob(os.DirFS(base), pattern)
matches, err = doublestar.FilepathGlob(t.path)

if err != nil {
return errors.Wrap(err, "filetarget.sync.filepath.Glob")
}
// Convert relative paths to absolute
matches = make([]string, len(relMatches))
for i, match := range relMatches {
matches[i] = filepath.Join(base, match)
matches[i], err = filepath.Abs(matches[i])
if err != nil {
return errors.Wrap(err, "filetarget.sync.filepath.Abs")
}
}
}

if fi, err := os.Stat(t.pathExclude); err == nil && !fi.IsDir() {
matchesExcluded = []string{t.pathExclude}
} else {
base, pattern := doublestar.SplitPattern(t.pathExclude)
relMatchesExcluded, err := doublestar.Glob(os.DirFS(base), pattern)
//matchesExcluded, err = doublestar.Glob(os.DirFS("/"), t.pathExclude)
matchesExcluded, err = doublestar.FilepathGlob(t.pathExclude)

if err != nil {
return errors.Wrap(err, "filetarget.sync.filepathexclude.Glob")
}
// Convert relative paths to absolute
matchesExcluded = make([]string, len(relMatchesExcluded))
for i, match := range relMatchesExcluded {
matchesExcluded[i] = filepath.Join(base, match)
matchesExcluded[i], err = filepath.Abs(matchesExcluded[i])
if err != nil {
return errors.Wrap(err, "filetarget.sync.filepath.Abs")
}
}
}

for i := 0; i < len(matchesExcluded); i++ {
Expand Down

0 comments on commit fa2cf3b

Please sign in to comment.