Fix restore filter

Internally rename restorer.Filter -> restorer.SelectForRestore to make
semantic clear.

In addition, swap parameters to filepath.Match() so that the pattern can
really be matched.

Limitation: The filter only works on the filename, not on any path
component, e.g. '*.go' selects all go files, 'subdir/foo*' doesn't
select anything.

Fixes #202.
This commit is contained in:
Alexander Neumann
2015-07-06 23:59:28 +02:00
parent 6e3486fee8
commit 3e0a97fb13
3 changed files with 49 additions and 16 deletions

View File

@@ -5,6 +5,7 @@ import (
"path/filepath"
"github.com/restic/restic"
"github.com/restic/restic/debug"
)
type CmdRestore struct {
@@ -78,11 +79,17 @@ func (cmd CmdRestore) Execute(args []string) error {
// TODO: a filter against the full path sucks as filepath.Match doesn't match
// directory separators on '*'. still, it's better than nothing.
if len(args) > 2 {
res.Filter = func(item string, dstpath string, node *restic.Node) bool {
matched, err := filepath.Match(item, args[2])
pattern := args[2]
cmd.global.Verbosef("filter pattern %q\n", pattern)
res.SelectForRestore = func(item string, dstpath string, node *restic.Node) bool {
matched, err := filepath.Match(pattern, node.Name)
if err != nil {
panic(err)
}
if !matched {
debug.Log("restic.restore", "item %v doesn't match pattern %q", item, pattern)
}
return matched
}
}