From 8058a551ee80f0cb519012b900cac2dba669df34 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 31 Jan 2024 20:20:20 +0100 Subject: useless changes --- src/c_utils.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'src/c_utils.go') 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 @@ -58,6 +58,46 @@ import ( "strings" ) +// 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 @@ -65,6 +105,7 @@ import ( 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) -- cgit v1.2.3