watcher

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package watcher implements recursive folder monitoring by wrapping the excellent fsnotify library

Index

Constants

View Source
const (
	BlockSize int64 = 4194304
)

Variables

View Source
var ErrSkip = errors.New("error: skipping file")

ErrSkip is less of an error, but more of a way for path hooks to skip a file or directory.

Functions

func GetEtagByReader added in v1.0.2

func GetEtagByReader(reader Reader, size int64) string

Types

type Event added in v1.0.2

type Event struct {
	SettingKey string
	File       *local.FileInfo
	Ori        *local.FileInfo
	HandlerKey string
	Op         fsnotify.Op
}

type FilterFileHookFunc

type FilterFileHookFunc func(info os.FileInfo, fullPath string) error

FilterFileHookFunc is a function that is called to filter files during listings. If a file is ok to be listed, nil is returned otherwise ErrSkip is returned.

func RegexFilterHook

func RegexFilterHook(r *regexp.Regexp, useFullPath bool) FilterFileHookFunc

RegexFilterHook is a function that accepts or rejects a file for listing based on whether it's filename or full path matches a regular expression.

type Option

type Option = func(w *Watcher)

func WithFilterHook

func WithFilterHook(f FilterFileHookFunc) Option

WithFilterHook

func WithIgnoreHiddenFiles

func WithIgnoreHiddenFiles(ignore bool) Option

WithIgnoreHiddenFiles sets the watcher to ignore any file or directory that starts with a dot.

func WithOpFilter

func WithOpFilter(op fsnotify.Op) Option

WithEventFilter filters which event op types should be returned when an event occurs.

type Reader added in v1.0.2

type Reader interface {
	Read([]byte) (int, error)
	ReadAt([]byte, int64) (int, error)
}

type Watcher

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

Watcher wraps fsnotify.Watcher. When fsnotify adds recursive watches, you should be able to switch your code to use fsnotify.Watcher

func NewWatcher

func NewWatcher(opts ...Option) (*Watcher, error)

NewWatcher establishes a new watcher with the underlying OS and begins waiting for events.

func (*Watcher) Add

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

Add starts watching the named file or directory (non-recursively).

func (*Watcher) AddRecursive

func (m *Watcher) AddRecursive(name string) error

AddRecursive starts watching the named directory and all sub-directories.

func (*Watcher) Close

func (m *Watcher) Close() error

Close removes all watches and closes the events channel.

func (*Watcher) Notify added in v1.0.1

func (m *Watcher) Notify(handlerKey string)

func (*Watcher) Remove

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

Remove stops watching the the named file or directory (non-recursively).

func (*Watcher) RemoveRecursive

func (m *Watcher) RemoveRecursive(name string) error

RemoveRecursive stops watching the named directory and all sub-directories.

func (*Watcher) Start added in v1.0.2

func (m *Watcher) Start(name string) error

Jump to

Keyboard shortcuts

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