inotify

package
Version: v0.0.0-...-6203023 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2021 License: Apache-2.0, BSD-3-Clause Imports: 7 Imported by: 15

README

This is a fork of golang.org/x/exp/inotify before it was deleted.

Please use gopkg.in/fsnotify.v0 instead.

For updates, see: https://fsnotify.org/

Documentation

Overview

Package inotify implements a wrapper for the Linux inotify system.

Example:

watcher, err := inotify.NewWatcher()
if err != nil {
    log.Fatal(err)
}
err = watcher.Watch("/tmp")
if err != nil {
    log.Fatal(err)
}
for {
    select {
    case ev := <-watcher.Event:
        log.Println("event:", ev)
    case err := <-watcher.Error:
        log.Println("error:", err)
    }
}

Index

Constants

View Source
const (

	// InDontFollow : Don't dereference pathname if it is a symbolic link
	InDontFollow uint32 = syscall.IN_DONT_FOLLOW
	// InOneshot : Monitor the filesystem object corresponding to pathname for one event, then remove from watch list
	InOneshot uint32 = syscall.IN_ONESHOT
	// InOnlydir : Watch pathname only if it is a directory
	InOnlydir uint32 = syscall.IN_ONLYDIR

	// InAccess : File was accessed
	InAccess uint32 = syscall.IN_ACCESS
	// InAllEvents : Bit mask for all notify events
	InAllEvents uint32 = syscall.IN_ALL_EVENTS
	// InAttrib : Metadata changed
	InAttrib uint32 = syscall.IN_ATTRIB
	// InClose : Equates to IN_CLOSE_WRITE | IN_CLOSE_NOWRITE
	InClose uint32 = syscall.IN_CLOSE
	// InCloseNowrite : File or directory not opened for writing was closed
	InCloseNowrite uint32 = syscall.IN_CLOSE_NOWRITE
	// InCloseWrite : File opened for writing was closed
	InCloseWrite uint32 = syscall.IN_CLOSE_WRITE
	// InCreate : File/directory created in watched directory
	InCreate uint32 = syscall.IN_CREATE
	// InDelete : File/directory deleted from watched directory
	InDelete uint32 = syscall.IN_DELETE
	// InDeleteSelf : Watched file/directory was itself deleted
	InDeleteSelf uint32 = syscall.IN_DELETE_SELF
	// InModify : File was modified
	InModify uint32 = syscall.IN_MODIFY
	// InMove : Equates to IN_MOVED_FROM | IN_MOVED_TO
	InMove uint32 = syscall.IN_MOVE
	// InMovedFrom : Generated for the directory containing the old filename when a file is renamed
	InMovedFrom uint32 = syscall.IN_MOVED_FROM
	// InMovedTo : Generated for the directory containing the new filename when a file is renamed
	InMovedTo uint32 = syscall.IN_MOVED_TO
	// InMoveSelf : Watched file/directory was itself moved
	InMoveSelf uint32 = syscall.IN_MOVE_SELF
	// InOpen : File or directory was opened
	InOpen uint32 = syscall.IN_OPEN

	// InIsdir : Subject of this event is a directory
	InIsdir uint32 = syscall.IN_ISDIR
	// InIgnored : Watch was removed explicitly or automatically
	InIgnored uint32 = syscall.IN_IGNORED
	// InQOverflow : Event queue overflowed
	InQOverflow uint32 = syscall.IN_Q_OVERFLOW
	// InUnmount : Filesystem containing watched object was unmounted
	InUnmount uint32 = syscall.IN_UNMOUNT
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Mask   uint32 // Mask of events
	Cookie uint32 // Unique cookie associating related events (for rename(2))
	Name   string // File name (optional)
}

Event represents a notification

func (*Event) String

func (e *Event) String() string

String formats the event e in the form "filename: 0xEventMask = IN_ACCESS|IN_ATTRIB_|..."

type Watcher

type Watcher struct {
	Error chan error  // Errors are sent on this channel
	Event chan *Event // Events are returned on this channel
	// contains filtered or unexported fields
}

Watcher represents an inotify instance

func NewWatcher

func NewWatcher() (*Watcher, error)

NewWatcher creates and returns a new inotify instance using inotify_init(2)

func (*Watcher) AddWatch

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

AddWatch adds path to the watched file set. The flags are interpreted as described in inotify_add_watch(2).

func (*Watcher) Close

func (w *Watcher) Close() error

Close closes an inotify watcher instance It sends a message to the reader goroutine to quit and removes all watches associated with the inotify instance

func (*Watcher) RemoveWatch

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

RemoveWatch removes path from the watched file set.

func (*Watcher) Watch

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

Watch adds path to the watched file set, watching all events.

Jump to

Keyboard shortcuts

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