Skip to content

Commit

Permalink
feat(scanner): support full scan cleanups in watcher (#496)
Browse files Browse the repository at this point in the history
* Added code to trigger rescan of entire tree upon file removal to clean as needed.

* Simplified ScanOptions initialization. Removed broken linter.

* gofmt fix
  • Loading branch information
brian-doherty committed Apr 21, 2024
1 parent 38ab0b0 commit 93ce039
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 0 additions & 1 deletion .golangci.yml
Expand Up @@ -45,7 +45,6 @@ linters:
- makezero
- mirror
- misspell
- musttag
- nakedret
- nestif
- nilerr
Expand Down
Binary file added cmd/gonic/gonic
Binary file not shown.
13 changes: 13 additions & 0 deletions scanner/scanner.go
Expand Up @@ -134,9 +134,18 @@ func (s *Scanner) ExecuteWatch(ctx context.Context) error {
}

batchSeen := map[string]struct{}{}
batchClean := false
for {
select {
case <-batchT.C:
if batchClean {
if _, err := s.ScanAndClean(ScanOptions{}); err != nil {
log.Printf("error scanning: %v", err)
}
clear(batchSeen)
batchClean = false
break
}
if !s.StartScanning() {
break
}
Expand Down Expand Up @@ -164,6 +173,10 @@ func (s *Scanner) ExecuteWatch(ctx context.Context) error {
clear(batchSeen)

case event := <-watcher.Events:
if event.Op&(fsnotify.Remove) == fsnotify.Remove {
batchClean = true
break
}
if event.Op&(fsnotify.Create|fsnotify.Write) == 0 {
break
}
Expand Down

0 comments on commit 93ce039

Please sign in to comment.