From: Nathan Youngman Date: Fri, 13 Jun 2014 05:32:47 +0000 (-0600) Subject: finally remove IsCreate and friends X-Git-Tag: v1.7.2~312^2~1 X-Git-Url: https://go.fuhry.dev/?a=commitdiff_plain;h=3b89edce5e91b03efd7f017c5630707007ea6f71;p=fsnotify.git finally remove IsCreate and friends --- diff --git a/fsnotify_bsd.go b/fsnotify_bsd.go index 512eb42..24af821 100644 --- a/fsnotify_bsd.go +++ b/fsnotify_bsd.go @@ -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 } } diff --git a/fsnotify_linux.go b/fsnotify_linux.go index 3bc34b3..ca60737 100644 --- a/fsnotify_linux.go +++ b/fsnotify_linux.go @@ -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 } diff --git a/fsnotify_windows.go b/fsnotify_windows.go index 501d87d..dc150b2 100644 --- a/fsnotify_windows.go +++ b/fsnotify_windows.go @@ -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