mirror of
https://github.com/octoleo/restic.git
synced 2024-12-22 19:08:55 +00:00
filter: document recursive wildcards
Match/ChildMatch accept a ** pattern which is not noted in the doc string, nor do any of the docs or tests specify whether the match is greedy (i.e., can 'foo/**/bar' match paths with additional intermediate bar directories?). Add a note to the doc string and add test cases for greedy matches.
This commit is contained in:
parent
8c40ae5a03
commit
92eb1cbffd
@ -17,6 +17,10 @@ var ErrBadString = errors.New("filter.Match: string is empty")
|
|||||||
//
|
//
|
||||||
// Pattern can be a combination of patterns suitable for filepath.Match, joined
|
// Pattern can be a combination of patterns suitable for filepath.Match, joined
|
||||||
// by filepath.Separator.
|
// by filepath.Separator.
|
||||||
|
//
|
||||||
|
// In addition patterns suitable for filepath.Match, pattern accepts a
|
||||||
|
// recursive wildcard '**', which greedily matches an arbitrary number of
|
||||||
|
// intermediate directories.
|
||||||
func Match(pattern, str string) (matched bool, err error) {
|
func Match(pattern, str string) (matched bool, err error) {
|
||||||
if pattern == "" {
|
if pattern == "" {
|
||||||
return true, nil
|
return true, nil
|
||||||
@ -46,6 +50,10 @@ func Match(pattern, str string) (matched bool, err error) {
|
|||||||
//
|
//
|
||||||
// Pattern can be a combination of patterns suitable for filepath.Match, joined
|
// Pattern can be a combination of patterns suitable for filepath.Match, joined
|
||||||
// by filepath.Separator.
|
// by filepath.Separator.
|
||||||
|
//
|
||||||
|
// In addition patterns suitable for filepath.Match, pattern accepts a
|
||||||
|
// recursive wildcard '**', which greedily matches an arbitrary number of
|
||||||
|
// intermediate directories.
|
||||||
func ChildMatch(pattern, str string) (matched bool, err error) {
|
func ChildMatch(pattern, str string) (matched bool, err error) {
|
||||||
if pattern == "" {
|
if pattern == "" {
|
||||||
return true, nil
|
return true, nil
|
||||||
|
@ -76,6 +76,7 @@ var matchTests = []struct {
|
|||||||
{"foo/**/bar/*.go", "/home/user/foo/bar/test.go", true},
|
{"foo/**/bar/*.go", "/home/user/foo/bar/test.go", true},
|
||||||
{"foo/**/bar/*.go", "x/foo/bar/test.go", true},
|
{"foo/**/bar/*.go", "x/foo/bar/test.go", true},
|
||||||
{"foo/**/bar/*.go", "foo/bar/test.go", true},
|
{"foo/**/bar/*.go", "foo/bar/test.go", true},
|
||||||
|
{"foo/**/bar/*.go", "foo/bar/baz/bar/test.go", true},
|
||||||
{"foo/**/bar/*.go", "/home/user/foo/test.c", false},
|
{"foo/**/bar/*.go", "/home/user/foo/test.c", false},
|
||||||
{"foo/**/bar/*.go", "bar/foo/main.go", false},
|
{"foo/**/bar/*.go", "bar/foo/main.go", false},
|
||||||
{"foo/**/bar/*.go", "/foo/bar/main.go", true},
|
{"foo/**/bar/*.go", "/foo/bar/main.go", true},
|
||||||
@ -144,6 +145,7 @@ var childMatchTests = []struct {
|
|||||||
{"/foo/bar/baz", "/foo/bar", true},
|
{"/foo/bar/baz", "/foo/bar", true},
|
||||||
{"/foo/bar/baz", "/foo/baz", false},
|
{"/foo/bar/baz", "/foo/baz", false},
|
||||||
{"/foo/**/baz", "/foo/bar/baz", true},
|
{"/foo/**/baz", "/foo/bar/baz", true},
|
||||||
|
{"/foo/**/baz", "/foo/bar/baz/blah", true},
|
||||||
{"/foo/**/qux", "/foo/bar/baz/qux", true},
|
{"/foo/**/qux", "/foo/bar/baz/qux", true},
|
||||||
{"/baz/bar", "/foo", false},
|
{"/baz/bar", "/foo", false},
|
||||||
{"/foo", "/foo/bar", true},
|
{"/foo", "/foo/bar", true},
|
||||||
|
Loading…
Reference in New Issue
Block a user