Skip to content

Commit 364f61b

Browse files
imsodincalmh
authored andcommitted
lib/db: Update global counts on invalidation (fixes syncthing#4701)
GitHub-Pull-Request: syncthing#4702
1 parent 050f9f8 commit 364f61b

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

lib/db/leveldb_transactions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ insert:
168168
if insertedAt == 0 {
169169
// We just inserted a new newest version. Fixup the global size
170170
// calculation.
171-
if !file.Version.Equal(oldFile.Version) {
171+
if !file.Version.Equal(oldFile.Version) || file.Invalid != oldFile.Invalid {
172172
meta.addFile(globalDeviceID, file)
173173
if hasOldFile {
174174
// We have the old file that was removed at the head of the list.

lib/db/set_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,47 @@ func TestDropFiles(t *testing.T) {
820820
}
821821
}
822822

823+
func TestIssue4701(t *testing.T) {
824+
ldb := db.OpenMemory()
825+
826+
s := db.NewFileSet("test)", fs.NewFilesystem(fs.FilesystemTypeBasic, "."), ldb)
827+
828+
localHave := fileList{
829+
protocol.FileInfo{Name: "a", Version: protocol.Vector{Counters: []protocol.Counter{{ID: myID, Value: 1000}}}},
830+
protocol.FileInfo{Name: "b", Version: protocol.Vector{Counters: []protocol.Counter{{ID: myID, Value: 1000}}}, Invalid: true},
831+
}
832+
833+
s.Update(protocol.LocalDeviceID, localHave)
834+
835+
if c := s.LocalSize(); c.Files != 1 {
836+
t.Errorf("Expected 1 local file, got %v", c.Files)
837+
}
838+
if c := s.GlobalSize(); c.Files != 1 {
839+
t.Errorf("Expected 1 global file, got %v", c.Files)
840+
}
841+
842+
localHave[1].Invalid = false
843+
s.Update(protocol.LocalDeviceID, localHave)
844+
845+
if c := s.LocalSize(); c.Files != 2 {
846+
t.Errorf("Expected 2 local files, got %v", c.Files)
847+
}
848+
if c := s.GlobalSize(); c.Files != 2 {
849+
t.Errorf("Expected 2 global files, got %v", c.Files)
850+
}
851+
852+
localHave[0].Invalid = true
853+
localHave[1].Invalid = true
854+
s.Update(protocol.LocalDeviceID, localHave)
855+
856+
if c := s.LocalSize(); c.Files != 0 {
857+
t.Errorf("Expected 0 local files, got %v", c.Files)
858+
}
859+
if c := s.GlobalSize(); c.Files != 0 {
860+
t.Errorf("Expected 0 global files, got %v", c.Files)
861+
}
862+
}
863+
823864
func replace(fs *db.FileSet, device protocol.DeviceID, files []protocol.FileInfo) {
824865
fs.Drop(device)
825866
fs.Update(device, files)

0 commit comments

Comments
 (0)