gfsnotify

package
v1.8.3 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

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

文件监控.

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 *Event) // 回调方法
	Path string             // 监听的文件/目录
	// contains filtered or unexported fields
}

注册的监听回调方法

func Add

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

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

type Event

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

监听事件对象

func (*Event) IsChmod

func (e *Event) IsChmod() bool

文件/目录修改权限

func (*Event) IsCreate

func (e *Event) IsCreate() bool

文件/目录创建

func (*Event) IsRemove

func (e *Event) IsRemove() bool

文件/目录删除

func (*Event) IsRename

func (e *Event) IsRename() bool

文件/目录重命名

func (*Event) IsWrite

func (e *Event) IsWrite() bool

文件/目录修改

func (*Event) String

func (e *Event) String() string

type Op

type Op uint32

按位进行识别的操作集合

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

必须放到一个const分组里面

type Watcher

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

监听管理对象

func New

func New() (*Watcher, error)

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

func (*Watcher) Add

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

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

func (*Watcher) Close

func (w *Watcher) Close()

关闭监听管理对象

func (*Watcher) Remove

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

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

func (*Watcher) RemoveCallback

func (w *Watcher) RemoveCallback(callbackId int)

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

Jump to

Keyboard shortcuts

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