diff --git a/shards/watcher.go b/shards/watcher.go index e8cde2e53..786548dcf 100644 --- a/shards/watcher.go +++ b/shards/watcher.go @@ -216,21 +216,38 @@ func (s *DirectoryWatcher) watch() error { signal := make(chan struct{}, 1) go func() { + notify := func() { + select { + case signal <- struct{}{}: + default: + } + } + + ticker := time.NewTicker(time.Minute) + for { select { - case <-watcher.Events: - select { - case signal <- struct{}{}: - default: + case event := <-watcher.Events: + // Only notify if a file we read in has changed. This is important to + // avoid all the events writing to temporary files. + if strings.HasSuffix(event.Name, ".zoekt") { + notify() } + + case <-ticker.C: + // Periodically just double check the disk + notify() + case err := <-watcher.Errors: // Ignore ErrEventOverflow since we rely on the presence of events so // safe to ignore. if err != nil && err != fsnotify.ErrEventOverflow { log.Println("watcher error:", err) } + case <-s.quit: watcher.Close() + ticker.Stop() close(signal) return }