mirror of
https://github.com/octoleo/syncthing.git
synced 2024-09-20 05:39:02 +00:00
parent
25bf406f0e
commit
3d02fcd473
34
vendor/github.com/syncthing/notify/node.go
generated
vendored
34
vendor/github.com/syncthing/notify/node.go
generated
vendored
@ -6,7 +6,6 @@ package notify
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
@ -60,7 +59,7 @@ func (nd node) Add(name string) node {
|
|||||||
return nd.addchild(name, name[i:])
|
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}
|
stack := []node{nd}
|
||||||
Traverse:
|
Traverse:
|
||||||
for n := len(stack); n != 0; n = len(stack) {
|
for n := len(stack); n != 0; n = len(stack) {
|
||||||
@ -78,13 +77,25 @@ Traverse:
|
|||||||
}
|
}
|
||||||
// TODO(rjeczalik): tolerate open failures - add failed names to
|
// TODO(rjeczalik): tolerate open failures - add failed names to
|
||||||
// AddDirError and notify users which names are not added to the tree.
|
// 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 {
|
if err != nil {
|
||||||
return err
|
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 {
|
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:]))
|
stack = append(stack, nd.addchild(name, name[len(nd.Name)+1:]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -141,7 +152,7 @@ func (nd node) Del(name string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nd node) Walk(fn walkFunc) error {
|
func (nd node) Walk(fn walkFunc, doNotWatch DoNotWatchFn) error {
|
||||||
stack := []node{nd}
|
stack := []node{nd}
|
||||||
Traverse:
|
Traverse:
|
||||||
for n := len(stack); n != 0; n = len(stack) {
|
for n := len(stack); n != 0; n = len(stack) {
|
||||||
@ -160,6 +171,9 @@ Traverse:
|
|||||||
// never has a parent node.
|
// never has a parent node.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if doNotWatch != nil && doNotWatch(nd.Name) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
stack = append(stack, nd)
|
stack = append(stack, nd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -233,8 +247,8 @@ func (r root) Add(name string) node {
|
|||||||
return r.addroot(name).Add(name)
|
return r.addroot(name).Add(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r root) AddDir(dir string, fn walkFunc) error {
|
func (r root) AddDir(dir string, fn walkFunc, doNotWatch DoNotWatchFn) error {
|
||||||
return r.Add(dir).AddDir(fn)
|
return r.Add(dir).AddDir(fn, doNotWatch)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r root) Del(name string) error {
|
func (r root) Del(name string) error {
|
||||||
@ -258,12 +272,12 @@ func (r root) Get(name string) (node, error) {
|
|||||||
return nd, nil
|
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)
|
nd, err := r.Get(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nd.Walk(fn)
|
return nd.Walk(fn, doNotWatch)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r root) WalkPath(name string, fn walkPathFunc) error {
|
func (r root) WalkPath(name string, fn walkPathFunc) error {
|
||||||
|
4
vendor/github.com/syncthing/notify/notify.go
generated
vendored
4
vendor/github.com/syncthing/notify/notify.go
generated
vendored
@ -23,6 +23,8 @@ import "fmt"
|
|||||||
|
|
||||||
var defaultTree tree // lazy init
|
var defaultTree tree // lazy init
|
||||||
|
|
||||||
|
type DoNotWatchFn func(string) bool
|
||||||
|
|
||||||
func lazyInitDefaultTree() (err error) {
|
func lazyInitDefaultTree() (err error) {
|
||||||
if defaultTree != nil {
|
if defaultTree != nil {
|
||||||
// already initialized
|
// 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
|
// doNotWatch. Given a path as argument doNotWatch should return true if the
|
||||||
// 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 DoNotWatchFn, events ...Event) error {
|
||||||
if err := lazyInitDefaultTree(); err != nil {
|
if err := lazyInitDefaultTree(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
2
vendor/github.com/syncthing/notify/tree.go
generated
vendored
2
vendor/github.com/syncthing/notify/tree.go
generated
vendored
@ -7,7 +7,7 @@ package notify
|
|||||||
const buffer = 128
|
const buffer = 128
|
||||||
|
|
||||||
type tree interface {
|
type tree interface {
|
||||||
Watch(string, chan<- EventInfo, func(string) bool, ...Event) error
|
Watch(string, chan<- EventInfo, DoNotWatchFn, ...Event) error
|
||||||
Stop(chan<- EventInfo)
|
Stop(chan<- EventInfo)
|
||||||
Close() error
|
Close() error
|
||||||
}
|
}
|
||||||
|
23
vendor/github.com/syncthing/notify/tree_nonrecursive.go
generated
vendored
23
vendor/github.com/syncthing/notify/tree_nonrecursive.go
generated
vendored
@ -93,7 +93,7 @@ func (t *nonrecursiveTree) internal(rec <-chan EventInfo) {
|
|||||||
t.rw.Unlock()
|
t.rw.Unlock()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
err := nd.Add(ei.Path()).AddDir(t.recFunc(eset, nil))
|
err := nd.Add(ei.Path()).AddDir(t.recFunc(eset), nil)
|
||||||
t.rw.Unlock()
|
t.rw.Unlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
dbgprintf("internal(%p) error: %v", rec, err)
|
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)
|
// Watch TODO(rjeczalik)
|
||||||
func (t *nonrecursiveTree) Watch(path string, c chan<- EventInfo,
|
func (t *nonrecursiveTree) Watch(path string, c chan<- EventInfo,
|
||||||
doNotWatch func(string) bool, events ...Event) error {
|
doNotWatch DoNotWatchFn, events ...Event) error {
|
||||||
if c == nil {
|
if c == nil {
|
||||||
panic("notify: Watch using nil channel")
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *nonrecursiveTree) recFunc(e Event, doNotWatch func(string) bool) walkFunc {
|
func (t *nonrecursiveTree) recFunc(e Event) walkFunc {
|
||||||
addWatch := func(nd node) (err error) {
|
return func(nd node) (err error) {
|
||||||
switch diff := nd.Watch.Add(t.rec, e|omit|Create); {
|
switch diff := nd.Watch.Add(t.rec, e|omit|Create); {
|
||||||
case diff == none:
|
case diff == none:
|
||||||
case diff[1] == 0:
|
case diff[1] == 0:
|
||||||
@ -202,20 +202,11 @@ func (t *nonrecursiveTree) recFunc(e Event, doNotWatch func(string) bool) walkFu
|
|||||||
}
|
}
|
||||||
return
|
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,
|
func (t *nonrecursiveTree) watchrec(nd node, c chan<- EventInfo, e Event,
|
||||||
doNotWatch func(string) bool) error {
|
doNotWatch DoNotWatchFn) error {
|
||||||
var traverse func(walkFunc) error
|
var traverse func(walkFunc, DoNotWatchFn) error
|
||||||
// Non-recursive tree listens on Create event for every recursive
|
// Non-recursive tree listens on Create event for every recursive
|
||||||
// watchpoint in order to automagically set a watch for every
|
// watchpoint in order to automagically set a watch for every
|
||||||
// created directory.
|
// 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
|
// TODO(rjeczalik): account every path that failed to be (re)watched
|
||||||
// and retry.
|
// and retry.
|
||||||
if err := traverse(t.recFunc(e, doNotWatch)); err != nil {
|
if err := traverse(t.recFunc(e), doNotWatch); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
t.watchAdd(nd, c, e)
|
t.watchAdd(nd, c, e)
|
||||||
|
8
vendor/github.com/syncthing/notify/tree_recursive.go
generated
vendored
8
vendor/github.com/syncthing/notify/tree_recursive.go
generated
vendored
@ -154,7 +154,7 @@ func (t *recursiveTree) dispatch() {
|
|||||||
|
|
||||||
// Watch TODO(rjeczalik)
|
// Watch TODO(rjeczalik)
|
||||||
func (t *recursiveTree) Watch(path string, c chan<- EventInfo,
|
func (t *recursiveTree) Watch(path string, c chan<- EventInfo,
|
||||||
doNotWatch func(string) bool, events ...Event) error {
|
_ DoNotWatchFn, events ...Event) error {
|
||||||
if c == nil {
|
if c == nil {
|
||||||
panic("notify: Watch using nil channel")
|
panic("notify: Watch using nil channel")
|
||||||
}
|
}
|
||||||
@ -233,7 +233,7 @@ func (t *recursiveTree) Watch(path string, c chan<- EventInfo,
|
|||||||
children = append(children, nd)
|
children = append(children, nd)
|
||||||
return errSkip
|
return errSkip
|
||||||
}
|
}
|
||||||
switch must(cur.Walk(fn)); len(children) {
|
switch must(cur.Walk(fn, nil)); len(children) {
|
||||||
case 0:
|
case 0:
|
||||||
// no child watches, cur holds a new watch
|
// no child watches, cur holds a new watch
|
||||||
case 1:
|
case 1:
|
||||||
@ -332,14 +332,14 @@ func (t *recursiveTree) Stop(c chan<- EventInfo) {
|
|||||||
watchDel(nd, c, all)
|
watchDel(nd, c, all)
|
||||||
return nil
|
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
|
// 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
|
// retry un/rewatching next time and/or let the user handle the failure
|
||||||
// vie Error event?
|
// vie Error event?
|
||||||
return errSkip
|
return errSkip
|
||||||
}
|
}
|
||||||
t.rw.Lock()
|
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()
|
t.rw.Unlock()
|
||||||
if e != nil {
|
if e != nil {
|
||||||
err = nonil(err, e)
|
err = nonil(err, e)
|
||||||
|
2
vendor/manifest
vendored
2
vendor/manifest
vendored
@ -451,7 +451,7 @@
|
|||||||
"importpath": "github.com/syncthing/notify",
|
"importpath": "github.com/syncthing/notify",
|
||||||
"repository": "https://github.com/syncthing/notify",
|
"repository": "https://github.com/syncthing/notify",
|
||||||
"vcs": "git",
|
"vcs": "git",
|
||||||
"revision": "e6390324ae88de3571a6b29ed1a20aa631b533d9",
|
"revision": "b9ceffc925039c77cd9e0d38f248279ccc4399e2",
|
||||||
"branch": "master",
|
"branch": "master",
|
||||||
"notests": true
|
"notests": true
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user