This adds a recover step to the notify package to avoid the panic. We should get something like this upstreamed.
This commit is contained in:
parent
b31bad1c4d
commit
470ef87dd5
35
vendor/github.com/Zillode/notify/notify.go
generated
vendored
35
vendor/github.com/Zillode/notify/notify.go
generated
vendored
@ -19,7 +19,31 @@
|
|||||||
|
|
||||||
package notify
|
package notify
|
||||||
|
|
||||||
var defaultTree = newTree()
|
import "fmt"
|
||||||
|
|
||||||
|
var defaultTree tree // lazy init
|
||||||
|
|
||||||
|
func lazyInitDefaultTree() (err error) {
|
||||||
|
if defaultTree != nil {
|
||||||
|
// already initialized
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
// newTree might panic. Patch it up.
|
||||||
|
if rec := recover(); rec != nil {
|
||||||
|
switch rec := rec.(type) {
|
||||||
|
case error:
|
||||||
|
err = rec
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("init default tree: %v", rec)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
defaultTree = newTree()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Watch sets up a watchpoint on path listening for events given by the events
|
// Watch sets up a watchpoint on path listening for events given by the events
|
||||||
// argument.
|
// argument.
|
||||||
@ -61,6 +85,9 @@ var defaultTree = newTree()
|
|||||||
// e.g. use persistent paths like %userprofile% or watch additionally parent
|
// e.g. use persistent paths like %userprofile% or watch additionally parent
|
||||||
// directory of a recursive watchpoint in order to receive delete events for it.
|
// directory of a recursive watchpoint in order to receive delete events for it.
|
||||||
func Watch(path string, c chan<- EventInfo, events ...Event) error {
|
func Watch(path string, c chan<- EventInfo, events ...Event) error {
|
||||||
|
if err := lazyInitDefaultTree(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return defaultTree.Watch(path, c, nil, events...)
|
return defaultTree.Watch(path, c, nil, events...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,6 +97,9 @@ func Watch(path string, c chan<- EventInfo, events ...Event) error {
|
|||||||
// file or directory should not be watched.
|
// file or directory should not be watched.
|
||||||
func WatchWithFilter(path string, c chan<- EventInfo,
|
func WatchWithFilter(path string, c chan<- EventInfo,
|
||||||
doNotWatch func(string) bool, events ...Event) error {
|
doNotWatch func(string) bool, events ...Event) error {
|
||||||
|
if err := lazyInitDefaultTree(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return defaultTree.Watch(path, c, doNotWatch, events...)
|
return defaultTree.Watch(path, c, doNotWatch, events...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,5 +109,8 @@ func WatchWithFilter(path string, c chan<- EventInfo,
|
|||||||
// Stop does not close c. When Stop returns, it is guaranteed that c will
|
// Stop does not close c. When Stop returns, it is guaranteed that c will
|
||||||
// receive no more signals.
|
// receive no more signals.
|
||||||
func Stop(c chan<- EventInfo) {
|
func Stop(c chan<- EventInfo) {
|
||||||
|
if defaultTree == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
defaultTree.Stop(c)
|
defaultTree.Stop(c)
|
||||||
}
|
}
|
||||||
|
|||||||
16
vendor/manifest
vendored
16
vendor/manifest
vendored
@ -41,6 +41,14 @@
|
|||||||
"branch": "master",
|
"branch": "master",
|
||||||
"notests": true
|
"notests": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"importpath": "github.com/Zillode/notify",
|
||||||
|
"repository": "https://github.com/calmh/notify",
|
||||||
|
"vcs": "git",
|
||||||
|
"revision": "53dd6873a851fc377c87d82f994b1fecdf25aadb",
|
||||||
|
"branch": "nopanic",
|
||||||
|
"notests": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"importpath": "github.com/a8m/mark",
|
"importpath": "github.com/a8m/mark",
|
||||||
"repository": "https://github.com/a8m/mark",
|
"repository": "https://github.com/a8m/mark",
|
||||||
@ -516,14 +524,6 @@
|
|||||||
"path": "/qr",
|
"path": "/qr",
|
||||||
"notests": true
|
"notests": true
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"importpath": "github.com/Zillode/notify",
|
|
||||||
"repository": "https://github.com/Zillode/notify",
|
|
||||||
"vcs": "git",
|
|
||||||
"revision": "a8abcfb1ce88ee8d79a300ed65d94b8fb616ddb3",
|
|
||||||
"branch": "master",
|
|
||||||
"notests": true
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"importpath": "golang.org/x/crypto/bcrypt",
|
"importpath": "golang.org/x/crypto/bcrypt",
|
||||||
"repository": "https://go.googlesource.com/crypto",
|
"repository": "https://go.googlesource.com/crypto",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user