ensure existing config file is removed prior to writing

This commit is contained in:
Bradley Cicenas 2020-10-26 13:04:00 +00:00
parent c0703db094
commit 2fdbb91f87
No known key found for this signature in database
GPG Key ID: AF579ED4B93CBB5C
2 changed files with 10 additions and 1 deletions

View File

@ -90,6 +90,13 @@ func Write() (path string, err error) {
}
}
// remove prior to writing new file
if err := os.Remove(path); err != nil {
if !os.IsNotExist(err) {
return path, err
}
}
file, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0644)
if err != nil {
return path, fmt.Errorf("failed to open config for writing: %s", err)

View File

@ -65,7 +65,9 @@ func main() {
// init global config and read config file if exists
config.Init()
config.Read()
if err := config.Read(); err != nil {
log.Warningf("reading config: %s", err)
}
// override default config values with command line flags
if *filterFlag != "" {