diff --git a/cmd/restic/cmd_cat.go b/cmd/restic/cmd_cat.go index 8926f11a5..7e66af734 100644 --- a/cmd/restic/cmd_cat.go +++ b/cmd/restic/cmd_cat.go @@ -1,7 +1,6 @@ package main import ( - "context" "encoding/json" "fmt" "os" @@ -75,7 +74,7 @@ func runCat(gopts GlobalOptions, args []string) error { fmt.Println(string(buf)) return nil case "index": - buf, err := repo.LoadAndDecrypt(context.TODO(), restic.IndexFile, id) + buf, err := repo.LoadAndDecrypt(gopts.ctx, restic.IndexFile, id) if err != nil { return err } @@ -85,7 +84,7 @@ func runCat(gopts GlobalOptions, args []string) error { case "snapshot": sn := &restic.Snapshot{} - err = repo.LoadJSONUnpacked(context.TODO(), restic.SnapshotFile, id, sn) + err = repo.LoadJSONUnpacked(gopts.ctx, restic.SnapshotFile, id, sn) if err != nil { return err } @@ -100,7 +99,7 @@ func runCat(gopts GlobalOptions, args []string) error { return nil case "key": h := restic.Handle{Type: restic.KeyFile, Name: id.String()} - buf, err := backend.LoadAll(context.TODO(), repo.Backend(), h) + buf, err := backend.LoadAll(gopts.ctx, repo.Backend(), h) if err != nil { return err } @@ -127,7 +126,7 @@ func runCat(gopts GlobalOptions, args []string) error { fmt.Println(string(buf)) return nil case "lock": - lock, err := restic.LoadLock(context.TODO(), repo, id) + lock, err := restic.LoadLock(gopts.ctx, repo, id) if err != nil { return err } @@ -143,7 +142,7 @@ func runCat(gopts GlobalOptions, args []string) error { } // load index, handle all the other types - err = repo.LoadIndex(context.TODO()) + err = repo.LoadIndex(gopts.ctx) if err != nil { return err } @@ -151,7 +150,7 @@ func runCat(gopts GlobalOptions, args []string) error { switch tpe { case "pack": h := restic.Handle{Type: restic.DataFile, Name: id.String()} - buf, err := backend.LoadAll(context.TODO(), repo.Backend(), h) + buf, err := backend.LoadAll(gopts.ctx, repo.Backend(), h) if err != nil { return err } @@ -173,7 +172,7 @@ func runCat(gopts GlobalOptions, args []string) error { blob := list[0] buf := make([]byte, blob.Length) - n, err := repo.LoadBlob(context.TODO(), t, id, buf) + n, err := repo.LoadBlob(gopts.ctx, t, id, buf) if err != nil { return err } diff --git a/cmd/restic/cmd_ls.go b/cmd/restic/cmd_ls.go index 7ea0759a5..4a046b7ef 100644 --- a/cmd/restic/cmd_ls.go +++ b/cmd/restic/cmd_ls.go @@ -46,8 +46,8 @@ func init() { flags.StringArrayVar(&lsOptions.Paths, "path", nil, "only consider snapshots which include this (absolute) `path`, when no snapshot ID is given") } -func printTree(repo *repository.Repository, id *restic.ID, prefix string) error { - tree, err := repo.LoadTree(context.TODO(), *id) +func printTree(ctx context.Context, repo *repository.Repository, id *restic.ID, prefix string) error { + tree, err := repo.LoadTree(ctx, *id) if err != nil { return err } @@ -56,7 +56,7 @@ func printTree(repo *repository.Repository, id *restic.ID, prefix string) error Printf("%s\n", formatNode(prefix, entry, lsOptions.ListLong)) if entry.Type == "dir" && entry.Subtree != nil { - if err = printTree(repo, entry.Subtree, filepath.Join(prefix, entry.Name)); err != nil { + if err = printTree(ctx, repo, entry.Subtree, filepath.Join(prefix, entry.Name)); err != nil { return err } } @@ -75,7 +75,7 @@ func runLs(opts LsOptions, gopts GlobalOptions, args []string) error { return err } - if err = repo.LoadIndex(context.TODO()); err != nil { + if err = repo.LoadIndex(gopts.ctx); err != nil { return err } @@ -84,7 +84,7 @@ func runLs(opts LsOptions, gopts GlobalOptions, args []string) error { for sn := range FindFilteredSnapshots(ctx, repo, opts.Host, opts.Tags, opts.Paths, args) { Verbosef("snapshot %s of %v at %s):\n", sn.ID().Str(), sn.Paths, sn.Time) - if err = printTree(repo, sn.Tree, string(filepath.Separator)); err != nil { + if err = printTree(gopts.ctx, repo, sn.Tree, string(filepath.Separator)); err != nil { return err } }