lib/db: Improve error message on meta inconsistency (#6751)

This commit is contained in:
Simon Frei
2020-06-17 10:03:39 +02:00
committed by GitHub
parent a218a69530
commit cbe0d2fffc
2 changed files with 16 additions and 2 deletions
+10 -1
View File
@@ -8,6 +8,7 @@ package db
import (
"bytes"
"errors"
"math/bits"
"time"
@@ -15,6 +16,8 @@ import (
"github.com/syncthing/syncthing/lib/sync"
)
var errMetaInconsistent = errors.New("inconsistent counts detected")
type countsMap struct {
counts CountsSet
indexes map[metaKey]int // device ID + local flags -> index in counts
@@ -104,7 +107,13 @@ func (m *metadataTracker) fromDB(db *Lowlevel, folder []byte) error {
if err != nil {
return err
}
return m.Unmarshal(bs)
if err = m.Unmarshal(bs); err != nil {
return err
}
if m.counts.Created == 0 {
return errMetaInconsistent
}
return nil
}
// countsPtr returns a pointer to the corresponding Counts struct, if