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:
@@ -45,7 +45,6 @@ linters:
|
|||||||
- makezero
|
- makezero
|
||||||
- mirror
|
- mirror
|
||||||
- misspell
|
- misspell
|
||||||
- musttag
|
|
||||||
- nakedret
|
- nakedret
|
||||||
- nestif
|
- nestif
|
||||||
- nilerr
|
- nilerr
|
||||||
|
|||||||
BIN
cmd/gonic/gonic
Executable file
BIN
cmd/gonic/gonic
Executable file
Binary file not shown.
@@ -134,9 +134,18 @@ func (s *Scanner) ExecuteWatch(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
batchSeen := map[string]struct{}{}
|
batchSeen := map[string]struct{}{}
|
||||||
|
batchClean := false
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-batchT.C:
|
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() {
|
if !s.StartScanning() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -164,6 +173,10 @@ func (s *Scanner) ExecuteWatch(ctx context.Context) error {
|
|||||||
clear(batchSeen)
|
clear(batchSeen)
|
||||||
|
|
||||||
case event := <-watcher.Events:
|
case event := <-watcher.Events:
|
||||||
|
if event.Op&(fsnotify.Remove) == fsnotify.Remove {
|
||||||
|
batchClean = true
|
||||||
|
break
|
||||||
|
}
|
||||||
if event.Op&(fsnotify.Create|fsnotify.Write) == 0 {
|
if event.Op&(fsnotify.Create|fsnotify.Write) == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user