From b9f71276912d0324e0a77a6c0a8f049265524bef Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Oct 2021 09:15:25 +0200 Subject: [PATCH] fs/StandardDirectory: add GetAppRuntimeDir() --- src/Listen.cxx | 7 ++----- src/fs/StandardDirectory.cxx | 14 ++++++++++++++ src/fs/StandardDirectory.hxx | 7 +++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/Listen.cxx b/src/Listen.cxx index 6ce7db6dc..a1a6d4c0f 100644 --- a/src/Listen.cxx +++ b/src/Listen.cxx @@ -86,13 +86,10 @@ ListenXdgRuntimeDir(ClientListener &listener) noexcept use $XDG_RUNTIME_DIR */ return false; - const auto xdg_runtime_dir = GetUserRuntimeDir(); - if (xdg_runtime_dir.IsNull()) + const auto mpd_runtime_dir = GetAppRuntimeDir(); + if (mpd_runtime_dir.IsNull()) return false; - const auto mpd_runtime_dir = xdg_runtime_dir / Path::FromFS("mpd"); - mkdir(mpd_runtime_dir.c_str(), 0700); - const auto socket_path = mpd_runtime_dir / Path::FromFS("socket"); unlink(socket_path.c_str()); diff --git a/src/fs/StandardDirectory.cxx b/src/fs/StandardDirectory.cxx index 36fc914d4..174f89612 100644 --- a/src/fs/StandardDirectory.cxx +++ b/src/fs/StandardDirectory.cxx @@ -292,6 +292,20 @@ GetUserRuntimeDir() noexcept #endif } +AllocatedPath +GetAppRuntimeDir() noexcept +{ +#ifdef USE_XDG + if (const auto user_dir = GetUserRuntimeDir(); !user_dir.IsNull()) { + auto dir = user_dir / Path::FromFS("mpd"); + mkdir(dir.c_str(), 0700); + return dir; + } +#endif + + return nullptr; +} + #ifdef _WIN32 AllocatedPath diff --git a/src/fs/StandardDirectory.hxx b/src/fs/StandardDirectory.hxx index 82b926073..99cf0dc70 100644 --- a/src/fs/StandardDirectory.hxx +++ b/src/fs/StandardDirectory.hxx @@ -50,6 +50,13 @@ GetUserCacheDir() noexcept; AllocatedPath GetUserRuntimeDir() noexcept; +/** + * Obtains the runtime directory for this application. + */ +[[gnu::const]] +AllocatedPath +GetAppRuntimeDir() noexcept; + #ifdef _WIN32 /**