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

Add InActive method to Filter to detect when no fiters are in use.

Nick Craig-Woodccb59480bdb0
diff --git a/fs/filter.go b/fs/filter.go
index 32b6ba59d..da97832ef 100644
--- a/fs/filter.go
+++ b/fs/filter.go
@@ -255,6 +255,16 @@ func (f *Filter) Clear() {
f.rules = nil
}
+// InActive returns false if any filters are active
+func (f *Filter) InActive() bool {
+ return (f.files == nil &&
+ f.ModTimeFrom.IsZero() &&
+ f.ModTimeTo.IsZero() &&
+ f.MinSize == 0 &&
+ f.MaxSize == 0 &&
+ len(f.rules) == 0)
+}
+
// Include returns whether this object should be included into the
// sync or not
func (f *Filter) Include(remote string, size int64, modTime time.Time) bool {
diff --git a/fs/filter_test.go b/fs/filter_test.go
index 90304eae6..01c3b03fa 100644
--- a/fs/filter_test.go
+++ b/fs/filter_test.go
@@ -62,6 +62,9 @@ func TestNewFilterDefault(t *testing.T) {
if f.files != nil {
t.Errorf("files want none got %v", f.files)
}
+ if !f.InActive() {
+ t.Errorf("want InActive")
+ }
}
// return a pointer to the string
@@ -168,6 +171,9 @@ func TestNewFilterFull(t *testing.T) {
t.Errorf("Didn't find file %q in f.files", name)
}
}
+ if f.InActive() {
+ t.Errorf("want !InActive")
+ }
}
type includeTest struct {
@@ -205,6 +211,9 @@ func TestNewFilterIncludeFiles(t *testing.T) {
{"potato/file2.jpg", 2, 0, false},
{"file3.jpg", 3, 0, false},
})
+ if f.InActive() {
+ t.Errorf("want !InActive")
+ }
}
func TestNewFilterMinSize(t *testing.T) {
@@ -218,6 +227,9 @@ func TestNewFilterMinSize(t *testing.T) {
{"file2.jpg", 101, 0, true},
{"potato/file2.jpg", 99, 0, false},
})
+ if f.InActive() {
+ t.Errorf("want !InActive")
+ }
}
func TestNewFilterMaxSize(t *testing.T) {
@@ -231,6 +243,9 @@ func TestNewFilterMaxSize(t *testing.T) {
{"file2.jpg", 101, 0, false},
{"potato/file2.jpg", 99, 0, true},
})
+ if f.InActive() {
+ t.Errorf("want !InActive")
+ }
}
func TestNewFilterMinAndMaxAge(t *testing.T) {
@@ -247,6 +262,9 @@ func TestNewFilterMinAndMaxAge(t *testing.T) {
{"potato/file1.jpg", 98, 1440000003, true},
{"potato/file2.jpg", 99, 1440000004, false},
})
+ if f.InActive() {
+ t.Errorf("want !InActive")
+ }
}
func TestNewFilterMinAge(t *testing.T) {
@@ -262,6 +280,9 @@ func TestNewFilterMinAge(t *testing.T) {
{"potato/file1.jpg", 98, 1440000003, false},
{"potato/file2.jpg", 99, 1440000004, false},
})
+ if f.InActive() {
+ t.Errorf("want !InActive")
+ }
}
func TestNewFilterMaxAge(t *testing.T) {
@@ -277,6 +298,9 @@ func TestNewFilterMaxAge(t *testing.T) {
{"potato/file1.jpg", 98, 1440000003, true},
{"potato/file2.jpg", 99, 1440000004, true},
})
+ if f.InActive() {
+ t.Errorf("want !InActive")
+ }
}
func TestNewFilterMatches(t *testing.T) {
@@ -316,6 +340,9 @@ func TestNewFilterMatches(t *testing.T) {
{"sausage3/potato", 101, 0, true},
{"unicorn", 99, 0, false},
})
+ if f.InActive() {
+ t.Errorf("want !InActive")
+ }
}
func TestFilterForEachLine(t *testing.T) {