]> go.fuhry.dev Git - fsnotify.git/commitdiff
Add an IsAttrib method on the FileEvent struct
authorAdrien Bustany <adrien@bustany.org>
Mon, 23 Dec 2013 14:03:50 +0000 (15:03 +0100)
committerAdrien Bustany <adrien@bustany.org>
Thu, 16 Jan 2014 17:07:52 +0000 (18:07 +0100)
This IsAttrib function can be used to distinguish events that only
concern a file's metadata (eg. atime, mtime etc.).

fsnotify.go
fsnotify_bsd.go
fsnotify_linux.go
fsnotify_windows.go

index f371960298fbd4221425fb2240ddaef4587cce71..dd26714e6c88e98ba97b7c76f59b1a87316f1e77 100644 (file)
@@ -102,6 +102,10 @@ func (e *FileEvent) String() string {
                events += "|" + "RENAME"
        }
 
+       if e.IsAttrib() {
+               events += "|" + "ATTRIB"
+       }
+
        if len(events) > 0 {
                events = events[1:]
        }
index 416382d2dfbbd72a5161a7ab4f07a9eb39e0613d..509ac79f2d1c9ba8071d04150eed9ade2d76a59d 100644 (file)
@@ -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)
index 79b0ec5cb03dfdb81e34d6913d51838700c5f69a..39c970d69b89cc018dc39c128dc58c7e176c1956 100644 (file)
@@ -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)
index 04dd5a05125f7d3763a342a402308cdade85801d..4673fa0bd87ff49602b1b8c0038bd6b4bd8e8a24 100644 (file)
@@ -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