File tree Expand file tree Collapse file tree 2 files changed +40
-5
lines changed Expand file tree Collapse file tree 2 files changed +40
-5
lines changed Original file line number Diff line number Diff line change @@ -277,6 +277,32 @@ func TestWriteGoodLink(t *testing.T) {
277
277
f .assertEvents (goodFile , link )
278
278
}
279
279
280
+ func TestWatchBrokenLink (t * testing.T ) {
281
+ f := newNotifyFixture (t )
282
+ defer f .tearDown ()
283
+
284
+ newRoot , err := NewDir (t .Name ())
285
+ if err != nil {
286
+ t .Fatal (err )
287
+ }
288
+ defer newRoot .TearDown ()
289
+
290
+ link := filepath .Join (newRoot .Path (), "brokenLink" )
291
+ missingFile := filepath .Join (newRoot .Path (), "missingFile" )
292
+ err = os .Symlink (missingFile , link )
293
+ if err != nil {
294
+ t .Fatal (err )
295
+ }
296
+
297
+ err = f .notify .Add (newRoot .Path ())
298
+ if err != nil {
299
+ t .Fatal (err )
300
+ }
301
+
302
+ os .Remove (link )
303
+ f .assertEvents (link )
304
+ }
305
+
280
306
type notifyFixture struct {
281
307
t * testing.T
282
308
root * TempDir
Original file line number Diff line number Diff line change 1
1
package watch
2
2
3
3
import (
4
+ "fmt"
4
5
"io/ioutil"
5
6
"log"
6
7
"os"
@@ -28,26 +29,27 @@ type linuxNotify struct {
28
29
func (d * linuxNotify ) Add (name string ) error {
29
30
fi , err := os .Stat (name )
30
31
if err != nil && ! os .IsNotExist (err ) {
31
- return err
32
+ return fmt . Errorf ( "notify.Add(%q): %v" , name , err )
32
33
}
34
+
33
35
// if it's a file that doesn't exist watch it's parent
34
36
if os .IsNotExist (err ) {
35
37
parent := filepath .Join (name , ".." )
36
38
err = d .watcher .Add (parent )
37
39
if err != nil {
38
- return err
40
+ return fmt . Errorf ( "notify.Add(%q): %v" , name , err )
39
41
}
40
42
d .watchList [parent ] = true
41
43
} else if fi .IsDir () {
42
44
err = d .watchRecursively (name )
43
45
if err != nil {
44
- return err
46
+ return fmt . Errorf ( "notify.Add(%q): %v" , name , err )
45
47
}
46
48
d .watchList [name ] = true
47
49
} else {
48
50
err = d .watcher .Add (name )
49
51
if err != nil {
50
- return err
52
+ return fmt . Errorf ( "notify.Add(%q): %v" , name , err )
51
53
}
52
54
d .watchList [name ] = true
53
55
}
@@ -61,7 +63,14 @@ func (d *linuxNotify) watchRecursively(dir string) error {
61
63
return err
62
64
}
63
65
64
- return d .watcher .Add (path )
66
+ err = d .watcher .Add (path )
67
+ if err != nil {
68
+ if os .IsNotExist (err ) {
69
+ return nil
70
+ }
71
+ return fmt .Errorf ("watcher.Add(%q): %v" , path , err )
72
+ }
73
+ return nil
65
74
})
66
75
}
67
76
You can’t perform that action at this time.
0 commit comments