Add pack size to ListAllPacks
This commit is contained in:
parent
1058a91b39
commit
f5daf33322
4 changed files with 18 additions and 7 deletions
|
@ -13,6 +13,7 @@ import (
|
||||||
|
|
||||||
// Pack contains information about the contents of a pack.
|
// Pack contains information about the contents of a pack.
|
||||||
type Pack struct {
|
type Pack struct {
|
||||||
|
Size int64
|
||||||
Entries []pack.Blob
|
Entries []pack.Blob
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +52,7 @@ func New(repo *repository.Repository) (*Index, error) {
|
||||||
if _, ok := idx.Packs[packID]; ok {
|
if _, ok := idx.Packs[packID]; ok {
|
||||||
return nil, fmt.Errorf("pack %v processed twice", packID.Str())
|
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
|
idx.Packs[packID] = p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ const rebuildIndexWorkers = 10
|
||||||
// ListAllPacksResult is returned in the channel from LoadBlobsFromAllPacks.
|
// ListAllPacksResult is returned in the channel from LoadBlobsFromAllPacks.
|
||||||
type ListAllPacksResult struct {
|
type ListAllPacksResult struct {
|
||||||
PackID backend.ID
|
PackID backend.ID
|
||||||
|
Size int64
|
||||||
Entries []pack.Blob
|
Entries []pack.Blob
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,9 +22,11 @@ type ListAllPacksResult struct {
|
||||||
func ListAllPacks(repo *Repository, ch chan<- worker.Job, done <-chan struct{}) {
|
func ListAllPacks(repo *Repository, ch chan<- worker.Job, done <-chan struct{}) {
|
||||||
f := func(job worker.Job, done <-chan struct{}) (interface{}, error) {
|
f := func(job worker.Job, done <-chan struct{}) (interface{}, error) {
|
||||||
packID := job.Data.(backend.ID)
|
packID := job.Data.(backend.ID)
|
||||||
entries, err := repo.ListPack(packID)
|
entries, size, err := repo.ListPack(packID)
|
||||||
|
|
||||||
return ListAllPacksResult{
|
return ListAllPacksResult{
|
||||||
PackID: packID,
|
PackID: packID,
|
||||||
|
Size: size,
|
||||||
Entries: entries,
|
Entries: entries,
|
||||||
}, err
|
}, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ func selectBlobs(t *testing.T, repo *repository.Repository, p float32) (list1, l
|
||||||
blobs := pack.NewBlobSet()
|
blobs := pack.NewBlobSet()
|
||||||
|
|
||||||
for id := range repo.List(backend.Data, done) {
|
for id := range repo.List(backend.Data, done) {
|
||||||
entries, err := repo.ListPack(id)
|
entries, _, err := repo.ListPack(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error listing pack %v: %v", id, err)
|
t.Fatalf("error listing pack %v: %v", id, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -544,17 +544,24 @@ func (r *Repository) List(t backend.Type, done <-chan struct{}) <-chan backend.I
|
||||||
return outCh
|
return outCh
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListPack returns the list of blobs saved in the pack id.
|
// ListPack returns the list of blobs saved in the pack id and the length of
|
||||||
func (r *Repository) ListPack(id backend.ID) ([]pack.Blob, error) {
|
// 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()}
|
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}
|
ldr := pack.BackendLoader{Backend: r.Backend(), Handle: h}
|
||||||
|
|
||||||
unpacker, err := pack.NewUnpacker(r.Key(), ldr)
|
unpacker, err := pack.NewUnpacker(r.Key(), ldr)
|
||||||
if err != nil {
|
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
|
// Delete calls backend.Delete() if implemented, and returns an error
|
||||||
|
|
Loading…
Reference in a new issue