From: Chris Howey Date: Mon, 17 Oct 2011 19:21:44 +0000 (-0700) Subject: Linux: added create and rule to ignore ignored events X-Git-Tag: v1.7.2~465 X-Git-Url: https://go.fuhry.dev/?a=commitdiff_plain;h=055165ae9e6a01f98edcbbcbb4a38aa5517f100e;p=fsnotify.git Linux: added create and rule to ignore ignored events --- diff --git a/fsnotify.go b/fsnotify.go index f3e4321..1381c2a 100644 --- a/fsnotify.go +++ b/fsnotify.go @@ -7,6 +7,10 @@ import "fmt" func (e *FileEvent) String() string { var events string = "" + if e.IsCreate() { + events += "|" + "CREATE" + } + if e.IsDelete() { events += "|" + "DELETE" } diff --git a/fsnotify_linux.go b/fsnotify_linux.go index ffb1390..d2b17c3 100644 --- a/fsnotify_linux.go +++ b/fsnotify_linux.go @@ -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"}, -}