diff options
Diffstat (limited to 'src/c_utils.go')
-rw-r--r-- | src/c_utils.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/c_utils.go b/src/c_utils.go index 01c8665..7ec70c0 100644 --- a/src/c_utils.go +++ b/src/c_utils.go @@ -60,11 +60,52 @@ import ( // this function will go get the data folder and try to create it if it does // not exist +// the first path being checked is $XDG_CONFIG_HOME then $HOME/.config +// it returns the full data directory path +func c_get_conf_dir(ui *HardUI) string { + var ptr string + var home string + + if home = os.Getenv("HOME"); len(home) == 0 { + if ui == nil { + c_die("env variable HOME not defined", nil) + } + c_error_mode("env variable HOME not defined", nil, ui) + return "" + } + xdg_home := os.Getenv("XDG_CONFIG_HOME") + + if len(xdg_home) > 0 { + ptr = xdg_home + } else { + ptr = home + "/.config" + } + ptr += "/" + CONF_DIR_NAME + if _, err := os.Stat(ptr); os.IsNotExist(err) { + if err := os.MkdirAll(ptr, os.ModePerm); err != nil { + if ui == nil { + c_die("could not create path " + ptr, err) + } + c_error_mode("could not create path" + ptr, err, ui) + } + } else if err != nil { + if ui == nil { + c_die("could read path " + ptr, err) + } + c_error_mode("could read path" + ptr, err, ui) + return "" + } + return ptr +} + +// this function will go get the data folder and try to create it if it does +// not exist // the first path being checked is $XDG_DATA_HOME then $HOME/.local/share // it returns the full data directory path func c_get_data_dir(ui *HardUI) string { var ptr string var home string + if home = os.Getenv("HOME"); len(home) == 0 { if ui == nil { c_die("env variable HOME not defined", nil) |