mirror of https://github.com/restic/restic.git
restorer: use options struct
This commit is contained in:
parent
0fcd89f892
commit
2b50c2606c
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue