From eec099e200d2cca0363364a9b15b44483ba34334 Mon Sep 17 00:00:00 2001 From: Nathan Youngman Date: Sun, 14 Sep 2014 16:01:22 -0600 Subject: [PATCH] kqueue: split off newCreateEvent more clear. --- kqueue.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/kqueue.go b/kqueue.go index 0cb7693..e72985b 100644 --- a/kqueue.go +++ b/kqueue.go @@ -282,13 +282,15 @@ func (w *Watcher) readEvents() { // Flush the events we received to the Events channel for len(kevents) > 0 { watchEvent := &kevents[0] + watchfd := int(watchEvent.Ident) mask := uint32(watchEvent.Fflags) + w.pmut.Lock() - name := w.paths[int(watchEvent.Ident)] - fileInfo := w.finfo[int(watchEvent.Ident)] + name := w.paths[watchfd] + fileInfo := w.finfo[watchfd] w.pmut.Unlock() - event := newEvent(name, mask, false) + event := newEvent(name, mask) if fileInfo != nil && fileInfo.IsDir() && !(event.Op&Remove == Remove) { // Double check to make sure the directory exist. This can happen when @@ -345,11 +347,8 @@ func (w *Watcher) readEvents() { } // newEvent returns an platform-independent Event based on kqueue Fflags. -func newEvent(name string, mask uint32, create bool) Event { +func newEvent(name string, mask uint32) Event { e := Event{Name: name} - if create { - e.Op |= Create - } if mask&syscall.NOTE_DELETE == syscall.NOTE_DELETE { e.Op |= Remove } @@ -365,6 +364,10 @@ func newEvent(name string, mask uint32, create bool) Event { return e } +func newCreateEvent(name string) Event { + return Event{Name: name, Op: Create} +} + // watchDirectoryFiles to mimic inotify when adding a watch on a directory func (w *Watcher) watchDirectoryFiles(dirPath string) error { // Get all files @@ -405,9 +408,8 @@ func (w *Watcher) sendDirectoryChangeEvents(dirPath string) { _, doesExist := w.fileExists[filePath] w.femut.Unlock() if !doesExist { - // Send create event (mask=0) - event := newEvent(filePath, 0, true) - w.Events <- event + // Send create event + w.Events <- newCreateEvent(filePath) } // like watchDirectoryFiles (but without doing another ReadDir) -- 2.50.1