Skip to content

Commit

Permalink
Update fsnotify package
Browse files Browse the repository at this point in the history
  • Loading branch information
abh committed Oct 19, 2014
1 parent f21ae42 commit 4755f70
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions config.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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)
}
}
Expand Down

0 comments on commit 4755f70

Please sign in to comment.