lib/db: Refactor key handling (ref #5198) (#5199)

This breaks out the key generation stuff into a separate type. It's
cleaner on its own, and it prepares for future stuff.
This commit is contained in:
Jakob Borg
2018-09-18 10:41:06 +02:00
committed by GitHub
parent 797a999585
commit 6a87aac84f
10 changed files with 465 additions and 371 deletions

View File

@@ -13,22 +13,6 @@ import (
"github.com/syncthing/syncthing/lib/protocol"
)
const (
KeyTypeDevice = iota
KeyTypeGlobal
KeyTypeBlock
KeyTypeDeviceStatistic
KeyTypeFolderStatistic
KeyTypeVirtualMtime
KeyTypeFolderIdx
KeyTypeDeviceIdx
KeyTypeIndexID
KeyTypeFolderMeta
KeyTypeMiscData
KeyTypeSequence
KeyTypeNeed
)
func (vl VersionList) String() string {
var b bytes.Buffer
var id protocol.DeviceID
@@ -86,7 +70,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.deviceKey(folder, v.Device, []byte(file.Name))); !ok || file.WinsConflict(of) {
if of, ok := db.getFile(db.keyer.GenerateDeviceFileKey(nil, folder, v.Device, []byte(file.Name))); !ok || file.WinsConflict(of) {
vl = vl.insertAt(i, nv)
return vl, removedFV, removedAt, i
}