Wallet/Migration: Skip moving the backup file back and forth for no reason

Since we no longer delete the wallet directory, there's no need to vacate it
The moving only served to risk errors by crossing filesystem boundaries (which fs::rename can't handle)

Github-Pull: 34370
Rebased-From: cef01d0be5223e9d33efc897d7fbe5d0a08692c0
This commit is contained in:
Luke Dashjr 2026-01-15 19:27:23 +00:00 committed by Ava Chow
parent 619480bd78
commit 6494072295

View File

@ -4576,9 +4576,6 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(const std::string& walle
}
if (!success) {
// Migration failed, cleanup
// Copy the backup to the actual wallet dir
fs::path temp_backup_location = fsbridge::AbsPathJoin(GetWalletDir(), backup_filename);
fs::rename(backup_path, temp_backup_location);
// Make list of wallets to cleanup
std::vector<std::shared_ptr<CWallet>> created_wallets;
@ -4619,16 +4616,15 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(const std::string& walle
}
// Restore the backup
DatabaseStatus status;
std::vector<bilingual_str> warnings;
if (!RestoreWallet(context, temp_backup_location, wallet_name, /*load_on_start=*/std::nullopt, status, error, warnings)) {
error += _("\nUnable to restore backup of wallet.");
// Convert the backup file to the wallet db file by renaming it and moving it into the wallet's directory.
// Reload it into memory if the wallet was previously loaded.
bilingual_str restore_error;
const auto& ptr_wallet = RestoreWallet(context, backup_path, wallet_name, /*load_on_start=*/std::nullopt, status, restore_error, warnings);
if (!restore_error.empty()) {
error += restore_error + _("\nUnable to restore backup of wallet.");
return util::Error{error};
}
// Move the backup to the wallet dir
fs::rename(temp_backup_location, backup_path);
return util::Error{error};
}
return res;