@@ -24,6 +24,8 @@ import (
2424 "github.com/fsnotify/fsnotify"
2525 "github.com/joeshaw/multierror"
2626 "github.com/pkg/errors"
27+
28+ "github.com/elastic/beats/libbeat/logp"
2729)
2830
2931type recursiveWatcher struct {
@@ -33,6 +35,7 @@ type recursiveWatcher struct {
3335 done chan bool
3436 addC chan string
3537 addErrC chan error
38+ log * logp.Logger
3639}
3740
3841func newRecursiveWatcher (inner * fsnotify.Watcher ) * recursiveWatcher {
@@ -42,6 +45,7 @@ func newRecursiveWatcher(inner *fsnotify.Watcher) *recursiveWatcher {
4245 eventC : make (chan fsnotify.Event , 1 ),
4346 addC : make (chan string ),
4447 addErrC : make (chan error ),
48+ log : logp .NewLogger (moduleName ),
4549 }
4650}
4751
@@ -101,6 +105,8 @@ func (watcher *recursiveWatcher) addRecursive(path string) error {
101105 }
102106 return err
103107 })
108+ watcher .log .Debugw ("Added recursive watch" , "path" , path )
109+
104110 if err != nil {
105111 errs = append (errs , errors .Wrapf (err , "failed to walk path '%s'" , path ))
106112 }
@@ -147,33 +153,47 @@ func (watcher *recursiveWatcher) forwardEvents() error {
147153 }
148154 switch event .Op {
149155 case fsnotify .Create :
150- if err := watcher .addRecursive (event .Name ); err != nil {
151- watcher .inner .Errors <- errors .Wrapf (err , "unable to recurse path '%s'" , event .Name )
156+ err := watcher .addRecursive (event .Name )
157+ if err != nil {
158+ watcher .inner .Errors <- errors .Wrapf (err , "failed to add created path '%s'" , event .Name )
152159 }
153- watcher .tree .Visit (event .Name , PreOrder , func (path string , _ bool ) error {
160+ err = watcher .tree .Visit (event .Name , PreOrder , func (path string , _ bool ) error {
154161 watcher .deliver (fsnotify.Event {
155162 Name : path ,
156163 Op : event .Op ,
157164 })
158165 return nil
159166 })
167+ if err != nil {
168+ watcher .inner .Errors <- errors .Wrapf (err , "failed to visit created path '%s'" , event .Name )
169+ }
160170
161171 case fsnotify .Remove :
162- watcher .tree .Visit (event .Name , PostOrder , func (path string , _ bool ) error {
172+ err := watcher .tree .Visit (event .Name , PostOrder , func (path string , _ bool ) error {
163173 watcher .deliver (fsnotify.Event {
164174 Name : path ,
165175 Op : event .Op ,
166176 })
167177 return nil
168178 })
169- watcher .tree .Remove (event .Name )
179+ if err != nil {
180+ watcher .inner .Errors <- errors .Wrapf (err , "failed to visit removed path '%s'" , event .Name )
181+ }
182+
183+ err = watcher .tree .Remove (event .Name )
184+ if err != nil {
185+ watcher .inner .Errors <- errors .Wrapf (err , "failed to visit removed path '%s'" , event .Name )
186+ }
170187
171188 // Handling rename (move) as a special case to give this recursion
172189 // the same semantics as macOS FSEvents:
173190 // - Removal of a dir notifies removal for all files inside it
174191 // - Moving a dir away sends only one notification for this dir
175192 case fsnotify .Rename :
176- watcher .tree .Remove (event .Name )
193+ err := watcher .tree .Remove (event .Name )
194+ if err != nil {
195+ watcher .inner .Errors <- errors .Wrapf (err , "failed to remove path '%s'" , event .Name )
196+ }
177197 fallthrough
178198
179199 default :
0 commit comments