2
2
mirror of https://github.com/octoleo/restic.git synced 2024-05-28 14:40:49 +00:00

debug: extract examinePack function

This commit is contained in:
Michael Eischer 2021-03-10 20:21:05 +01:00
parent 84491ff40b
commit 096f15db5c

View File

@ -426,8 +426,14 @@ func runDebugExamine(gopts GlobalOptions, args []string) error {
return err
}
blobsLoaded := false
for _, name := range args {
examinePack(gopts.ctx, repo, name)
}
return nil
}
func examinePack(ctx context.Context, repo restic.Repository, name string) {
blobsLoaded := false
fmt.Printf("examine %v\n", name)
id, err := restic.ParseID(name)
if err != nil {
@ -438,14 +444,14 @@ func runDebugExamine(gopts GlobalOptions, args []string) error {
Type: restic.PackFile,
Name: name,
}
fi, err := repo.Backend().Stat(gopts.ctx, h)
fi, err := repo.Backend().Stat(ctx, h)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
}
fmt.Printf(" file size is %v\n", fi.Size)
buf, err := backend.LoadAll(gopts.ctx, nil, repo.Backend(), h)
buf, err := backend.LoadAll(ctx, nil, repo.Backend(), h)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
}
@ -507,7 +513,7 @@ func runDebugExamine(gopts GlobalOptions, args []string) error {
list = append(list, b.Blob)
}
err = loadBlobs(gopts.ctx, repo, name, list)
err = loadBlobs(ctx, repo, name, list)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
} else {
@ -518,10 +524,10 @@ func runDebugExamine(gopts GlobalOptions, args []string) error {
fmt.Printf(" ========================================\n")
fmt.Printf(" inspect the pack itself\n")
blobs, _, err := pack.List(repo.Key(), restic.ReaderAt(gopts.ctx, repo.Backend(), h), fi.Size)
blobs, _, err := pack.List(repo.Key(), restic.ReaderAt(ctx, repo.Backend(), h), fi.Size)
if err != nil {
fmt.Fprintf(os.Stderr, "error for pack %v: %v\n", id.Str(), err)
return nil
return
}
// track current size and offset
@ -552,11 +558,9 @@ func runDebugExamine(gopts GlobalOptions, args []string) error {
}
if !blobsLoaded {
err = loadBlobs(gopts.ctx, repo, name, blobs)
err = loadBlobs(ctx, repo, name, blobs)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
}
}
}
return nil
}