]> go.fuhry.dev Git - fsnotify.git/commitdiff
Linux: added create and rule to ignore ignored events
authorChris Howey <chris@howey.me>
Mon, 17 Oct 2011 19:21:44 +0000 (12:21 -0700)
committerChris Howey <chris@howey.me>
Mon, 17 Oct 2011 19:21:44 +0000 (12:21 -0700)
fsnotify.go
fsnotify_linux.go

index f3e43213ba77a0c6d0d8d06a9ad904de4995eea7..1381c2a7d7979d928db8cb12abfd430a119aac2b 100644 (file)
@@ -7,6 +7,10 @@ import "fmt"
 func (e *FileEvent) String() string {
        var events string = ""
 
+       if e.IsCreate() {
+               events += "|" + "CREATE"
+       }
+
        if e.IsDelete() {
                events += "|" + "DELETE"
        }
index ffb139048b3ec97ab5a4cf8f0f18353b03a02a6e..d2b17c3b970a056f164085c2095783de26be5733 100644 (file)
@@ -40,8 +40,13 @@ type FileEvent struct {
        Name   string // File name (optional)
 }
 
+// IsCreate reports whether the FileEvent was triggerd by a creation
+func (e *FileEvent) IsCreate() bool { return (e.mask & IN_CREATE) == IN_CREATE }
+
 // IsDelete reports whether the FileEvent was triggerd by a delete
-func (e *FileEvent) IsDelete() bool { return (e.mask & IN_DELETE_SELF) == IN_DELETE_SELF }
+func (e *FileEvent) IsDelete() bool {
+       return (e.mask&IN_DELETE_SELF) == IN_DELETE_SELF || (e.mask&IN_DELETE) == IN_DELETE
+}
 
 // IsModify reports whether the FileEvent was triggerd by a file modification
 func (e *FileEvent) IsModify() bool { return (e.mask & IN_MODIFY) == IN_MODIFY }
@@ -205,8 +210,10 @@ func (w *Watcher) readEvents() {
                                // The filename is padded with NUL bytes. TrimRight() gets rid of those.
                                event.Name += "/" + strings.TrimRight(string(bytes[0:nameLen]), "\000")
                        }
-                       // Send the event on the events channel
-                       w.Event <- event
+                       // Send the events that are not ignored on the events channel
+                       if (event.mask & IN_IGNORED) == 0 {
+                               w.Event <- event
+                       }
 
                        // Move to the next event in the buffer
                        offset += syscall.SizeofInotifyEvent + nameLen
@@ -253,27 +260,3 @@ const (
        IN_Q_OVERFLOW uint32 = syscall.IN_Q_OVERFLOW
        IN_UNMOUNT    uint32 = syscall.IN_UNMOUNT
 )
-
-var eventBits = []struct {
-       Value uint32
-       Name  string
-}{
-       {IN_ACCESS, "IN_ACCESS"},
-       {IN_ATTRIB, "IN_ATTRIB"},
-       {IN_CLOSE, "IN_CLOSE"},
-       {IN_CLOSE_NOWRITE, "IN_CLOSE_NOWRITE"},
-       {IN_CLOSE_WRITE, "IN_CLOSE_WRITE"},
-       {IN_CREATE, "IN_CREATE"},
-       {IN_DELETE, "IN_DELETE"},
-       {IN_DELETE_SELF, "IN_DELETE_SELF"},
-       {IN_MODIFY, "IN_MODIFY"},
-       {IN_MOVE, "IN_MOVE"},
-       {IN_MOVED_FROM, "IN_MOVED_FROM"},
-       {IN_MOVED_TO, "IN_MOVED_TO"},
-       {IN_MOVE_SELF, "IN_MOVE_SELF"},
-       {IN_OPEN, "IN_OPEN"},
-       {IN_ISDIR, "IN_ISDIR"},
-       {IN_IGNORED, "IN_IGNORED"},
-       {IN_Q_OVERFLOW, "IN_Q_OVERFLOW"},
-       {IN_UNMOUNT, "IN_UNMOUNT"},
-}