Smarter filter when children won't match

This improves restore performance by several orders of magniture by not
going through the whole tree recursively when we can anticipate that no
match will ever occur.
This commit is contained in:
Loic Nageleisen
2017-06-16 16:46:16 +02:00
parent d87b2f189d
commit 4a36993c19
5 changed files with 145 additions and 21 deletions

View File

@@ -417,7 +417,7 @@ func runBackup(opts BackupOptions, gopts GlobalOptions, args []string) error {
}
selectFilter := func(item string, fi os.FileInfo) bool {
matched, err := filter.List(opts.Excludes, item)
matched, _, err := filter.List(opts.Excludes, item)
if err != nil {
Warnf("error for exclude pattern: %v", err)
}

View File

@@ -113,22 +113,22 @@ func runRestore(opts RestoreOptions, gopts GlobalOptions, args []string) error {
return nil
}
selectExcludeFilter := func(item string, dstpath string, node *restic.Node) bool {
matched, err := filter.List(opts.Exclude, item)
selectExcludeFilter := func(item string, dstpath string, node *restic.Node) (bool, bool) {
matched, childMayMatch, err := filter.List(opts.Exclude, item)
if err != nil {
Warnf("error for exclude pattern: %v", err)
}
return !matched
return !matched, childMayMatch
}
selectIncludeFilter := func(item string, dstpath string, node *restic.Node) bool {
matched, err := filter.List(opts.Include, item)
selectIncludeFilter := func(item string, dstpath string, node *restic.Node) (bool, bool) {
matched, childMayMatch, err := filter.List(opts.Include, item)
if err != nil {
Warnf("error for include pattern: %v", err)
}
return matched
return matched, childMayMatch
}
if len(opts.Exclude) > 0 {