watch

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package watch provides file system watching with debouncing for convertr watch mode.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleDeletion

func HandleDeletion(outPath string, policy DeletePolicy) error

HandleDeletion applies the delete policy for srcPath whose output lives at outPath.

Types

type Config

type Config struct {
	Debounce     time.Duration // how long to wait after last event before emitting
	DeletePolicy DeletePolicy
}

Config holds watcher options.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults.

type DeletePolicy

type DeletePolicy int

DeletePolicy controls what happens to the output file when the source is deleted.

const (
	DeleteKeep    DeletePolicy = iota // leave output file as-is
	DeleteRemove                      // remove corresponding output file
	DeleteArchive                     // move output file to .archive/ subdirectory
)

func ParseDeletePolicy

func ParseDeletePolicy(s string) (DeletePolicy, error)

ParseDeletePolicy parses a string delete policy name.

type Event

type Event struct {
	Path    string // absolute path of changed/deleted file
	Deleted bool   // true when the source file was removed or renamed away
}

Event is emitted when a file changes or is deleted.

type Watcher

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

Watcher watches a directory tree and emits debounced Events on changes.

func New

func New(cfg Config) (*Watcher, <-chan Event, error)

New creates a Watcher that emits to the returned channel. The caller must call Close to release resources.

func (*Watcher) Add

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

Add recursively watches root and all subdirectories.

func (*Watcher) Close

func (w *Watcher) Close() error

Close stops the underlying fsnotify watcher.

func (*Watcher) Run

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

Run processes fsnotify events until ctx is cancelled. It emits debounced Events on the channel returned by New.

Jump to

Keyboard shortcuts

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