feat(scanner): support full scan cleanups in watcher (#496)

* Added code to trigger rescan of entire tree upon file removal to clean as needed.

* Simplified ScanOptions initialization. Removed broken linter.

* gofmt fix
This commit is contained in:
brian-doherty
2024-04-20 19:04:53 -05:00
committed by GitHub
parent 38ab0b0929
commit 93ce039963
3 changed files with 13 additions and 1 deletions

View File

@@ -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
}
@@ -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
}