From 4b3dc415ef41593fdd5e3cc0db3b78b3bbef5411 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sat, 4 Sep 2021 14:08:53 +0200 Subject: [PATCH] checker: cleanup header extraction --- internal/checker/checker.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/checker/checker.go b/internal/checker/checker.go index ce6eafd74..5262789d0 100644 --- a/internal/checker/checker.go +++ b/internal/checker/checker.go @@ -6,6 +6,7 @@ import ( "context" "fmt" "io" + "io/ioutil" "sort" "sync" @@ -470,7 +471,7 @@ func checkPack(ctx context.Context, r restic.Repository, id restic.ID, blobs []r // calculate hash on-the-fly while reading the pack and capture pack header var hash restic.ID - var hdrBuf *bytes.Buffer + var hdrBuf []byte hashingLoader := func(ctx context.Context, h restic.Handle, length int, offset int64, fn func(rd io.Reader) error) error { return r.Backend().Load(ctx, h, int(size), 0, func(rd io.Reader) error { hrd := hashing.NewReader(rd, sha256.New()) @@ -498,8 +499,7 @@ func checkPack(ctx context.Context, r restic.Repository, id restic.ID, blobs []r } // read remainder, which should be the pack header - hdrBuf = new(bytes.Buffer) - _, err = io.Copy(hdrBuf, bufRd) + hdrBuf, err = ioutil.ReadAll(bufRd) if err != nil { return err } @@ -527,7 +527,7 @@ func checkPack(ctx context.Context, r restic.Repository, id restic.ID, blobs []r return errors.Errorf("Pack ID does not match, want %v, got %v", id.Str(), hash.Str()) } - blobs, hdrSize, err := pack.List(r.Key(), bytes.NewReader(hdrBuf.Bytes()), int64(hdrBuf.Len())) + blobs, hdrSize, err := pack.List(r.Key(), bytes.NewReader(hdrBuf), int64(len(hdrBuf))) if err != nil { return err }