@@ -36,10 +36,10 @@ const (
3636)
3737
3838type input struct {
39- op int
40- path string
41- flags uint32
42- reply chan error
39+ op int
40+ path string
41+ flags uint32
42+ reply chan error
4343 recurse bool
4444}
4545
@@ -50,13 +50,13 @@ type inode struct {
5050}
5151
5252type watch struct {
53- ov syscall.Overlapped
54- ino * inode // i-number
55- path string // Directory path
56- mask uint64 // Directory itself is being watched with these notify flags
57- names map [string ]uint64 // Map of names being watched and their notify flags
58- rename string // Remembers the old name while renaming a file
59- buf [4096 ]byte
53+ ov syscall.Overlapped
54+ ino * inode // i-number
55+ path string // Directory path
56+ mask uint64 // Directory itself is being watched with these notify flags
57+ names map [string ]uint64 // Map of names being watched and their notify flags
58+ rename string // Remembers the old name while renaming a file
59+ buf [4096 ]byte
6060 recurse bool
6161}
6262
@@ -113,16 +113,35 @@ func (w *Watcher) Close() error {
113113}
114114
115115// AddWatch adds path to the watched file set.
116- func (w * Watcher ) AddWatch (path string , flags uint32 , isRecursive bool ) error {
116+ func (w * Watcher ) AddWatch (path string , flags uint32 ) error {
117117 if w .isClosed {
118118 return errors .New ("watcher already closed" )
119119 }
120120 in := & input {
121- op : opAddWatch ,
122- path : filepath .Clean (path ),
123- flags : flags ,
124- reply : make (chan error ),
125- recurse : isRecursive
121+ op : opAddWatch ,
122+ path : filepath .Clean (path ),
123+ flags : flags ,
124+ reply : make (chan error ),
125+ recurse : false ,
126+ }
127+ w .input <- in
128+ if err := w .wakeupReader (); err != nil {
129+ return err
130+ }
131+ return <- in .reply
132+ }
133+
134+ // AddDeepWatch adds path to the watched file set which will monitor the entire subtree.
135+ func (w * Watcher ) AddDeepWatch (path string , flags uint32 ) error {
136+ if w .isClosed {
137+ return errors .New ("watcher already closed" )
138+ }
139+ in := & input {
140+ op : opAddWatch ,
141+ path : filepath .Clean (path ),
142+ flags : flags ,
143+ reply : make (chan error ),
144+ recurse : true ,
126145 }
127146 w .input <- in
128147 if err := w .wakeupReader (); err != nil {
@@ -136,6 +155,11 @@ func (w *Watcher) Watch(path string) error {
136155 return w .AddWatch (path , FS_ALL_EVENTS )
137156}
138157
158+ // DeepWatch adds path to the watched file set, watching all events in the entire subtree.
159+ func (w * Watcher ) DeepWatch (path string ) error {
160+ return w .AddDeepWatch (path , FS_ALL_EVENTS )
161+ }
162+
139163// RemoveWatch removes path from the watched file set.
140164func (w * Watcher ) RemoveWatch (path string ) error {
141165 in := & input {
@@ -240,10 +264,10 @@ func (w *Watcher) addWatch(pathname string, flags uint64, isRecursive bool) erro
240264 return os .NewSyscallError ("CreateIoCompletionPort" , e )
241265 }
242266 watchEntry = & watch {
243- ino : ino ,
244- path : dir ,
245- names : make (map [string ]uint64 ),
246- recurse : isRecursive
267+ ino : ino ,
268+ path : dir ,
269+ names : make (map [string ]uint64 ),
270+ recurse : isRecursive ,
247271 }
248272 w .watches .set (ino , watchEntry )
249273 flags |= provisional
0 commit comments