fswatch

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: MIT, MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package fswatch turns inotify events into coalesced change ticks (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

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

type Batch struct {
	Events []Event
	Rescan bool
}

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 Event

type Event struct {
	Name string
	Mask uint32
}

Event is one name in a watched directory and every event it saw since the last Take.

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

Watcher is one inotify instance.

func New

func New(mask uint32, recursive bool) (*Watcher, error)

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

func NewNamed(mask uint32) (*Watcher, error)

NewNamed starts a watcher for mask on single directories that also keeps the names that changed for Take.

func (*Watcher) Add

func (w *Watcher) Add(path string) error

Add watches path (and, recursively, every directory below it).

func (*Watcher) Changed

func (w *Watcher) Changed() <-chan struct{}

Changed ticks once per burst of events; it closes after Close.

func (*Watcher) Close

func (w *Watcher) Close() error

Close stops the reader, releases the fds, and closes Changed.

func (*Watcher) Take

func (w *Watcher) Take() Batch

Take hands over what changed since the last Take; a watcher not made by NewNamed has no names to hand over.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL