Only attempt a config migration once per launch
This commit is contained in:
@@ -106,12 +106,16 @@ namespace platf {
|
||||
*/
|
||||
fs::path
|
||||
appdata() {
|
||||
static std::once_flag migration_flag;
|
||||
static fs::path config_path;
|
||||
|
||||
// Ensure migration is only attempted once
|
||||
std::call_once(migration_flag, []() {
|
||||
bool found = false;
|
||||
bool migrate_config = true;
|
||||
const char *dir;
|
||||
const char *homedir;
|
||||
const char *migrate_envvar;
|
||||
fs::path config_path;
|
||||
|
||||
// Get the home directory
|
||||
if ((homedir = getenv("HOME")) == nullptr || strlen(homedir) == 0) {
|
||||
@@ -147,7 +151,7 @@ namespace platf {
|
||||
fs::rename(old_config_path, config_path, ec);
|
||||
if (ec) {
|
||||
std::cerr << "Migration failed: " << ec.message() << std::endl;
|
||||
return old_config_path;
|
||||
config_path = old_config_path;
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -157,6 +161,7 @@ namespace platf {
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return config_path;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user