Skip to content

Commit 93ce039

Browse files
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
1 parent 38ab0b0 commit 93ce039

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ linters:
4545
- makezero
4646
- mirror
4747
- misspell
48-
- musttag
4948
- nakedret
5049
- nestif
5150
- nilerr

cmd/gonic/gonic

23.4 MB
Binary file not shown.

scanner/scanner.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,18 @@ func (s *Scanner) ExecuteWatch(ctx context.Context) error {
134134
}
135135

136136
batchSeen := map[string]struct{}{}
137+
batchClean := false
137138
for {
138139
select {
139140
case <-batchT.C:
141+
if batchClean {
142+
if _, err := s.ScanAndClean(ScanOptions{}); err != nil {
143+
log.Printf("error scanning: %v", err)
144+
}
145+
clear(batchSeen)
146+
batchClean = false
147+
break
148+
}
140149
if !s.StartScanning() {
141150
break
142151
}
@@ -164,6 +173,10 @@ func (s *Scanner) ExecuteWatch(ctx context.Context) error {
164173
clear(batchSeen)
165174

166175
case event := <-watcher.Events:
176+
if event.Op&(fsnotify.Remove) == fsnotify.Remove {
177+
batchClean = true
178+
break
179+
}
167180
if event.Op&(fsnotify.Create|fsnotify.Write) == 0 {
168181
break
169182
}

0 commit comments

Comments
 (0)