]> go.fuhry.dev Git - fsnotify.git/commitdiff
kqueue: split off newCreateEvent
authorNathan Youngman <git@nathany.com>
Sun, 14 Sep 2014 22:01:22 +0000 (16:01 -0600)
committerNathan Youngman <git@nathany.com>
Wed, 24 Sep 2014 21:34:04 +0000 (15:34 -0600)
more clear.

kqueue.go

index 0cb7693f422086bae704baa7116332b10fa528a1..e72985b399813aca9cb49284825bee3795960dc0 100644 (file)
--- 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)