From 7ebaf6e899373a1f3bca675e208137b957269444 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Fri, 9 Sep 2022 22:32:39 +0200 Subject: [PATCH] rewrite: start repository uploader goroutines --- cmd/restic/cmd_rewrite.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/cmd/restic/cmd_rewrite.go b/cmd/restic/cmd_rewrite.go index bf256bbd7..9e3ab370d 100644 --- a/cmd/restic/cmd_rewrite.go +++ b/cmd/restic/cmd_rewrite.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/spf13/cobra" + "golang.org/x/sync/errgroup" "github.com/restic/restic/internal/backend" "github.com/restic/restic/internal/debug" @@ -89,11 +90,22 @@ func rewriteSnapshot(ctx context.Context, repo *repository.Repository, sn *resti return false } - filteredTree, err := walker.FilterTree(ctx, repo, "/", *sn.Tree, &walker.TreeFilterVisitor{ - CheckExclude: checkExclude, - PrintExclude: func(path string) { Verbosef(fmt.Sprintf("excluding %s\n", path)) }, - }) + wg, wgCtx := errgroup.WithContext(ctx) + repo.StartPackUploader(wgCtx, wg) + var filteredTree restic.ID + wg.Go(func() error { + filteredTree, err = walker.FilterTree(wgCtx, repo, "/", *sn.Tree, &walker.TreeFilterVisitor{ + CheckExclude: checkExclude, + PrintExclude: func(path string) { Verbosef(fmt.Sprintf("excluding %s\n", path)) }, + }) + if err != nil { + return err + } + + return repo.Flush(wgCtx) + }) + err = wg.Wait() if err != nil { return false, err } @@ -109,11 +121,6 @@ func rewriteSnapshot(ctx context.Context, repo *repository.Repository, sn *resti return true, nil } - err = repo.Flush(ctx) - if err != nil { - return false, err - } - // Retain the original snapshot id over all tag changes. if sn.Original == nil { sn.Original = sn.ID()