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 (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/stephenafamo/bob"
|
"github.com/stephenafamo/bob"
|
||||||
@@ -83,8 +84,23 @@ func writeWithPreparedStatement(ctx context.Context, pStmt *bob.StdPrepared, r r
|
|||||||
r.Lock()
|
r.Lock()
|
||||||
defer r.Unlock()
|
defer r.Unlock()
|
||||||
|
|
||||||
// Serialize to JSON.
|
// default serialization format - JSON
|
||||||
data, err := r.MarshalDataOnly(r, dsd.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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -94,7 +110,7 @@ func writeWithPreparedStatement(ctx context.Context, pStmt *bob.StdPrepared, r r
|
|||||||
|
|
||||||
// Insert.
|
// Insert.
|
||||||
if len(data) > 0 {
|
if len(data) > 0 {
|
||||||
format := strconv.Itoa(dsd.JSON)
|
format := strconv.Itoa(int(format))
|
||||||
_, err = pStmt.ExecContext(
|
_, err = pStmt.ExecContext(
|
||||||
ctx,
|
ctx,
|
||||||
r.DatabaseKey(),
|
r.DatabaseKey(),
|
||||||
|
|||||||
@@ -161,13 +161,28 @@ func (db *SQLite) putRecord(r record.Record, tx *bob.Tx) (record.Record, error)
|
|||||||
defer r.Unlock()
|
defer r.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serialize to JSON.
|
// default serialization format - JSON
|
||||||
data, err := r.MarshalDataOnly(r, dsd.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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// Prepare for setter.
|
// Prepare for setter.
|
||||||
setFormat := omitnull.From(int16(dsd.JSON))
|
setFormat := omitnull.From(int16(format))
|
||||||
setData := omitnull.From(data)
|
setData := omitnull.From(data)
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
setFormat.Null()
|
setFormat.Null()
|
||||||
|
|||||||
Reference in New Issue
Block a user