package recwatch

import "github.com/purpleidea/mgmt/util/recwatch"

Package recwatch provides recursive file watching events via fsnotify.

Index

Functions

func MergeChannels

func MergeChannels(chanList ...<-chan Event) <-chan Event

MergeChannels is a helper function to combine different recwatch events. It would be preferable to actually fix the horrible recwatch code to allow it to monitor more than one path from the start.

Types

type Event

type Event struct {
	Error error
	Body  *fsnotify.Event
}

Event represents a watcher event. These can include errors.

type Option

type Option func(*recwatchOptions)

Option is a type that can be used to configure the recwatcher.

func Debug

func Debug(debug bool) Option

Debug specifies whether we should run in debug mode or not.

func Logf

func Logf(logf func(format string, v ...interface{})) Option

Logf passes a logger function that we can use if so desired.

type RecWatcher

type RecWatcher struct {
	// Path is the computer path that we're watching.
	Path string

	// Recurse specifies if we should watch recursively.
	// TODO: Should this get converted into an Option?
	Recurse bool

	// Opts are the list of options that we are using this with.
	Opts []Option
	// contains filtered or unexported fields
}

RecWatcher is the struct for the recursive watcher. Run Init() on it.

func NewRecWatcher

func NewRecWatcher(path string, recurse bool, opts ...Option) (*RecWatcher, error)

NewRecWatcher creates an initializes a new recursive watcher.

func (*RecWatcher) Close

func (obj *RecWatcher) Close() error

Close shuts down the watcher.

func (*RecWatcher) Events

func (obj *RecWatcher) Events() chan Event

Events returns a channel of events. These include events for errors.

func (*RecWatcher) Init

func (obj *RecWatcher) Init() error

Init starts the recursive file watcher.

func (*RecWatcher) Watch

func (obj *RecWatcher) Watch() error

Watch is the primary listener for this resource and it outputs events.

Source Files

recwatch.go

Version
v0.0.0-20250322185616-c50a578426f1 (latest)
Published
Mar 22, 2025
Platform
linux/amd64
Imports
10 packages
Last checked
4 days ago

Tools for package owners.