Documentation
¶
Overview ¶
Package watch reports changes under a directory tree. It is deliberately coarse: it reports which paths may have changed, and leaves deciding what actually changed to the caller, which compares content hashes. That keeps it correct across the many ways editors and tools write files (in place, write-then-rename, delete-then-create) without per-platform special cases.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrOverflow = fsnotify.ErrEventOverflow
ErrOverflow is reported when the OS dropped events, so changes may have been missed. See Options.OnError.
Functions ¶
This section is empty.
Types ¶
type Batcher ¶
type Batcher struct {
// contains filtered or unexported fields
}
Batcher coalesces changed paths into batches. A batch is flushed once changes stop for the idle duration, or after maxWait during a sustained burst. Flushes run one at a time, in the order their batches closed, so checkpoint uploads never overlap or reorder.
A Batcher starts paused: paths added before Batcher.Start accumulate and flush once it is called.
func NewBatcher ¶
func NewBatcher(idle, maxWait time.Duration, flush func(ctx context.Context, paths []string)) *Batcher
NewBatcher returns a paused batcher that hands each batch to flush. The callback may call Batcher.Add to requeue paths that failed to sync.
func (*Batcher) Add ¶
Add marks paths as changed. It is a no-op after Batcher.Close.
type Options ¶
type Options struct {
// Root is the absolute directory to watch.
Root string
// Ignore reports whether a slash-separated path relative to Root is
// excluded. Ignored directories are not descended into.
Ignore func(rel string, isDir bool) bool
// Stability is how long a path must go without events before it is
// reported, so a file is not read while it is still being written.
Stability time.Duration
// OnChange receives the relative path of each file that may have been
// created, modified, or removed, including directories that were removed
// or renamed away. It is called from timer goroutines.
OnChange func(rel string)
// OnError receives watch errors. On [ErrOverflow] the watcher has already
// started a rescan that reports every existing file; the caller should
// also re-check files it knows of, since deletions cannot be rediscovered.
OnError func(error)
}
Options configures a Watcher.
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher watches a directory tree recursively.
func New ¶
New starts watching opts.Root and every directory beneath it that is not ignored. Existing files are not reported.