Config file fixes

This commit is contained in:
Sasha Koshka 2022-11-26 22:36:16 -05:00
parent 46b2ca3d43
commit 639e43cfa7
1 changed files with 10 additions and 7 deletions

View File

@ -118,7 +118,7 @@ type Config struct {
// <home>/.config/<name>/<name>.conf, unless the corresponding XDG environment
// variables are set - then it uses those.
func (config *Config) Load (name string) (err error) {
if !nameIsLegal(name) {
if nameIsIllegal(name) {
err = ErrorIllegalName
return
}
@ -126,6 +126,7 @@ func (config *Config) Load (name string) (err error) {
var configHome string
configHome, err = getConfigHome()
if err != nil { return }
println(configHome)
configDirsString := os.Getenv("XDG_CONFIG_DIRS")
if configDirsString == "" {
@ -240,7 +241,7 @@ func (config *Config) LoadFrom (reader io.Reader) (err error) {
// <home>/.config/<name>/<name>.conf unless $XDG_CONFIG_HOME has been set, in
// which case the value of that variable is used instead.
func (config *Config) Save (name string) (err error) {
if !nameIsLegal(name) {
if nameIsIllegal(name) {
err = ErrorIllegalName
return
}
@ -280,13 +281,15 @@ func (config *Config) SaveTo (writer io.Writer) (err error) {
fmt.Fprintf(writer,"%s: #%x\n", key, colorInt)
case int:
fmt.Fprintf(writer,"%s: %i\n", key, value.(int))
fmt.Fprintf(writer,"%s: %d\n", key, value.(int))
case float64:
fmt.Fprintf(writer,"%s: %f\n", key, value.(float64))
case bool:
fmt.Fprintf(writer,"%s: %t\n", key, value.(bool))
default:
fmt.Fprintf(writer,"# %s: unknown type\n", key)
}
}
@ -326,15 +329,15 @@ func getConfigHome () (home string, err error) {
homeDirectory, err = os.UserHomeDir()
if err != nil { return }
configHome := os.Getenv("XDG_CONFIG_HOME")
if configHome == "" {
configHome = filepath.Join(homeDirectory, "/.config/")
home = os.Getenv("XDG_CONFIG_HOME")
if home == "" {
home = filepath.Join(homeDirectory, "/.config/")
}
return
}
func nameIsLegal (name string) (legal bool) {
func nameIsIllegal (name string) (legal bool) {
legal = strings.ContainsAny(name, "/\\|:.%")
return
}