From a1b5a3d5c0d29cbf653804740cb2e0080284b8e4 Mon Sep 17 00:00:00 2001 From: Simon Frei Date: Fri, 20 Apr 2018 17:01:03 +0200 Subject: [PATCH] vendor: Update github.com/syncthing/notify (fixes #4885) (#4894) --- vendor/github.com/syncthing/notify/node.go | 34 +++++++++++++------ vendor/github.com/syncthing/notify/notify.go | 4 ++- vendor/github.com/syncthing/notify/tree.go | 2 +- .../syncthing/notify/tree_nonrecursive.go | 23 ++++--------- .../syncthing/notify/tree_recursive.go | 8 ++--- vendor/manifest | 2 +- 6 files changed, 40 insertions(+), 33 deletions(-) diff --git a/vendor/github.com/syncthing/notify/node.go b/vendor/github.com/syncthing/notify/node.go index aced8b9c4..3be131c9e 100644 --- a/vendor/github.com/syncthing/notify/node.go +++ b/vendor/github.com/syncthing/notify/node.go @@ -6,7 +6,6 @@ package notify import ( "errors" - "io/ioutil" "os" "path/filepath" ) @@ -60,7 +59,7 @@ func (nd node) Add(name string) node { return nd.addchild(name, name[i:]) } -func (nd node) AddDir(fn walkFunc) error { +func (nd node) AddDir(fn walkFunc, doNotWatch DoNotWatchFn) error { stack := []node{nd} Traverse: for n := len(stack); n != 0; n = len(stack) { @@ -78,13 +77,25 @@ Traverse: } // TODO(rjeczalik): tolerate open failures - add failed names to // AddDirError and notify users which names are not added to the tree. - fi, err := ioutil.ReadDir(nd.Name) + f, err := os.Open(nd.Name) if err != nil { return err } - for _, fi := range fi { + names, err := f.Readdirnames(-1) + f.Close() + if err != nil { + return err + } + for _, name := range names { + name = filepath.Join(nd.Name, name) + if doNotWatch != nil && doNotWatch(name) { + continue + } + fi, err := os.Lstat(name) + if err != nil { + return err + } if fi.Mode()&(os.ModeSymlink|os.ModeDir) == os.ModeDir { - name := filepath.Join(nd.Name, fi.Name()) stack = append(stack, nd.addchild(name, name[len(nd.Name)+1:])) } } @@ -141,7 +152,7 @@ func (nd node) Del(name string) error { return nil } -func (nd node) Walk(fn walkFunc) error { +func (nd node) Walk(fn walkFunc, doNotWatch DoNotWatchFn) error { stack := []node{nd} Traverse: for n := len(stack); n != 0; n = len(stack) { @@ -160,6 +171,9 @@ Traverse: // never has a parent node. continue } + if doNotWatch != nil && doNotWatch(nd.Name) { + continue + } stack = append(stack, nd) } } @@ -233,8 +247,8 @@ func (r root) Add(name string) node { return r.addroot(name).Add(name) } -func (r root) AddDir(dir string, fn walkFunc) error { - return r.Add(dir).AddDir(fn) +func (r root) AddDir(dir string, fn walkFunc, doNotWatch DoNotWatchFn) error { + return r.Add(dir).AddDir(fn, doNotWatch) } func (r root) Del(name string) error { @@ -258,12 +272,12 @@ func (r root) Get(name string) (node, error) { return nd, nil } -func (r root) Walk(name string, fn walkFunc) error { +func (r root) Walk(name string, fn walkFunc, doNotWatch DoNotWatchFn) error { nd, err := r.Get(name) if err != nil { return err } - return nd.Walk(fn) + return nd.Walk(fn, doNotWatch) } func (r root) WalkPath(name string, fn walkPathFunc) error { diff --git a/vendor/github.com/syncthing/notify/notify.go b/vendor/github.com/syncthing/notify/notify.go index 31da71fb7..83ec74199 100644 --- a/vendor/github.com/syncthing/notify/notify.go +++ b/vendor/github.com/syncthing/notify/notify.go @@ -23,6 +23,8 @@ import "fmt" var defaultTree tree // lazy init +type DoNotWatchFn func(string) bool + func lazyInitDefaultTree() (err error) { if defaultTree != nil { // already initialized @@ -96,7 +98,7 @@ func Watch(path string, c chan<- EventInfo, events ...Event) error { // doNotWatch. Given a path as argument doNotWatch should return true if the // file or directory should not be watched. func WatchWithFilter(path string, c chan<- EventInfo, - doNotWatch func(string) bool, events ...Event) error { + doNotWatch DoNotWatchFn, events ...Event) error { if err := lazyInitDefaultTree(); err != nil { return err } diff --git a/vendor/github.com/syncthing/notify/tree.go b/vendor/github.com/syncthing/notify/tree.go index e5f86ae7d..d1a13b924 100644 --- a/vendor/github.com/syncthing/notify/tree.go +++ b/vendor/github.com/syncthing/notify/tree.go @@ -7,7 +7,7 @@ package notify const buffer = 128 type tree interface { - Watch(string, chan<- EventInfo, func(string) bool, ...Event) error + Watch(string, chan<- EventInfo, DoNotWatchFn, ...Event) error Stop(chan<- EventInfo) Close() error } diff --git a/vendor/github.com/syncthing/notify/tree_nonrecursive.go b/vendor/github.com/syncthing/notify/tree_nonrecursive.go index b492a8a5e..e4526af08 100644 --- a/vendor/github.com/syncthing/notify/tree_nonrecursive.go +++ b/vendor/github.com/syncthing/notify/tree_nonrecursive.go @@ -93,7 +93,7 @@ func (t *nonrecursiveTree) internal(rec <-chan EventInfo) { t.rw.Unlock() continue } - err := nd.Add(ei.Path()).AddDir(t.recFunc(eset, nil)) + err := nd.Add(ei.Path()).AddDir(t.recFunc(eset), nil) t.rw.Unlock() if err != nil { dbgprintf("internal(%p) error: %v", rec, err) @@ -146,7 +146,7 @@ func (t *nonrecursiveTree) watchDel(nd node, c chan<- EventInfo, e Event) eventD // Watch TODO(rjeczalik) func (t *nonrecursiveTree) Watch(path string, c chan<- EventInfo, - doNotWatch func(string) bool, events ...Event) error { + doNotWatch DoNotWatchFn, events ...Event) error { if c == nil { panic("notify: Watch using nil channel") } @@ -188,8 +188,8 @@ func (t *nonrecursiveTree) watch(nd node, c chan<- EventInfo, e Event) (err erro return nil } -func (t *nonrecursiveTree) recFunc(e Event, doNotWatch func(string) bool) walkFunc { - addWatch := func(nd node) (err error) { +func (t *nonrecursiveTree) recFunc(e Event) walkFunc { + return func(nd node) (err error) { switch diff := nd.Watch.Add(t.rec, e|omit|Create); { case diff == none: case diff[1] == 0: @@ -202,20 +202,11 @@ func (t *nonrecursiveTree) recFunc(e Event, doNotWatch func(string) bool) walkFu } return } - if doNotWatch != nil { - return func(nd node) (err error) { - if doNotWatch(nd.Name) { - return errSkip - } - return addWatch(nd) - } - } - return addWatch } func (t *nonrecursiveTree) watchrec(nd node, c chan<- EventInfo, e Event, - doNotWatch func(string) bool) error { - var traverse func(walkFunc) error + doNotWatch DoNotWatchFn) error { + var traverse func(walkFunc, DoNotWatchFn) error // Non-recursive tree listens on Create event for every recursive // watchpoint in order to automagically set a watch for every // created directory. @@ -236,7 +227,7 @@ func (t *nonrecursiveTree) watchrec(nd node, c chan<- EventInfo, e Event, } // TODO(rjeczalik): account every path that failed to be (re)watched // and retry. - if err := traverse(t.recFunc(e, doNotWatch)); err != nil { + if err := traverse(t.recFunc(e), doNotWatch); err != nil { return err } t.watchAdd(nd, c, e) diff --git a/vendor/github.com/syncthing/notify/tree_recursive.go b/vendor/github.com/syncthing/notify/tree_recursive.go index 4d0aaba14..e246fe824 100644 --- a/vendor/github.com/syncthing/notify/tree_recursive.go +++ b/vendor/github.com/syncthing/notify/tree_recursive.go @@ -154,7 +154,7 @@ func (t *recursiveTree) dispatch() { // Watch TODO(rjeczalik) func (t *recursiveTree) Watch(path string, c chan<- EventInfo, - doNotWatch func(string) bool, events ...Event) error { + _ DoNotWatchFn, events ...Event) error { if c == nil { panic("notify: Watch using nil channel") } @@ -233,7 +233,7 @@ func (t *recursiveTree) Watch(path string, c chan<- EventInfo, children = append(children, nd) return errSkip } - switch must(cur.Walk(fn)); len(children) { + switch must(cur.Walk(fn, nil)); len(children) { case 0: // no child watches, cur holds a new watch case 1: @@ -332,14 +332,14 @@ func (t *recursiveTree) Stop(c chan<- EventInfo) { watchDel(nd, c, all) return nil } - err = nonil(err, e, nd.Walk(fn)) + err = nonil(err, e, nd.Walk(fn, nil)) // TODO(rjeczalik): if e != nil store dummy chan in nd.Watch just to // retry un/rewatching next time and/or let the user handle the failure // vie Error event? return errSkip } t.rw.Lock() - e := t.root.Walk("", fn) // TODO(rjeczalik): use max root per c + e := t.root.Walk("", fn, nil) // TODO(rjeczalik): use max root per c t.rw.Unlock() if e != nil { err = nonil(err, e) diff --git a/vendor/manifest b/vendor/manifest index b8984dfe0..0dc380ad4 100644 --- a/vendor/manifest +++ b/vendor/manifest @@ -451,7 +451,7 @@ "importpath": "github.com/syncthing/notify", "repository": "https://github.com/syncthing/notify", "vcs": "git", - "revision": "e6390324ae88de3571a6b29ed1a20aa631b533d9", + "revision": "b9ceffc925039c77cd9e0d38f248279ccc4399e2", "branch": "master", "notests": true },