diff options
author | Joe <rbo@gmx.us> | 2024-01-31 20:20:20 +0100 |
---|---|---|
committer | Joe <rbo@gmx.us> | 2024-01-31 20:20:20 +0100 |
commit | 8058a551ee80f0cb519012b900cac2dba669df34 (patch) | |
tree | a916fca198401c4baa3595fe661797078322d98e /src/c_utils.go | |
parent | fuck ye gpg done (diff) | |
download | hardflip-8058a551ee80f0cb519012b900cac2dba669df34.tar.gz hardflip-8058a551ee80f0cb519012b900cac2dba669df34.tar.bz2 hardflip-8058a551ee80f0cb519012b900cac2dba669df34.tar.xz hardflip-8058a551ee80f0cb519012b900cac2dba669df34.tar.zst hardflip-8058a551ee80f0cb519012b900cac2dba669df34.zip |
useless changes
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) |