mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-03 15:17:25 +00:00
lib/db: Improve error message on meta inconsistency (#6751)
This commit is contained in:
parent
a218a69530
commit
cbe0d2fffc
@ -811,7 +811,12 @@ func (db *Lowlevel) getMetaAndCheck(folder string) *metadataTracker {
|
||||
func (db *Lowlevel) loadMetadataTracker(folder string) *metadataTracker {
|
||||
meta := newMetadataTracker()
|
||||
if err := meta.fromDB(db, []byte(folder)); err != nil {
|
||||
if err == errMetaInconsistent {
|
||||
l.Infof("Stored folder metadata for %q is inconsistent; recalculating", folder)
|
||||
} else {
|
||||
l.Infof("No stored folder metadata for %q; recalculating", folder)
|
||||
|
||||
}
|
||||
return db.getMetaAndCheck(folder)
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user