Skip to content

Commit

Permalink
add WatchList() method for bsd and windows platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
NitroCao committed Apr 19, 2022
1 parent 34a61b2 commit 43df2ef
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
8 changes: 4 additions & 4 deletions inotify.go
Expand Up @@ -165,16 +165,16 @@ func (w *Watcher) Remove(name string) error {

// WatchList returns the directories and files that are being monitered.
func (w *Watcher) WatchList() []string {
var dirs []string
var entries []string

w.mu.Lock()
defer w.mu.Unlock()

for key := range w.watches {
dirs = append(dirs, key)
for pathname, _ := range w.watches {
entries = append(entries, pathname)
}

return dirs
return entries
}

type watch struct {
Expand Down
14 changes: 14 additions & 0 deletions kqueue.go
Expand Up @@ -148,6 +148,20 @@ func (w *Watcher) Remove(name string) error {
return nil
}

// WatchList returns the directories and files that are being monitered.
func (w *Watcher) WatchList() []string {
var entries []string

w.mu.Lock()
defer w.mu.Unlock()

for pathname, _ := range w.watches {
entries = append(entries, pathname)
}

return entries
}

// Watch all events (except NOTE_EXTEND, NOTE_LINK, NOTE_REVOKE)
const noteAllEvents = unix.NOTE_DELETE | unix.NOTE_WRITE | unix.NOTE_ATTRIB | unix.NOTE_RENAME

Expand Down
13 changes: 13 additions & 0 deletions windows.go
Expand Up @@ -97,6 +97,19 @@ func (w *Watcher) Remove(name string) error {
return <-in.reply
}

// WatchList returns the directories and files that are being monitered.
func (w *Watcher) WatchList() []string {
var entries []string

w.mu.Lock()
w.mu.Unlock()
for _, entry := range w.watches {
entries = append(entries, entry.path)
}

return entries
}

const (
// Options for AddWatch
sysFSONESHOT = 0x80000000
Expand Down

0 comments on commit 43df2ef

Please sign in to comment.