diff options
author | Andinus <andinus@nand.sh> | 2020-04-06 22:11:15 +0530 |
---|---|---|
committer | Andinus <andinus@nand.sh> | 2020-04-06 22:11:15 +0530 |
commit | da2255557fa395eeabeff9a4f2949582f8811980 (patch) | |
tree | c48de12ff76b54f67303585190773e6551609f1d /storage/getdir_unix.go | |
parent | 69e919cd4e887a606dc1c007c2ce1f36b35477d1 (diff) | |
download | grus-da2255557fa395eeabeff9a4f2949582f8811980.tar.gz |
Initial grus version
Diffstat (limited to 'storage/getdir_unix.go')
-rw-r--r-- | storage/getdir_unix.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/storage/getdir_unix.go b/storage/getdir_unix.go new file mode 100644 index 0000000..29bedbe --- /dev/null +++ b/storage/getdir_unix.go @@ -0,0 +1,37 @@ +// +build linux netbsd openbsd freebsd dragonfly + +package storage + +import ( + "fmt" + "os" +) + +// GetDir returns grus data directory. Check if the user has set +// GRUS_DIR, if not then check if XDG_DATA_HOME is set & if that is +// not set then assume it to be the default value which is +// $HOME/.local/share according to XDG Base Directory Specification. +func GetDir() string { + cacheDir := SysDir() + + // Grus cache directory is cacheDir/grus. + grusCacheDir := fmt.Sprintf("%s/%s", cacheDir, + "grus") + + return grusCacheDir +} + +// SysDir returns the system data directory, this is useful for unveil in +// OpenBSD. +func SysDir() string { + cacheDir := os.Getenv("GRUS_DIR") + if len(cacheDir) == 0 { + cacheDir = os.Getenv("XDG_DATA_HOME") + } + if len(cacheDir) == 0 { + cacheDir = fmt.Sprintf("%s/%s/%s", os.Getenv("HOME"), + ".local", "share") + } + + return cacheDir +} |