File tree 2 files changed +29
-19
lines changed
2 files changed +29
-19
lines changed Original file line number Diff line number Diff line change @@ -290,6 +290,25 @@ func TestMoveAndReplace(t *testing.T) {
290
290
f .assertEvents (file )
291
291
}
292
292
293
+ func TestWatchBothDirAndFile (t * testing.T ) {
294
+ f := newNotifyFixture (t )
295
+ defer f .tearDown ()
296
+
297
+ dir := f .JoinPath ("foo" )
298
+ fileA := f .JoinPath ("foo" , "a" )
299
+ fileB := f .JoinPath ("foo" , "b" )
300
+ f .WriteFile (fileA , "a" )
301
+ f .WriteFile (fileB , "b" )
302
+
303
+ f .watch (fileA )
304
+ f .watch (dir )
305
+ f .fsync ()
306
+ f .events = nil
307
+
308
+ f .WriteFile (fileB , "b-new" )
309
+ f .assertEvents (fileB )
310
+ }
311
+
293
312
type notifyFixture struct {
294
313
* tempdir.TempDirFixture
295
314
notify Notify
@@ -318,6 +337,13 @@ func newNotifyFixture(t *testing.T) *notifyFixture {
318
337
}
319
338
}
320
339
340
+ func (f * notifyFixture ) watch (path string ) {
341
+ err := f .notify .Add (path )
342
+ if err != nil {
343
+ f .T ().Fatalf ("notify.Add: %s" , path )
344
+ }
345
+ }
346
+
321
347
func (f * notifyFixture ) assertEvents (expected ... string ) {
322
348
f .fsync ()
323
349
Original file line number Diff line number Diff line change 1
1
package watch
2
2
3
- import (
4
- "os"
5
- "path/filepath"
6
- "strings"
7
- )
3
+ import "github.com/windmilleng/tilt/internal/ospath"
8
4
9
5
func pathIsChildOf (path string , parent string ) bool {
10
- relPath , err := filepath .Rel (parent , path )
11
- if err != nil {
12
- return true
13
- }
14
-
15
- if relPath == "." {
16
- return true
17
- }
18
-
19
- if filepath .IsAbs (relPath ) || strings .HasPrefix (relPath , ".." + string (os .PathSeparator )) {
20
- return false
21
- }
22
-
23
- return true
6
+ _ , isChild := ospath .Child (parent , path )
7
+ return isChild
24
8
}
You can’t perform that action at this time.
0 commit comments