From b23818a1f517aabf4465a60d5376c5793a35ca9c Mon Sep 17 00:00:00 2001 From: mattn Date: Thu, 6 Nov 2014 10:03:08 +0900 Subject: [PATCH] Fixes for new fsnotify --- cmd/gondola/dev.go | 26 +++++++++++--------------- cmd/gondola/gae.go | 11 ++++++----- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/cmd/gondola/dev.go b/cmd/gondola/dev.go index 5aa65fd..bd9978c 100644 --- a/cmd/gondola/dev.go +++ b/cmd/gondola/dev.go @@ -23,7 +23,7 @@ import ( "syscall" "time" - "code.google.com/p/go.exp/fsnotify" + "github.com/go-fsnotify/fsnotify" "gnd.la/app" "gnd.la/config" "gnd.la/internal/runtimeutil" @@ -260,27 +260,20 @@ func (p *Project) StartMonitoring() error { toWatch = generic.Map(pkgs, func(pkg *build.Package) string { return pkg.Dir }).([]string) } for _, v := range toWatch { - if err := watcher.Watch(v); err != nil { + if err := watcher.Add(v); err != nil { return err } } - watcher.Watch(p.configPath) + watcher.Add(p.configPath) p.watcher = watcher go func() { var t *time.Timer finished: for { select { - case ev := <-watcher.Event: - if ev == nil { - // Closed - break finished - } - if ev.IsAttrib() { - break - } + case ev := <-watcher.Events: if ev.Name == p.configPath { - if ev.IsDelete() { + if ev.Op == fsnotify.Remove { // It seems the Watcher stops watching a file // if it receives a DELETE event for it. For some // reason, some editors generate a DELETE event @@ -288,8 +281,8 @@ func (p *Project) StartMonitoring() error { // file again. Since fsnotify is in exp/ and its // API might change, remove the watch first, just // in case. - watcher.RemoveWatch(ev.Name) - watcher.Watch(ev.Name) + watcher.Remove(ev.Name) + watcher.Add(ev.Name) } else { log.Infof("Config file %s changed, restarting...", p.configPath) if err := p.Stop(); err != nil { @@ -310,12 +303,15 @@ func (p *Project) StartMonitoring() error { p.Build() }) } - case err := <-watcher.Error: + case err := <-watcher.Errors: if err == nil { // Closed break finished } log.Errorf("Error watching: %s", err) + default: + // Closed + break finished } } }() diff --git a/cmd/gondola/gae.go b/cmd/gondola/gae.go index 17cb5b5..60d5e74 100644 --- a/cmd/gondola/gae.go +++ b/cmd/gondola/gae.go @@ -10,7 +10,7 @@ import ( "strconv" "strings" - "code.google.com/p/go.exp/fsnotify" + "github.com/go-fsnotify/fsnotify" "gnd.la/log" ) @@ -96,15 +96,16 @@ func watchAppResources(buildArgs []string, resources []string) error { return err } for _, v := range resources { - w.Watch(v) + w.Add(v) } for { select { - case e := <-w.Error: + case e := <-w.Errors: return e - case ev := <-w.Event: + case ev := <-w.Events: name := filepath.Base(ev.Name) - if strings.HasPrefix(name, ".") || strings.HasSuffix(name, "~") || ev.IsAttrib() || ev.IsDelete() || ev.IsRename() { + op := ev.Op + if strings.HasPrefix(name, ".") || strings.HasSuffix(name, "~") || op == fsnotify.Remove || op == fsnotify.Rename { continue } makeAppAssets(buildArgs)