// String formats the event e in the form
// "filename: DELETE|MODIFY|..."
-func (e *FileEvent) String() string {
+func (e *Event) String() string {
var events string = ""
if e.IsCreate() {
keventWaitTime = 100e6
)
-type FileEvent struct {
+type Event struct {
mask uint32 // Mask of events
Name string // File name (optional)
create bool // set by fsnotify package if found new file
}
-// IsCreate reports whether the FileEvent was triggered by a creation
-func (e *FileEvent) IsCreate() bool { return e.create }
+// IsCreate reports whether the Event was triggered by a creation
+func (e *Event) IsCreate() bool { return e.create }
-// IsDelete reports whether the FileEvent was triggered by a delete
-func (e *FileEvent) IsDelete() bool { return (e.mask & sys_NOTE_DELETE) == sys_NOTE_DELETE }
+// 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 FileEvent was triggered by a file modification
-func (e *FileEvent) IsModify() bool {
+// 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 FileEvent was triggered by a change name
-func (e *FileEvent) IsRename() bool { return (e.mask & sys_NOTE_RENAME) == sys_NOTE_RENAME }
+// 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 FileEvent was triggered by a change in the file metadata.
-func (e *FileEvent) IsAttrib() bool {
+// 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
}
externalWatches map[string]bool // Map of watches added by user of the library.
ewmut sync.Mutex // Protects access to externalWatches.
Errors chan error // Errors are sent on this channel
- Events chan *FileEvent // Events are returned on this channel
+ Events chan *Event // Events are returned on this channel
done chan bool // Channel for sending a "quit message" to the reader goroutine
isClosed bool // Set to true when Close() is first called
}
finfo: make(map[int]os.FileInfo),
fileExists: make(map[string]bool),
externalWatches: make(map[string]bool),
- Events: make(chan *FileEvent),
+ Events: make(chan *Event),
Errors: make(chan error),
done: make(chan bool, 1),
}
// Flush the events we received to the events channel
for len(events) > 0 {
- fileEvent := new(FileEvent)
+ fileEvent := new(Event)
watchEvent := &events[0]
fileEvent.mask = uint32(watchEvent.Fflags)
w.pmut.Lock()
w.femut.Unlock()
if !doesExist {
// Send create event
- fileEvent := new(FileEvent)
+ fileEvent := new(Event)
fileEvent.Name = filePath
fileEvent.create = true
w.Events <- fileEvent
sys_IN_UNMOUNT uint32 = syscall.IN_UNMOUNT
)
-type FileEvent struct {
+type Event struct {
mask uint32 // Mask of events
cookie uint32 // Unique cookie associating related events (for rename(2))
Name string // File name (optional)
}
-// IsCreate reports whether the FileEvent was triggered by a creation
-func (e *FileEvent) IsCreate() bool {
+// 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 FileEvent was triggered by a delete
-func (e *FileEvent) IsDelete() bool {
+// 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 FileEvent was triggered by a file modification or attribute change
-func (e *FileEvent) IsModify() bool {
+// 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 FileEvent was triggered by a change name
-func (e *FileEvent) IsRename() bool {
+// 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 FileEvent was triggered by a change in the file metadata.
-func (e *FileEvent) IsAttrib() bool {
+// 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
}
watches map[string]*watch // Map of inotify watches (key: path)
paths map[int]string // Map of watched paths (key: watch descriptor)
Errors chan error // Errors are sent on this channel
- Events chan *FileEvent // Events are returned on this channel
+ Events chan *Event // Events are returned on this channel
done chan bool // Channel for sending a "quit message" to the reader goroutine
isClosed bool // Set to true when Close() is first called
}
fd: fd,
watches: make(map[string]*watch),
paths: make(map[int]string),
- Events: make(chan *FileEvent),
+ Events: make(chan *Event),
Errors: make(chan error),
done: make(chan bool, 1),
}
for offset <= uint32(n-syscall.SizeofInotifyEvent) {
// Point "raw" to the event in the buffer
raw := (*syscall.InotifyEvent)(unsafe.Pointer(&buf[offset]))
- event := new(FileEvent)
+ event := new(Event)
event.mask = uint32(raw.Mask)
event.cookie = uint32(raw.Cookie)
nameLen := uint32(raw.Len)
// 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 *FileEvent) ignoreLinux() bool {
+func (e *Event) ignoreLinux() bool {
// Ignore anything the inotify API says to ignore
if e.mask&sys_IN_IGNORED == sys_IN_IGNORED {
return true
// Event is the type of the notification messages
// received on the watcher's Events channel.
-type FileEvent struct {
+type Event struct {
mask uint32 // Mask of events
cookie uint32 // Unique cookie associating related events (for rename)
Name string // File name (optional)
}
-// IsCreate reports whether the FileEvent was triggered by a creation
-func (e *FileEvent) IsCreate() bool { return (e.mask & sys_FS_CREATE) == sys_FS_CREATE }
+// 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 FileEvent was triggered by a delete
-func (e *FileEvent) IsDelete() bool {
+// 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 FileEvent was triggered by a file modification or attribute change
-func (e *FileEvent) IsModify() bool {
+// 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 FileEvent was triggered by a change name
-func (e *FileEvent) IsRename() bool {
+// 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 FileEvent was triggered by a change in the file metadata.
-func (e *FileEvent) IsAttrib() bool {
+// 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
}
// A Watcher waits for and receives event notifications
// for a specific set of files and directories.
type Watcher struct {
- mu sync.Mutex // Map access
- port syscall.Handle // Handle to completion port
- watches watchMap // Map of watches (key: i-number)
- input chan *input // Inputs to the reader are sent on this channel
- Events chan *FileEvent // Events are returned on this channel
- Errors chan error // Errors are sent on this channel
- isClosed bool // Set to true when Close() is first called
+ mu sync.Mutex // Map access
+ port syscall.Handle // Handle to completion port
+ watches watchMap // Map of watches (key: i-number)
+ input chan *input // Inputs to the reader are sent on this channel
+ Events chan *Event // Events are returned on this channel
+ Errors chan error // Errors are sent on this channel
+ isClosed bool // Set to true when Close() is first called
quit chan chan<- error
cookie uint32
}
port: port,
watches: make(watchMap),
input: make(chan *input, 1),
- Events: make(chan *FileEvent, 50),
+ Events: make(chan *Event, 50),
Errors: make(chan error),
quit: make(chan chan<- error, 1),
}
var offset uint32
for {
if n == 0 {
- w.Events <- &FileEvent{mask: sys_FS_Q_OVERFLOW}
+ w.Events <- &Event{mask: sys_FS_Q_OVERFLOW}
w.Errors <- errors.New("short read in readEvents()")
break
}
if mask == 0 {
return false
}
- event := &FileEvent{mask: uint32(mask), Name: name}
+ event := &Event{mask: uint32(mask), Name: name}
if mask&sys_FS_MOVE != 0 {
if mask&sys_FS_MOVED_FROM != 0 {
w.cookie++