Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

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

Nick Craig-Wood8897377a5414
diff --git a/fs/filter/filter.go b/fs/filter/filter.go
index 1714dabf5..304ab87f8 100644
--- a/fs/filter/filter.go
+++ b/fs/filter/filter.go
@@ -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
}
diff --git a/fs/filter/filter_test.go b/fs/filter/filter_test.go
index 1fc4ef671..3d5439fe2 100644
--- a/fs/filter/filter_test.go
+++ b/fs/filter/filter_test.go
@@ -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,