diff options
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/util.cc | 12 | ||||
-rw-r--r-- | src/libutil/util.hh | 3 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 88a2f752c023..026e493514ea 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -441,6 +441,18 @@ Path getConfigDir() } +Path getDataDir() +{ + Path dataDir = getEnv("XDG_DATA_HOME"); + if (dataDir.empty()) { + Path homeDir = getEnv("HOME"); + if (homeDir.empty()) throw Error("$XDG_DATA_HOME and $HOME are not set"); + dataDir = homeDir + "/.local/share"; + } + return dataDir; +} + + Paths createDirs(const Path & path) { Paths created; diff --git a/src/libutil/util.hh b/src/libutil/util.hh index ae40dcd4cd2d..a9950f830c50 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -116,6 +116,9 @@ Path getCacheDir(); /* Return $XDG_CONFIG_HOME or $HOME/.config. */ Path getConfigDir(); +/* Return $XDG_DATA_HOME or $HOME/.local/share. */ +Path getDataDir(); + /* Create a directory and all its parents, if necessary. Returns the list of created directories, in order of creation. */ Paths createDirs(const Path & path); |