@@ -40,6 +40,7 @@ type input struct {
4040 path string
4141 flags uint32
4242 reply chan error
43+ recurse bool
4344}
4445
4546type inode struct {
@@ -56,6 +57,7 @@ type watch struct {
5657 names map [string ]uint64 // Map of names being watched and their notify flags
5758 rename string // Remembers the old name while renaming a file
5859 buf [4096 ]byte
60+ recurse bool
5961}
6062
6163type indexMap map [uint64 ]* watch
@@ -111,7 +113,7 @@ func (w *Watcher) Close() error {
111113}
112114
113115// AddWatch adds path to the watched file set.
114- func (w * Watcher ) AddWatch (path string , flags uint32 ) error {
116+ func (w * Watcher ) AddWatch (path string , flags uint32 , isRecursive bool ) error {
115117 if w .isClosed {
116118 return errors .New ("watcher already closed" )
117119 }
@@ -120,6 +122,7 @@ func (w *Watcher) AddWatch(path string, flags uint32) error {
120122 path : filepath .Clean (path ),
121123 flags : flags ,
122124 reply : make (chan error ),
125+ recurse : isRecursive
123126 }
124127 w .input <- in
125128 if err := w .wakeupReader (); err != nil {
@@ -218,7 +221,7 @@ func (m watchMap) set(ino *inode, watch *watch) {
218221}
219222
220223// Must run within the I/O thread.
221- func (w * Watcher ) addWatch (pathname string , flags uint64 ) error {
224+ func (w * Watcher ) addWatch (pathname string , flags uint64 , isRecursive bool ) error {
222225 dir , err := getDir (pathname )
223226 if err != nil {
224227 return err
@@ -240,6 +243,7 @@ func (w *Watcher) addWatch(pathname string, flags uint64) error {
240243 ino : ino ,
241244 path : dir ,
242245 names : make (map [string ]uint64 ),
246+ recurse : isRecursive
243247 }
244248 w .watches .set (ino , watchEntry )
245249 flags |= provisional
@@ -321,7 +325,7 @@ func (w *Watcher) startRead(watch *watch) error {
321325 return nil
322326 }
323327 e := syscall .ReadDirectoryChanges (watch .ino .handle , & watch .buf [0 ],
324- uint32 (unsafe .Sizeof (watch .buf )), false , mask , nil , & watch .ov , 0 )
328+ uint32 (unsafe .Sizeof (watch .buf )), watch . recurse , mask , nil , & watch .ov , 0 )
325329 if e != nil {
326330 err := os .NewSyscallError ("ReadDirectoryChanges" , e )
327331 if e == syscall .ERROR_ACCESS_DENIED && watch .mask & provisional == 0 {
@@ -374,7 +378,7 @@ func (w *Watcher) readEvents() {
374378 case in := <- w .input :
375379 switch in .op {
376380 case opAddWatch :
377- in .reply <- w .addWatch (in .path , uint64 (in .flags ))
381+ in .reply <- w .addWatch (in .path , uint64 (in .flags ), in . recurse )
378382 case opRemoveWatch :
379383 in .reply <- w .removeWatch (in .path )
380384 }
0 commit comments