mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-03 07:12:27 +00:00
lib/db: Fix zero length global version lists in db check
This commit is contained in:
parent
94c6110f2e
commit
c08cb6544b
@ -557,12 +557,37 @@ func (db *Instance) checkGlobals(folder []byte, globalSize *sizeTracker) {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
name := db.globalKeyName(gk)
|
||||||
|
|
||||||
|
if len(vl.versions) == 0 {
|
||||||
|
// A zero length version list is not OK here. If the file exists
|
||||||
|
// at all it should contain, at the very least, our local
|
||||||
|
// version. If we don't have a local version then the global
|
||||||
|
// entry should be deleted.
|
||||||
|
|
||||||
|
fi, ok := t.getFile(folder, protocol.LocalDeviceID[:], name)
|
||||||
|
if !ok {
|
||||||
|
// No local version of the file. Delete and move on.
|
||||||
|
t.Batch.Delete(dbi.Key())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// We have a local version. Set the version list to point to it,
|
||||||
|
// write it, and continue.
|
||||||
|
vl.versions = append(vl.versions, fileVersion{
|
||||||
|
fi.Version,
|
||||||
|
protocol.LocalDeviceID[:],
|
||||||
|
})
|
||||||
|
t.Put(dbi.Key(), vl.MustMarshalXDR())
|
||||||
|
t.checkFlush()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// Check the global version list for consistency. An issue in previous
|
// Check the global version list for consistency. An issue in previous
|
||||||
// versions of goleveldb could result in reordered writes so that
|
// versions of goleveldb could result in reordered writes so that
|
||||||
// there are global entries pointing to no longer existing files. Here
|
// there are global entries pointing to no longer existing files. Here
|
||||||
// we find those and clear them out.
|
// we find those and clear them out.
|
||||||
|
|
||||||
name := db.globalKeyName(gk)
|
|
||||||
var newVL versionList
|
var newVL versionList
|
||||||
for i, version := range vl.versions {
|
for i, version := range vl.versions {
|
||||||
fk = db.deviceKeyInto(fk[:cap(fk)], folder, version.device, name)
|
fk = db.deviceKeyInto(fk[:cap(fk)], folder, version.device, name)
|
||||||
|
Loading…
Reference in New Issue
Block a user