lib/db, lib/model: Resolve identical recv only items (fixes #5130) (#5230)

This commit is contained in:
Simon Frei
2018-10-10 12:43:07 +02:00
committed by Jakob Borg
parent caa2356409
commit d10773c311
5 changed files with 173 additions and 14 deletions

View File

@@ -12,6 +12,7 @@ package db
import (
"bytes"
"fmt"
"sort"
"time"
"github.com/syncthing/syncthing/lib/protocol"
@@ -150,7 +151,7 @@ func (vl VersionList) String() string {
b.WriteString(", ")
}
copy(id[:], v.Device)
fmt.Fprintf(&b, "{%v, %v, %v}", v.Version, id, v.Invalid)
fmt.Fprintf(&b, "{%v, %v}", v.Version, id)
}
b.WriteString("}")
return b.String()
@@ -175,12 +176,15 @@ func (vl VersionList) update(folder, device []byte, file protocol.FileInfo, db *
Version: file.Version,
Invalid: file.IsInvalid(),
}
for i, v := range vl.Versions {
switch v.Version.Compare(file.Version) {
i := 0
if nv.Invalid {
i = sort.Search(len(vl.Versions), func(j int) bool {
return vl.Versions[j].Invalid
})
}
for ; i < len(vl.Versions); i++ {
switch vl.Versions[i].Version.Compare(file.Version) {
case protocol.Equal:
if nv.Invalid {
continue
}
fallthrough
case protocol.Lesser:
@@ -198,7 +202,7 @@ func (vl VersionList) update(folder, device []byte, file protocol.FileInfo, db *
// to determine the winner.)
//
// A surprise missing file entry here is counted as a win for us.
if of, ok := db.getFile(db.keyer.GenerateDeviceFileKey(nil, folder, v.Device, []byte(file.Name))); !ok || file.WinsConflict(of) {
if of, ok := db.getFile(db.keyer.GenerateDeviceFileKey(nil, folder, vl.Versions[i].Device, []byte(file.Name))); !ok || file.WinsConflict(of) {
vl = vl.insertAt(i, nv)
return vl, removedFV, removedAt, i
}