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.
This commit is contained in:
Reto Brunner 2021-04-17 18:50:35 +02:00
parent 98d778eeae
commit 60c5a82a76

View file

@ -462,19 +462,20 @@ func LoadConfigFromFile(root *string, sharedir string) (*AercConfig, error) {
return nil, err return nil, err
} }
filename = path.Join(*root, "aerc.conf") 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{ file, err := ini.LoadSources(ini.LoadOptions{
KeyValueDelimiters: "=", KeyValueDelimiters: "=",
}, filename) }, filename)
if err != nil { if err != nil {
if err := installTemplate(*root, sharedir, "aerc.conf"); err != nil {
return nil, err return nil, err
} }
if file, err = ini.LoadSources(ini.LoadOptions{
KeyValueDelimiters: "=",
}, filename); err != nil {
return nil, err
}
}
file.NameMapper = mapName file.NameMapper = mapName
config := &AercConfig{ config := &AercConfig{
Bindings: BindingConfig{ Bindings: BindingConfig{