From 4960b841e6813a2a743567c757391ad4ccdd6ba1 Mon Sep 17 00:00:00 2001
From: Alexander Weiss <alex@weissfam.de>
Date: Mon, 16 Nov 2020 04:51:53 +0100
Subject: [PATCH] Use PackSize in rebuild-index

---
 cmd/restic/cmd_rebuild_index.go | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/cmd/restic/cmd_rebuild_index.go b/cmd/restic/cmd_rebuild_index.go
index 850c03dd2..e1fdcd7e4 100644
--- a/cmd/restic/cmd_rebuild_index.go
+++ b/cmd/restic/cmd_rebuild_index.go
@@ -1,7 +1,6 @@
 package main
 
 import (
-	"github.com/restic/restic/internal/pack"
 	"github.com/restic/restic/internal/repository"
 	"github.com/restic/restic/internal/restic"
 
@@ -91,17 +90,7 @@ func rebuildIndex(opts RebuildIndexOptions, gopts GlobalOptions, repo *repositor
 		}
 
 		Verbosef("getting pack files to read...\n")
-
-		// Compute size of each pack from index entries
-		packSizeFromIndex := make(map[restic.ID]int64)
-		for blob := range repo.Index().Each(ctx) {
-			size, ok := packSizeFromIndex[blob.PackID]
-			if !ok {
-				size = pack.HeaderSize
-			}
-			// update packSizeFromIndex
-			packSizeFromIndex[blob.PackID] = size + int64(pack.PackedSizeOfBlob(blob.Length))
-		}
+		packSizeFromIndex := repo.Index().PackSize(ctx, false)
 
 		err = repo.List(ctx, restic.PackFile, func(id restic.ID, packSize int64) error {
 			size, ok := packSizeFromIndex[id]