From 27456f6545dff58d488e0a02032ba4709b8a94a8 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Fri, 10 Apr 2020 11:34:37 +0200 Subject: [PATCH] debug: use proper context This allows the debug commands to be properly interrupted. --- cmd/restic/cmd_debug.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/cmd/restic/cmd_debug.go b/cmd/restic/cmd_debug.go index abae130db..4c2eb5ec6 100644 --- a/cmd/restic/cmd_debug.go +++ b/cmd/restic/cmd_debug.go @@ -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 }