Skip to content

Commit

Permalink
Merge c622a36 into 4d16730
Browse files Browse the repository at this point in the history
  • Loading branch information
rjeczalik committed Feb 8, 2015
2 parents 4d16730 + c622a36 commit fea16b7
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions watcher_fsevents.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"sync/atomic"
)

// TODO(rjeczalik): get rid of calls to canonical, it's tree responsibility

const (
failure = uint32(FSEventsMustScanSubDirs | FSEventsUserDropped | FSEventsKernelDropped)
filter = uint32(FSEventsCreated | FSEventsRemoved | FSEventsRenamed |
Expand Down Expand Up @@ -138,7 +140,8 @@ func (w *watch) Dispatch(ev []FSEvent) {
if !strings.HasPrefix(ev[i].Path, w.path) {
continue
}
n, base := len(w.path), ""
n := len(w.path)
base := ""
if len(ev[i].Path) > n {
if ev[i].Path[n] != '/' {
continue
Expand Down Expand Up @@ -179,7 +182,7 @@ func newWatcher(c chan<- EventInfo) watcher {

func (fse *fsevents) watch(path string, event Event, isrec int32) (err error) {
if path, err = canonical(path); err != nil {
return
return err
}
if _, ok := fse.watches[path]; ok {
return errAlreadyWatched
Expand All @@ -193,7 +196,7 @@ func (fse *fsevents) watch(path string, event Event, isrec int32) (err error) {
}
w.stream = newStream(path, w.Dispatch)
if err = w.stream.Start(); err != nil {
return
return err
}
fse.watches[path] = w
return nil
Expand Down Expand Up @@ -236,6 +239,7 @@ func (fse *fsevents) Rewatch(path string, oldevent, newevent Event) error {
if !atomic.CompareAndSwapUint32(&w.events, uint32(oldevent), uint32(newevent)) {
return errInvalidEventSet
}
atomic.StoreInt32(&w.isrec, 0)
return nil
}

Expand Down Expand Up @@ -271,7 +275,7 @@ func (fse *fsevents) RecursiveRewatch(oldpath, newpath string, oldevent, neweven
if !ok {
return errNotWatched
}
atomic.CompareAndSwapInt32(&w.isrec, 0, 1)
atomic.StoreInt32(&w.isrec, 1)
return nil
case [2]bool{true, false}:
w, ok := fse.watches[oldpath]
Expand All @@ -281,7 +285,7 @@ func (fse *fsevents) RecursiveRewatch(oldpath, newpath string, oldevent, neweven
if !atomic.CompareAndSwapUint32(&w.events, uint32(oldevent), uint32(newevent)) {
return errors.New("invalid event state diff")
}
atomic.CompareAndSwapInt32(&w.isrec, 0, 1)
atomic.StoreInt32(&w.isrec, 1)
return nil
default:
// TODO(rjeczalik): rewatch newpath only if exists?
Expand Down

0 comments on commit fea16b7

Please sign in to comment.