fswatch

package
v0.0.0-...-fd058c7 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NONE     = iota // No event, initial state.
	CREATED         // File was created.
	DELETED         // File was deleted.
	MODIFIED        // File was modified.
	PERM            // Changed permissions
	NOEXIST         // File does not exist.
	NOPERM          // No permissions for the file (see const block comment).
	INVALID         // Any type of error not represented above.
)

These values represent the events fswatch knows about. fswatch uses a stat(2) call to look up file information; a file will only have a NOPERM event if the parent directory has no search permission (i.e. parent directory doesn't have executable permissions for the current user).

Variables

View Source
var NotificationBufLen = 16

NotificationBufLen is the number of notifications that should be buffered in the channel.

View Source
var WatchDelay time.Duration

WatchDelay is the duration between path scans. It defaults to 100ms.

Functions

This section is empty.

Types

type Notification

type Notification struct {
	Path  string
	Event int
}

Notification represents a file state change. The Path field indicates the file that was changed, while last event corresponds to one of the event type constants.

type Watcher

type Watcher struct {

	// ignoreFn is used to ignore paths
	IgnorePathFn func(path string) bool
	// contains filtered or unexported fields
}

Watcher represents a file system watcher. It should be initialised with NewWatcher or NewAutoWatcher, and started with Watcher.Start().

func NewAutoWatcher

func NewAutoWatcher(paths ...string) *Watcher

NewAutoWatcher initialises a new Watcher with an initial set of paths. It behaves the same as NewWatcher, except it will automatically add files created in directories it is watching, including adding any subdirectories.

func NewWatcher

func NewWatcher(paths ...string) *Watcher

NewWatcher initialises a new Watcher with an initial set of paths. It does not start listening, and this Watcher will not automatically add files created under any directories it is watching.

func (*Watcher) Active

func (w *Watcher) Active() bool

Active returns true if the Watcher is actively looking for changes.

func (*Watcher) Add

func (w *Watcher) Add(inpaths ...string)

Add method takes a variable number of string arguments and adds those files to the watch list, returning the number of files added.

func (*Watcher) Start

func (w *Watcher) Start() <-chan *Notification

Start begins watching the files, sending notifications when files change. It returns a channel that notifications are sent on.

func (*Watcher) State

func (w *Watcher) State() (state []Notification)

State returns a slice of Notifications representing the files being watched and their last event.

func (*Watcher) Stop

func (w *Watcher) Stop()

Stop listening for changes to the files.

func (*Watcher) Watching

func (w *Watcher) Watching() (paths []string)

Watching returns a list of the files being watched.

Jump to

Keyboard shortcuts

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