From 603bb0e30976a70b7bb018d62c14bb6f368d87e5 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Fri, 10 Apr 2020 11:36:14 +0200 Subject: [PATCH] restore: Use proper context while loading snapshot --- cmd/restic/cmd_restore.go | 2 +- internal/restorer/restorer.go | 4 ++-- internal/restorer/restorer_test.go | 6 +++--- internal/restorer/restorer_unix_test.go | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/restic/cmd_restore.go b/cmd/restic/cmd_restore.go index ec7d4a9e9..2ab7916f5 100644 --- a/cmd/restic/cmd_restore.go +++ b/cmd/restic/cmd_restore.go @@ -128,7 +128,7 @@ func runRestore(opts RestoreOptions, gopts GlobalOptions, args []string) error { } } - res, err := restorer.NewRestorer(repo, id) + res, err := restorer.NewRestorer(ctx, repo, id) if err != nil { Exitf(2, "creating restorer failed: %v\n", err) } diff --git a/internal/restorer/restorer.go b/internal/restorer/restorer.go index 06e590532..e8966b50a 100644 --- a/internal/restorer/restorer.go +++ b/internal/restorer/restorer.go @@ -24,7 +24,7 @@ type Restorer struct { var restorerAbortOnAllErrors = func(location string, err error) error { return err } // NewRestorer creates a restorer preloaded with the content from the snapshot id. -func NewRestorer(repo restic.Repository, id restic.ID) (*Restorer, error) { +func NewRestorer(ctx context.Context, repo restic.Repository, id restic.ID) (*Restorer, error) { r := &Restorer{ repo: repo, Error: restorerAbortOnAllErrors, @@ -33,7 +33,7 @@ func NewRestorer(repo restic.Repository, id restic.ID) (*Restorer, error) { var err error - r.sn, err = restic.LoadSnapshot(context.TODO(), repo, id) + r.sn, err = restic.LoadSnapshot(ctx, repo, id) if err != nil { return nil, err } diff --git a/internal/restorer/restorer_test.go b/internal/restorer/restorer_test.go index 00c56bccd..38c24e9ff 100644 --- a/internal/restorer/restorer_test.go +++ b/internal/restorer/restorer_test.go @@ -316,7 +316,7 @@ func TestRestorer(t *testing.T) { _, id := saveSnapshot(t, repo, test.Snapshot) t.Logf("snapshot saved as %v", id.Str()) - res, err := NewRestorer(repo, id) + res, err := NewRestorer(context.TODO(), repo, id) if err != nil { t.Fatal(err) } @@ -434,7 +434,7 @@ func TestRestorerRelative(t *testing.T) { _, id := saveSnapshot(t, repo, test.Snapshot) t.Logf("snapshot saved as %v", id.Str()) - res, err := NewRestorer(repo, id) + res, err := NewRestorer(context.TODO(), repo, id) if err != nil { t.Fatal(err) } @@ -665,7 +665,7 @@ func TestRestorerTraverseTree(t *testing.T) { defer cleanup() sn, id := saveSnapshot(t, repo, test.Snapshot) - res, err := NewRestorer(repo, id) + res, err := NewRestorer(context.TODO(), repo, id) if err != nil { t.Fatal(err) } diff --git a/internal/restorer/restorer_unix_test.go b/internal/restorer/restorer_unix_test.go index fc80015c1..f3f23cd16 100644 --- a/internal/restorer/restorer_unix_test.go +++ b/internal/restorer/restorer_unix_test.go @@ -29,7 +29,7 @@ func TestRestorerRestoreEmptyHardlinkedFileds(t *testing.T) { }, }) - res, err := NewRestorer(repo, id) + res, err := NewRestorer(context.TODO(), repo, id) rtest.OK(t, err) res.SelectFilter = func(item string, dstpath string, node *restic.Node) (selectedForRestore bool, childMayBeSelected bool) {