fix(linux): automatically migrate config directory (#2240)
This commit is contained in:
@@ -11,6 +11,7 @@ separate-locales: false
|
|||||||
finish-args:
|
finish-args:
|
||||||
- --device=all # access all devices
|
- --device=all # access all devices
|
||||||
- --env=PULSE_PROP_media.category=Manager # allow sunshine to manage audio sinks
|
- --env=PULSE_PROP_media.category=Manager # allow sunshine to manage audio sinks
|
||||||
|
- --env=SUNSHINE_MIGRATE_CONFIG=1 # migrate config files to the new location
|
||||||
- --filesystem=home # need to save files in user's home directory
|
- --filesystem=home # need to save files in user's home directory
|
||||||
- --share=ipc # required for X11 shared memory extension
|
- --share=ipc # required for X11 shared memory extension
|
||||||
- --share=network # access network
|
- --share=network # access network
|
||||||
|
|||||||
@@ -100,22 +100,54 @@ namespace platf {
|
|||||||
|
|
||||||
fs::path
|
fs::path
|
||||||
appdata() {
|
appdata() {
|
||||||
|
bool found = false;
|
||||||
|
bool migrate_config = true;
|
||||||
const char *dir;
|
const char *dir;
|
||||||
|
const char *homedir;
|
||||||
|
fs::path config_path;
|
||||||
|
|
||||||
|
// Get the home directory
|
||||||
|
if ((homedir = getenv("HOME")) == nullptr || strlen(homedir) == 0) {
|
||||||
|
// If HOME is empty or not set, use the current user's home directory
|
||||||
|
homedir = getpwuid(geteuid())->pw_dir;
|
||||||
|
}
|
||||||
|
|
||||||
// May be set if running under a systemd service with the ConfigurationDirectory= option set.
|
// May be set if running under a systemd service with the ConfigurationDirectory= option set.
|
||||||
if ((dir = getenv("CONFIGURATION_DIRECTORY")) != nullptr) {
|
if ((dir = getenv("CONFIGURATION_DIRECTORY")) != nullptr && strlen(dir) > 0) {
|
||||||
return fs::path { dir } / "sunshine"sv;
|
found = true;
|
||||||
|
config_path = fs::path(dir) / "sunshine"sv;
|
||||||
}
|
}
|
||||||
// Otherwise, follow the XDG base directory specification:
|
// Otherwise, follow the XDG base directory specification:
|
||||||
// https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
// https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
||||||
if ((dir = getenv("XDG_CONFIG_HOME")) != nullptr) {
|
if (!found && (dir = getenv("XDG_CONFIG_HOME")) != nullptr && strlen(dir) > 0) {
|
||||||
return fs::path { dir } / "sunshine"sv;
|
found = true;
|
||||||
|
config_path = fs::path(dir) / "sunshine"sv;
|
||||||
}
|
}
|
||||||
if ((dir = getenv("HOME")) == nullptr) {
|
// As a last resort, use the home directory
|
||||||
dir = getpwuid(geteuid())->pw_dir;
|
if (!found) {
|
||||||
|
migrate_config = false;
|
||||||
|
config_path = fs::path(homedir) / ".config/sunshine"sv;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fs::path { dir } / ".config/sunshine"sv;
|
// migrate from the old config location if necessary
|
||||||
|
if (migrate_config && found && getenv("SUNSHINE_MIGRATE_CONFIG") == "1"sv) {
|
||||||
|
fs::path old_config_path = fs::path(homedir) / ".config/sunshine"sv;
|
||||||
|
if (old_config_path != config_path && fs::exists(old_config_path)) {
|
||||||
|
if (!fs::exists(config_path)) {
|
||||||
|
BOOST_LOG(info) << "Migrating config from "sv << old_config_path << " to "sv << config_path;
|
||||||
|
std::error_code ec;
|
||||||
|
fs::rename(old_config_path, config_path, ec);
|
||||||
|
if (ec) {
|
||||||
|
return old_config_path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
BOOST_LOG(warning) << "Config exists in both "sv << old_config_path << " and "sv << config_path << ", using "sv << config_path << "... it is recommended to remove "sv << old_config_path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return config_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
|
|||||||
Reference in New Issue
Block a user