restore: Use proper context while loading snapshot
This commit is contained in:
parent
27456f6545
commit
603bb0e309
4 changed files with 7 additions and 7 deletions
|
@ -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 {
|
if err != nil {
|
||||||
Exitf(2, "creating restorer failed: %v\n", err)
|
Exitf(2, "creating restorer failed: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ type Restorer struct {
|
||||||
var restorerAbortOnAllErrors = func(location string, err error) error { return err }
|
var restorerAbortOnAllErrors = func(location string, err error) error { return err }
|
||||||
|
|
||||||
// NewRestorer creates a restorer preloaded with the content from the snapshot id.
|
// 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{
|
r := &Restorer{
|
||||||
repo: repo,
|
repo: repo,
|
||||||
Error: restorerAbortOnAllErrors,
|
Error: restorerAbortOnAllErrors,
|
||||||
|
@ -33,7 +33,7 @@ func NewRestorer(repo restic.Repository, id restic.ID) (*Restorer, error) {
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
r.sn, err = restic.LoadSnapshot(context.TODO(), repo, id)
|
r.sn, err = restic.LoadSnapshot(ctx, repo, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -316,7 +316,7 @@ func TestRestorer(t *testing.T) {
|
||||||
_, id := saveSnapshot(t, repo, test.Snapshot)
|
_, id := saveSnapshot(t, repo, test.Snapshot)
|
||||||
t.Logf("snapshot saved as %v", id.Str())
|
t.Logf("snapshot saved as %v", id.Str())
|
||||||
|
|
||||||
res, err := NewRestorer(repo, id)
|
res, err := NewRestorer(context.TODO(), repo, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -434,7 +434,7 @@ func TestRestorerRelative(t *testing.T) {
|
||||||
_, id := saveSnapshot(t, repo, test.Snapshot)
|
_, id := saveSnapshot(t, repo, test.Snapshot)
|
||||||
t.Logf("snapshot saved as %v", id.Str())
|
t.Logf("snapshot saved as %v", id.Str())
|
||||||
|
|
||||||
res, err := NewRestorer(repo, id)
|
res, err := NewRestorer(context.TODO(), repo, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -665,7 +665,7 @@ func TestRestorerTraverseTree(t *testing.T) {
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
sn, id := saveSnapshot(t, repo, test.Snapshot)
|
sn, id := saveSnapshot(t, repo, test.Snapshot)
|
||||||
|
|
||||||
res, err := NewRestorer(repo, id)
|
res, err := NewRestorer(context.TODO(), repo, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
rtest.OK(t, err)
|
||||||
|
|
||||||
res.SelectFilter = func(item string, dstpath string, node *restic.Node) (selectedForRestore bool, childMayBeSelected bool) {
|
res.SelectFilter = func(item string, dstpath string, node *restic.Node) (selectedForRestore bool, childMayBeSelected bool) {
|
||||||
|
|
Loading…
Reference in a new issue