forked from TrueCloudLab/restic
restore: remove unused parameter from SelectFilter
This commit is contained in:
parent
ac44bdf6dd
commit
013a6156bd
3 changed files with 21 additions and 27 deletions
|
@ -164,7 +164,7 @@ func runRestore(ctx context.Context, opts RestoreOptions, gopts GlobalOptions,
|
|||
msg.E("Warning: %s\n", message)
|
||||
}
|
||||
|
||||
selectExcludeFilter := func(item string, _ string, isDir bool) (selectedForRestore bool, childMayBeSelected bool) {
|
||||
selectExcludeFilter := func(item string, isDir bool) (selectedForRestore bool, childMayBeSelected bool) {
|
||||
matched := false
|
||||
for _, rejectFn := range excludePatternFns {
|
||||
matched = matched || rejectFn(item)
|
||||
|
@ -186,7 +186,7 @@ func runRestore(ctx context.Context, opts RestoreOptions, gopts GlobalOptions,
|
|||
return selectedForRestore, childMayBeSelected
|
||||
}
|
||||
|
||||
selectIncludeFilter := func(item string, _ string, isDir bool) (selectedForRestore bool, childMayBeSelected bool) {
|
||||
selectIncludeFilter := func(item string, isDir bool) (selectedForRestore bool, childMayBeSelected bool) {
|
||||
selectedForRestore = false
|
||||
childMayBeSelected = false
|
||||
for _, includeFn := range includePatternFns {
|
||||
|
|
|
@ -29,7 +29,7 @@ type Restorer struct {
|
|||
Warn func(message string)
|
||||
// SelectFilter determines whether the item is selectedForRestore or whether a childMayBeSelected.
|
||||
// selectedForRestore must not depend on isDir as `removeUnexpectedFiles` always passes false to isDir.
|
||||
SelectFilter func(item string, dstpath string, isDir bool) (selectedForRestore bool, childMayBeSelected bool)
|
||||
SelectFilter func(item string, isDir bool) (selectedForRestore bool, childMayBeSelected bool)
|
||||
}
|
||||
|
||||
var restorerAbortOnAllErrors = func(_ string, err error) error { return err }
|
||||
|
@ -100,7 +100,7 @@ func NewRestorer(repo restic.Repository, sn *restic.Snapshot, opts Options) *Res
|
|||
opts: opts,
|
||||
fileList: make(map[string]bool),
|
||||
Error: restorerAbortOnAllErrors,
|
||||
SelectFilter: func(string, string, bool) (bool, bool) { return true, true },
|
||||
SelectFilter: func(string, bool) (bool, bool) { return true, true },
|
||||
sn: sn,
|
||||
}
|
||||
|
||||
|
@ -200,7 +200,7 @@ func (res *Restorer) traverseTreeInner(ctx context.Context, target, location str
|
|||
continue
|
||||
}
|
||||
|
||||
selectedForRestore, childMayBeSelected := res.SelectFilter(nodeLocation, nodeTarget, node.Type == "dir")
|
||||
selectedForRestore, childMayBeSelected := res.SelectFilter(nodeLocation, node.Type == "dir")
|
||||
debug.Log("SelectFilter returned %v %v for %q", selectedForRestore, childMayBeSelected, nodeLocation)
|
||||
|
||||
if selectedForRestore {
|
||||
|
@ -496,7 +496,7 @@ func (res *Restorer) removeUnexpectedFiles(target, location string, expectedFile
|
|||
}
|
||||
|
||||
// TODO pass a proper value to the isDir parameter once this becomes relevant for the filters
|
||||
selectedForRestore, _ := res.SelectFilter(nodeLocation, nodeTarget, false)
|
||||
selectedForRestore, _ := res.SelectFilter(nodeLocation, false)
|
||||
// only delete files that were selected for restore
|
||||
if selectedForRestore {
|
||||
if !res.opts.DryRun {
|
||||
|
|
|
@ -193,7 +193,7 @@ func TestRestorer(t *testing.T) {
|
|||
Files map[string]string
|
||||
ErrorsMust map[string]map[string]struct{}
|
||||
ErrorsMay map[string]map[string]struct{}
|
||||
Select func(item string, dstpath string, isDir bool) (selectForRestore bool, childMayBeSelected bool)
|
||||
Select func(item string, isDir bool) (selectForRestore bool, childMayBeSelected bool)
|
||||
}{
|
||||
// valid test cases
|
||||
{
|
||||
|
@ -285,7 +285,7 @@ func TestRestorer(t *testing.T) {
|
|||
Files: map[string]string{
|
||||
"dir/file": "content: file\n",
|
||||
},
|
||||
Select: func(item, dstpath string, isDir bool) (selectedForRestore bool, childMayBeSelected bool) {
|
||||
Select: func(item string, isDir bool) (selectedForRestore bool, childMayBeSelected bool) {
|
||||
switch item {
|
||||
case filepath.FromSlash("/dir"):
|
||||
childMayBeSelected = true
|
||||
|
@ -371,16 +371,10 @@ func TestRestorer(t *testing.T) {
|
|||
// make sure we're creating a new subdir of the tempdir
|
||||
tempdir = filepath.Join(tempdir, "target")
|
||||
|
||||
res.SelectFilter = func(item, dstpath string, isDir bool) (selectedForRestore bool, childMayBeSelected bool) {
|
||||
t.Logf("restore %v to %v", item, dstpath)
|
||||
if !fs.HasPathPrefix(tempdir, dstpath) {
|
||||
t.Errorf("would restore %v to %v, which is not within the target dir %v",
|
||||
item, dstpath, tempdir)
|
||||
return false, false
|
||||
}
|
||||
|
||||
res.SelectFilter = func(item string, isDir bool) (selectedForRestore bool, childMayBeSelected bool) {
|
||||
t.Logf("restore %v", item)
|
||||
if test.Select != nil {
|
||||
return test.Select(item, dstpath, isDir)
|
||||
return test.Select(item, isDir)
|
||||
}
|
||||
|
||||
return true, true
|
||||
|
@ -582,7 +576,7 @@ func checkVisitOrder(list []TreeVisit) TraverseTreeCheck {
|
|||
func TestRestorerTraverseTree(t *testing.T) {
|
||||
var tests = []struct {
|
||||
Snapshot
|
||||
Select func(item string, dstpath string, isDir bool) (selectForRestore bool, childMayBeSelected bool)
|
||||
Select func(item string, isDir bool) (selectForRestore bool, childMayBeSelected bool)
|
||||
Visitor TraverseTreeCheck
|
||||
}{
|
||||
{
|
||||
|
@ -598,7 +592,7 @@ func TestRestorerTraverseTree(t *testing.T) {
|
|||
"foo": File{Data: "content: foo\n"},
|
||||
},
|
||||
},
|
||||
Select: func(item string, dstpath string, isDir bool) (selectForRestore bool, childMayBeSelected bool) {
|
||||
Select: func(item string, isDir bool) (selectForRestore bool, childMayBeSelected bool) {
|
||||
return true, true
|
||||
},
|
||||
Visitor: checkVisitOrder([]TreeVisit{
|
||||
|
@ -627,7 +621,7 @@ func TestRestorerTraverseTree(t *testing.T) {
|
|||
"foo": File{Data: "content: foo\n"},
|
||||
},
|
||||
},
|
||||
Select: func(item string, dstpath string, isDir bool) (selectForRestore bool, childMayBeSelected bool) {
|
||||
Select: func(item string, isDir bool) (selectForRestore bool, childMayBeSelected bool) {
|
||||
if item == "/foo" {
|
||||
return true, false
|
||||
}
|
||||
|
@ -651,7 +645,7 @@ func TestRestorerTraverseTree(t *testing.T) {
|
|||
}},
|
||||
},
|
||||
},
|
||||
Select: func(item string, dstpath string, isDir bool) (selectForRestore bool, childMayBeSelected bool) {
|
||||
Select: func(item string, isDir bool) (selectForRestore bool, childMayBeSelected bool) {
|
||||
if item == "/aaa" {
|
||||
return true, false
|
||||
}
|
||||
|
@ -677,7 +671,7 @@ func TestRestorerTraverseTree(t *testing.T) {
|
|||
"foo": File{Data: "content: foo\n"},
|
||||
},
|
||||
},
|
||||
Select: func(item string, dstpath string, isDir bool) (selectForRestore bool, childMayBeSelected bool) {
|
||||
Select: func(item string, isDir bool) (selectForRestore bool, childMayBeSelected bool) {
|
||||
if strings.HasPrefix(item, "/dir") {
|
||||
return true, true
|
||||
}
|
||||
|
@ -708,7 +702,7 @@ func TestRestorerTraverseTree(t *testing.T) {
|
|||
"foo": File{Data: "content: foo\n"},
|
||||
},
|
||||
},
|
||||
Select: func(item string, dstpath string, isDir bool) (selectForRestore bool, childMayBeSelected bool) {
|
||||
Select: func(item string, isDir bool) (selectForRestore bool, childMayBeSelected bool) {
|
||||
switch item {
|
||||
case "/dir":
|
||||
return false, true
|
||||
|
@ -811,7 +805,7 @@ func TestRestorerConsistentTimestampsAndPermissions(t *testing.T) {
|
|||
|
||||
res := NewRestorer(repo, sn, Options{})
|
||||
|
||||
res.SelectFilter = func(item string, dstpath string, isDir bool) (selectedForRestore bool, childMayBeSelected bool) {
|
||||
res.SelectFilter = func(item string, isDir bool) (selectedForRestore bool, childMayBeSelected bool) {
|
||||
switch filepath.ToSlash(item) {
|
||||
case "/dir":
|
||||
childMayBeSelected = true
|
||||
|
@ -1256,7 +1250,7 @@ func TestRestoreDelete(t *testing.T) {
|
|||
}, noopGetGenericAttributes)
|
||||
|
||||
tests := []struct {
|
||||
selectFilter func(item string, dstpath string, isDir bool) (selectedForRestore bool, childMayBeSelected bool)
|
||||
selectFilter func(item string, isDir bool) (selectedForRestore bool, childMayBeSelected bool)
|
||||
fileState map[string]bool
|
||||
}{
|
||||
{
|
||||
|
@ -1271,7 +1265,7 @@ func TestRestoreDelete(t *testing.T) {
|
|||
},
|
||||
},
|
||||
{
|
||||
selectFilter: func(item, dstpath string, isDir bool) (selectedForRestore bool, childMayBeSelected bool) {
|
||||
selectFilter: func(item string, isDir bool) (selectedForRestore bool, childMayBeSelected bool) {
|
||||
return false, false
|
||||
},
|
||||
fileState: map[string]bool{
|
||||
|
@ -1284,7 +1278,7 @@ func TestRestoreDelete(t *testing.T) {
|
|||
},
|
||||
},
|
||||
{
|
||||
selectFilter: func(item, dstpath string, isDir bool) (selectedForRestore bool, childMayBeSelected bool) {
|
||||
selectFilter: func(item string, isDir bool) (selectedForRestore bool, childMayBeSelected bool) {
|
||||
switch item {
|
||||
case filepath.FromSlash("/dir"):
|
||||
selectedForRestore = true
|
||||
|
|
Loading…
Reference in a new issue