gfsnotify

package
v2.7.8 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2024 License: MIT Imports: 18 Imported by: 1

Documentation

Overview

Package gfsnotify provides a platform-independent interface for file system notifications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exit

func Exit()

Exit is only used in the callback function, which can be used to remove current callback of itself from the watcher.

func Remove

func Remove(path string) error

Remove removes all monitoring callbacks of given `path` from watcher recursively.

func RemoveCallback

func RemoveCallback(callbackId int) error

RemoveCallback removes specified callback with given id from watcher.

Types

type Callback

type Callback struct {
	Id   int                // Unique id for callback object.
	Func func(event *Event) // Callback function.
	Path string             // Bound file path (absolute).
	// contains filtered or unexported fields
}

Callback is the callback function for Watcher.

func Add

func Add(path string, callbackFunc func(event *Event), option ...WatchOption) (callback *Callback, err error)

Add monitors `path` using default watcher with callback function `callbackFunc`.

The parameter `path` can be either a file or a directory path. The optional parameter `recursive` specifies whether monitoring the `path` recursively, which is true in default.

func AddOnce

func AddOnce(name, path string, callbackFunc func(event *Event), option ...WatchOption) (callback *Callback, err error)

AddOnce monitors `path` using default watcher with callback function `callbackFunc` only once using unique name `name`.

If AddOnce is called multiple times with the same `name` parameter, `path` is only added to monitor once. It returns error if it's called twice with the same `name`.

The parameter `path` can be either a file or a directory path. The optional parameter `recursive` specifies whether monitoring the `path` recursively, which is true in default.

type Event

type Event struct {
	Path    string   // Absolute file path.
	Op      Op       // File operation.
	Watcher *Watcher // Parent watcher.
	// contains filtered or unexported fields
}

Event is the event produced by underlying fsnotify.

func (*Event) IsChmod

func (e *Event) IsChmod() bool

IsChmod checks whether current event contains file/folder chmod event.

func (*Event) IsCreate

func (e *Event) IsCreate() bool

IsCreate checks whether current event contains file/folder create event.

func (*Event) IsRemove

func (e *Event) IsRemove() bool

IsRemove checks whether current event contains file/folder remove event.

func (*Event) IsRename

func (e *Event) IsRename() bool

IsRename checks whether current event contains file/folder rename event.

func (*Event) IsWrite

func (e *Event) IsWrite() bool

IsWrite checks whether current event contains file/folder write event.

func (*Event) String

func (e *Event) String() string

String returns current event as string.

type Op

type Op uint32

Op is the bits union for file operations.

const (
	CREATE Op = 1 << iota
	WRITE
	REMOVE
	RENAME
	CHMOD
)

type WatchOption added in v2.7.8

type WatchOption struct {
	// NoRecursive explicitly specifies no recursive watching.
	// Recursive watching will also watch all its current and following created subfolders and sub-files.
	//
	// Note that the recursive watching is enabled in default.
	NoRecursive bool
}

WatchOption holds the option for watching.

type Watcher

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

Watcher is the monitor for file changes.

func New

func New() (*Watcher, error)

New creates and returns a new watcher. Note that the watcher number is limited by the file handle setting of the system. Example: fs.inotify.max_user_instances system variable in linux systems.

In most case, you can use the default watcher for usage instead of creating one.

func (*Watcher) Add

func (w *Watcher) Add(
	path string, callbackFunc func(event *Event), option ...WatchOption,
) (callback *Callback, err error)

Add monitors `path` with callback function `callbackFunc` to the watcher.

The parameter `path` can be either a file or a directory path. The optional parameter `recursive` specifies whether monitoring the `path` recursively, which is true in default.

func (*Watcher) AddOnce

func (w *Watcher) AddOnce(
	name, path string, callbackFunc func(event *Event), option ...WatchOption,
) (callback *Callback, err error)

AddOnce monitors `path` with callback function `callbackFunc` only once using unique name `name` to the watcher. If AddOnce is called multiple times with the same `name` parameter, `path` is only added to monitor once.

It returns error if it's called twice with the same `name`.

The parameter `path` can be either a file or a directory path. The optional parameter `recursive` specifies whether monitoring the `path` recursively, which is true in default.

func (*Watcher) Close

func (w *Watcher) Close()

Close closes the watcher.

func (*Watcher) Remove

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

Remove removes watching and all callbacks associated with the `path` recursively. Note that, it's recursive in default if given `path` is a directory.

func (*Watcher) RemoveCallback

func (w *Watcher) RemoveCallback(callbackId int)

RemoveCallback removes callback with given callback id from watcher.

Note that, it auto removes the path watching if there's no callback bound on it.

Jump to

Keyboard shortcuts

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