lib/db: Filter repeat files in one update (ref #6650) (#6651)

This commit is contained in:
Simon Frei
2020-05-16 14:40:20 +02:00
committed by Jakob Borg
parent 6768daec07
commit f5ca213682
3 changed files with 103 additions and 4 deletions
+38
View File
@@ -1615,6 +1615,44 @@ func TestIgnoreAfterReceiveOnly(t *testing.T) {
}
}
// https://github.com/syncthing/syncthing/issues/6650
func TestUpdateWithOneFileTwice(t *testing.T) {
ldb := db.NewLowlevel(backend.OpenMemory())
defer ldb.Close()
file := "foo"
s := db.NewFileSet("test", fs.NewFilesystem(fs.FilesystemTypeFake, ""), ldb)
fs := fileList{{
Name: file,
Version: protocol.Vector{Counters: []protocol.Counter{{ID: myID, Value: 1}}},
Sequence: 1,
}}
s.Update(protocol.LocalDeviceID, fs)
fs = append(fs, fs[0])
for i := range fs {
fs[i].Sequence++
fs[i].Version = fs[i].Version.Update(myID)
}
fs[1].Sequence++
fs[1].Version = fs[1].Version.Update(myID)
s.Update(protocol.LocalDeviceID, fs)
snap := s.Snapshot()
defer snap.Release()
count := 0
snap.WithHaveSequence(0, func(f db.FileIntf) bool {
count++
return true
})
if count != 1 {
t.Error("Expected to have one file, got", count)
}
}
func replace(fs *db.FileSet, device protocol.DeviceID, files []protocol.FileInfo) {
fs.Drop(device)
fs.Update(device, files)