From 97a8475364e3cab5229c73090ef1902f0518f0ce Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 28 Apr 2020 09:56:23 +0200 Subject: [PATCH] Fix hierarchical config handling --- profile/config-update.go | 14 ++++++++++---- profile/database.go | 5 +++++ profile/profile.go | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/profile/config-update.go b/profile/config-update.go index b4c3f5e4..6a515753 100644 --- a/profile/config-update.go +++ b/profile/config-update.go @@ -5,6 +5,8 @@ import ( "fmt" "sync" + "github.com/safing/portbase/config" + "github.com/safing/portmaster/intel/filterlists" "github.com/safing/portmaster/profile/endpoints" ) @@ -77,20 +79,24 @@ func updateGlobalConfigProfile(ctx context.Context, data interface{}) error { internalSave: true, } + newConfig := make(map[string]interface{}) // fill profile config options for key, value := range cfgStringOptions { - profile.Config[key] = value() + newConfig[key] = value() } for key, value := range cfgStringArrayOptions { - profile.Config[key] = value() + newConfig[key] = value() } for key, value := range cfgIntOptions { - profile.Config[key] = value() + newConfig[key] = value() } for key, value := range cfgBoolOptions { - profile.Config[key] = value() + newConfig[key] = value() } + // expand and assign + profile.Config = config.Expand(newConfig) + // save profile err = profile.Save() if err != nil && lastErr == nil { diff --git a/profile/database.go b/profile/database.go index 1d6e0a09..75414f1f 100644 --- a/profile/database.go +++ b/profile/database.go @@ -5,6 +5,8 @@ import ( "errors" "strings" + "github.com/safing/portbase/config" + "github.com/safing/portbase/database" "github.com/safing/portbase/database/query" "github.com/safing/portbase/database/record" @@ -87,6 +89,9 @@ func (h *databaseHook) PrePut(r record.Record) (record.Record, error) { return nil, err } + // clean config + config.CleanHierarchicalConfig(profile.Config) + // prepare config err = profile.prepConfig() if err != nil { diff --git a/profile/profile.go b/profile/profile.go index bf228fdb..0a66e8f1 100644 --- a/profile/profile.go +++ b/profile/profile.go @@ -237,7 +237,7 @@ func (profile *Profile) addEndpointyEntry(cfgKey, newEntry string) { endpointList = make([]string, 0, 1) } endpointList = append(endpointList, newEntry) - profile.Config[cfgKey] = endpointList + config.PutValueIntoHierarchicalConfig(profile.Config, cfgKey, endpointList) profile.Unlock() err := profile.Save()