mirror of
https://github.com/restic/restic.git
synced 2024-12-25 01:06:39 +00:00
pipe: Ignore excluded directories
When top-level directories are ignored, they were still added to the top-level Dir{} object. This commit ignores them.
This commit is contained in:
parent
68db75b4e3
commit
26484d0c7b
1 changed files with 11 additions and 2 deletions
13
pipe/pipe.go
13
pipe/pipe.go
|
@ -82,7 +82,7 @@ var errCancelled = errors.New("walk cancelled")
|
||||||
// dirs). If false is returned, files are ignored and dirs are not even walked.
|
// dirs). If false is returned, files are ignored and dirs are not even walked.
|
||||||
type SelectFunc func(item string, fi os.FileInfo) bool
|
type SelectFunc func(item string, fi os.FileInfo) bool
|
||||||
|
|
||||||
func walk(basedir, dir string, selectFunc SelectFunc, done <-chan struct{}, jobs chan<- Job, res chan<- Result) {
|
func walk(basedir, dir string, selectFunc SelectFunc, done <-chan struct{}, jobs chan<- Job, res chan<- Result) (excluded bool) {
|
||||||
debug.Log("pipe.walk", "start on %q, basedir %q", dir, basedir)
|
debug.Log("pipe.walk", "start on %q, basedir %q", dir, basedir)
|
||||||
|
|
||||||
relpath, err := filepath.Rel(basedir, dir)
|
relpath, err := filepath.Rel(basedir, dir)
|
||||||
|
@ -102,6 +102,7 @@ func walk(basedir, dir string, selectFunc SelectFunc, done <-chan struct{}, jobs
|
||||||
|
|
||||||
if !selectFunc(dir, info) {
|
if !selectFunc(dir, info) {
|
||||||
debug.Log("pipe.walk", "file %v excluded by filter, res %p", dir, res)
|
debug.Log("pipe.walk", "file %v excluded by filter, res %p", dir, res)
|
||||||
|
excluded = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,6 +166,8 @@ func walk(basedir, dir string, selectFunc SelectFunc, done <-chan struct{}, jobs
|
||||||
case jobs <- Dir{basedir: basedir, path: relpath, info: info, Entries: entries, result: res}:
|
case jobs <- Dir{basedir: basedir, path: relpath, info: info, Entries: entries, result: res}:
|
||||||
case <-done:
|
case <-done:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// cleanupPath is used to clean a path. For a normal path, a slice with just
|
// cleanupPath is used to clean a path. For a normal path, a slice with just
|
||||||
|
@ -214,7 +217,13 @@ func Walk(walkPaths []string, selectFunc SelectFunc, done chan struct{}, jobs ch
|
||||||
for _, path := range paths {
|
for _, path := range paths {
|
||||||
debug.Log("pipe.Walk", "start walker for %v", path)
|
debug.Log("pipe.Walk", "start walker for %v", path)
|
||||||
ch := make(chan Result, 1)
|
ch := make(chan Result, 1)
|
||||||
walk(filepath.Dir(path), path, selectFunc, done, jobs, ch)
|
excluded := walk(filepath.Dir(path), path, selectFunc, done, jobs, ch)
|
||||||
|
|
||||||
|
if excluded {
|
||||||
|
debug.Log("pipe.Walk", "walker for %v done, it was excluded by the filter", path)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
entries = append(entries, ch)
|
entries = append(entries, ch)
|
||||||
debug.Log("pipe.Walk", "walker for %v done", path)
|
debug.Log("pipe.Walk", "walker for %v done", path)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue