Documentation ¶
Overview ¶
Package watcher provides a recursive file watcher implementation with support for glob expression based exclusions and event deduplication based on xxhash file checksums.
Index ¶
- Variables
- type Watcher
- func (w *Watcher) Add(dir string) error
- func (w *Watcher) Close() error
- func (w *Watcher) Ignore(globExpression string) error
- func (w *Watcher) RangeWatchedDirs(fn func(path string) (continueIter bool))
- func (w *Watcher) Remove(dir string) error
- func (w *Watcher) Run(ctx context.Context) (err error)
- func (w *Watcher) Unignore(globExpression string)
- func (w *Watcher) WaitRunning()
Constants ¶
This section is empty.
Variables ¶
var ( ErrClosed = errors.New("closed") ErrRunning = errors.New("watcher is already running") )
Functions ¶
This section is empty.
Types ¶
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher is a recursive file watcher.
func New ¶
func New( baseDir string, onChange func(ctx context.Context, e fsnotify.Event) error, ) (*Watcher, error)
New creates a new file watcher that executes onChange for any remove/create/change/chmod filesystem event. onChange will receive the ctx that was passed to Run. baseDir is used as the base path for relative ignore expressions.
func (*Watcher) Add ¶
Add starts watching the directory and all of its subdirectories recursively. Returns ErrClosed if the watcher is already closed or not running.
func (*Watcher) Close ¶
Close stops watching everything and closes the watcher. Noop if the watcher is closed.
func (*Watcher) Ignore ¶
Ignore adds an ignore glob filter and removes all currently watched directories that match the expression. Returns ErrClosed if the watcher is already closed or not running.
func (*Watcher) RangeWatchedDirs ¶
RangeWatchedDirs calls fn for every currently watched directory. Noop if the watcher is closed.
func (*Watcher) Remove ¶
Remove stops watching the directory and all of its subdirectories recursively. Returns ErrClosed if the watcher is already closed or not running.
func (*Watcher) Run ¶
Run runs the watcher. Can only be called once. Returns ErrClosed if closed, or ErrRunning if already running.
func (*Watcher) Unignore ¶
Unignore removes an ignore glob filter. Noop if filter doesn't exist or the watcher is closed or not running.
func (*Watcher) WaitRunning ¶
func (w *Watcher) WaitRunning()
WaitRunning blocks and returns once the watcher is running. Returns immediately if the watcher is closed or running.