mirror of
https://github.com/safing/portmaster
synced 2025-09-02 18:49:14 +00:00
Fix profile config parsing
This commit is contained in:
parent
888b33918a
commit
3be1c78e16
3 changed files with 14 additions and 24 deletions
|
@ -131,12 +131,8 @@ func (h *databaseHook) PrePut(r record.Record) (record.Record, error) {
|
||||||
// clean config
|
// clean config
|
||||||
config.CleanHierarchicalConfig(profile.Config)
|
config.CleanHierarchicalConfig(profile.Config)
|
||||||
|
|
||||||
// prepare config
|
// prepare profile
|
||||||
err = profile.prepConfig()
|
profile.prepProfile()
|
||||||
if err != nil {
|
|
||||||
// error here, warning when loading
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse config
|
// parse config
|
||||||
err = profile.parseConfig()
|
err = profile.parseConfig()
|
||||||
|
|
|
@ -178,11 +178,8 @@ func prepProfile(r record.Record) (*Profile, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepare config
|
// prepare profile
|
||||||
err = profile.prepConfig()
|
profile.prepProfile()
|
||||||
if err != nil {
|
|
||||||
log.Errorf("profiles: profile %s has (partly) invalid configuration: %s", profile.ID, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse config
|
// parse config
|
||||||
err = profile.parseConfig()
|
err = profile.parseConfig()
|
||||||
|
|
|
@ -137,28 +137,27 @@ type Profile struct { //nolint:maligned // not worth the effort
|
||||||
savedInternally bool
|
savedInternally bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (profile *Profile) prepConfig() (err error) {
|
func (profile *Profile) prepProfile() {
|
||||||
// prepare configuration
|
// prepare configuration
|
||||||
profile.configPerspective, err = config.NewPerspective(profile.Config)
|
|
||||||
profile.outdated = abool.New()
|
profile.outdated = abool.New()
|
||||||
profile.lastActive = new(int64)
|
profile.lastActive = new(int64)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (profile *Profile) parseConfig() error {
|
func (profile *Profile) parseConfig() error {
|
||||||
if profile.configPerspective == nil {
|
// Check if already parsed.
|
||||||
return errors.New("config not prepared")
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if already parsed
|
|
||||||
if profile.dataParsed {
|
if profile.dataParsed {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create new perspective and marked as parsed.
|
||||||
|
var err error
|
||||||
|
profile.configPerspective, err = config.NewPerspective(profile.Config)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create config perspective: %w", err)
|
||||||
|
}
|
||||||
profile.dataParsed = true
|
profile.dataParsed = true
|
||||||
|
|
||||||
var err error
|
|
||||||
var lastErr error
|
var lastErr error
|
||||||
|
|
||||||
action, ok := profile.configPerspective.GetAsString(CfgOptionDefaultActionKey)
|
action, ok := profile.configPerspective.GetAsString(CfgOptionDefaultActionKey)
|
||||||
profile.defaultAction = DefaultActionNotSet
|
profile.defaultAction = DefaultActionNotSet
|
||||||
if ok {
|
if ok {
|
||||||
|
@ -238,9 +237,7 @@ func New(
|
||||||
profile.makeKey()
|
profile.makeKey()
|
||||||
|
|
||||||
// Prepare and parse initial profile config.
|
// Prepare and parse initial profile config.
|
||||||
if err := profile.prepConfig(); err != nil {
|
profile.prepProfile()
|
||||||
log.Errorf("profile: failed to prep new profile: %s", err)
|
|
||||||
}
|
|
||||||
if err := profile.parseConfig(); err != nil {
|
if err := profile.parseConfig(); err != nil {
|
||||||
log.Errorf("profile: failed to parse new profile: %s", err)
|
log.Errorf("profile: failed to parse new profile: %s", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue