]> go.fuhry.dev Git - fsnotify.git/commitdiff
finally remove IsCreate and friends
authorNathan Youngman <git@nathany.com>
Fri, 13 Jun 2014 05:32:47 +0000 (23:32 -0600)
committerNathan Youngman <git@nathany.com>
Fri, 13 Jun 2014 05:32:47 +0000 (23:32 -0600)
fsnotify_bsd.go
fsnotify_linux.go
fsnotify_windows.go

index 512eb42c958bc07bd001c9817471fff261d269de..24af8211840f4b1c3539b7b26564e0f3cce476d8 100644 (file)
@@ -34,54 +34,31 @@ const (
 )
 
 type Event struct {
-       Name   string // Relative path to the file/directory.
-       Op     Op     // Platform-independent bitmask.
-       mask   uint32 // Mask of events
-       create bool   // set by fsnotify package if found new file
+       Name string // Relative path to the file/directory.
+       Op   Op     // Platform-independent mask.
 }
 
 func newEvent(name string, mask uint32, create bool) *Event {
        e := new(Event)
        e.Name = name
-       e.mask = mask
-       e.create = create
-       if e.IsCreate() {
+       if create {
                e.Op |= Create
        }
-       if e.IsDelete() {
+       if mask&sys_NOTE_DELETE == sys_NOTE_DELETE {
                e.Op |= Remove
        }
-       if e.IsModify() {
+       if mask&sys_NOTE_WRITE == sys_NOTE_WRITE || mask&sys_NOTE_ATTRIB == sys_NOTE_ATTRIB {
                e.Op |= Write
        }
-       if e.IsRename() {
+       if mask&sys_NOTE_RENAME == sys_NOTE_RENAME {
                e.Op |= Rename
        }
-       if e.IsAttrib() {
+       if mask&sys_NOTE_ATTRIB == sys_NOTE_ATTRIB {
                e.Op |= Chmod
        }
        return e
 }
 
-// IsCreate reports whether the Event was triggered by a creation
-func (e *Event) IsCreate() bool { return e.create }
-
-// IsDelete reports whether the Event was triggered by a delete
-func (e *Event) IsDelete() bool { return (e.mask & sys_NOTE_DELETE) == sys_NOTE_DELETE }
-
-// IsModify reports whether the Event was triggered by a file modification
-func (e *Event) IsModify() bool {
-       return ((e.mask&sys_NOTE_WRITE) == sys_NOTE_WRITE || (e.mask&sys_NOTE_ATTRIB) == sys_NOTE_ATTRIB)
-}
-
-// IsRename reports whether the Event was triggered by a change name
-func (e *Event) IsRename() bool { return (e.mask & sys_NOTE_RENAME) == sys_NOTE_RENAME }
-
-// IsAttrib reports whether the Event was triggered by a change in the file metadata.
-func (e *Event) IsAttrib() bool {
-       return (e.mask & sys_NOTE_ATTRIB) == sys_NOTE_ATTRIB
-}
-
 type Watcher struct {
        mu              sync.Mutex          // Mutex for the Watcher itself.
        kq              int                 // File descriptor (as returned by the kqueue() syscall)
@@ -377,7 +354,7 @@ func (w *Watcher) readEvents() {
                                // receive the delete event
                                if _, err := os.Lstat(fileEvent.Name); os.IsNotExist(err) {
                                        // mark is as delete event
-                                       fileEvent.mask |= sys_NOTE_DELETE
+                                       fileEvent.Op |= Remove
                                }
                        }
 
index 3bc34b31d421260e59fa72e356365c871cf9be09..ca607376902201eeb4e714abb885c70e1fd2ce90 100644 (file)
@@ -58,59 +58,30 @@ const (
 
 type Event struct {
        Name   string // Relative path to the file/directory.
-       Op     Op     // Platform-independent bitmask.
-       mask   uint32 // Mask of events
+       Op     Op     // Platform-independent mask.
        cookie uint32 // Unique cookie associating related events (for rename(2))
 }
 
 func newEvent(name string, mask uint32, cookie uint32) *Event {
-       e := new(Event)
-       e.Name = name
-       e.mask = mask
-       e.cookie = cookie
-       if e.IsCreate() {
+       e := &Event{Name: name, cookie: cookie}
+       if mask&sys_IN_CREATE == sys_IN_CREATE || mask&sys_IN_MOVED_TO == sys_IN_MOVED_TO {
                e.Op |= Create
        }
-       if e.IsDelete() {
+       if mask&sys_IN_DELETE_SELF == sys_IN_DELETE_SELF || mask&sys_IN_DELETE == sys_IN_DELETE {
                e.Op |= Remove
        }
-       if e.IsModify() {
+       if mask&sys_IN_MODIFY == sys_IN_MODIFY || mask&sys_IN_ATTRIB == sys_IN_ATTRIB {
                e.Op |= Write
        }
-       if e.IsRename() {
+       if mask&sys_IN_MOVE_SELF == sys_IN_MOVE_SELF || mask&sys_IN_MOVED_FROM == sys_IN_MOVED_FROM {
                e.Op |= Rename
        }
-       if e.IsAttrib() {
+       if mask&sys_IN_ATTRIB == sys_IN_ATTRIB {
                e.Op |= Chmod
        }
        return e
 }
 
-// IsCreate reports whether the Event was triggered by a creation
-func (e *Event) IsCreate() bool {
-       return (e.mask&sys_IN_CREATE) == sys_IN_CREATE || (e.mask&sys_IN_MOVED_TO) == sys_IN_MOVED_TO
-}
-
-// IsDelete reports whether the Event was triggered by a delete
-func (e *Event) IsDelete() bool {
-       return (e.mask&sys_IN_DELETE_SELF) == sys_IN_DELETE_SELF || (e.mask&sys_IN_DELETE) == sys_IN_DELETE
-}
-
-// IsModify reports whether the Event was triggered by a file modification or attribute change
-func (e *Event) IsModify() bool {
-       return ((e.mask&sys_IN_MODIFY) == sys_IN_MODIFY || (e.mask&sys_IN_ATTRIB) == sys_IN_ATTRIB)
-}
-
-// IsRename reports whether the Event was triggered by a change name
-func (e *Event) IsRename() bool {
-       return ((e.mask&sys_IN_MOVE_SELF) == sys_IN_MOVE_SELF || (e.mask&sys_IN_MOVED_FROM) == sys_IN_MOVED_FROM)
-}
-
-// IsAttrib reports whether the Event was triggered by a change in the file metadata.
-func (e *Event) IsAttrib() bool {
-       return (e.mask & sys_IN_ATTRIB) == sys_IN_ATTRIB
-}
-
 type watch struct {
        wd    uint32 // Watch descriptor (as returned by the inotify_add_watch() syscall)
        flags uint32 // inotify flags of this watch (see inotify(7) for the list of valid flags)
@@ -280,7 +251,7 @@ func (w *Watcher) readEvents() {
                        event := newEvent(name, mask, cookie)
 
                        // Send the events that are not ignored on the events channel
-                       if !event.ignoreLinux() {
+                       if !event.ignoreLinux(mask) {
                                w.Events <- event
                        }
 
@@ -293,9 +264,9 @@ func (w *Watcher) readEvents() {
 // Certain types of events can be "ignored" and not sent over the Events
 // channel. Such as events marked ignore by the kernel, or MODIFY events
 // against files that do not exist.
-func (e *Event) ignoreLinux() bool {
+func (e *Event) ignoreLinux(mask uint32) bool {
        // Ignore anything the inotify API says to ignore
-       if e.mask&sys_IN_IGNORED == sys_IN_IGNORED {
+       if mask&sys_IN_IGNORED == sys_IN_IGNORED {
                return true
        }
 
index 501d87d000e08013ddd5be256d5ec9868fb786b5..dc150b2d2051280e7c8164837b9a679bb085c9ec 100644 (file)
@@ -51,53 +51,29 @@ const (
 type Event struct {
        Name   string // Relative path to the file/directory.
        Op     Op     // Platform-independent bitmask.
-       mask   uint32 // Mask of events
        cookie uint32 // Unique cookie associating related events (for rename)
 }
 
 func newEvent(name string, mask uint32) *Event {
-       e := &Event{mask: mask, Name: name}
-       if e.IsCreate() {
+       e := &Event{Name: name}
+       if mask&sys_FS_CREATE == sys_FS_CREATE {
                e.Op |= Create
        }
-       if e.IsDelete() {
+       if mask&sys_FS_DELETE == sys_FS_DELETE || mask&sys_FS_DELETE_SELF == sys_FS_DELETE_SELF {
                e.Op |= Remove
        }
-       if e.IsModify() {
+       if mask&sys_FS_MODIFY == sys_FS_MODIFY || mask&sys_FS_ATTRIB == sys_FS_ATTRIB {
                e.Op |= Write
        }
-       if e.IsRename() {
+       if mask&sys_FS_MOVE == sys_FS_MOVE || mask&sys_FS_MOVE_SELF == sys_FS_MOVE_SELF || mask&sys_FS_MOVED_FROM == sys_FS_MOVED_FROM || mask&sys_FS_MOVED_TO == sys_FS_MOVED_TO {
                e.Op |= Rename
        }
-       if e.IsAttrib() {
+       if mask&sys_FS_ATTRIB == sys_FS_ATTRIB {
                e.Op |= Chmod
        }
        return e
 }
 
-// IsCreate reports whether the Event was triggered by a creation
-func (e *Event) IsCreate() bool { return (e.mask & sys_FS_CREATE) == sys_FS_CREATE }
-
-// IsDelete reports whether the Event was triggered by a delete
-func (e *Event) IsDelete() bool {
-       return ((e.mask&sys_FS_DELETE) == sys_FS_DELETE || (e.mask&sys_FS_DELETE_SELF) == sys_FS_DELETE_SELF)
-}
-
-// IsModify reports whether the Event was triggered by a file modification or attribute change
-func (e *Event) IsModify() bool {
-       return ((e.mask&sys_FS_MODIFY) == sys_FS_MODIFY || (e.mask&sys_FS_ATTRIB) == sys_FS_ATTRIB)
-}
-
-// IsRename reports whether the Event was triggered by a change name
-func (e *Event) IsRename() bool {
-       return ((e.mask&sys_FS_MOVE) == sys_FS_MOVE || (e.mask&sys_FS_MOVE_SELF) == sys_FS_MOVE_SELF || (e.mask&sys_FS_MOVED_FROM) == sys_FS_MOVED_FROM || (e.mask&sys_FS_MOVED_TO) == sys_FS_MOVED_TO)
-}
-
-// IsAttrib reports whether the Event was triggered by a change in the file metadata.
-func (e *Event) IsAttrib() bool {
-       return (e.mask & sys_FS_ATTRIB) == sys_FS_ATTRIB
-}
-
 const (
        opAddWatch = iota
        opRemoveWatch