1// +build go1.3,!plan9,!solaris
10 "github.com/fsnotify/fsnotify"
12 "github.com/oauth2-proxy/oauth2-proxy/pkg/logger"
15// WaitForReplacement waits for a file to exist on disk and then starts a watch
17func WaitForReplacement(filename string, op fsnotify.Op,
18 watcher *fsnotify.Watcher) {
19 const sleepInterval = 50 * time.Millisecond
21 // Avoid a race when fsnofity.Remove is preceded by fsnotify.Chmod.
22 if op&fsnotify.Chmod != 0 {
23 time.Sleep(sleepInterval)
26 if _, err := os.Stat(filename); err == nil {
27 if err := watcher.Add(filename); err == nil {
28 logger.Printf("watching resumed for %s", filename)
32 time.Sleep(sleepInterval)
36// WatchForUpdates performs an action every time a file on disk is updated
37func WatchForUpdates(filename string, done <-chan bool, action func()) {
38 filename = filepath.Clean(filename)
39 watcher, err := fsnotify.NewWatcher()
41 logger.Fatal("failed to create watcher for ", filename, ": ", err)
48 logger.Printf("Shutting down watcher for: %s", filename)
50 case event := <-watcher.Events:
51 // On Arch Linux, it appears Chmod events precede Remove events,
52 // which causes a race between action() and the coming Remove event.
53 // If the Remove wins, the action() (which calls
54 // UserMap.LoadAuthenticatedEmailsFile()) crashes when the file
56 if event.Op&(fsnotify.Remove|fsnotify.Rename|fsnotify.Chmod) != 0 {
57 logger.Printf("watching interrupted on event: %s", event)
58 watcher.Remove(filename)
59 WaitForReplacement(filename, event.Op, watcher)
61 logger.Printf("reloading after event: %s", event)
63 case err = <-watcher.Errors:
64 logger.Printf("error watching %s: %s", filename, err)
68 if err = watcher.Add(filename); err != nil {
69 logger.Fatal("failed to add ", filename, " to watcher: ", err)
71 logger.Printf("watching %s for updates", filename)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list