From 1ea518d5ef3ccf315aedbfa42dccd8e7a1185c91 Mon Sep 17 00:00:00 2001 From: Fabian Wickborn Date: Mon, 27 Nov 2017 17:30:53 +0100 Subject: [PATCH] cmd/restic: Use a dedicated cache for each rejectIfPresent --- cmd/restic/cmd_backup.go | 3 +-- cmd/restic/exclude.go | 3 ++- cmd/restic/exclude_test.go | 5 ++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go index eb04b6c4c..af6e1ece1 100644 --- a/cmd/restic/cmd_backup.go +++ b/cmd/restic/cmd_backup.go @@ -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 } diff --git a/cmd/restic/exclude.go b/cmd/restic/exclude.go index 0a6d8bcec..e4a934d9b 100644 --- a/cmd/restic/exclude.go +++ b/cmd/restic/exclude.go @@ -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) } diff --git a/cmd/restic/exclude_test.go b/cmd/restic/exclude_test.go index 7932080fd..6cdf990ce 100644 --- a/cmd/restic/exclude_test.go +++ b/cmd/restic/exclude_test.go @@ -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 {