]> go.fuhry.dev Git - fsnotify.git/commitdiff
Common event printer
authorChris Howey <chris@howey.me>
Mon, 17 Oct 2011 19:06:53 +0000 (12:06 -0700)
committerChris Howey <chris@howey.me>
Mon, 17 Oct 2011 19:06:53 +0000 (12:06 -0700)
Makefile
fsnotify.go [new file with mode: 0644]
fsnotify_bsd.go
fsnotify_linux.go

index c6e89e8037e22ce010ec7dda272af7b5052bee6b..9f3a8b83a7c5c6f5b9f79ba979d0a56dcbbfa6ce 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,6 +2,9 @@ include $(GOROOT)/src/Make.inc
 
 TARG=exp/fsnotify
 
+GOFILES=\
+       fsnotify.go
+
 GOFILES_linux=\
        fsnotify_linux.go\
 
diff --git a/fsnotify.go b/fsnotify.go
new file mode 100644 (file)
index 0000000..f3e4321
--- /dev/null
@@ -0,0 +1,31 @@
+package fsnotify
+
+import "fmt"
+
+// String formats the event e in the form
+// "filename: DELETE|MODIFY|..."
+func (e *FileEvent) String() string {
+       var events string = ""
+
+       if e.IsDelete() {
+               events += "|" + "DELETE"
+       }
+
+       if e.IsModify() {
+               events += "|" + "MODIFY"
+       }
+
+       if e.IsAttribute() {
+               events += "|" + "ATTRIB"
+       }
+
+       if e.IsRename() {
+               events += "|" + "RENAME"
+       }
+
+       if len(events) > 0 {
+               events = events[1:]
+       }
+
+       return fmt.Sprintf("%q: %s", e.Name, events)
+}
index 54e7fa92a6d5a1775f53b0691b9ef019629b3c42..f5afbdce993b5cbdb707167787d6c587051ae3ac 100644 (file)
@@ -216,29 +216,6 @@ func (w *Watcher) readEvents() {
        }
 }
 
-// String formats the event e in the form
-// "filename: 0xEventMask = NOTE_EXTEND|NOTE_ATTRIB|..."
-func (e *FileEvent) String() string {
-       var events string = ""
-
-       m := e.mask
-       for _, b := range eventBits {
-               if m&b.Value != 0 {
-                       m &^= b.Value
-                       events += "|" + b.Name
-               }
-       }
-
-       if m != 0 {
-               events += fmt.Sprintf("|%#x", m)
-       }
-       if len(events) > 0 {
-               events = " == " + events[1:]
-       }
-
-       return fmt.Sprintf("%q: %#x%s", e.Name, e.mask, events)
-}
-
 const (
        // Flags (from <sys/event.h>)
        NOTE_DELETE = 0x0001 /* vnode was removed */
@@ -255,16 +232,3 @@ const (
        // Block for 100 ms on each call to kevent
        keventWaitTime = 100e6
 )
-
-var eventBits = []struct {
-       Value uint32
-       Name  string
-}{
-       {NOTE_DELETE, "NOTE_DELETE"},
-       {NOTE_WRITE, "NOTE_WRITE"},
-       {NOTE_EXTEND, "NOTE_EXTEND"},
-       {NOTE_ATTRIB, "NOTE_ATTRIB"},
-       {NOTE_LINK, "NOTE_LINK"},
-       {NOTE_RENAME, "NOTE_RENAME"},
-       {NOTE_REVOKE, "NOTE_REVOKE"},
-}
index abf84c273deb06a4b8542f7223afadee10f7ce36..ffb139048b3ec97ab5a4cf8f0f18353b03a02a6e 100644 (file)
@@ -214,29 +214,6 @@ func (w *Watcher) readEvents() {
        }
 }
 
-// String formats the event e in the form
-// "filename: 0xEventMask = IN_ACCESS|IN_ATTRIB_|..."
-func (e *FileEvent) String() string {
-       var events string = ""
-
-       m := e.mask
-       for _, b := range eventBits {
-               if m&b.Value != 0 {
-                       m &^= b.Value
-                       events += "|" + b.Name
-               }
-       }
-
-       if m != 0 {
-               events += fmt.Sprintf("|%#x", m)
-       }
-       if len(events) > 0 {
-               events = " == " + events[1:]
-       }
-
-       return fmt.Sprintf("%q: %#x%s", e.Name, e.mask, events)
-}
-
 const (
        // Options for inotify_init() are not exported
        // IN_CLOEXEC    uint32 = syscall.IN_CLOEXEC