Documentation ¶
Overview ¶
Package inotify provides a no-frills, fully exposed, Linux inotify implementation in go.
There are several other packages available which already provide inotify functionality, but many of them provide abstractions which restrict what you can do. This package is meant to fully expose inotify, allowing as much control as desired. There are no hidden struct members, and the code is extremely simple.
In addition, the package does not utilize Cgo, and should thus work with the native go compiler, avoiding all the little gotchas that Cgo brings.
Example ¶
in, err := inotify.New() if err != nil { fmt.Printf("Error: %s\n", err) return } w, err := in.AddWatch("/tmp", inotify.IN_CREATE|inotify.IN_DELETE) if err != nil { fmt.Printf("Error: %s\n", err) return } // Test IN_CREATE tf, _ := ioutil.TempFile("/tmp", "") tf.Close() event, err := in.Read() if err != nil { fmt.Printf("Error: %s\n", err) return } fmt.Printf("Event: %+v\n", event) // Test IN_DELETE os.Remove(tf.Name()) event, err = in.Read() if err != nil { fmt.Printf("Error: %s\n", err) return } fmt.Printf("Event: %+v\n", event) // Stop watching the specific watch in.RemoveWatch(w) // Shut down entirely in.Close()
Output:
Index ¶
Examples ¶
Constants ¶
const ( IN_ACCESS Mask = unix.IN_ACCESS IN_ATTRIB Mask = unix.IN_ATTRIB IN_CLOSE_WRITE Mask = unix.IN_CLOSE_WRITE IN_CLOSE_NOWRITE Mask = unix.IN_CLOSE_NOWRITE IN_CREATE Mask = unix.IN_CREATE IN_DELETE Mask = unix.IN_DELETE IN_DELETE_SELF Mask = unix.IN_DELETE_SELF IN_MODIFY Mask = unix.IN_MODIFY IN_MOVE_SELF Mask = unix.IN_MOVE_SELF IN_MOVED_FROM Mask = unix.IN_MOVED_FROM IN_MOVED_TO Mask = unix.IN_MOVED_TO IN_OPEN Mask = unix.IN_OPEN IN_MOVE Mask = unix.IN_MOVE IN_CLOSE Mask = unix.IN_CLOSE IN_ALL_EVENTS Mask = unix.IN_ALL_EVENTS IN_DONT_FOLLOW Mask = unix.IN_DONT_FOLLOW IN_MASK_ADD Mask = unix.IN_MASK_ADD IN_ONESHOT Mask = unix.IN_ONESHOT IN_ONLYDIR Mask = unix.IN_ONLYDIR IN_MASK_CREATE Mask = unix.IN_MASK_CREATE IN_IGNORED uint32 = unix.IN_IGNORED IN_ISDIR uint32 = unix.IN_ISDIR IN_Q_OVERFLOW uint32 = unix.IN_Q_OVERFLOW IN_UNMOUNT uint32 = unix.IN_UNMOUNT )
These are duplicated locally and type converted for convenience.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct { // type InotifyEvent struct { // Wd int32 // Mask uint32 // Cookie uint32 // Len uint32 // } unix.InotifyEvent Name string }
type Inotify ¶
func (*Inotify) AddWatch ¶
func (in *Inotify) AddWatch(pathname string, mask Mask) (InotifyWatchDesc, error)
AddWatch adds the given path to the watch list and returns a new watch descriptor. The watch descriptor can be provided to RemoveWatch() to stop watching.
func (*Inotify) RemoveWatch ¶
func (in *Inotify) RemoveWatch(watchDesc InotifyWatchDesc) error
Removes the given watch descriptor from the watch list.
type InotifyWatchDesc ¶
type InotifyWatchDesc int32