mirror of
https://github.com/restic/restic.git
synced 2025-08-12 11:47:43 +00:00
make Lookup() return all blobs
+ simplify syntax
This commit is contained in:

committed by
Michael Eischer

parent
020cab8e08
commit
9d1fb94c6c
@@ -51,7 +51,7 @@ type packInfo struct {
|
||||
// fileRestorer restores set of files
|
||||
type fileRestorer struct {
|
||||
key *crypto.Key
|
||||
idx func(restic.ID, restic.BlobType) ([]restic.PackedBlob, bool)
|
||||
idx func(restic.ID, restic.BlobType) []restic.PackedBlob
|
||||
packLoader func(ctx context.Context, h restic.Handle, length int, offset int64, fn func(rd io.Reader) error) error
|
||||
|
||||
filesWriter *filesWriter
|
||||
@@ -63,7 +63,7 @@ type fileRestorer struct {
|
||||
func newFileRestorer(dst string,
|
||||
packLoader func(ctx context.Context, h restic.Handle, length int, offset int64, fn func(rd io.Reader) error) error,
|
||||
key *crypto.Key,
|
||||
idx func(restic.ID, restic.BlobType) ([]restic.PackedBlob, bool)) *fileRestorer {
|
||||
idx func(restic.ID, restic.BlobType) []restic.PackedBlob) *fileRestorer {
|
||||
|
||||
return &fileRestorer{
|
||||
key: key,
|
||||
@@ -88,8 +88,8 @@ func (r *fileRestorer) forEachBlob(blobIDs []restic.ID, fn func(packID restic.ID
|
||||
}
|
||||
|
||||
for _, blobID := range blobIDs {
|
||||
packs, found := r.idx(blobID, restic.DataBlob)
|
||||
if !found {
|
||||
packs := r.idx(blobID, restic.DataBlob)
|
||||
if len(packs) == 0 {
|
||||
return errors.Errorf("Unknown blob %s", blobID.String())
|
||||
}
|
||||
fn(packs[0].PackID, packs[0].Blob)
|
||||
@@ -208,13 +208,11 @@ func (r *fileRestorer) downloadPack(ctx context.Context, pack *packInfo) {
|
||||
})
|
||||
} else if packsMap, ok := file.blobs.(map[restic.ID][]fileBlobInfo); ok {
|
||||
for _, blob := range packsMap[pack.id] {
|
||||
idxPacks, found := r.idx(blob.id, restic.DataBlob)
|
||||
if found {
|
||||
for _, idxPack := range idxPacks {
|
||||
if idxPack.PackID.Equal(pack.id) {
|
||||
addBlob(idxPack.Blob, blob.offset)
|
||||
break
|
||||
}
|
||||
idxPacks := r.idx(blob.id, restic.DataBlob)
|
||||
for _, idxPack := range idxPacks {
|
||||
if idxPack.PackID.Equal(pack.id) {
|
||||
addBlob(idxPack.Blob, blob.offset)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -39,9 +39,9 @@ type TestRepo struct {
|
||||
loader func(ctx context.Context, h restic.Handle, length int, offset int64, fn func(rd io.Reader) error) error
|
||||
}
|
||||
|
||||
func (i *TestRepo) Lookup(blobID restic.ID, _ restic.BlobType) ([]restic.PackedBlob, bool) {
|
||||
packs, found := i.blobs[blobID]
|
||||
return packs, found
|
||||
func (i *TestRepo) Lookup(blobID restic.ID, _ restic.BlobType) []restic.PackedBlob {
|
||||
packs := i.blobs[blobID]
|
||||
return packs
|
||||
}
|
||||
|
||||
func (i *TestRepo) packName(pack *packInfo) string {
|
||||
|
@@ -5,7 +5,6 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/restic/restic/internal/crypto"
|
||||
"github.com/restic/restic/internal/errors"
|
||||
|
||||
"github.com/restic/restic/internal/debug"
|
||||
@@ -313,8 +312,7 @@ func (res *Restorer) VerifyFiles(ctx context.Context, dst string) (int, error) {
|
||||
|
||||
offset := int64(0)
|
||||
for _, blobID := range node.Content {
|
||||
blobs, _ := res.repo.Index().Lookup(blobID, restic.DataBlob)
|
||||
length := blobs[0].Length - uint(crypto.Extension)
|
||||
length, _ := res.repo.LookupBlobSize(blobID, restic.DataBlob)
|
||||
buf := make([]byte, length) // TODO do I want to reuse the buffer somehow?
|
||||
_, err = file.ReadAt(buf, offset)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user