watcher

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2024 License: MIT Imports: 11 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

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

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

func (w *Watcher) Close() error

Close stops watching everything and closes the watcher. Noop if the watcher is closed.

func (*Watcher) Ignore

func (w *Watcher) Ignore(globExpression string) error

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

func (w *Watcher) RangeWatchedDirs(fn func(path string) (continueIter bool))

RangeWatchedDirs calls fn for every currently watched directory. Noop if the watcher is closed.

func (*Watcher) Remove

func (w *Watcher) Remove(dir string) error

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

func (w *Watcher) Run(ctx context.Context) (err error)

Run runs the watcher. Can only be called once. Returns ErrClosed if closed, or ErrRunning if already running.

func (*Watcher) Unignore

func (w *Watcher) Unignore(globExpression string)

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.

Jump to

Keyboard shortcuts

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