1// +build go1.3,!plan9,!solaris
11 "gopkg.in/fsnotify.v1"
14func WaitForReplacement(filename string, op fsnotify.Op,
15 watcher *fsnotify.Watcher) {
16 const sleep_interval = 50 * time.Millisecond
18 // Avoid a race when fsnofity.Remove is preceded by fsnotify.Chmod.
19 if op&fsnotify.Chmod != 0 {
20 time.Sleep(sleep_interval)
23 if _, err := os.Stat(filename); err == nil {
24 if err := watcher.Add(filename); err == nil {
25 log.Printf("watching resumed for %s", filename)
29 time.Sleep(sleep_interval)
33func WatchForUpdates(filename string, done <-chan bool, action func()) {
34 filename = filepath.Clean(filename)
35 watcher, err := fsnotify.NewWatcher()
37 log.Fatal("failed to create watcher for ", filename, ": ", err)
44 log.Printf("Shutting down watcher for: %s", filename)
46 case event := <-watcher.Events:
47 // On Arch Linux, it appears Chmod events precede Remove events,
48 // which causes a race between action() and the coming Remove event.
49 // If the Remove wins, the action() (which calls
50 // UserMap.LoadAuthenticatedEmailsFile()) crashes when the file
52 if event.Op&(fsnotify.Remove|fsnotify.Rename|fsnotify.Chmod) != 0 {
53 log.Printf("watching interrupted on event: %s", event)
54 watcher.Remove(filename)
55 WaitForReplacement(filename, event.Op, watcher)
57 log.Printf("reloading after event: %s", event)
59 case err := <-watcher.Errors:
60 log.Printf("error watching %s: %s", filename, err)
64 if err = watcher.Add(filename); err != nil {
65 log.Fatal("failed to add ", filename, " to watcher: ", err)
67 log.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