fix(linux)!: use XDG spec for fetching Linux configuration directory (#2034)

This commit is contained in:
Rafael 2024-01-19 02:24:55 +00:00 committed by GitHub
parent 21e4450ee1
commit 2e995355dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -99,12 +99,22 @@ namespace platf {
fs::path
appdata() {
const char *homedir;
if ((homedir = getenv("HOME")) == nullptr) {
homedir = getpwuid(geteuid())->pw_dir;
const char *dir;
// May be set if running under a systemd service with the ConfigurationDirectory= option set.
if ((dir = getenv("CONFIGURATION_DIRECTORY")) != nullptr) {
return fs::path { dir } / "sunshine"sv;
}
// Otherwise, follow the XDG base directory specification:
// https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
if ((dir = getenv("XDG_CONFIG_HOME")) != nullptr) {
return fs::path { dir } / "sunshine"sv;
}
if ((dir = getenv("HOME")) == nullptr) {
dir = getpwuid(geteuid())->pw_dir;
}
return fs::path { homedir } / ".config/sunshine"sv;
return fs::path { dir } / ".config/sunshine"sv;
}
std::string