Report bad entries in storage.conf to the user

Currently if a user puts a typo into a storage.conf
or puts the keys in the wrong section, then tools using
container/storage ignore them. This patch will print them
as warnings, so that the user has some idea what is going on.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
Daniel J Walsh 2021-06-30 10:23:21 -04:00
parent e159777f1e
commit d65940d8a0
1 changed files with 9 additions and 10 deletions

View File

@ -2,7 +2,6 @@ package types
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@ -272,21 +271,21 @@ func ReloadConfigurationFileIfNeeded(configFile string, storeOptions *StoreOptio
// ReloadConfigurationFile parses the specified configuration file and overrides
// the configuration in storeOptions.
func ReloadConfigurationFile(configFile string, storeOptions *StoreOptions) {
data, err := ioutil.ReadFile(configFile)
if err != nil {
config := new(tomlConfig)
meta, err := toml.DecodeFile(configFile, &config)
if err == nil {
keys := meta.Undecoded()
if len(keys) > 0 {
logrus.Warningf("Failed to decode the keys %q from %q.", keys, configFile)
}
} else {
if !os.IsNotExist(err) {
fmt.Printf("Failed to read %s %v\n", configFile, err.Error())
return
}
}
config := new(tomlConfig)
if _, err := toml.Decode(string(data), config); err != nil {
fmt.Printf("Failed to parse %s %v\n", configFile, err.Error())
return
}
// Clear storeOptions of previos settings
*storeOptions = StoreOptions{}
if config.Storage.Driver != "" {