@@ -4230,9 +4230,8 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>
4230
4230
}
4231
4231
4232
4232
// Make a backup of the DB
4233
- fs::path this_wallet_dir = fs::absolute (fs::PathFromString (local_wallet->GetDatabase ().Filename ())).parent_path ();
4234
4233
fs::path backup_filename = fs::PathFromString (strprintf (" %s_%d.legacy.bak" , (wallet_name.empty () ? " default_wallet" : wallet_name), GetTime ()));
4235
- fs::path backup_path = this_wallet_dir / backup_filename;
4234
+ fs::path backup_path = fsbridge::AbsPathJoin ( GetWalletDir (), backup_filename) ;
4236
4235
if (!local_wallet->BackupWallet (fs::PathToString (backup_path))) {
4237
4236
return util::Error{_ (" Error: Unable to make a backup of your wallet" )};
4238
4237
}
@@ -4314,11 +4313,6 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>
4314
4313
}
4315
4314
}
4316
4315
if (!success) {
4317
- // Migration failed, cleanup
4318
- // Before deleting the wallet's directory, copy the backup file to the top-level wallets dir
4319
- fs::path temp_backup_location = fsbridge::AbsPathJoin (GetWalletDir (), backup_filename);
4320
- fs::copy_file (backup_path, temp_backup_location, fs::copy_options::none);
4321
-
4322
4316
// Make list of wallets to cleanup
4323
4317
std::vector<std::shared_ptr<CWallet>> created_wallets;
4324
4318
if (local_wallet) created_wallets.push_back (std::move (local_wallet));
@@ -4354,18 +4348,14 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>
4354
4348
// Restore the backup
4355
4349
// Convert the backup file to the wallet db file by renaming it and moving it into the wallet's directory.
4356
4350
bilingual_str restore_error;
4357
- const auto & ptr_wallet = RestoreWallet (context, temp_backup_location , wallet_name, /* load_on_start=*/ std::nullopt, status, restore_error, warnings, /* load_after_restore=*/ false );
4351
+ const auto & ptr_wallet = RestoreWallet (context, backup_path , wallet_name, /* load_on_start=*/ std::nullopt, status, restore_error, warnings, /* load_after_restore=*/ false );
4358
4352
if (!restore_error.empty ()) {
4359
4353
error += restore_error + _ (" \n Unable to restore backup of wallet." );
4360
4354
return util::Error{error};
4361
4355
}
4362
4356
// Verify that the legacy wallet is not loaded after restoring from the backup.
4363
4357
assert (!ptr_wallet);
4364
4358
4365
- // The wallet directory has been restored, but just in case, copy the previously created backup to the wallet dir
4366
- fs::copy_file (temp_backup_location, backup_path, fs::copy_options::none);
4367
- fs::remove (temp_backup_location);
4368
-
4369
4359
return util::Error{error};
4370
4360
}
4371
4361
return res;
0 commit comments