Commit 36ca57a5 authored by Max Kellermann's avatar Max Kellermann

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.
parent efa6678b
...@@ -34,6 +34,7 @@ ver 0.19 (not yet released) ...@@ -34,6 +34,7 @@ ver 0.19 (not yet released)
- name each thread (for debugging) - name each thread (for debugging)
* configuration * configuration
- allow playlist directory without music directory - allow playlist directory without music directory
- use XDG to auto-detect "music_directory" and "db_file"
* new resampler option using libsoxr * new resampler option using libsoxr
* install systemd unit for socket activation * install systemd unit for socket activation
* Android port * Android port
......
...@@ -23,16 +23,11 @@ ...@@ -23,16 +23,11 @@
#include "config/ConfigGlobal.hxx" #include "config/ConfigGlobal.hxx"
#include "config/ConfigData.hxx" #include "config/ConfigData.hxx"
#include "config/ConfigError.hxx" #include "config/ConfigError.hxx"
#include "fs/AllocatedPath.hxx"
#include "fs/StandardDirectory.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx" #include "Log.hxx"
#ifdef ANDROID
#include "Main.hxx"
#include "android/Context.hxx"
#include "fs/AllocatedPath.hxx"
#include "plugins/simple/SimpleDatabasePlugin.hxx"
#endif
Database * Database *
CreateConfiguredDatabase(EventLoop &loop, DatabaseListener &listener, CreateConfiguredDatabase(EventLoop &loop, DatabaseListener &listener,
Error &error) Error &error)
...@@ -57,12 +52,9 @@ CreateConfiguredDatabase(EventLoop &loop, DatabaseListener &listener, ...@@ -57,12 +52,9 @@ CreateConfiguredDatabase(EventLoop &loop, DatabaseListener &listener,
} }
if (param == nullptr) { if (param == nullptr) {
#ifdef ANDROID /* if there is no override, use the cache directory */
/* if there is no override, use the Android cache
directory */
const AllocatedPath cache_dir = const AllocatedPath cache_dir = GetUserCacheDir();
context->GetCacheDir(Java::GetEnv());
if (cache_dir.IsNull()) if (cache_dir.IsNull())
return nullptr; return nullptr;
...@@ -71,9 +63,6 @@ CreateConfiguredDatabase(EventLoop &loop, DatabaseListener &listener, ...@@ -71,9 +63,6 @@ CreateConfiguredDatabase(EventLoop &loop, DatabaseListener &listener,
allocated = new config_param("database"); allocated = new config_param("database");
allocated->AddBlockParam("path", db_file.c_str(), -1); allocated->AddBlockParam("path", db_file.c_str(), -1);
param = allocated; param = allocated;
#else
return nullptr;
#endif
} }
Database *db = DatabaseGlobalInit(loop, listener, *param, Database *db = DatabaseGlobalInit(loop, listener, *param,
......
...@@ -50,6 +50,8 @@ ...@@ -50,6 +50,8 @@
#ifdef ANDROID #ifdef ANDROID
#include "java/Global.hxx" #include "java/Global.hxx"
#include "android/Environment.hxx" #include "android/Environment.hxx"
#include "android/Context.hxx"
#include "Main.hxx"
#endif #endif
#ifndef WIN32 #ifndef WIN32
...@@ -252,6 +254,18 @@ AllocatedPath GetUserMusicDir() ...@@ -252,6 +254,18 @@ AllocatedPath GetUserMusicDir()
#endif #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 #ifdef WIN32
AllocatedPath GetSystemConfigDir() AllocatedPath GetSystemConfigDir()
......
...@@ -33,6 +33,13 @@ AllocatedPath GetUserConfigDir(); ...@@ -33,6 +33,13 @@ AllocatedPath GetUserConfigDir();
*/ */
AllocatedPath GetUserMusicDir(); AllocatedPath GetUserMusicDir();
/**
* Obtains cache directory for the current user.
*/
gcc_pure
AllocatedPath
GetUserCacheDir();
#ifdef WIN32 #ifdef WIN32
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment