filter: Fix crash for '**' pattern

This commit is contained in:
Michael Eischer 2021-05-14 22:14:05 +02:00
parent 6d8ceefd67
commit 55bea6e7a6
3 changed files with 13 additions and 0 deletions

View file

@ -0,0 +1,7 @@
Bugfix: Fix crash of `backup --exclude='**'`
The exclude filter '**', which excludes all files, caused restic to crash. This
has been fixed.
https://github.com/restic/restic/issues/3380
https://github.com/restic/restic/pull/3393

View file

@ -166,6 +166,11 @@ func match(patterns Pattern, strs []string) (matched bool, err error) {
return true, nil
}
// an empty pattern never matches a non-empty path
if len(patterns) == 0 {
return false, nil
}
if len(patterns) <= len(strs) {
minOffset := 0
maxOffset := len(strs) - len(patterns)

View file

@ -23,6 +23,7 @@ var matchTests = []struct {
{"*.go", "/foo/bar/test.go", true},
{"*.c", "/foo/bar/test.go", false},
{"*", "/foo/bar/test.go", true},
{"**", "/foo/bar/test.go", true},
{"foo*", "/foo/bar/test.go", true},
{"bar*", "/foo/bar/test.go", true},
{"/bar*", "/foo/bar/test.go", false},