From f5daf333221e3a3787d581d38828b413f7a10661 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 7 Aug 2016 21:56:42 +0200 Subject: [PATCH] Add pack size to ListAllPacks --- src/restic/index/index.go | 3 ++- src/restic/repository/index_rebuild.go | 5 ++++- src/restic/repository/repack_test.go | 2 +- src/restic/repository/repository.go | 15 +++++++++++---- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/restic/index/index.go b/src/restic/index/index.go index 9a4937011..ffb5272dd 100644 --- a/src/restic/index/index.go +++ b/src/restic/index/index.go @@ -13,6 +13,7 @@ import ( // Pack contains information about the contents of a pack. type Pack struct { + Size int64 Entries []pack.Blob } @@ -51,7 +52,7 @@ func New(repo *repository.Repository) (*Index, error) { if _, ok := idx.Packs[packID]; ok { return nil, fmt.Errorf("pack %v processed twice", packID.Str()) } - p := Pack{Entries: j.Entries} + p := Pack{Entries: j.Entries, Size: j.Size} idx.Packs[packID] = p } diff --git a/src/restic/repository/index_rebuild.go b/src/restic/repository/index_rebuild.go index 2fd3e4ea5..dea5be0d3 100644 --- a/src/restic/repository/index_rebuild.go +++ b/src/restic/repository/index_rebuild.go @@ -14,6 +14,7 @@ const rebuildIndexWorkers = 10 // ListAllPacksResult is returned in the channel from LoadBlobsFromAllPacks. type ListAllPacksResult struct { PackID backend.ID + Size int64 Entries []pack.Blob } @@ -21,9 +22,11 @@ type ListAllPacksResult struct { func ListAllPacks(repo *Repository, ch chan<- worker.Job, done <-chan struct{}) { f := func(job worker.Job, done <-chan struct{}) (interface{}, error) { packID := job.Data.(backend.ID) - entries, err := repo.ListPack(packID) + entries, size, err := repo.ListPack(packID) + return ListAllPacksResult{ PackID: packID, + Size: size, Entries: entries, }, err } diff --git a/src/restic/repository/repack_test.go b/src/restic/repository/repack_test.go index 37b213bd8..b29c7e622 100644 --- a/src/restic/repository/repack_test.go +++ b/src/restic/repository/repack_test.go @@ -76,7 +76,7 @@ func selectBlobs(t *testing.T, repo *repository.Repository, p float32) (list1, l blobs := pack.NewBlobSet() for id := range repo.List(backend.Data, done) { - entries, err := repo.ListPack(id) + entries, _, err := repo.ListPack(id) if err != nil { t.Fatalf("error listing pack %v: %v", id, err) } diff --git a/src/restic/repository/repository.go b/src/restic/repository/repository.go index 654994af1..ca53fb39d 100644 --- a/src/restic/repository/repository.go +++ b/src/restic/repository/repository.go @@ -544,17 +544,24 @@ func (r *Repository) List(t backend.Type, done <-chan struct{}) <-chan backend.I return outCh } -// ListPack returns the list of blobs saved in the pack id. -func (r *Repository) ListPack(id backend.ID) ([]pack.Blob, error) { +// ListPack returns the list of blobs saved in the pack id and the length of +// the file as stored in the backend. +func (r *Repository) ListPack(id backend.ID) ([]pack.Blob, int64, error) { h := backend.Handle{Type: backend.Data, Name: id.String()} + + blobInfo, err := r.Backend().Stat(h) + if err != nil { + return nil, 0, err + } + ldr := pack.BackendLoader{Backend: r.Backend(), Handle: h} unpacker, err := pack.NewUnpacker(r.Key(), ldr) if err != nil { - return nil, err + return nil, 0, err } - return unpacker.Entries, nil + return unpacker.Entries, blobInfo.Size, nil } // Delete calls backend.Delete() if implemented, and returns an error