fix: Some configuration data is not stored in the core database when using SQLite.
https://github.com/safing/portmaster/issues/1989
This commit is contained in:
@@ -2,6 +2,7 @@ package sqlite
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/stephenafamo/bob"
|
||||
@@ -83,8 +84,23 @@ func writeWithPreparedStatement(ctx context.Context, pStmt *bob.StdPrepared, r r
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
|
||||
// Serialize to JSON.
|
||||
data, err := r.MarshalDataOnly(r, dsd.JSON)
|
||||
// default serialization format - JSON
|
||||
format := uint8(dsd.JSON)
|
||||
|
||||
// For wrapped records, check the required format
|
||||
if r.IsWrapped() {
|
||||
wrapper, ok := r.(*record.Wrapper)
|
||||
if !ok {
|
||||
return errors.New("record is malformed (reports to be wrapped but is not of type *record.Wrapper)")
|
||||
}
|
||||
format, ok = dsd.ValidateSerializationFormat(wrapper.Format)
|
||||
if !ok {
|
||||
return dsd.ErrIncompatibleFormat
|
||||
}
|
||||
}
|
||||
|
||||
// Serialize.
|
||||
data, err := r.MarshalDataOnly(r, format)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -94,7 +110,7 @@ func writeWithPreparedStatement(ctx context.Context, pStmt *bob.StdPrepared, r r
|
||||
|
||||
// Insert.
|
||||
if len(data) > 0 {
|
||||
format := strconv.Itoa(dsd.JSON)
|
||||
format := strconv.Itoa(int(format))
|
||||
_, err = pStmt.ExecContext(
|
||||
ctx,
|
||||
r.DatabaseKey(),
|
||||
|
||||
@@ -161,13 +161,28 @@ func (db *SQLite) putRecord(r record.Record, tx *bob.Tx) (record.Record, error)
|
||||
defer r.Unlock()
|
||||
}
|
||||
|
||||
// Serialize to JSON.
|
||||
data, err := r.MarshalDataOnly(r, dsd.JSON)
|
||||
// default serialization format - JSON
|
||||
format := uint8(dsd.JSON)
|
||||
|
||||
// For wrapped records, check the required format
|
||||
if r.IsWrapped() {
|
||||
wrapper, ok := r.(*record.Wrapper)
|
||||
if !ok {
|
||||
return nil, errors.New("record is malformed (reports to be wrapped but is not of type *record.Wrapper)")
|
||||
}
|
||||
format, ok = dsd.ValidateSerializationFormat(wrapper.Format)
|
||||
if !ok {
|
||||
return nil, dsd.ErrIncompatibleFormat
|
||||
}
|
||||
}
|
||||
|
||||
// Serialize.
|
||||
data, err := r.MarshalDataOnly(r, format)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Prepare for setter.
|
||||
setFormat := omitnull.From(int16(dsd.JSON))
|
||||
setFormat := omitnull.From(int16(format))
|
||||
setData := omitnull.From(data)
|
||||
if len(data) == 0 {
|
||||
setFormat.Null()
|
||||
|
||||
Reference in New Issue
Block a user