forked from TrueCloudLab/restic
restore: cleanup downloadPack
This commit is contained in:
parent
b856e9489a
commit
cf352ccafb
1 changed files with 11 additions and 8 deletions
|
@ -199,18 +199,18 @@ func (r *fileRestorer) restoreFiles(ctx context.Context) error {
|
||||||
|
|
||||||
type blobToFileOffsetsMapping map[restic.ID]struct {
|
type blobToFileOffsetsMapping map[restic.ID]struct {
|
||||||
files map[*fileInfo][]int64 // file -> offsets (plural!) of the blob in the file
|
files map[*fileInfo][]int64 // file -> offsets (plural!) of the blob in the file
|
||||||
|
blob restic.Blob
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *fileRestorer) downloadPack(ctx context.Context, pack *packInfo) error {
|
func (r *fileRestorer) downloadPack(ctx context.Context, pack *packInfo) error {
|
||||||
// calculate blob->[]files->[]offsets mappings
|
// calculate blob->[]files->[]offsets mappings
|
||||||
blobs := make(blobToFileOffsetsMapping)
|
blobs := make(blobToFileOffsetsMapping)
|
||||||
var blobList []restic.Blob
|
|
||||||
for file := range pack.files {
|
for file := range pack.files {
|
||||||
addBlob := func(blob restic.Blob, fileOffset int64) {
|
addBlob := func(blob restic.Blob, fileOffset int64) {
|
||||||
blobInfo, ok := blobs[blob.ID]
|
blobInfo, ok := blobs[blob.ID]
|
||||||
if !ok {
|
if !ok {
|
||||||
blobInfo.files = make(map[*fileInfo][]int64)
|
blobInfo.files = make(map[*fileInfo][]int64)
|
||||||
blobList = append(blobList, blob)
|
blobInfo.blob = blob
|
||||||
blobs[blob.ID] = blobInfo
|
blobs[blob.ID] = blobInfo
|
||||||
}
|
}
|
||||||
blobInfo.files[file] = append(blobInfo.files[file], fileOffset)
|
blobInfo.files[file] = append(blobInfo.files[file], fileOffset)
|
||||||
|
@ -242,17 +242,16 @@ func (r *fileRestorer) downloadPack(ctx context.Context, pack *packInfo) error {
|
||||||
|
|
||||||
// track already processed blobs for precise error reporting
|
// track already processed blobs for precise error reporting
|
||||||
processedBlobs := restic.NewBlobSet()
|
processedBlobs := restic.NewBlobSet()
|
||||||
err := r.downloadBlobs(ctx, pack.id, blobList, blobs, processedBlobs)
|
err := r.downloadBlobs(ctx, pack.id, blobs, processedBlobs)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// only report error for not yet processed blobs
|
// only report error for not yet processed blobs
|
||||||
affectedFiles := make(map[*fileInfo]struct{})
|
affectedFiles := make(map[*fileInfo]struct{})
|
||||||
for _, blob := range blobList {
|
for _, entry := range blobs {
|
||||||
if processedBlobs.Has(blob.BlobHandle) {
|
if processedBlobs.Has(entry.blob.BlobHandle) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
blob := blobs[blob.ID]
|
for file := range entry.files {
|
||||||
for file := range blob.files {
|
|
||||||
affectedFiles[file] = struct{}{}
|
affectedFiles[file] = struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -274,9 +273,13 @@ func (r *fileRestorer) sanitizeError(file *fileInfo, err error) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *fileRestorer) downloadBlobs(ctx context.Context, packID restic.ID, blobList []restic.Blob,
|
func (r *fileRestorer) downloadBlobs(ctx context.Context, packID restic.ID,
|
||||||
blobs blobToFileOffsetsMapping, processedBlobs restic.BlobSet) error {
|
blobs blobToFileOffsetsMapping, processedBlobs restic.BlobSet) error {
|
||||||
|
|
||||||
|
blobList := make([]restic.Blob, 0, len(blobs))
|
||||||
|
for _, entry := range blobs {
|
||||||
|
blobList = append(blobList, entry.blob)
|
||||||
|
}
|
||||||
return repository.StreamPack(ctx, r.packLoader, r.key, packID, blobList,
|
return repository.StreamPack(ctx, r.packLoader, r.key, packID, blobList,
|
||||||
func(h restic.BlobHandle, blobData []byte, err error) error {
|
func(h restic.BlobHandle, blobData []byte, err error) error {
|
||||||
processedBlobs.Insert(h)
|
processedBlobs.Insert(h)
|
||||||
|
|
Loading…
Reference in a new issue