diff --git a/lib/db/lowlevel.go b/lib/db/lowlevel.go index 2b315d56f..34bf57203 100644 --- a/lib/db/lowlevel.go +++ b/lib/db/lowlevel.go @@ -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. diff --git a/lib/db/transactions.go b/lib/db/transactions.go index 803c8abc3..cac81f5cf 100644 --- a/lib/db/transactions.go +++ b/lib/db/transactions.go @@ -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)