Only attempt a config migration once per launch

This commit is contained in:
Cameron Gutman 2024-03-15 00:15:55 -05:00
parent aa1985dec8
commit 8c9e14e335

View File

@ -106,12 +106,16 @@ namespace platf {
*/ */
fs::path fs::path
appdata() { 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 found = false;
bool migrate_config = true; bool migrate_config = true;
const char *dir; const char *dir;
const char *homedir; const char *homedir;
const char *migrate_envvar; const char *migrate_envvar;
fs::path config_path;
// Get the home directory // Get the home directory
if ((homedir = getenv("HOME")) == nullptr || strlen(homedir) == 0) { if ((homedir = getenv("HOME")) == nullptr || strlen(homedir) == 0) {
@ -147,7 +151,7 @@ namespace platf {
fs::rename(old_config_path, config_path, ec); fs::rename(old_config_path, config_path, ec);
if (ec) { if (ec) {
std::cerr << "Migration failed: " << ec.message() << std::endl; std::cerr << "Migration failed: " << ec.message() << std::endl;
return old_config_path; config_path = old_config_path;
} }
} }
else { else {
@ -157,6 +161,7 @@ namespace platf {
} }
} }
} }
});
return config_path; return config_path;
} }