fswatcher

package
v1.16.13 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2025 License: Apache-2.0 Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	// Path to the file or directory.
	Name string

	// File operation that triggered the event.
	//
	// This is a bitmask and some systems may send multiple operations at once.
	// Use the Event.Has() method instead of comparing with ==.
	Op Op
}

Event closely resembles what fsnotify.Event provided

func (Event) Has added in v1.16.11

func (e Event) Has(op Op) bool

Has reports if this event has the given operation.

type Op added in v1.16.11

type Op uint

Op describes a set of file operations.

const (
	// A new pathname was created.
	Create Op = 1 << iota

	// The pathname was written to; this does *not* mean the write has finished,
	// and a write can be followed by more writes.
	Write

	// The path was removed
	Remove
)

Subset from fsnotify

func (Op) Has added in v1.16.11

func (o Op) Has(h Op) bool

Has reports if this operation has the given operation.

type Option added in v1.16.11

type Option func(*Watcher)

Option to configure the Watcher

func WithInterval added in v1.16.11

func WithInterval(d time.Duration) Option

WithInterval sets the interval at which the Watcher checks for changes

type Watcher

type Watcher struct {
	// Events is used to signal changes to any of the tracked files. It is
	// guaranteed that Event.Name will always match one of the file paths
	// passed in trackedFiles to the constructor. This channel is unbuffered
	// and must be read by the consumer to avoid deadlocks.
	Events chan Event
	// Errors reports any errors which may occur while watching. This channel
	// is unbuffered and must be read by the consumer to avoid deadlocks.
	Errors chan error
	// contains filtered or unexported fields
}

Watcher implements a file polling mechanism which can track non-existing files and emit creation events for them. All files which are supposed to be tracked need to passed to the New constructor.

When a directory is passed in as a tracked file, the watcher will watch all the files inside that directory, including recursion into any subdirectories.

One of the primary use cases for the watcher is tracking kubernetes projected secrets which create a maze of symlinks. It is safe to watch symlink targets as they are properly resolved, even in the case of multiple symlinks chained together. Only the content of the final destination is considered when issuing Write events.

func New

func New(trackedFiles []string, options ...Option) (*Watcher, error)

New creates a new Watcher which watches all trackedFile paths (they do not need to exist yet).

func (*Watcher) Close

func (w *Watcher) Close()

Jump to

Keyboard shortcuts

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