diff options
author | Mantas Mikulėnas <grawity@gmail.com> | 2014-07-10 22:56:53 +0300 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-07-11 08:09:19 +0200 |
commit | cd289843f70e57ab12deb63bfe603b7a81890021 (patch) | |
tree | a34f6b4e45e4ff8380e4fc22a087fe25fbdcfa68 /src/fs/StandardDirectory.cxx | |
parent | b1233925928b86a4ff1acb0028f3c8d3b1b2e5e1 (diff) | |
download | mpd-cd289843f70e57ab12deb63bfe603b7a81890021.tar.gz mpd-cd289843f70e57ab12deb63bfe603b7a81890021.tar.xz mpd-cd289843f70e57ab12deb63bfe603b7a81890021.zip |
fs/StandardDirectory: look for cache dir in environment, not user-dirs
The XDG cache directory is part of the "base directories" spec like
$XDG_CONFIG_HOME, not "user directories".
Diffstat (limited to '')
-rw-r--r-- | src/fs/StandardDirectory.cxx | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/fs/StandardDirectory.cxx b/src/fs/StandardDirectory.cxx index 6456c0254..c8cc7263e 100644 --- a/src/fs/StandardDirectory.cxx +++ b/src/fs/StandardDirectory.cxx @@ -254,11 +254,23 @@ AllocatedPath GetUserMusicDir() #endif } -AllocatedPath -GetUserCacheDir() +AllocatedPath GetUserCacheDir() { #ifdef USE_XDG - return GetUserDir("XDG_CACHE_DIR"); + // Check for $XDG_CACHE_HOME + auto cache_home = getenv("XDG_CACHE_HOME"); + if (IsValidPathString(cache_home) && IsValidDir(cache_home)) + return AllocatedPath::FromFS(cache_home); + + // Check for $HOME/.cache + auto home = GetHomeDir(); + if (!home.IsNull()) { + AllocatedPath fallback = AllocatedPath::Build(home, ".cache"); + if (IsValidDir(fallback.c_str())) + return fallback; + } + + return AllocatedPath::Null(); #elif defined(ANDROID) return context->GetCacheDir(Java::GetEnv()); #else |