From: Adrien Bustany Date: Mon, 23 Dec 2013 14:03:50 +0000 (+0100) Subject: Add an IsAttrib method on the FileEvent struct X-Git-Tag: v1.7.2~327^2~3 X-Git-Url: https://go.fuhry.dev/?a=commitdiff_plain;h=bd50c45aeddf1be05074364f9b986ad8b6c50b31;p=fsnotify.git Add an IsAttrib method on the FileEvent struct This IsAttrib function can be used to distinguish events that only concern a file's metadata (eg. atime, mtime etc.). --- diff --git a/fsnotify.go b/fsnotify.go index f371960..dd26714 100644 --- a/fsnotify.go +++ b/fsnotify.go @@ -102,6 +102,10 @@ func (e *FileEvent) String() string { events += "|" + "RENAME" } + if e.IsAttrib() { + events += "|" + "ATTRIB" + } + if len(events) > 0 { events = events[1:] } diff --git a/fsnotify_bsd.go b/fsnotify_bsd.go index 416382d..509ac79 100644 --- a/fsnotify_bsd.go +++ b/fsnotify_bsd.go @@ -53,6 +53,12 @@ func (e *FileEvent) IsModify() bool { // IsRename reports whether the FileEvent was triggerd by a change name func (e *FileEvent) IsRename() bool { return (e.mask & sys_NOTE_RENAME) == sys_NOTE_RENAME } +// IsAttrib reports whether the FileEvent was triggered by a change in the file metadata (eg. +// atime, mtime etc.) +func (e *FileEvent) 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) diff --git a/fsnotify_linux.go b/fsnotify_linux.go index 79b0ec5..39c970d 100644 --- a/fsnotify_linux.go +++ b/fsnotify_linux.go @@ -85,6 +85,12 @@ func (e *FileEvent) 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 FileEvent was triggered by a change in the file metadata (eg. +// atime, mtime etc.) +func (e *FileEvent) 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) diff --git a/fsnotify_windows.go b/fsnotify_windows.go index 04dd5a0..4673fa0 100644 --- a/fsnotify_windows.go +++ b/fsnotify_windows.go @@ -71,6 +71,12 @@ func (e *FileEvent) 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 FileEvent was triggered by a change in the file metadata (eg. +// atime, mtime etc.) +func (e *FileEvent) IsAttrib() bool { + return (e.mask & sys_FS_ATTRIB) == sys_FS_ATTRIB +} + const ( opAddWatch = iota opRemoveWatch