From 21b787a4d129e877e6ee88ca9d670641dcc8f208 Mon Sep 17 00:00:00 2001 From: greatroar <@> Date: Sun, 8 Nov 2020 21:03:59 +0100 Subject: [PATCH] Stop Counters where they're constructed and started --- cmd/restic/cmd_check.go | 1 + cmd/restic/cmd_prune.go | 1 + cmd/restic/cmd_rebuild_index.go | 1 + internal/checker/checker.go | 5 ++--- internal/checker/checker_test.go | 2 +- internal/checker/testing.go | 2 +- internal/index/index.go | 4 ---- internal/repository/repack.go | 2 -- 8 files changed, 7 insertions(+), 11 deletions(-) diff --git a/cmd/restic/cmd_check.go b/cmd/restic/cmd_check.go index a4553b3c9..edcd3fe46 100644 --- a/cmd/restic/cmd_check.go +++ b/cmd/restic/cmd_check.go @@ -259,6 +259,7 @@ func runCheck(opts CheckOptions, gopts GlobalOptions, args []string) error { errorsFound = true Warnf("%v\n", err) } + p.Done() } switch { diff --git a/cmd/restic/cmd_prune.go b/cmd/restic/cmd_prune.go index 92f37e1b9..d4073107c 100644 --- a/cmd/restic/cmd_prune.go +++ b/cmd/restic/cmd_prune.go @@ -482,6 +482,7 @@ func prune(opts PruneOptions, gopts GlobalOptions, repo restic.Repository, usedB Verbosef("repacking packs\n") bar := newProgressMax(!gopts.Quiet, uint64(len(repackPacks)), "packs repacked") _, err := repository.Repack(ctx, repo, repackPacks, keepBlobs, bar) + bar.Done() if err != nil { return err } diff --git a/cmd/restic/cmd_rebuild_index.go b/cmd/restic/cmd_rebuild_index.go index 87b78b4b4..edae215a6 100644 --- a/cmd/restic/cmd_rebuild_index.go +++ b/cmd/restic/cmd_rebuild_index.go @@ -63,6 +63,7 @@ func rebuildIndex(ctx context.Context, repo restic.Repository, ignorePacks resti bar := newProgressMax(!globalOptions.Quiet, packs-uint64(len(ignorePacks)), "packs") idx, invalidFiles, err := index.New(ctx, repo, ignorePacks, bar) + bar.Done() if err != nil { return err } diff --git a/internal/checker/checker.go b/internal/checker/checker.go index 6db11d876..533337cf4 100644 --- a/internal/checker/checker.go +++ b/internal/checker/checker.go @@ -773,14 +773,13 @@ func checkPack(ctx context.Context, r restic.Repository, id restic.ID) error { } // ReadData loads all data from the repository and checks the integrity. -func (c *Checker) ReadData(ctx context.Context, p *progress.Counter, errChan chan<- error) { - c.ReadPacks(ctx, c.packs, p, errChan) +func (c *Checker) ReadData(ctx context.Context, errChan chan<- error) { + c.ReadPacks(ctx, c.packs, nil, errChan) } // ReadPacks loads data from specified packs and checks the integrity. func (c *Checker) ReadPacks(ctx context.Context, packs restic.IDSet, p *progress.Counter, errChan chan<- error) { defer close(errChan) - defer p.Done() g, ctx := errgroup.WithContext(ctx) ch := make(chan restic.ID) diff --git a/internal/checker/checker_test.go b/internal/checker/checker_test.go index ce12420eb..8218a94fc 100644 --- a/internal/checker/checker_test.go +++ b/internal/checker/checker_test.go @@ -50,7 +50,7 @@ func checkData(chkr *checker.Checker) []error { return collectErrors( context.TODO(), func(ctx context.Context, errCh chan<- error) { - chkr.ReadData(ctx, nil, errCh) + chkr.ReadData(ctx, errCh) }, ) } diff --git a/internal/checker/testing.go b/internal/checker/testing.go index 4a7bf48d2..8e49b562c 100644 --- a/internal/checker/testing.go +++ b/internal/checker/testing.go @@ -44,7 +44,7 @@ func TestCheckRepo(t testing.TB, repo restic.Repository) { // read data errChan = make(chan error) - go chkr.ReadData(context.TODO(), nil, errChan) + go chkr.ReadData(context.TODO(), errChan) for err := range errChan { t.Error(err) diff --git a/internal/index/index.go b/internal/index/index.go index f1e37b608..4c0f5fee7 100644 --- a/internal/index/index.go +++ b/internal/index/index.go @@ -51,8 +51,6 @@ type Lister interface { // New creates a new index for repo from scratch. InvalidFiles contains all IDs // of files that cannot be listed successfully. func New(ctx context.Context, repo Lister, ignorePacks restic.IDSet, p *progress.Counter) (idx *Index, invalidFiles restic.IDs, err error) { - defer p.Done() - type Job struct { PackID restic.ID Size int64 @@ -191,8 +189,6 @@ func loadIndexJSON(ctx context.Context, repo ListLoader, id restic.ID) (*indexJS func Load(ctx context.Context, repo ListLoader, p *progress.Counter) (*Index, error) { debug.Log("loading indexes") - defer p.Done() - supersedes := make(map[restic.ID]restic.IDSet) results := make(map[restic.ID]map[restic.ID]Pack) diff --git a/internal/repository/repack.go b/internal/repository/repack.go index 23b4254ee..9304204e1 100644 --- a/internal/repository/repack.go +++ b/internal/repository/repack.go @@ -25,8 +25,6 @@ const numRepackWorkers = 8 // The map keepBlobs is modified by Repack, it is used to keep track of which // blobs have been processed. func Repack(ctx context.Context, repo restic.Repository, packs restic.IDSet, keepBlobs restic.BlobSet, p *progress.Counter) (obsoletePacks restic.IDSet, err error) { - defer p.Done() - debug.Log("repacking %d packs while keeping %d blobs", len(packs), len(keepBlobs)) wg, wgCtx := errgroup.WithContext(ctx)