Skip to content

Commit

Permalink
Fix default search paths for config file
Browse files Browse the repository at this point in the history
  • Loading branch information
ioppermann committed Sep 7, 2023
1 parent f6d5064 commit 0f4c88b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions config/store/location.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (

// Location returns the path to the config file. If no path is provided,
// different standard location will be probed:
// - os.UserConfigDir() + /datarhei-core/config.js
// - os.UserHomeDir() + /.config/datarhei-core/config.js
// - ./config/config.js
// - os.UserConfigDir() + /datarhei-core/config.json
// - os.UserHomeDir() + /.config/datarhei-core/config.json
// - ./config/config.json
// If the config doesn't exist in none of these locations, it will be assumed
// at ./config/config.js
// at ./config/config.json
func Location(filepath string) string {
configfile := filepath
if len(configfile) != 0 {
Expand All @@ -22,13 +22,16 @@ func Location(filepath string) string {

if dir, err := os.UserConfigDir(); err == nil {
locations = append(locations, dir+"/datarhei-core/config.js")
locations = append(locations, dir+"/datarhei-core/config.json")
}

if dir, err := os.UserHomeDir(); err == nil {
locations = append(locations, dir+"/.config/datarhei-core/config.js")
locations = append(locations, dir+"/.config/datarhei-core/config.json")
}

locations = append(locations, "./config/config.js")
locations = append(locations, "./config/config.json")

for _, path := range locations {
info, err := os.Stat(path)
Expand All @@ -44,7 +47,7 @@ func Location(filepath string) string {
}

if len(configfile) == 0 {
configfile = "./config/config.js"
configfile = "./config/config.json"
}

os.MkdirAll(path.Dir(configfile), 0740)
Expand Down

0 comments on commit 0f4c88b

Please sign in to comment.