summary refs log tree commit diff stats
path: root/cache/getdir_unix.go
diff options
context:
space:
mode:
Diffstat (limited to 'cache/getdir_unix.go')
-rw-r--r--cache/getdir_unix.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/cache/getdir_unix.go b/cache/getdir_unix.go
new file mode 100644
index 0000000..b1358d7
--- /dev/null
+++ b/cache/getdir_unix.go
@@ -0,0 +1,29 @@
+// +build linux netbsd openbsd freebsd dragonfly
+
+package cache
+
+import (
+	"fmt"
+	"os"
+)
+
+// GetDir returns cetus cache directory. Check if the user has set
+// CETUS_CACHE_DIR, if not then check if XDG_CACHE_HOME is set & if
+// that is not set then assume it to be the default value which is
+// $HOME/.cache according to XDG Base Directory Specification.
+func GetDir() string {
+	cacheDir := os.Getenv("CETUS_CACHE_DIR")
+	if len(cacheDir) == 0 {
+		cacheDir = os.Getenv("XDG_CACHE_HOME")
+	}
+	if len(cacheDir) == 0 {
+		cacheDir = fmt.Sprintf("%s/%s", os.Getenv("HOME"),
+			".cache")
+	}
+
+	// Cetus cache directory is cacheDir/cetus.
+	cetusCacheDir = fmt.Sprintf("%s/%s", cacheDir,
+		"cetus")
+
+	return cetusCacheDir
+}