mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-05 08:02:13 +00:00
Add test for LocalSize/GlobalSize results
This commit is contained in:
parent
c268e4ad1b
commit
1eca4170f7
@ -427,18 +427,19 @@ func ldbUpdateGlobal(db dbReader, batch dbWriter, folder, device []byte, file pr
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(fl.versions) > 0 {
|
|
||||||
// Keep the current neweset file around so we can subtract it from
|
|
||||||
// the globalSize if we replace it.
|
|
||||||
oldFile, hasOldFile = ldbGet(db, folder, fl.versions[0].device, name)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := range fl.versions {
|
for i := range fl.versions {
|
||||||
if bytes.Compare(fl.versions[i].device, device) == 0 {
|
if bytes.Compare(fl.versions[i].device, device) == 0 {
|
||||||
if fl.versions[i].version.Equal(file.Version) {
|
if fl.versions[i].version.Equal(file.Version) {
|
||||||
// No need to do anything
|
// No need to do anything
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if i == 0 {
|
||||||
|
// Keep the current newest file around so we can subtract it from
|
||||||
|
// the globalSize if we replace it.
|
||||||
|
oldFile, hasOldFile = ldbGet(db, folder, fl.versions[0].device, name)
|
||||||
|
}
|
||||||
|
|
||||||
fl.versions = append(fl.versions[:i], fl.versions[i+1:]...)
|
fl.versions = append(fl.versions[:i], fl.versions[i+1:]...)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -492,6 +493,14 @@ done:
|
|||||||
if !file.Version.Equal(oldFile.Version) {
|
if !file.Version.Equal(oldFile.Version) {
|
||||||
globalSize.addFile(file)
|
globalSize.addFile(file)
|
||||||
if hasOldFile {
|
if hasOldFile {
|
||||||
|
// We have the old file that was removed at the head of the list.
|
||||||
|
globalSize.removeFile(oldFile)
|
||||||
|
} else if len(fl.versions) > 1 {
|
||||||
|
// The previous newest version is now at index 1, grab it from there.
|
||||||
|
oldFile, ok := ldbGet(db, folder, fl.versions[1].device, name)
|
||||||
|
if !ok {
|
||||||
|
panic("file referenced in version list does not exist")
|
||||||
|
}
|
||||||
globalSize.removeFile(oldFile)
|
globalSize.removeFile(oldFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,6 +173,29 @@ func TestGlobalSet(t *testing.T) {
|
|||||||
t.Errorf("Global incorrect;\n A: %v !=\n E: %v", g, expectedGlobal)
|
t.Errorf("Global incorrect;\n A: %v !=\n E: %v", g, expectedGlobal)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
globalFiles, globalDeleted, globalBytes := 0, 0, int64(0)
|
||||||
|
for _, f := range g {
|
||||||
|
if f.IsInvalid() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if f.IsDeleted() {
|
||||||
|
globalDeleted++
|
||||||
|
} else {
|
||||||
|
globalFiles++
|
||||||
|
}
|
||||||
|
globalBytes += f.Size()
|
||||||
|
}
|
||||||
|
gsFiles, gsDeleted, gsBytes := m.GlobalSize()
|
||||||
|
if gsFiles != globalFiles {
|
||||||
|
t.Errorf("Incorrect GlobalSize files; %d != %d", gsFiles, globalFiles)
|
||||||
|
}
|
||||||
|
if gsDeleted != globalDeleted {
|
||||||
|
t.Errorf("Incorrect GlobalSize deleted; %d != %d", gsDeleted, globalDeleted)
|
||||||
|
}
|
||||||
|
if gsBytes != globalBytes {
|
||||||
|
t.Errorf("Incorrect GlobalSize bytes; %d != %d", gsBytes, globalBytes)
|
||||||
|
}
|
||||||
|
|
||||||
h := fileList(haveList(m, protocol.LocalDeviceID))
|
h := fileList(haveList(m, protocol.LocalDeviceID))
|
||||||
sort.Sort(h)
|
sort.Sort(h)
|
||||||
|
|
||||||
@ -180,6 +203,29 @@ func TestGlobalSet(t *testing.T) {
|
|||||||
t.Errorf("Have incorrect;\n A: %v !=\n E: %v", h, localTot)
|
t.Errorf("Have incorrect;\n A: %v !=\n E: %v", h, localTot)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
haveFiles, haveDeleted, haveBytes := 0, 0, int64(0)
|
||||||
|
for _, f := range h {
|
||||||
|
if f.IsInvalid() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if f.IsDeleted() {
|
||||||
|
haveDeleted++
|
||||||
|
} else {
|
||||||
|
haveFiles++
|
||||||
|
}
|
||||||
|
haveBytes += f.Size()
|
||||||
|
}
|
||||||
|
lsFiles, lsDeleted, lsBytes := m.LocalSize()
|
||||||
|
if lsFiles != haveFiles {
|
||||||
|
t.Errorf("Incorrect LocalSize files; %d != %d", lsFiles, haveFiles)
|
||||||
|
}
|
||||||
|
if lsDeleted != haveDeleted {
|
||||||
|
t.Errorf("Incorrect LocalSize deleted; %d != %d", lsDeleted, haveDeleted)
|
||||||
|
}
|
||||||
|
if lsBytes != haveBytes {
|
||||||
|
t.Errorf("Incorrect LocalSize bytes; %d != %d", lsBytes, haveBytes)
|
||||||
|
}
|
||||||
|
|
||||||
h = fileList(haveList(m, remoteDevice0))
|
h = fileList(haveList(m, remoteDevice0))
|
||||||
sort.Sort(h)
|
sort.Sort(h)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user