debug: use proper context

This allows the debug commands to be properly interrupted.
This commit is contained in:
Michael Eischer 2020-04-10 11:34:37 +02:00
parent c458e114d4
commit 27456f6545

View file

@ -54,9 +54,9 @@ func prettyPrintJSON(wr io.Writer, item interface{}) error {
return err
}
func debugPrintSnapshots(repo *repository.Repository, wr io.Writer) error {
return repo.List(context.TODO(), restic.SnapshotFile, func(id restic.ID, size int64) error {
snapshot, err := restic.LoadSnapshot(context.TODO(), repo, id)
func debugPrintSnapshots(ctx context.Context, repo *repository.Repository, wr io.Writer) error {
return repo.List(ctx, restic.SnapshotFile, func(id restic.ID, size int64) error {
snapshot, err := restic.LoadSnapshot(ctx, repo, id)
if err != nil {
return err
}
@ -82,9 +82,9 @@ type Blob struct {
Offset uint `json:"offset"`
}
func printPacks(repo *repository.Repository, wr io.Writer) error {
func printPacks(ctx context.Context, repo *repository.Repository, wr io.Writer) error {
return repo.List(context.TODO(), restic.PackFile, func(id restic.ID, size int64) error {
return repo.List(ctx, restic.PackFile, func(id restic.ID, size int64) error {
h := restic.Handle{Type: restic.PackFile, Name: id.String()}
blobs, err := pack.List(repo.Key(), restic.ReaderAt(repo.Backend(), h), size)
@ -110,11 +110,11 @@ func printPacks(repo *repository.Repository, wr io.Writer) error {
})
}
func dumpIndexes(repo restic.Repository, wr io.Writer) error {
return repo.List(context.TODO(), restic.IndexFile, func(id restic.ID, size int64) error {
func dumpIndexes(ctx context.Context, repo restic.Repository, wr io.Writer) error {
return repo.List(ctx, restic.IndexFile, func(id restic.ID, size int64) error {
Printf("index_id: %v\n", id)
idx, err := repository.LoadIndex(context.TODO(), repo, id)
idx, err := repository.LoadIndex(ctx, repo, id)
if err != nil {
return err
}
@ -145,20 +145,20 @@ func runDebugDump(gopts GlobalOptions, args []string) error {
switch tpe {
case "indexes":
return dumpIndexes(repo, gopts.stdout)
return dumpIndexes(gopts.ctx, repo, gopts.stdout)
case "snapshots":
return debugPrintSnapshots(repo, gopts.stdout)
return debugPrintSnapshots(gopts.ctx, repo, gopts.stdout)
case "packs":
return printPacks(repo, gopts.stdout)
return printPacks(gopts.ctx, repo, gopts.stdout)
case "all":
Printf("snapshots:\n")
err := debugPrintSnapshots(repo, gopts.stdout)
err := debugPrintSnapshots(gopts.ctx, repo, gopts.stdout)
if err != nil {
return err
}
Printf("\nindexes:\n")
err = dumpIndexes(repo, gopts.stdout)
err = dumpIndexes(gopts.ctx, repo, gopts.stdout)
if err != nil {
return err
}