fs: make sure config is persisted to the config file when using config.Mapper

This commit is contained in:
Nick Craig-Wood 2019-08-14 17:06:13 +01:00
parent fa539b9d9b
commit 24161d12ab
3 changed files with 10 additions and 5 deletions

View file

@ -4,6 +4,8 @@ import (
"net" "net"
"strings" "strings"
"time" "time"
"github.com/pkg/errors"
) )
// Global // Global
@ -17,12 +19,12 @@ var (
// implementation from the fs // implementation from the fs
ConfigFileGet = func(section, key string) (string, bool) { return "", false } ConfigFileGet = func(section, key string) (string, bool) { return "", false }
// Set a value into the config file // Set a value into the config file and persist it
// //
// This is a function pointer to decouple the config // This is a function pointer to decouple the config
// implementation from the fs // implementation from the fs
ConfigFileSet = func(section, key, value string) { ConfigFileSet = func(section, key, value string) (err error) {
Errorf(nil, "No config handler to set %q = %q in section %q of the config file", key, value, section) return errors.New("no config file set handler")
} }
// CountError counts an error. If any errors have been // CountError counts an error. If any errors have been

View file

@ -93,7 +93,7 @@ var (
func init() { func init() {
// Set the function pointers up in fs // Set the function pointers up in fs
fs.ConfigFileGet = FileGetFlag fs.ConfigFileGet = FileGetFlag
fs.ConfigFileSet = FileSet fs.ConfigFileSet = SetValueAndSave
} }
func getConfigData() *goconfig.ConfigFile { func getConfigData() *goconfig.ConfigFile {

View file

@ -1150,7 +1150,10 @@ type setConfigFile string
// Set a config item into the config file // Set a config item into the config file
func (section setConfigFile) Set(key, value string) { func (section setConfigFile) Set(key, value string) {
Debugf(nil, "Saving config %q = %q in section %q of the config file", key, value, section) Debugf(nil, "Saving config %q = %q in section %q of the config file", key, value, section)
ConfigFileSet(string(section), key, value) err := ConfigFileSet(string(section), key, value)
if err != nil {
Errorf(nil, "Failed saving config %q = %q in section %q of the config file: %v", key, value, section, err)
}
} }
// A configmap.Getter to read from the config file // A configmap.Getter to read from the config file