1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-23 08:16:36 +00:00

cmd/restic: Use a dedicated cache for each rejectIfPresent

This commit is contained in:
Fabian Wickborn 2017-11-27 17:30:53 +01:00
parent 901cd5edef
commit 1ea518d5ef
3 changed files with 5 additions and 6 deletions

View file

@ -372,9 +372,8 @@ func runBackup(opts BackupOptions, gopts GlobalOptions, args []string) error {
opts.ExcludeIfPresent = append(opts.ExcludeIfPresent, "CACHEDIR.TAG:Signature: 8a477f597d28d172789f06886806bc55")
}
rc := &rejectionCache{}
for _, spec := range opts.ExcludeIfPresent {
f, err := rejectIfPresent(spec, rc)
f, err := rejectIfPresent(spec)
if err != nil {
return err
}

View file

@ -90,7 +90,7 @@ func rejectByPattern(patterns []string) RejectFunc {
// non-nil if the filename component of excludeFileSpec is empty. If rc is
// non-nil, it is going to be used in the RejectFunc to expedite the evaluation
// of a directory based on previous visits.
func rejectIfPresent(excludeFileSpec string, rc *rejectionCache) (RejectFunc, error) {
func rejectIfPresent(excludeFileSpec string) (RejectFunc, error) {
if excludeFileSpec == "" {
return nil, errors.New("name for exclusion tagfile is empty")
}
@ -106,6 +106,7 @@ func rejectIfPresent(excludeFileSpec string, rc *rejectionCache) (RejectFunc, er
tf = excludeFileSpec
}
debug.Log("using %q as exclusion tagfile", tf)
rc := &rejectionCache{}
fn := func(filename string, _ os.FileInfo) bool {
return isExcludedByFile(filename, tf, tc, rc)
}

View file

@ -111,9 +111,8 @@ func TestMultipleIsExcludedByFile(t *testing.T) {
errs = append(errs, ioutil.WriteFile(p, []byte(f.path), 0600))
}
test.OKs(t, errs)
rc := &rejectionCache{}
fooExclude, _ := rejectIfPresent("NOFOO", rc)
barExclude, _ := rejectIfPresent("NOBAR", rc)
fooExclude, _ := rejectIfPresent("NOFOO")
barExclude, _ := rejectIfPresent("NOBAR")
m := make(map[string]bool)
walk := func(p string, fi os.FileInfo, err error) error {
if err != nil {