git.iko.soy/typeable/oauth2-proxy
on master help sign in
Remove file watch upon interruption
020a35eMike Bland
watcher.go+8−6
@@ -12,17 +12,18 @@ import (
12 "gopkg.in/fsnotify.v1"
12 "gopkg.in/fsnotify.v1"
13)
13)
14
14
15−func WaitForReplacement(event fsnotify.Event, watcher *fsnotify.Watcher) {
15+func WaitForReplacement(filename string, op fsnotify.Op,
16+ watcher *fsnotify.Watcher) {
16 const sleep_interval = 50 * time.Millisecond
17 const sleep_interval = 50 * time.Millisecond
17
18
18 // Avoid a race when fsnofity.Remove is preceded by fsnotify.Chmod.
19 // Avoid a race when fsnofity.Remove is preceded by fsnotify.Chmod.
19− if event.Op&fsnotify.Chmod != 0 {
20+ if op&fsnotify.Chmod != 0 {
20 time.Sleep(sleep_interval)
21 time.Sleep(sleep_interval)
21 }
22 }
22 for {
23 for {
23− if _, err := os.Stat(event.Name); err == nil {
24+ if _, err := os.Stat(filename); err == nil {
24− if err := watcher.Add(event.Name); err == nil {
25+ if err := watcher.Add(filename); err == nil {
25− log.Printf("watching resumed for %s", event.Name)
26+ log.Printf("watching resumed for %s", filename)
26 return
27 return
27 }
28 }
28 }
29 }
@@ -52,7 +53,8 @@ func WatchForUpdates(filename string, done <-chan bool, action func()) bool {
52 // can't be opened.
53 // can't be opened.
53 if event.Op&(fsnotify.Remove|fsnotify.Rename|fsnotify.Chmod) != 0 {
54 if event.Op&(fsnotify.Remove|fsnotify.Rename|fsnotify.Chmod) != 0 {
54 log.Printf("watching interrupted on event: %s", event)
55 log.Printf("watching interrupted on event: %s", event)
56+ watcher.Remove(filename)
55− WaitForReplacement(event, watcher)
57+ WaitForReplacement(filename, event.Op, watcher)
56 }
58 }
57 log.Printf("reloading after event: %s", event)
59 log.Printf("reloading after event: %s", event)
58 action()
60 action()