forked from TrueCloudLab/rclone
Fix filters to add ** rules to directory rules
This fixes `--exclude ".*{,/**}"` to exclude all . files and . directories.
This commit is contained in:
parent
de2d967abd
commit
78c1f2839e
2 changed files with 67 additions and 1 deletions
|
@ -273,7 +273,7 @@ func (f *Filter) addDirGlobs(Include bool, glob string) error {
|
|||
func (f *Filter) Add(Include bool, glob string) error {
|
||||
isDirRule := strings.HasSuffix(glob, "/")
|
||||
isFileRule := !isDirRule
|
||||
if strings.HasSuffix(glob, "**") {
|
||||
if strings.Contains(glob, "**") {
|
||||
isDirRule, isFileRule = true, true
|
||||
}
|
||||
re, err := globToRegexp(glob)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package fs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
@ -338,6 +339,71 @@ func TestNewFilterMatches(t *testing.T) {
|
|||
assert.False(t, f.InActive())
|
||||
}
|
||||
|
||||
func TestFilterAddDirRuleOrFileRule(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
included bool
|
||||
glob string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
false,
|
||||
"potato",
|
||||
`--- File filter rules ---
|
||||
- (^|/)potato$
|
||||
--- Directory filter rules ---`,
|
||||
},
|
||||
{
|
||||
true,
|
||||
"potato",
|
||||
`--- File filter rules ---
|
||||
+ (^|/)potato$
|
||||
--- Directory filter rules ---
|
||||
+ ^.*$`,
|
||||
},
|
||||
{
|
||||
false,
|
||||
"*",
|
||||
`--- File filter rules ---
|
||||
- (^|/)[^/]*$
|
||||
--- Directory filter rules ---
|
||||
- ^.*$`,
|
||||
},
|
||||
{
|
||||
true,
|
||||
"*",
|
||||
`--- File filter rules ---
|
||||
+ (^|/)[^/]*$
|
||||
--- Directory filter rules ---
|
||||
+ ^.*$`,
|
||||
},
|
||||
{
|
||||
false,
|
||||
".*{,/**}",
|
||||
`--- File filter rules ---
|
||||
- (^|/)\.[^/]*(|/.*)$
|
||||
--- Directory filter rules ---
|
||||
- (^|/)\.[^/]*(|/.*)$`,
|
||||
},
|
||||
{
|
||||
true,
|
||||
"a/b/c/d",
|
||||
`--- File filter rules ---
|
||||
+ (^|/)a/b/c/d$
|
||||
--- Directory filter rules ---
|
||||
+ (^|/)a/b/c/$
|
||||
+ (^|/)a/b/$
|
||||
+ (^|/)a/$`,
|
||||
},
|
||||
} {
|
||||
f, err := NewFilter()
|
||||
require.NoError(t, err)
|
||||
err = f.Add(test.included, test.glob)
|
||||
require.NoError(t, err)
|
||||
got := f.DumpFilters()
|
||||
assert.Equal(t, test.want, got, fmt.Sprintf("Add(%v, %q)", test.included, test.glob))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterForEachLine(t *testing.T) {
|
||||
file := testFile(t, `; comment
|
||||
one
|
||||
|
|
Loading…
Reference in a new issue