Use XDG_CONFIG_HOME as default config directory instead of hardcoded when available. Fixes #50
This commit is contained in:
1 parent
131e61af5d
commit
93de8ba9b3
4 files changed
+16
-4
No files matched your search
@@ -20,3 +20,4 @@ _cgo_export.*
|
||||
*.exe
|
||||
*.test
|
||||
*.prof
|
||||
yay
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -42,10 +43,22 @@ func init() {
|
||||
defaultSettings(&config)
|
||||
|
||||
var err error
|
||||
configfile := os.Getenv("HOME") + "/.config/yay/config.json"
|
||||
if dir := os.Getenv("XDG_CONFIG_HOME"); dir != "" {
|
||||
if info, err := os.Stat(dir); err == nil && info.IsDir() == true {
|
||||
configfile = os.Getenv("XDG_CONFIG_HOME") + "/yay/config.json"
|
||||
} else {
|
||||
configfile = os.Getenv("HOME") + "/.config/yay/config.json"
|
||||
}
|
||||
} else {
|
||||
configfile = os.Getenv("HOME") + "/.config/yay/config.json"
|
||||
}
|
||||
|
||||
if _, err = os.Stat(configfile); os.IsNotExist(err) {
|
||||
_ = os.MkdirAll(os.Getenv("HOME")+"/.config/yay", 0755)
|
||||
err = os.MkdirAll(filepath.Dir(configfile), 0755)
|
||||
if err != nil {
|
||||
fmt.Println("Unable to create config directory:", filepath.Dir(configfile), err)
|
||||
os.Exit(2)
|
||||
}
|
||||
// Save the default config if nothing is found
|
||||
config.saveConfig()
|
||||
} else {
|
||||
|
||||
@@ -79,7 +79,6 @@ func readAlpmConfig(pacmanconf string) (conf alpm.PacmanConfig, err error) {
|
||||
// SaveConfig writes yay config to file.
|
||||
func (config *Configuration) saveConfig() error {
|
||||
config.NoConfirm = false
|
||||
configfile := os.Getenv("HOME") + "/.config/yay/config.json"
|
||||
marshalledinfo, _ := json.MarshalIndent(config, "", "\t")
|
||||
in, err := os.OpenFile(configfile, os.O_RDWR|os.O_CREATE, 0644)
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user