watcher

package
v3.0.0-rc19+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package watcher provides a way of watching for filesystem events and notifying observers when they occur.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Op       OpType
	Pathname string
}

Event is a generalisation of events sent from the watcher to its listeners.

type FakeWatcher

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

FakeWatcher implements an in-memory Watcher.

func NewFakeWatcher

func NewFakeWatcher() *FakeWatcher

NewFakeWatcher returns a fake Watcher for use in tests.

func (*FakeWatcher) Add

func (w *FakeWatcher) Add(name string, handle int) error

Add adds a watch to the FakeWatcher

func (*FakeWatcher) Close

func (w *FakeWatcher) Close() error

Close closes down the FakeWatcher

func (*FakeWatcher) Events

func (w *FakeWatcher) Events() (int, <-chan Event)

Events returns a new channel of messages.

func (*FakeWatcher) InjectCreate

func (w *FakeWatcher) InjectCreate(name string)

InjectCreate lets a test inject a fake creation event.

func (*FakeWatcher) InjectDelete

func (w *FakeWatcher) InjectDelete(name string)

InjectDelete lets a test inject a fake deletion event.

func (*FakeWatcher) InjectUpdate

func (w *FakeWatcher) InjectUpdate(name string)

InjectUpdate lets a test inject a fake update event.

func (*FakeWatcher) Remove

func (w *FakeWatcher) Remove(name string) error

Remove removes a watch from the FakeWatcher

type LogWatcher

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

LogWatcher implements a Watcher for watching real filesystems.

func NewLogWatcher

func NewLogWatcher(pollInterval time.Duration, enableFsnotify bool) (*LogWatcher, error)

NewLogWatcher returns a new LogWatcher, or returns an error.

func (*LogWatcher) Add

func (w *LogWatcher) Add(path string, handle int) error

Add adds a path to the list of watched items. If the path is already being watched, then nothing is changed -- the new handle does not replace the old one.

func (*LogWatcher) Close

func (w *LogWatcher) Close() (err error)

Close shuts down the LogWatcher. It is safe to call this from multiple clients.

func (*LogWatcher) Events

func (w *LogWatcher) Events() (int, <-chan Event)

Events returns a new readable channel of events from this watcher.

func (*LogWatcher) IsWatching

func (w *LogWatcher) IsWatching(path string) bool

IsWatching indicates if the path is being watched. It includes both filenames and directories.

func (*LogWatcher) Remove

func (w *LogWatcher) Remove(path string) error

type OpType

type OpType int
const (
	Create OpType = iota
	Update
	Delete
)

type Watcher

type Watcher interface {
	Add(name string, handle int) error
	Close() error
	Remove(name string) error
	Events() (handle int, ch <-chan Event)
}

Watcher describes an interface for filesystem watching.

Jump to

Keyboard shortcuts

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