aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-03-01 22:50:11 +0100
committerMax Kellermann <max@duempel.org>2014-03-01 22:51:51 +0100
commit36ca57a54ebcbdfb2fa4374378280867a089bb91 (patch)
tree02eca17f29c90d367d9c964f921961fa16f061c1 /src
parentefa6678bcc0cbd6679061809c464c91f06b552ec (diff)
downloadmpd-36ca57a54ebcbdfb2fa4374378280867a089bb91.tar.gz
mpd-36ca57a54ebcbdfb2fa4374378280867a089bb91.tar.xz
mpd-36ca57a54ebcbdfb2fa4374378280867a089bb91.zip
fs/StandardDirectory: add GetUserCacheDir()
Move code from CreateConfiguredDatabase() and add XDG support. This implements an automatic Linux fallback for the setting "db_file" if none was specified.
Diffstat (limited to 'src')
-rw-r--r--src/db/Configured.cxx19
-rw-r--r--src/fs/StandardDirectory.cxx14
-rw-r--r--src/fs/StandardDirectory.hxx7
3 files changed, 25 insertions, 15 deletions
diff --git a/src/db/Configured.cxx b/src/db/Configured.cxx
index 78be3e999..625300d75 100644
--- a/src/db/Configured.cxx
+++ b/src/db/Configured.cxx
@@ -23,16 +23,11 @@
#include "config/ConfigGlobal.hxx"
#include "config/ConfigData.hxx"
#include "config/ConfigError.hxx"
+#include "fs/AllocatedPath.hxx"
+#include "fs/StandardDirectory.hxx"
#include "util/Error.hxx"
#include "Log.hxx"
-#ifdef ANDROID
-#include "Main.hxx"
-#include "android/Context.hxx"
-#include "fs/AllocatedPath.hxx"
-#include "plugins/simple/SimpleDatabasePlugin.hxx"
-#endif
-
Database *
CreateConfiguredDatabase(EventLoop &loop, DatabaseListener &listener,
Error &error)
@@ -57,12 +52,9 @@ CreateConfiguredDatabase(EventLoop &loop, DatabaseListener &listener,
}
if (param == nullptr) {
-#ifdef ANDROID
- /* if there is no override, use the Android cache
- directory */
+ /* if there is no override, use the cache directory */
- const AllocatedPath cache_dir =
- context->GetCacheDir(Java::GetEnv());
+ const AllocatedPath cache_dir = GetUserCacheDir();
if (cache_dir.IsNull())
return nullptr;
@@ -71,9 +63,6 @@ CreateConfiguredDatabase(EventLoop &loop, DatabaseListener &listener,
allocated = new config_param("database");
allocated->AddBlockParam("path", db_file.c_str(), -1);
param = allocated;
-#else
- return nullptr;
-#endif
}
Database *db = DatabaseGlobalInit(loop, listener, *param,
diff --git a/src/fs/StandardDirectory.cxx b/src/fs/StandardDirectory.cxx
index 20d66bb10..6456c0254 100644
--- a/src/fs/StandardDirectory.cxx
+++ b/src/fs/StandardDirectory.cxx
@@ -50,6 +50,8 @@
#ifdef ANDROID
#include "java/Global.hxx"
#include "android/Environment.hxx"
+#include "android/Context.hxx"
+#include "Main.hxx"
#endif
#ifndef WIN32
@@ -252,6 +254,18 @@ AllocatedPath GetUserMusicDir()
#endif
}
+AllocatedPath
+GetUserCacheDir()
+{
+#ifdef USE_XDG
+ return GetUserDir("XDG_CACHE_DIR");
+#elif defined(ANDROID)
+ return context->GetCacheDir(Java::GetEnv());
+#else
+ return AllocatedPath::Null();
+#endif
+}
+
#ifdef WIN32
AllocatedPath GetSystemConfigDir()
diff --git a/src/fs/StandardDirectory.hxx b/src/fs/StandardDirectory.hxx
index dca35b486..e3fba375a 100644
--- a/src/fs/StandardDirectory.hxx
+++ b/src/fs/StandardDirectory.hxx
@@ -33,6 +33,13 @@ AllocatedPath GetUserConfigDir();
*/
AllocatedPath GetUserMusicDir();
+/**
+ * Obtains cache directory for the current user.
+ */
+gcc_pure
+AllocatedPath
+GetUserCacheDir();
+
#ifdef WIN32
/**