xfileNotify

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2020 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const (
	REPEAT_EVENT_FILTER_INTERVAL = 1 // (毫秒)重复事件过滤间隔

)

Variables

This section is empty.

Functions

func Exit

func Exit()

在回调方法中调用该方法退出回调注册

func Remove

func Remove(path string) error

递归移除对指定文件/目录的所有监听回调

func RemoveCallback

func RemoveCallback(callbackId int) error

根据指定的回调函数ID,移出指定的inotify回调函数

Types

type Callback

type Callback struct {
	Id   int                 // 唯一ID
	Func func(event *TEvent) // 回调方法
	Path string              // 监听的文件/目录
	// contains filtered or unexported fields
}

注册的监听回调方法

func Add

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

添加对指定文件/目录的监听,并给定回调函数;如果给定的是一个目录,默认递归监控。

type Op

type Op uint32

按位进行识别的操作集合

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

必须放到一个const分组里面

type TEvent

type TEvent struct {
	Path    string    // 文件绝对路径
	Op      Op        // 触发监听的文件操作
	Watcher *TWatcher // 事件对应的监听对象
	// contains filtered or unexported fields
}

监听事件对象

func (*TEvent) IsChmod

func (e *TEvent) IsChmod() bool

文件/目录修改权限

func (*TEvent) IsCreate

func (e *TEvent) IsCreate() bool

文件/目录创建

func (*TEvent) IsRemove

func (e *TEvent) IsRemove() bool

文件/目录删除

func (*TEvent) IsRename

func (e *TEvent) IsRename() bool

文件/目录重命名

func (*TEvent) IsWrite

func (e *TEvent) IsWrite() bool

文件/目录修改

func (*TEvent) String

func (e *TEvent) String() string

type TWatcher

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

监听管理对象

func New

func New() (*TWatcher, error)

创建监听管理对象,主要注意的是创建监听对象会占用系统的inotify句柄数量,受到 fs.inotify.max_user_instances 的限制

func (*TWatcher) Add

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

添加监控,path参数支持文件或者目录路径,recursive为非必需参数,默认为递归监控(当path为目录时)。 如果添加目录,这里只会返回目录的callback,按照callback删除时会递归删除。

func (*TWatcher) Close

func (w *TWatcher) Close()

关闭监听管理对象

func (*TWatcher) Remove

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

递归移除对指定文件/目录的所有监听回调

func (*TWatcher) RemoveCallback

func (w *TWatcher) RemoveCallback(callbackId int)

根据指定的回调函数ID,移出指定的inotify回调函数

Jump to

Keyboard shortcuts

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