Skip to content

Commit

Permalink
fs: make sure config is persisted to the config file when using confi…
Browse files Browse the repository at this point in the history
…g.Mapper
  • Loading branch information
ncw committed Aug 14, 2019
1 parent fa539b9 commit 24161d1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
8 changes: 5 additions & 3 deletions fs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"net"
"strings"
"time"

"github.com/pkg/errors"
)

// Global
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion fs/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 24161d1

Please sign in to comment.