From ad14d6e4ac01a3ca3aa122e5aa72456e05a567db Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Fri, 9 Sep 2022 22:33:12 +0200 Subject: [PATCH] rewrite: use SelectByName like in the backup command --- cmd/restic/cmd_rewrite.go | 8 ++++---- internal/walker/rewriter.go | 8 +++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/cmd/restic/cmd_rewrite.go b/cmd/restic/cmd_rewrite.go index 9e3ab370d..b4544719d 100644 --- a/cmd/restic/cmd_rewrite.go +++ b/cmd/restic/cmd_rewrite.go @@ -81,13 +81,13 @@ func rewriteSnapshot(ctx context.Context, repo *repository.Repository, sn *resti return false, err } - checkExclude := func(nodepath string) bool { + selectByName := func(nodepath string) bool { for _, reject := range rejectByNameFuncs { if reject(nodepath) { - return true + return false } } - return false + return true } wg, wgCtx := errgroup.WithContext(ctx) @@ -96,7 +96,7 @@ func rewriteSnapshot(ctx context.Context, repo *repository.Repository, sn *resti var filteredTree restic.ID wg.Go(func() error { filteredTree, err = walker.FilterTree(wgCtx, repo, "/", *sn.Tree, &walker.TreeFilterVisitor{ - CheckExclude: checkExclude, + SelectByName: selectByName, PrintExclude: func(path string) { Verbosef(fmt.Sprintf("excluding %s\n", path)) }, }) if err != nil { diff --git a/internal/walker/rewriter.go b/internal/walker/rewriter.go index e4e049da5..091c4bb2e 100644 --- a/internal/walker/rewriter.go +++ b/internal/walker/rewriter.go @@ -8,10 +8,12 @@ import ( "github.com/restic/restic/internal/restic" ) -type RejectByNameFunc func(path string) bool +// SelectByNameFunc returns true for all items that should be included (files and +// dirs). If false is returned, files are ignored and dirs are not even walked. +type SelectByNameFunc func(item string) bool type TreeFilterVisitor struct { - CheckExclude RejectByNameFunc + SelectByName SelectByNameFunc PrintExclude func(string) } @@ -27,7 +29,7 @@ func FilterTree(ctx context.Context, repo restic.Repository, nodepath string, no tb := restic.NewTreeJSONBuilder() for _, node := range curTree.Nodes { path := path.Join(nodepath, node.Name) - if visitor.CheckExclude(path) { + if !visitor.SelectByName(path) { if visitor.PrintExclude != nil { visitor.PrintExclude(path) }