diff options
Diffstat (limited to 'watcher.go')
| -rw-r--r-- | watcher.go | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -18,7 +18,8 @@ func watch(ctx context.Context, hostDir, dataDir string, manifest *Manifest, sta defer watcher.Close() var mu sync.Mutex - debounce := make(map[string]*time.Timer) + debounceTimers := make(map[string]*time.Timer) + debounceOps := make(map[string]fsnotify.Op) if err := addWatchersRecursively(watcher, hostDir, stack); err != nil { return err @@ -50,14 +51,20 @@ func watch(ctx context.Context, hostDir, dataDir string, manifest *Manifest, sta logDebug("event: %s %s", event.Op, relPath) mu.Lock() - if t, exists := debounce[relPath]; exists { - t.Stop() + if existing, exists := debounceOps[relPath]; exists { + debounceTimers[relPath].Stop() + debounceOps[relPath] = existing | event.Op + } else { + debounceOps[relPath] = event.Op } - debounce[relPath] = time.AfterFunc(200*time.Millisecond, func() { + path := relPath + debounceTimers[relPath] = time.AfterFunc(200*time.Millisecond, func() { mu.Lock() - delete(debounce, relPath) + op := debounceOps[path] + delete(debounceOps, path) + delete(debounceTimers, path) mu.Unlock() - handleEvent(event.Op, hostDir, dataDir, relPath, manifest, stack, dryRun, watcher) + handleEvent(op, hostDir, dataDir, path, manifest, stack, dryRun, watcher) }) mu.Unlock() |
