watcher

package
v4.0.6+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWatcherStarted = errors.New("watcher already started")
	ErrWatcherClosed  = errors.New("watcher already closed")
)

errors created by Watcher

Functions

This section is empty.

Types

type Event

type Event struct {
	Path     string
	Op       Op
	FileInfo os.FileInfo
}

Event represents a single file operation event

func (*Event) HasOps

func (e *Event) HasOps(ops ...Op) bool

HasOps checks whether has any specified operation types

func (*Event) IsDirEvent

func (e *Event) IsDirEvent() bool

IsDirEvent returns whether is a event for a directory

type Op

type Op uint32

Op represents file operation type

const (
	Create Op = 1 << iota
	Remove
	Modify
	Rename
	Chmod
	Move
)

Operations type current supported

func (Op) String

func (op Op) String() string

type Watcher

type Watcher struct {
	Events chan Event
	Errors chan error
	// contains filtered or unexported fields
}

Watcher watches for files or directory changes by polling currently, if multi operations applied to one file or directory, only one event (with single Op) will be sent the priority of Op is:

  1. Modify
  2. Chmod
  3. Rename / Move
  4. Create / Remove

func NewWatcher

func NewWatcher() *Watcher

NewWatcher creates a new Watcher instance

func (*Watcher) Add

func (w *Watcher) Add(name string) error

Add adds named file or directory (non-recursively) to the watching list this can only be success if all events be sent (lock release)

func (*Watcher) Close

func (w *Watcher) Close()

Close stops the watching

func (*Watcher) Remove

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

Remove removes named file or directory (non-recursively) from the watching list this can only be success if all events be sent (lock release)

func (*Watcher) Start

func (w *Watcher) Start(d time.Duration) error

Start starts the watching

Jump to

Keyboard shortcuts

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