package inotify
import "k8s.io/utils/inotify"
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 ¶
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 )
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 ¶
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 ¶
NewWatcher creates and returns a new inotify instance using inotify_init(2)
func (*Watcher) AddWatch ¶
AddWatch adds path to the watched file set. The flags are interpreted as described in inotify_add_watch(2).
func (*Watcher) Close ¶
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 ¶
RemoveWatch removes path from the watched file set.
func (*Watcher) Watch ¶
Watch adds path to the watched file set, watching all events.
Source Files ¶
inotify.go inotify_linux.go
- Version
- v0.0.0-20250321185631-1f6e0b77f77e (latest)
- Published
- Mar 21, 2025
- Platform
- linux/amd64
- Imports
- 7 packages
- Last checked
- 2 weeks ago –
Tools for package owners.