文件监控类

package
v0.0.0-...-2910145 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package gfsnotify 提供了一个跨平台的文件系统通知接口。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exit

func Exit()

Exit 仅在回调函数中使用,可用于从监视器中移除自身的当前回调。

func Remove

func Remove(path string) error

Remove 递归地从 watcher 中移除指定 `path` 的所有监控回调函数。

func RemoveCallback

func RemoveCallback(callbackId int) error

RemoveCallback 从观察者中移除具有给定id的指定回调函数。

Types

type Callback

type Callback struct {
	Id   int                // 唯一标识回调对象的ID。
	Func func(event *Event) // 回调函数。
	Path string             // 绑定文件路径(绝对路径)。
	// contains filtered or unexported fields
}

Callback是Watcher的回调函数。

func Add

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

Add 使用默认观察器监控`path`,并使用回调函数`callbackFunc`。 可选参数`recursive`指定了是否递归地监控`path`,默认为true。

func AddOnce

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

AddOnce 使用默认的监视器,通过回调函数 `callbackFunc` 仅对 `path` 进行一次性监控,并使用唯一的名称 `name` 标识。 如果多次调用 AddOnce 并传入相同的 `name` 参数,`path` 只会被添加监控一次。如果两次调用时使用了相同的 `name`,将会返回错误。

可选参数 `recursive` 指定是否递归地监控 `path`,默认情况下其值为 true。

type Event

type Event struct {
	Path    string   // 绝对文件路径。
	Op      Op       // File operation.
	Watcher *Watcher // Parent watcher.
	// contains filtered or unexported fields
}

Event 是由底层 fsnotify 产生的事件。

func (*Event) IsChmod

func (e *Event) IsChmod() bool

IsChmod 检查当前事件是否包含文件/文件夹权限更改事件。

func (*Event) IsCreate

func (e *Event) IsCreate() bool

IsCreate 检查当前事件是否包含文件/文件夹创建事件。

func (*Event) IsRemove

func (e *Event) IsRemove() bool

IsRemove 检查当前事件是否包含文件/文件夹移除事件。

func (*Event) IsRename

func (e *Event) IsRename() bool

IsRename 检查当前事件是否包含文件/文件夹重命名事件。

func (*Event) IsWrite

func (e *Event) IsWrite() bool

IsWrite 检查当前事件是否包含文件/文件夹写入事件。

func (*Event) String

func (e *Event) String() string

String 返回当前事件的字符串表示。

type Op

type Op uint32

Op 是用于文件操作的位集合(联合体)。

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

type Watcher

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

Watcher 是用于文件变化监测的监视器。

func New

func New() (*Watcher, error)

New 创建并返回一个新的监视器。 注意,监视器的数量受系统文件句柄设置的限制。 例如:在Linux系统中,fs.inotify.max_user_instances系统变量。

func (*Watcher) Add

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

添加监控,将回调函数`callbackFunc`添加到watcher中,并监控路径`path`。 可选参数`recursive`指定了是否递归地监控路径`path`,默认为true。

func (*Watcher) AddOnce

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

AddOnce 通过唯一名称 `name` 使用回调函数 `callbackFunc` 仅对 `path` 进行一次性监控。 如果多次调用 AddOnce 并传入相同的 `name` 参数,`path` 只会被添加一次进行监控。

若同一 `name` 被调用两次,将会返回错误。

可选参数 `recursive` 指定是否递归地监控 `path`,默认情况下其值为 true。

func (*Watcher) Close

func (w *Watcher) Close()

Close 关闭监视器。

func (*Watcher) Remove

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

Remove 递归地移除与`path`关联的监视器及其所有回调。

func (*Watcher) RemoveCallback

func (w *Watcher) RemoveCallback(callbackId int)

RemoveCallback 从 watcher 中移除具有给定回调 id 的回调函数。

Jump to

Keyboard shortcuts

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