inotify

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2023 License: BSD-2-Clause Imports: 7 Imported by: 0

README

inotify

Linux inotify

简介

这是一个可以监听多个文件和目录的项目,可以实现多路监听者。所有监听者保留监听文件或者目录的绝对路径,所有如果监听的文件或者目录本身发生了
DELETE_SELF、MOVE_SELF这两个事件的时候,将会被完全关闭监听者。

例子


func main() {
	w, err := inotify.NewWatcher()
	if err != nil {
		fmt.Println("NewWatcher err", err)
		return
	}
	w.AddWatch("/temp", syscall.IN_OPEN|syscall.IN_CLOSE|syscall.IN_DELETE|syscall.IN_DELETE_SELF|syscall.IN_CREATE|syscall.IN_IGNORED|syscall.IN_MODIFY|syscall.IN_MOVE|syscall.IN_MOVE_SELF|syscall.IN_MOVED_FROM|syscall.IN_MOVED_TO|syscall.IN_MOVE_SELF|syscall.IN_ATTRIB)
	fmt.Println("start")
	for {
		ws, err := w.WaitEvent()
		if err != nil {
			fmt.Println("WaitEvent Error", err)
			time.Sleep(time.Millisecond*300)
			continue
		}
		fmt.Println("WaitEvent:", ws.Mask, ws.FileName, ws.GetEventName())
	}
	fmt.Println("end")
}

Documentation

Overview

@@ @ Author : Eacher @ Date : 2023-02-25 11:49:47 @ LastEditTime : 2023-02-28 10:05:26 @ LastEditors : Eacher @ --------------------------------------------------------------------------------< @ Description : @ --------------------------------------------------------------------------------< @ FilePath : /inotify/inotify.go @@

+build linux @@ @ Author : Eacher @ Date : 2023-02-20 08:45:05 @ LastEditTime : 2023-02-28 10:06:20 @ LastEditors : Eacher @ --------------------------------------------------------------------------------< @ Description : Linux inotify 文件监听功能 @ --------------------------------------------------------------------------------< @ FilePath : /inotify/inotify_linux.go @@

Index

Constants

View Source
const (
	IN_ATTRIB        = in_ATTRIB
	IN_CLOSE         = in_CLOSE
	IN_CLOSE_NOWRITE = in_CLOSE_NOWRITE
	IN_CLOSE_WRITE   = in_CLOSE_WRITE
	IN_CREATE        = in_CREATE
	IN_DELETE        = in_DELETE
	IN_DELETE_SELF   = in_DELETE_SELF
	IN_MODIFY        = in_MODIFY
	IN_MOVE          = in_MOVE
	IN_MOVED_FROM    = in_MOVED_FROM
	IN_MOVED_TO      = in_MOVED_TO
	IN_MOVE_SELF     = in_MOVE_SELF
	IN_OPEN          = in_OPEN
)
View Source
const MAX_ITEM = syscall.SizeofInotifyEvent * 20

防止数组溢出

Variables

This section is empty.

Functions

This section is empty.

Types

type WatchSingle

type WatchSingle struct {
	FileName string
	Mask     uint32
	// contains filtered or unexported fields
}

func (WatchSingle) GetEventName

func (ws WatchSingle) GetEventName() string

type Watcher

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

func NewWatcher

func NewWatcher() (*Watcher, error)

func (*Watcher) AddWatch

func (w *Watcher) AddWatch(path string, flags uint32) error

func (*Watcher) Close

func (w *Watcher) Close()

func (*Watcher) WaitEvent

func (w *Watcher) WaitEvent() (WatchSingle, error)

Jump to

Keyboard shortcuts

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