aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--watcher.go19
1 files changed, 13 insertions, 6 deletions
diff --git a/watcher.go b/watcher.go
index 8c8177e..68a1a1b 100644
--- a/watcher.go
+++ b/watcher.go
@@ -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()