Documentation
¶
Overview ¶
Package fswatch turns inotify events into coalesced change ticks, the Go counterpart of the `notify` crate watchers the Rust services use (the mail service's recursive maildir watch, the brightness sysfs watch). Most consumers only need "something under here changed": each burst is one tick. A named watcher (NewNamed) also keeps the names that changed, coalesced per name, for a consumer that applies each change instead of reading everything again.
The reader blocks in poll(2) on the inotify fd and an eventfd, so an idle watcher costs nothing and Close wakes it without a timeout.
Index ¶
Constants ¶
const Changes uint32 = unix.IN_CREATE | unix.IN_MODIFY | unix.IN_DELETE | unix.IN_MOVED_FROM | unix.IN_MOVED_TO | unix.IN_ATTRIB | unix.IN_DELETE_SELF | unix.IN_MOVE_SELF
Changes is the event mask that counts as a change for a directory tree: files created, written, removed, renamed (maildir flags are renames), or their metadata changed. It matches notify's Create | Modify | Remove kinds.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Batch ¶
Batch is what changed since the last Take: each name once, in the order it first changed. Rescan reports that names were lost (the kernel queue overflowed, or more names changed than a batch holds) or the watched directory itself was deleted or moved, so only reading it again is right; Events is then empty.
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher is one inotify instance.
func New ¶
New starts a watcher for mask. With recursive set, Add walks the whole tree and directories created later are watched as they appear, which is what a recursive notify watcher does.
func NewNamed ¶
NewNamed starts a watcher for mask on single directories that also keeps the names that changed for Take.
func (*Watcher) Changed ¶
func (w *Watcher) Changed() <-chan struct{}
Changed ticks once per burst of events; it closes after Close.