Documentation
¶
Overview ¶
Package fsnotify provides a platform-independent interface for file system notifications.
Index ¶
Examples ¶
Constants ¶
View Source
const DefaultFlags = unix.IN_MOVED_TO | unix.IN_MOVED_FROM | unix.IN_CREATE | unix.IN_ATTRIB | unix.IN_MODIFY | unix.IN_MOVE_SELF | unix.IN_DELETE | unix.IN_DELETE_SELF
Variables ¶
View Source
var (
ErrEventOverflow = errors.New("queue overflow")
)
Common errors that can be reported by a watcher
Functions ¶
This section is empty.
Types ¶
type Event ¶ added in v1.0.0
type Event struct {
Name string // Relative path to the file or directory.
Op Op // File operation that triggered the event.
File *os.File
}
Event represents a single file system notification.
type FanotifyWatcher ¶
type FanotifyWatcher struct {
Events chan Event
Errors chan error
// contains filtered or unexported fields
}
func NewFanotifyWatcher ¶
func NewFanotifyWatcher() (*FanotifyWatcher, error)
func (*FanotifyWatcher) Add ¶
func (fw *FanotifyWatcher) Add(path string) error
func (*FanotifyWatcher) Close ¶
func (fw *FanotifyWatcher) Close() error
type Op ¶ added in v1.0.0
type Op uint32
Op describes a set of file operations.
These are the generalized file operations that can trigger a notification.
type Watcher ¶
type Watcher struct {
Events chan Event
Errors chan error
// contains filtered or unexported fields
}
Watcher watches a set of files, delivering events to a channel.
func NewWatcher ¶
NewWatcher establishes a new watcher with the underlying OS and begins waiting for events.
Example ¶
package main
import (
"log"
"github.com/cloudlinux/fsnotify"
)
func main() {
watcher, err := fsnotify.NewWatcher(fsnotify.DefaultFlags)
if err != nil {
log.Fatal(err)
}
defer watcher.Close()
done := make(chan bool)
go func() {
for {
select {
case event, ok := <-watcher.Events:
if !ok {
return
}
log.Println("event:", event)
if event.Op&fsnotify.Write == fsnotify.Write {
log.Println("modified file:", event.Name)
}
case err, ok := <-watcher.Errors:
if !ok {
return
}
log.Println("error:", err)
}
}
}()
err = watcher.Add("/tmp/foo")
if err != nil {
log.Fatal(err)
}
<-done
}
func (*Watcher) Add ¶ added in v1.0.0
Add starts watching the named file or directory (non-recursively).
Click to show internal directories.
Click to hide internal directories.