diff --git a/cmd/restic/cmd_restore.go b/cmd/restic/cmd_restore.go index 5161be50d..f86391b20 100644 --- a/cmd/restic/cmd_restore.go +++ b/cmd/restic/cmd_restore.go @@ -162,7 +162,10 @@ func runRestore(ctx context.Context, opts RestoreOptions, gopts GlobalOptions, } progress := restoreui.NewProgress(printer, calculateProgressInterval(!gopts.Quiet, gopts.JSON)) - res := restorer.NewRestorer(repo, sn, opts.Sparse, progress) + res := restorer.NewRestorer(repo, sn, restorer.Options{ + Sparse: opts.Sparse, + Progress: progress, + }) totalErrors := 0 res.Error = func(location string, err error) error { diff --git a/internal/restorer/restorer.go b/internal/restorer/restorer.go index 12ce84d5c..8b39f138f 100644 --- a/internal/restorer/restorer.go +++ b/internal/restorer/restorer.go @@ -17,10 +17,9 @@ import ( // Restorer is used to restore a snapshot to a directory. type Restorer struct { - repo restic.Repository - sn *restic.Snapshot - sparse bool - + repo restic.Repository + sn *restic.Snapshot + sparse bool progress *restoreui.Progress Error func(location string, err error) error @@ -30,15 +29,19 @@ type Restorer struct { var restorerAbortOnAllErrors = func(_ string, err error) error { return err } +type Options struct { + Sparse bool + Progress *restoreui.Progress +} + // NewRestorer creates a restorer preloaded with the content from the snapshot id. -func NewRestorer(repo restic.Repository, sn *restic.Snapshot, sparse bool, - progress *restoreui.Progress) *Restorer { +func NewRestorer(repo restic.Repository, sn *restic.Snapshot, opts Options) *Restorer { r := &Restorer{ repo: repo, - sparse: sparse, + sparse: opts.Sparse, + progress: opts.Progress, Error: restorerAbortOnAllErrors, SelectFilter: func(string, string, *restic.Node) (bool, bool) { return true, true }, - progress: progress, sn: sn, } diff --git a/internal/restorer/restorer_test.go b/internal/restorer/restorer_test.go index 757a317b2..64e10a6e8 100644 --- a/internal/restorer/restorer_test.go +++ b/internal/restorer/restorer_test.go @@ -343,7 +343,7 @@ func TestRestorer(t *testing.T) { sn, id := saveSnapshot(t, repo, test.Snapshot, noopGetGenericAttributes) t.Logf("snapshot saved as %v", id.Str()) - res := NewRestorer(repo, sn, false, nil) + res := NewRestorer(repo, sn, Options{}) tempdir := rtest.TempDir(t) // make sure we're creating a new subdir of the tempdir @@ -460,7 +460,7 @@ func TestRestorerRelative(t *testing.T) { sn, id := saveSnapshot(t, repo, test.Snapshot, noopGetGenericAttributes) t.Logf("snapshot saved as %v", id.Str()) - res := NewRestorer(repo, sn, false, nil) + res := NewRestorer(repo, sn, Options{}) tempdir := rtest.TempDir(t) cleanup := rtest.Chdir(t, tempdir) @@ -689,7 +689,7 @@ func TestRestorerTraverseTree(t *testing.T) { repo := repository.TestRepository(t) sn, _ := saveSnapshot(t, repo, test.Snapshot, noopGetGenericAttributes) - res := NewRestorer(repo, sn, false, nil) + res := NewRestorer(repo, sn, Options{}) res.SelectFilter = test.Select @@ -765,7 +765,7 @@ func TestRestorerConsistentTimestampsAndPermissions(t *testing.T) { }, }, noopGetGenericAttributes) - res := NewRestorer(repo, sn, false, nil) + res := NewRestorer(repo, sn, Options{}) res.SelectFilter = func(item string, dstpath string, node *restic.Node) (selectedForRestore bool, childMayBeSelected bool) { switch filepath.ToSlash(item) { @@ -820,7 +820,7 @@ func TestVerifyCancel(t *testing.T) { repo := repository.TestRepository(t) sn, _ := saveSnapshot(t, repo, snapshot, noopGetGenericAttributes) - res := NewRestorer(repo, sn, false, nil) + res := NewRestorer(repo, sn, Options{}) tempdir := rtest.TempDir(t) ctx, cancel := context.WithCancel(context.Background()) @@ -862,7 +862,7 @@ func TestRestorerSparseFiles(t *testing.T) { archiver.SnapshotOptions{}) rtest.OK(t, err) - res := NewRestorer(repo, sn, true, nil) + res := NewRestorer(repo, sn, Options{Sparse: true}) tempdir := rtest.TempDir(t) ctx, cancel := context.WithCancel(context.Background()) diff --git a/internal/restorer/restorer_unix_test.go b/internal/restorer/restorer_unix_test.go index 0cbfefa92..95a83cdf7 100644 --- a/internal/restorer/restorer_unix_test.go +++ b/internal/restorer/restorer_unix_test.go @@ -31,7 +31,7 @@ func TestRestorerRestoreEmptyHardlinkedFileds(t *testing.T) { }, }, noopGetGenericAttributes) - res := NewRestorer(repo, sn, false, nil) + res := NewRestorer(repo, sn, Options{}) res.SelectFilter = func(item string, dstpath string, node *restic.Node) (selectedForRestore bool, childMayBeSelected bool) { return true, true @@ -99,7 +99,7 @@ func TestRestorerProgressBar(t *testing.T) { mock := &printerMock{} progress := restoreui.NewProgress(mock, 0) - res := NewRestorer(repo, sn, false, progress) + res := NewRestorer(repo, sn, Options{Progress: progress}) res.SelectFilter = func(item string, dstpath string, node *restic.Node) (selectedForRestore bool, childMayBeSelected bool) { return true, true } diff --git a/internal/restorer/restorer_windows_test.go b/internal/restorer/restorer_windows_test.go index 684d51ace..90ece474d 100644 --- a/internal/restorer/restorer_windows_test.go +++ b/internal/restorer/restorer_windows_test.go @@ -269,7 +269,7 @@ func setup(t *testing.T, nodesMap map[string]Node) *Restorer { sn, _ := saveSnapshot(t, repo, Snapshot{ Nodes: nodesMap, }, getFileAttributes) - res := NewRestorer(repo, sn, false, nil) + res := NewRestorer(repo, sn, Options{}) return res }