Skip to content

Commit

Permalink
The new AddDeepWatch() and DeepWatch() functions were missing for som…
Browse files Browse the repository at this point in the history
…e reason.
  • Loading branch information
b0bh00d committed Mar 3, 2021
1 parent 97ee442 commit 1305fe5
Showing 1 changed file with 45 additions and 21 deletions.
66 changes: 45 additions & 21 deletions winfsnotify/winfsnotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ const (
)

type input struct {
op int
path string
flags uint32
reply chan error
op int
path string
flags uint32
reply chan error
recurse bool
}

Expand All @@ -50,13 +50,13 @@ type inode struct {
}

type watch struct {
ov syscall.Overlapped
ino *inode // i-number
path string // Directory path
mask uint64 // Directory itself is being watched with these notify flags
names map[string]uint64 // Map of names being watched and their notify flags
rename string // Remembers the old name while renaming a file
buf [4096]byte
ov syscall.Overlapped
ino *inode // i-number
path string // Directory path
mask uint64 // Directory itself is being watched with these notify flags
names map[string]uint64 // Map of names being watched and their notify flags
rename string // Remembers the old name while renaming a file
buf [4096]byte
recurse bool
}

Expand Down Expand Up @@ -113,16 +113,35 @@ func (w *Watcher) Close() error {
}

// AddWatch adds path to the watched file set.
func (w *Watcher) AddWatch(path string, flags uint32, isRecursive bool) error {
func (w *Watcher) AddWatch(path string, flags uint32) error {
if w.isClosed {
return errors.New("watcher already closed")
}
in := &input{
op: opAddWatch,
path: filepath.Clean(path),
flags: flags,
reply: make(chan error),
recurse: isRecursive
op: opAddWatch,
path: filepath.Clean(path),
flags: flags,
reply: make(chan error),
recurse: false,
}
w.input <- in
if err := w.wakeupReader(); err != nil {
return err
}
return <-in.reply
}

// AddDeepWatch adds path to the watched file set which will monitor the entire subtree.
func (w *Watcher) AddDeepWatch(path string, flags uint32) error {
if w.isClosed {
return errors.New("watcher already closed")
}
in := &input{
op: opAddWatch,
path: filepath.Clean(path),
flags: flags,
reply: make(chan error),
recurse: true,
}
w.input <- in
if err := w.wakeupReader(); err != nil {
Expand All @@ -136,6 +155,11 @@ func (w *Watcher) Watch(path string) error {
return w.AddWatch(path, FS_ALL_EVENTS)
}

// DeepWatch adds path to the watched file set, watching all events in the entire subtree.
func (w *Watcher) DeepWatch(path string) error {
return w.AddDeepWatch(path, FS_ALL_EVENTS)
}

// RemoveWatch removes path from the watched file set.
func (w *Watcher) RemoveWatch(path string) error {
in := &input{
Expand Down Expand Up @@ -240,10 +264,10 @@ func (w *Watcher) addWatch(pathname string, flags uint64, isRecursive bool) erro
return os.NewSyscallError("CreateIoCompletionPort", e)
}
watchEntry = &watch{
ino: ino,
path: dir,
names: make(map[string]uint64),
recurse: isRecursive
ino: ino,
path: dir,
names: make(map[string]uint64),
recurse: isRecursive,
}
w.watches.set(ino, watchEntry)
flags |= provisional
Expand Down

0 comments on commit 1305fe5

Please sign in to comment.