Fix config watch
* Only add *the* config file, not all possible folders
* Trigger reload on both write and create events;
the latter is what we get from atomic save editors (like TextMate) once https://github.com/go-fsnotify/fsnotify/pull/111 is merged
See #142
diff --git a/viper.go b/viper.go
index 389a58e..68ebf8c 100644
--- a/viper.go
+++ b/viper.go
@@ -242,7 +242,7 @@
for {
select {
case event := <-watcher.Events:
- if event.Op&fsnotify.Write == fsnotify.Write {
+ if event.Op&fsnotify.Write == fsnotify.Write || event.Op&fsnotify.Create == fsnotify.Create {
err := v.ReadInConfig()
if err != nil {
log.Println("error:", err)
@@ -255,16 +255,7 @@
}
}()
- if v.configFile != "" {
- watcher.Add(v.configFile)
- } else {
- for _, x := range v.configPaths {
- err = watcher.Add(x)
- if err != nil {
- log.Fatal(err)
- }
- }
- }
+ watcher.Add(v.getConfigFile())
<-done
}()
}