add regex matching to include/exclude filters

This commit is contained in:
Jeff Thompson
2017-09-12 13:47:35 -05:00
parent 554f63263f
commit b56d7dedba
5 changed files with 164 additions and 11 deletions

View File

@@ -679,6 +679,8 @@ func restoreRepository(context *cli.Context) {
var patterns [] string
for _, pattern := range context.Args() {
pattern = strings.TrimSpace(pattern)
for strings.HasPrefix(pattern, "--") {
pattern = pattern[1:]
}
@@ -687,14 +689,21 @@ func restoreRepository(context *cli.Context) {
pattern = pattern[1:]
}
if pattern[0] != '+' && pattern[0] != '-' {
if duplicacy.IsUnspecifiedFilter(pattern) {
pattern = "+" + pattern
}
if pattern == "+" || pattern == "-" {
if duplicacy.IsEmptyFilter(pattern) {
continue
}
if strings.HasPrefix(pattern, "i:") || strings.HasPrefix(pattern, "e:") {
valid, err := duplicacy.IsValidRegex(pattern[2:])
if !valid || err != nil {
duplicacy.LOG_ERROR("SNAPSHOT_FILTER", "Invalid regular expression encountered for filter: \"%s\", error: %v", pattern, err)
}
}
patterns = append(patterns, pattern)
}