const ( // InDontFollow : Don't dereference pathname if it is a symbolic link InDontFollow uint32 = syscall.IN_DONT_FOLLOW // InOneshot : Monitor the filesystem object corresponding to pathname for one event, then remove from watch list InOneshot uint32 = syscall.IN_ONESHOT // InOnlydir : Watch pathname only if it is a directory InOnlydir uint32 = syscall.IN_ONLYDIR // InAccess : File was accessed InAccess uint32 = syscall.IN_ACCESS // InAllEvents : Bit mask for all notify events InAllEvents uint32 = syscall.IN_ALL_EVENTS // InAttrib : Metadata changed InAttrib uint32 = syscall.IN_ATTRIB // InClose : Equates to IN_CLOSE_WRITE | IN_CLOSE_NOWRITE InClose uint32 = syscall.IN_CLOSE // InCloseNowrite : File or directory not opened for writing was closed InCloseNowrite uint32 = syscall.IN_CLOSE_NOWRITE // InCloseWrite : File opened for writing was closed InCloseWrite uint32 = syscall.IN_CLOSE_WRITE // InCreate : File/directory created in watched directory InCreate uint32 = syscall.IN_CREATE // InDelete : File/directory deleted from watched directory InDelete uint32 = syscall.IN_DELETE // InDeleteSelf : Watched file/directory was itself deleted InDeleteSelf uint32 = syscall.IN_DELETE_SELF // InModify : File was modified InModify uint32 = syscall.IN_MODIFY // InMove : Equates to IN_MOVED_FROM | IN_MOVED_TO InMove uint32 = syscall.IN_MOVE // InMovedFrom : Generated for the directory containing the old filename when a file is renamed InMovedFrom uint32 = syscall.IN_MOVED_FROM // InMovedTo : Generated for the directory containing the new filename when a file is renamed InMovedTo uint32 = syscall.IN_MOVED_TO // InMoveSelf : Watched file/directory was itself moved InMoveSelf uint32 = syscall.IN_MOVE_SELF // InOpen : File or directory was opened InOpen uint32 = syscall.IN_OPEN // InIsdir : Subject of this event is a directory InIsdir uint32 = syscall.IN_ISDIR // InIgnored : Watch was removed explicitly or automatically InIgnored uint32 = syscall.IN_IGNORED // InQOverflow : Event queue overflowed InQOverflow uint32 = syscall.IN_Q_OVERFLOW // InUnmount : Filesystem containing watched object was unmounted InUnmount uint32 = syscall.IN_UNMOUNT )
Event represents a notification
type Event struct { Mask uint32 // Mask of events Cookie uint32 // Unique cookie associating related events (for rename(2)) Name string // File name (optional) }
func (e *Event) String() string
String formats the event e in the form "filename: 0xEventMask = IN_ACCESS|IN_ATTRIB_|..."
Watcher represents an inotify instance
type Watcher struct { Error chan error // Errors are sent on this channel Event chan *Event // Events are returned on this channel // contains filtered or unexported fields }
func NewWatcher() (*Watcher, error)
NewWatcher creates and returns a new inotify instance using inotify_init(2)
func (w *Watcher) AddWatch(path string, flags uint32) error
AddWatch adds path to the watched file set. The flags are interpreted as described in inotify_add_watch(2).
func (w *Watcher) Close() error
Close closes an inotify watcher instance It sends a message to the reader goroutine to quit and removes all watches associated with the inotify instance
func (w *Watcher) RemoveWatch(path string) error
RemoveWatch removes path from the watched file set.
func (w *Watcher) Watch(path string) error
Watch adds path to the watched file set, watching all events.