lib/db: Update global counts on invalidation (fixes #4701)
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4702
This commit is contained in:
parent
050f9f8091
commit
364f61bda6
@ -168,7 +168,7 @@ insert:
|
|||||||
if insertedAt == 0 {
|
if insertedAt == 0 {
|
||||||
// We just inserted a new newest version. Fixup the global size
|
// We just inserted a new newest version. Fixup the global size
|
||||||
// calculation.
|
// calculation.
|
||||||
if !file.Version.Equal(oldFile.Version) {
|
if !file.Version.Equal(oldFile.Version) || file.Invalid != oldFile.Invalid {
|
||||||
meta.addFile(globalDeviceID, file)
|
meta.addFile(globalDeviceID, file)
|
||||||
if hasOldFile {
|
if hasOldFile {
|
||||||
// We have the old file that was removed at the head of the list.
|
// We have the old file that was removed at the head of the list.
|
||||||
|
|||||||
@ -820,6 +820,47 @@ func TestDropFiles(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIssue4701(t *testing.T) {
|
||||||
|
ldb := db.OpenMemory()
|
||||||
|
|
||||||
|
s := db.NewFileSet("test)", fs.NewFilesystem(fs.FilesystemTypeBasic, "."), ldb)
|
||||||
|
|
||||||
|
localHave := fileList{
|
||||||
|
protocol.FileInfo{Name: "a", Version: protocol.Vector{Counters: []protocol.Counter{{ID: myID, Value: 1000}}}},
|
||||||
|
protocol.FileInfo{Name: "b", Version: protocol.Vector{Counters: []protocol.Counter{{ID: myID, Value: 1000}}}, Invalid: true},
|
||||||
|
}
|
||||||
|
|
||||||
|
s.Update(protocol.LocalDeviceID, localHave)
|
||||||
|
|
||||||
|
if c := s.LocalSize(); c.Files != 1 {
|
||||||
|
t.Errorf("Expected 1 local file, got %v", c.Files)
|
||||||
|
}
|
||||||
|
if c := s.GlobalSize(); c.Files != 1 {
|
||||||
|
t.Errorf("Expected 1 global file, got %v", c.Files)
|
||||||
|
}
|
||||||
|
|
||||||
|
localHave[1].Invalid = false
|
||||||
|
s.Update(protocol.LocalDeviceID, localHave)
|
||||||
|
|
||||||
|
if c := s.LocalSize(); c.Files != 2 {
|
||||||
|
t.Errorf("Expected 2 local files, got %v", c.Files)
|
||||||
|
}
|
||||||
|
if c := s.GlobalSize(); c.Files != 2 {
|
||||||
|
t.Errorf("Expected 2 global files, got %v", c.Files)
|
||||||
|
}
|
||||||
|
|
||||||
|
localHave[0].Invalid = true
|
||||||
|
localHave[1].Invalid = true
|
||||||
|
s.Update(protocol.LocalDeviceID, localHave)
|
||||||
|
|
||||||
|
if c := s.LocalSize(); c.Files != 0 {
|
||||||
|
t.Errorf("Expected 0 local files, got %v", c.Files)
|
||||||
|
}
|
||||||
|
if c := s.GlobalSize(); c.Files != 0 {
|
||||||
|
t.Errorf("Expected 0 global files, got %v", c.Files)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func replace(fs *db.FileSet, device protocol.DeviceID, files []protocol.FileInfo) {
|
func replace(fs *db.FileSet, device protocol.DeviceID, files []protocol.FileInfo) {
|
||||||
fs.Drop(device)
|
fs.Drop(device)
|
||||||
fs.Update(device, files)
|
fs.Update(device, files)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user