@@ -12,17 +12,18 @@ import (
1212 "gopkg.in/fsnotify.v1"
1313)
1414
15−func WaitForReplacement(event fsnotify.Event, watcher *fsnotify.Watcher) {
15+func WaitForReplacement(filename string, op fsnotify.Op,
16+ watcher *fsnotify.Watcher) {
1617 const sleep_interval = 50 * time.Millisecond
1718
1819 // Avoid a race when fsnofity.Remove is preceded by fsnotify.Chmod.
19− if event.Op&fsnotify.Chmod != 0 {
20+ if op&fsnotify.Chmod != 0 {
2021 time.Sleep(sleep_interval)
2122 }
2223 for {
23− if _, err := os.Stat(event.Name); err == nil {
24− if err := watcher.Add(event.Name); err == nil {
25− log.Printf("watching resumed for %s", event.Name)
24+ if _, err := os.Stat(filename); err == nil {
25+ if err := watcher.Add(filename); err == nil {
26+ log.Printf("watching resumed for %s", filename)
2627 return
2728 }
2829 }
@@ -52,7 +53,8 @@ func WatchForUpdates(filename string, done <-chan bool, action func()) bool {
5253 // can't be opened.
5354 if event.Op&(fsnotify.Remove|fsnotify.Rename|fsnotify.Chmod) != 0 {
5455 log.Printf("watching interrupted on event: %s", event)
55− WaitForReplacement(event, watcher)
56+ watcher.Remove(filename)
57+ WaitForReplacement(filename, event.Op, watcher)
5658 }
5759 log.Printf("reloading after event: %s", event)
5860 action()