mirror of
https://github.com/rclone/rclone
synced 2024-11-29 07:55:12 +01:00
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:
parent
f50b4e51ed
commit
8897377a54
@ -267,6 +267,10 @@ func (f *Filter) addDirGlobs(Include bool, glob string) error {
|
|||||||
func (f *Filter) Add(Include bool, glob string) error {
|
func (f *Filter) Add(Include bool, glob string) error {
|
||||||
isDirRule := strings.HasSuffix(glob, "/")
|
isDirRule := strings.HasSuffix(glob, "/")
|
||||||
isFileRule := !isDirRule
|
isFileRule := !isDirRule
|
||||||
|
// Make excluding "dir/" equivalent to excluding "dir/**"
|
||||||
|
if isDirRule && !Include {
|
||||||
|
glob += "**"
|
||||||
|
}
|
||||||
if strings.Contains(glob, "**") {
|
if strings.Contains(glob, "**") {
|
||||||
isDirRule, isFileRule = true, true
|
isDirRule, isFileRule = true, true
|
||||||
}
|
}
|
||||||
|
@ -523,6 +523,21 @@ func TestFilterAddDirRuleOrFileRule(t *testing.T) {
|
|||||||
+ (^|/)potato$
|
+ (^|/)potato$
|
||||||
--- Directory filter rules ---
|
--- Directory filter rules ---
|
||||||
+ ^.*$`,
|
+ ^.*$`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
false,
|
||||||
|
"potato/",
|
||||||
|
`--- File filter rules ---
|
||||||
|
- (^|/)potato/.*$
|
||||||
|
--- Directory filter rules ---
|
||||||
|
- (^|/)potato/.*$`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
true,
|
||||||
|
"potato/",
|
||||||
|
`--- File filter rules ---
|
||||||
|
--- Directory filter rules ---
|
||||||
|
+ (^|/)potato/$`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
false,
|
false,
|
||||||
|
Loading…
Reference in New Issue
Block a user