@@ -36,10 +36,10 @@ const (
36
36
)
37
37
38
38
type 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
43
43
recurse bool
44
44
}
45
45
@@ -50,13 +50,13 @@ type inode struct {
50
50
}
51
51
52
52
type 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
60
60
recurse bool
61
61
}
62
62
@@ -113,16 +113,35 @@ func (w *Watcher) Close() error {
113
113
}
114
114
115
115
// 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 {
117
117
if w .isClosed {
118
118
return errors .New ("watcher already closed" )
119
119
}
120
120
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 ,
126
145
}
127
146
w .input <- in
128
147
if err := w .wakeupReader (); err != nil {
@@ -136,6 +155,11 @@ func (w *Watcher) Watch(path string) error {
136
155
return w .AddWatch (path , FS_ALL_EVENTS )
137
156
}
138
157
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
+
139
163
// RemoveWatch removes path from the watched file set.
140
164
func (w * Watcher ) RemoveWatch (path string ) error {
141
165
in := & input {
@@ -240,10 +264,10 @@ func (w *Watcher) addWatch(pathname string, flags uint64, isRecursive bool) erro
240
264
return os .NewSyscallError ("CreateIoCompletionPort" , e )
241
265
}
242
266
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 ,
247
271
}
248
272
w .watches .set (ino , watchEntry )
249
273
flags |= provisional
0 commit comments