Add pack size to ListAllPacks

This commit is contained in:
Alexander Neumann 2016-08-07 21:56:42 +02:00
parent 1058a91b39
commit f5daf33322
4 changed files with 18 additions and 7 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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)
}

View File

@ -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