Implement FileWatcher

This commit is contained in:
Ben Johnson
2022-02-06 09:27:26 -07:00
parent 8009bcf654
commit 762c7ae531
15 changed files with 1132 additions and 53 deletions

36
internal/file_watcher.go Normal file
View File

@@ -0,0 +1,36 @@
package internal
import (
"errors"
)
// File event mask constants.
const (
FileEventCreated = 1 << iota
FileEventModified
FileEventDeleted
)
// FileEvent represents an event on a watched file.
type FileEvent struct {
Name string
Mask int
}
// ErrFileEventQueueOverflow is returned when the file event queue has overflowed.
var ErrFileEventQueueOverflow = errors.New("file event queue overflow")
// FileWatcher represents a watcher of file events.
type FileWatcher interface {
Open() error
Close() error
// Returns a channel of events for watched files.
Events() <-chan FileEvent
// Adds a specific file to be watched.
Watch(filename string) error
// Removes a specific file from being watched.
Unwatch(filename string) error
}