mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-08 22:31:04 +00:00
lib/db: Don't ignore failures unmarshaling version lists (#6411)
This commit is contained in:
parent
a1cb1d70c4
commit
1bd4ea0cbb
@ -380,9 +380,11 @@ func (db *Lowlevel) checkGlobals(folder []byte, meta *metadataTracker) error {
|
|||||||
|
|
||||||
var dk []byte
|
var dk []byte
|
||||||
for dbi.Next() {
|
for dbi.Next() {
|
||||||
vl, ok := unmarshalVersionList(dbi.Value())
|
var vl VersionList
|
||||||
if !ok {
|
if err := vl.Unmarshal(dbi.Value()); err != nil || len(vl.Versions) == 0 {
|
||||||
continue
|
if err := t.Delete(dbi.Key()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the global version list for consistency. An issue in previous
|
// Check the global version list for consistency. An issue in previous
|
||||||
@ -621,19 +623,6 @@ func (db *Lowlevel) gcIndirect() error {
|
|||||||
return db.Compact()
|
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.
|
// 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
|
// Local flags or the invalid bit might change without the version
|
||||||
// being bumped.
|
// being bumped.
|
||||||
|
@ -133,9 +133,9 @@ func (t readOnlyTransaction) getGlobal(keyBuf, folder, file []byte, truncate boo
|
|||||||
return nil, nil, false, err
|
return nil, nil, false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
vl, ok := unmarshalVersionList(bs)
|
var vl VersionList
|
||||||
if !ok {
|
if err := vl.Unmarshal(bs); err != nil {
|
||||||
return keyBuf, nil, false, nil
|
return nil, nil, false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
keyBuf, err = t.keyer.GenerateDeviceFileKey(keyBuf, folder, vl.Versions[0].Device, file)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
vl, ok := unmarshalVersionList(dbi.Value())
|
var vl VersionList
|
||||||
if !ok {
|
if err := vl.Unmarshal(dbi.Value()); err != nil {
|
||||||
continue
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
dk, err = t.keyer.GenerateDeviceFileKey(dk, folder, vl.Versions[0].Device, name)
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
vl, ok := unmarshalVersionList(bs)
|
var vl VersionList
|
||||||
if !ok {
|
if err := vl.Unmarshal(bs); err != nil {
|
||||||
return nil, nil
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var devices []protocol.DeviceID
|
var devices []protocol.DeviceID
|
||||||
@ -347,9 +347,9 @@ func (t *readOnlyTransaction) withNeed(folder, device []byte, truncate bool, fn
|
|||||||
var dk []byte
|
var dk []byte
|
||||||
devID := protocol.DeviceIDFromBytes(device)
|
devID := protocol.DeviceIDFromBytes(device)
|
||||||
for dbi.Next() {
|
for dbi.Next() {
|
||||||
vl, ok := unmarshalVersionList(dbi.Value())
|
var vl VersionList
|
||||||
if !ok {
|
if err := vl.Unmarshal(dbi.Value()); err != nil {
|
||||||
continue
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
haveFV, have := vl.Get(device)
|
haveFV, have := vl.Get(device)
|
||||||
|
Loading…
Reference in New Issue
Block a user