|
@@ -1455,6 +1455,58 @@ func TestIssue3164(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func TestScanNoDatabaseWrite(t *testing.T) {
|
|
|
+ // When scanning, nothing should be committed to database unless
|
|
|
+ // something actually changed.
|
|
|
+
|
|
|
+ db := db.OpenMemory()
|
|
|
+ m := NewModel(defaultConfig, protocol.LocalDeviceID, "device", "syncthing", "dev", db, nil)
|
|
|
+ m.AddFolder(defaultFolderConfig)
|
|
|
+ m.StartFolder("default")
|
|
|
+ m.ServeBackground()
|
|
|
+
|
|
|
+ // Start with no ignores, and restore the previous state when the test completes
|
|
|
+
|
|
|
+ curIgn, _, err := m.GetIgnores("default")
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+ defer m.SetIgnores("default", curIgn)
|
|
|
+ m.SetIgnores("default", nil)
|
|
|
+
|
|
|
+ // Scan the folder twice. The second scan should be a no-op database wise
|
|
|
+
|
|
|
+ m.ScanFolder("default")
|
|
|
+ c0 := db.Committed()
|
|
|
+
|
|
|
+ m.ScanFolder("default")
|
|
|
+ c1 := db.Committed()
|
|
|
+
|
|
|
+ if c1 != c0 {
|
|
|
+ t.Errorf("scan should not commit data when nothing changed but %d != %d", c1, c0)
|
|
|
+ }
|
|
|
+
|
|
|
+ // Ignore a file we know exists. It'll be updated in the database.
|
|
|
+
|
|
|
+ m.SetIgnores("default", []string{"foo"})
|
|
|
+
|
|
|
+ m.ScanFolder("default")
|
|
|
+ c2 := db.Committed()
|
|
|
+
|
|
|
+ if c2 <= c1 {
|
|
|
+ t.Errorf("scan should commit data when something got ignored but %d <= %d", c2, c1)
|
|
|
+ }
|
|
|
+
|
|
|
+ // Scan again. Nothing should happen.
|
|
|
+
|
|
|
+ m.ScanFolder("default")
|
|
|
+ c3 := db.Committed()
|
|
|
+
|
|
|
+ if c3 != c2 {
|
|
|
+ t.Errorf("scan should not commit data when nothing changed (with ignores) but %d != %d", c3, c2)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
type fakeAddr struct{}
|
|
|
|
|
|
func (fakeAddr) Network() string {
|