|
@@ -1,12 +1,13 @@
|
|
|
package main
|
|
|
|
|
|
import (
|
|
|
- "code.google.com/p/gcfg"
|
|
|
"fmt"
|
|
|
- "github.com/howeyc/fsnotify"
|
|
|
"log"
|
|
|
"os"
|
|
|
"time"
|
|
|
+
|
|
|
+ "code.google.com/p/gcfg"
|
|
|
+ "gopkg.in/fsnotify.v1"
|
|
|
)
|
|
|
|
|
|
type AppConfig struct {
|
|
@@ -33,21 +34,26 @@ func configWatcher(fileName string) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if err := watcher.Watch(*flagconfig); err != nil {
|
|
|
+ if err := watcher.Add(*flagconfig); err != nil {
|
|
|
fmt.Println(err)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
for {
|
|
|
select {
|
|
|
- case ev := <-watcher.Event:
|
|
|
+ case ev := <-watcher.Events:
|
|
|
if ev.Name == fileName {
|
|
|
- if ev.IsCreate() || ev.IsModify() || ev.IsRename() {
|
|
|
+ // Write = when the file is updated directly
|
|
|
+ // Rename = when it's updated atomicly
|
|
|
+ // Chmod = for `touch`
|
|
|
+ if ev.Op&fsnotify.Write == fsnotify.Write ||
|
|
|
+ ev.Op&fsnotify.Rename == fsnotify.Rename ||
|
|
|
+ ev.Op&fsnotify.Chmod == fsnotify.Chmod {
|
|
|
time.Sleep(200 * time.Millisecond)
|
|
|
configReader(fileName)
|
|
|
}
|
|
|
}
|
|
|
- case err := <-watcher.Error:
|
|
|
+ case err := <-watcher.Errors:
|
|
|
log.Println("fsnotify error:", err)
|
|
|
}
|
|
|
}
|