filter: Make --exclude "dir/" equivalent to --exclude "dir/**"

Rclone uses directory exclusions to cut down the listing it has to do,
so before this fix `--exclude dir/` would make sure nothing in `dir/`
was scanned, **except** if --fast-list was used, in which case only
the directory was excluded and everything within it was included.

This is rather unexpected, so this patch makes `--exclude dir/` be
equivalent to `--exclude dir/**`, meaning that excluding a directory
excludes it and its contents.

We can't do the same for --include without changing the semantics of
filtering slightly.

Fixes #3375
This commit is contained in:
Nick Craig-Wood 2020-10-27 13:08:20 +00:00
parent f50b4e51ed
commit 8897377a54
2 changed files with 19 additions and 0 deletions

View File

@ -267,6 +267,10 @@ func (f *Filter) addDirGlobs(Include bool, glob string) error {
func (f *Filter) Add(Include bool, glob string) error {
isDirRule := strings.HasSuffix(glob, "/")
isFileRule := !isDirRule
// Make excluding "dir/" equivalent to excluding "dir/**"
if isDirRule && !Include {
glob += "**"
}
if strings.Contains(glob, "**") {
isDirRule, isFileRule = true, true
}

View File

@ -523,6 +523,21 @@ func TestFilterAddDirRuleOrFileRule(t *testing.T) {
+ (^|/)potato$
--- Directory filter rules ---
+ ^.*$`,
},
{
false,
"potato/",
`--- File filter rules ---
- (^|/)potato/.*$
--- Directory filter rules ---
- (^|/)potato/.*$`,
},
{
true,
"potato/",
`--- File filter rules ---
--- Directory filter rules ---
+ (^|/)potato/$`,
},
{
false,