diff options
author | Reto Brunner <reto@labrat.space> | 2021-04-17 18:50:35 +0200 |
---|---|---|
committer | Reto Brunner <reto@labrat.space> | 2021-04-17 18:57:19 +0200 |
commit | 60c5a82a76a639137a15a1446bc71434e432d8cd (patch) | |
tree | 8ffc53b973333eae01d5a97a399ddda4ba909698 /config | |
parent | 98d778eeae63428721b900ca1b8c4972966d8395 (diff) | |
download | aerc-60c5a82a76a639137a15a1446bc71434e432d8cd.tar.gz |
load config: do not overwrite the config upon error
It makes absolutely no sense to copy over the default template from aerc.conf when the syntax is invalid and our ini parser fails. The only valid case to do that is if the file is actually missing.
Diffstat (limited to 'config')
-rw-r--r-- | config/config.go | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/config/config.go b/config/config.go index 8032201..af9c63b 100644 --- a/config/config.go +++ b/config/config.go @@ -462,18 +462,19 @@ func LoadConfigFromFile(root *string, sharedir string) (*AercConfig, error) { return nil, err } filename = path.Join(*root, "aerc.conf") + + // if it doesn't exist copy over the template, then load + if _, err := os.Stat(filename); errors.Is(err, os.ErrNotExist) { + if err := installTemplate(*root, sharedir, "aerc.conf"); err != nil { + return nil, err + } + } + file, err := ini.LoadSources(ini.LoadOptions{ KeyValueDelimiters: "=", }, filename) if err != nil { - if err := installTemplate(*root, sharedir, "aerc.conf"); err != nil { - return nil, err - } - if file, err = ini.LoadSources(ini.LoadOptions{ - KeyValueDelimiters: "=", - }, filename); err != nil { - return nil, err - } + return nil, err } file.NameMapper = mapName config := &AercConfig{ |