lib/db: Don't ignore failures unmarshaling version lists (#6411)

This commit is contained in:
Simon Frei 2020-03-16 10:09:27 +01:00 committed by GitHub
parent a1cb1d70c4
commit 1bd4ea0cbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 28 deletions

View File

@ -380,9 +380,11 @@ func (db *Lowlevel) checkGlobals(folder []byte, meta *metadataTracker) error {
var dk []byte
for dbi.Next() {
vl, ok := unmarshalVersionList(dbi.Value())
if !ok {
continue
var vl VersionList
if err := vl.Unmarshal(dbi.Value()); err != nil || len(vl.Versions) == 0 {
if err := t.Delete(dbi.Key()); err != nil {
return err
}
}
// Check the global version list for consistency. An issue in previous
@ -621,19 +623,6 @@ func (db *Lowlevel) gcIndirect() error {
return db.Compact()
}
func unmarshalVersionList(data []byte) (VersionList, bool) {
var vl VersionList
if err := vl.Unmarshal(data); err != nil {
l.Debugln("unmarshal error:", err)
return VersionList{}, false
}
if len(vl.Versions) == 0 {
l.Debugln("empty version list")
return VersionList{}, false
}
return vl, true
}
// unchanged checks if two files are the same and thus don't need to be updated.
// Local flags or the invalid bit might change without the version
// being bumped.

View File

@ -133,9 +133,9 @@ func (t readOnlyTransaction) getGlobal(keyBuf, folder, file []byte, truncate boo
return nil, nil, false, err
}
vl, ok := unmarshalVersionList(bs)
if !ok {
return keyBuf, nil, false, nil
var vl VersionList
if err := vl.Unmarshal(bs); err != nil {
return nil, nil, false, err
}
keyBuf, err = t.keyer.GenerateDeviceFileKey(keyBuf, folder, vl.Versions[0].Device, file)
@ -268,9 +268,9 @@ func (t *readOnlyTransaction) withGlobal(folder, prefix []byte, truncate bool, f
return nil
}
vl, ok := unmarshalVersionList(dbi.Value())
if !ok {
continue
var vl VersionList
if err := vl.Unmarshal(dbi.Value()); err != nil {
return err
}
dk, err = t.keyer.GenerateDeviceFileKey(dk, folder, vl.Versions[0].Device, name)
@ -309,9 +309,9 @@ func (t *readOnlyTransaction) availability(folder, file []byte) ([]protocol.Devi
return nil, err
}
vl, ok := unmarshalVersionList(bs)
if !ok {
return nil, nil
var vl VersionList
if err := vl.Unmarshal(bs); err != nil {
return nil, err
}
var devices []protocol.DeviceID
@ -347,9 +347,9 @@ func (t *readOnlyTransaction) withNeed(folder, device []byte, truncate bool, fn
var dk []byte
devID := protocol.DeviceIDFromBytes(device)
for dbi.Next() {
vl, ok := unmarshalVersionList(dbi.Value())
if !ok {
continue
var vl VersionList
if err := vl.Unmarshal(dbi.Value()); err != nil {
return err
}
haveFV, have := vl.Get(device)