mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-09 23:00:58 +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 (
|
||||
"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 {
|
||||
|
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
|
||||
|
||||
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
|
||||
}
|
||||
|
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
|
||||
|
||||
type tree interface {
|
||||
Watch(string, chan<- EventInfo, func(string) bool, ...Event) error
|
||||
Watch(string, chan<- EventInfo, DoNotWatchFn, ...Event) error
|
||||
Stop(chan<- EventInfo)
|
||||
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()
|
||||
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)
|
||||
|
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)
|
||||
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)
|
||||
|
2
vendor/manifest
vendored
2
vendor/manifest
vendored
@ -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
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user