From 24161d12abebef2fb7235668f1912bd2c7752608 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Wed, 14 Aug 2019 17:06:13 +0100 Subject: [PATCH] fs: make sure config is persisted to the config file when using config.Mapper --- fs/config.go | 8 +++++--- fs/config/config.go | 2 +- fs/fs.go | 5 ++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/fs/config.go b/fs/config.go index fdd9b7e45..42adf1c77 100644 --- a/fs/config.go +++ b/fs/config.go @@ -4,6 +4,8 @@ import ( "net" "strings" "time" + + "github.com/pkg/errors" ) // Global @@ -17,12 +19,12 @@ var ( // implementation from the fs 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 // implementation from the fs - ConfigFileSet = func(section, key, value string) { - Errorf(nil, "No config handler to set %q = %q in section %q of the config file", key, value, section) + ConfigFileSet = func(section, key, value string) (err error) { + return errors.New("no config file set handler") } // CountError counts an error. If any errors have been diff --git a/fs/config/config.go b/fs/config/config.go index 913138217..4ec86e84c 100644 --- a/fs/config/config.go +++ b/fs/config/config.go @@ -93,7 +93,7 @@ var ( func init() { // Set the function pointers up in fs fs.ConfigFileGet = FileGetFlag - fs.ConfigFileSet = FileSet + fs.ConfigFileSet = SetValueAndSave } func getConfigData() *goconfig.ConfigFile { diff --git a/fs/fs.go b/fs/fs.go index 9dadc8716..2dbeb1e11 100644 --- a/fs/fs.go +++ b/fs/fs.go @@ -1150,7 +1150,10 @@ type setConfigFile string // Set a config item into the config file func (section setConfigFile) Set(key, value string) { 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