fswatcher

package
v1.11.5 Latest Latest
Warning

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

Go to latest
Published: May 10, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event fsnotify.Event

Event currently wraps fsnotify.Event

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 is a wrapper around fsnotify.Watcher 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.

  1. If the file already exists, the watcher will emit write, chmod, remove and rename events for the file (same as fsnotify).
  2. If the file does not yet exist, then the Watcher makes sure to watch the appropriate parent folder instead. Once the file is created, this watcher will emit a creation event for the tracked file and enter case 1.
  3. If the file already exists, but is removed, then a remove event is emitted and we enter case 2.

Special care has to be taken around symlinks. Support for symlink is limited, but it supports the following cases in order to support Kubernetes volume mounts:

  1. If the tracked file is a symlink, then the watcher will emit write, chmod, remove and rename events for the *target* of the symlink.
  2. If a tracked file is a symlink and the symlink target is removed, then the remove event is emitted and the watcher tries to re-resolve the symlink target. If the new target exists, a creation event is emitted and we enter case 1). If the new target does not exist, an error is emitted and the path will not be watched anymore.

Most notably, if a tracked file is a symlink, any update of the symlink itself does not emit an event. Only if the target of the symlink observes an event is the symlink re-evaluated.

func New

func New(trackedFiles []string) (*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