MCPcopy
hub / github.com/yusing/godoxy / NewDirectoryWatcher

Function NewDirectoryWatcher

internal/watcher/directory_watcher.go:39–62  ·  view source on GitHub ↗

NewDirectoryWatcher returns a DirWatcher instance. The DirWatcher watches the given directory for file system events. Currently, only events on files directly in the given directory are watched, not recursively. Note that the returned DirWatcher is not ready to use until the goroutine started by N

(parent task.Parent, dirPath string)

Source from the content-addressed store, hash-verified

37// Note that the returned DirWatcher is not ready to use until the goroutine
38// started by NewDirectoryWatcher has finished.
39func NewDirectoryWatcher(parent task.Parent, dirPath string) *DirWatcher {
40 //! subdirectories are not watched
41 w, err := fsnotify.NewWatcher()
42 if err != nil {
43 log.Panic().Err(err).Msg("unable to create fs watcher")
44 }
45 if err = w.Add(dirPath); err != nil {
46 log.Panic().Err(err).Msg("unable to create fs watcher")
47 }
48 helper := &DirWatcher{
49 Logger: log.With().
50 Str("type", "dir").
51 Str("path", dirPath).
52 Logger(),
53 dir: dirPath,
54 w: w,
55 fwMap: make(map[string]*fileWatcher),
56 eventCh: make(chan Event),
57 errCh: make(chan error),
58 task: parent.Subtask("dir_watcher("+dirPath+")", true),
59 }
60 go helper.start()
61 return helper
62}
63
64var _ Watcher = (*DirWatcher)(nil)
65

Callers 2

setupFunction · 0.92
initConfigDirWatcherFunction · 0.85

Calls 5

startMethod · 0.95
ErrMethod · 0.80
NewWatcherMethod · 0.65
AddMethod · 0.65
LoggerMethod · 0.65

Tested by

no test coverage detected