Skip to content

Commit

Permalink
check dir files in notify by base paths from include patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryRomanov committed Mar 5, 2024
1 parent 9945f6a commit 0e46da7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ require (
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137
github.com/alicebob/miniredis/v2 v2.30.5
github.com/bitly/go-simplejson v0.5.1
github.com/bmatcuk/doublestar/v4 v4.0.2
github.com/cenkalti/backoff/v4 v4.2.1
github.com/cespare/xxhash/v2 v2.2.0
github.com/bmatcuk/doublestar/v4 v4.0.2
github.com/euank/go-kmsg-parser v2.0.0+incompatible
github.com/go-redis/redis v6.15.9+incompatible
github.com/golang/mock v1.6.0
Expand Down
6 changes: 3 additions & 3 deletions plugin/input/file/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ func TestProvierWatcherPaths(t *testing.T) {
config := tt.config
test.NewConfig(config, map[string]int{"gomaxprocs": runtime.GOMAXPROCS(0)})
metrics := newMetricCollection(
ctl.RegisterCounter("worker", "help_test"),
ctl.RegisterCounter("worker", "help_test"),
ctl.RegisterGauge("worker", "help_test"),
ctl.RegisterCounter("worker1", "help_test"),
ctl.RegisterCounter("worker2", "help_test"),
ctl.RegisterGauge("worker3", "help_test"),
)
jp := NewJobProvider(config, metrics, &zap.SugaredLogger{})

Expand Down
16 changes: 16 additions & 0 deletions plugin/input/file/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,12 @@ func (w *watcher) notify(e notify.Event, path string) {

if stat.IsDir() {
dirFilename := filename
check_dir:
for {
for _, path := range w.basePaths {
if path == dirFilename {
w.tryAddPath(filename)
break check_dir
}
}
if dirFilename == w.commonPath {
Expand All @@ -166,6 +168,20 @@ func (w *watcher) notify(e notify.Event, path string) {
return
}

dirFilename := filepath.Dir(filename)
check_file:
for {
for _, path := range w.basePaths {
if path == dirFilename {
break check_file
}
}
if dirFilename == w.commonPath {
return
}

Check warning on line 181 in plugin/input/file/watcher.go

View check run for this annotation

Codecov / codecov/patch

plugin/input/file/watcher.go#L180-L181

Added lines #L180 - L181 were not covered by tests
dirFilename = filepath.Dir(dirFilename)
}

w.logger.Infof("%s %s", e, path)

for _, pattern := range w.paths.Include {
Expand Down
1 change: 1 addition & 0 deletions plugin/input/file/watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func TestWatcher(t *testing.T) {
}
}

// nolint:gocritic
func TestWatcherPaths(t *testing.T) {
dir := t.TempDir()
shouldCreate := atomic.Int64{}
Expand Down

0 comments on commit 0e46da7

Please sign in to comment.