1
mirror of https://github.com/rclone/rclone synced 2024-12-18 07:45:55 +01:00

filter: export GlobToRegexp #5164

This commit is contained in:
Ivan Andreev 2021-04-25 14:55:51 +03:00
parent 5c646dff9a
commit c142e3edcc
3 changed files with 6 additions and 6 deletions

View File

@ -254,7 +254,7 @@ func (f *Filter) addDirGlobs(Include bool, glob string) error {
if dirGlob == "/" {
continue
}
dirRe, err := globToRegexp(dirGlob, f.Opt.IgnoreCase)
dirRe, err := GlobToRegexp(dirGlob, f.Opt.IgnoreCase)
if err != nil {
return err
}
@ -274,7 +274,7 @@ func (f *Filter) Add(Include bool, glob string) error {
if strings.Contains(glob, "**") {
isDirRule, isFileRule = true, true
}
re, err := globToRegexp(glob, f.Opt.IgnoreCase)
re, err := GlobToRegexp(glob, f.Opt.IgnoreCase)
if err != nil {
return err
}

View File

@ -10,10 +10,10 @@ import (
"github.com/pkg/errors"
)
// globToRegexp converts an rsync style glob to a regexp
// GlobToRegexp converts an rsync style glob to a regexp
//
// documented in filtering.md
func globToRegexp(glob string, ignoreCase bool) (*regexp.Regexp, error) {
func GlobToRegexp(glob string, ignoreCase bool) (*regexp.Regexp, error) {
var re bytes.Buffer
if ignoreCase {
_, _ = re.WriteString("(?i)")

View File

@ -42,7 +42,7 @@ func TestGlobToRegexp(t *testing.T) {
{`a\\b`, `(^|/)a\\b$`, ``},
} {
for _, ignoreCase := range []bool{false, true} {
gotRe, err := globToRegexp(test.in, ignoreCase)
gotRe, err := GlobToRegexp(test.in, ignoreCase)
if test.error == "" {
prefix := ""
if ignoreCase {
@ -102,7 +102,7 @@ func TestGlobToDirGlobs(t *testing.T) {
{"/sausage3**", []string{`/sausage3**/`, "/"}},
{"/a/*.jpg", []string{`/a/`, "/"}},
} {
_, err := globToRegexp(test.in, false)
_, err := GlobToRegexp(test.in, false)
assert.NoError(t, err)
got := globToDirGlobs(test.in)
assert.Equal(t, test.want, got, test.in)