2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 10:58:55 +00:00

rewrite: use SelectByName like in the backup command

This commit is contained in:
Michael Eischer 2022-09-09 22:33:12 +02:00
parent 7ebaf6e899
commit ad14d6e4ac
2 changed files with 9 additions and 7 deletions

View File

@ -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 {

View File

@ -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)
}