Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for new fsnotify #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions cmd/gondola/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -260,36 +260,29 @@ 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
// for a file when saving it, so we must watch the
// 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 {
Expand All @@ -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
}
}
}()
Expand Down
11 changes: 6 additions & 5 deletions cmd/gondola/gae.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strconv"
"strings"

"code.google.com/p/go.exp/fsnotify"
"github.com/go-fsnotify/fsnotify"

"gnd.la/log"
)
Expand Down Expand Up @@ -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)
Expand Down