mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 23:18:14 +01:00
Merge bitcoin/bitcoin#26740: wallet: Migrate wallets that are not in a wallet dir
a1e653828btest: Add test for migrating default wallet and plain file wallet (Andrew Chow)bdbe3fd76bwallet: Generated migrated wallet's path from walletdir and name (Andrew Chow) Pull request description: This PR fixes an assertion error that is hit during the setup of the new database during migration of a wallet that was not contained in a wallet dir. Also added a test for this case as well as one for migrating the default wallet. ACKs for top commit: ryanofsky: Code review ACKa1e653828bfurszy: ACKa1e65382Tree-SHA512: 96b218c0de8567d8650ec96e1bf58b0f8ca4c4726f5efc6362453979b56b9d569baea0bb09befb3a5aed8d16d29bf75ed5cd8ffc432bbd4cbcad3ac5574bc479
This commit is contained in:
@@ -3856,16 +3856,19 @@ bool CWallet::MigrateToSQLite(bilingual_str& error)
|
||||
|
||||
// Close this database and delete the file
|
||||
fs::path db_path = fs::PathFromString(m_database->Filename());
|
||||
fs::path db_dir = db_path.parent_path();
|
||||
m_database->Close();
|
||||
fs::remove(db_path);
|
||||
|
||||
// Generate the path for the location of the migrated wallet
|
||||
// Wallets that are plain files rather than wallet directories will be migrated to be wallet directories.
|
||||
const fs::path wallet_path = fsbridge::AbsPathJoin(GetWalletDir(), fs::PathFromString(m_name));
|
||||
|
||||
// Make new DB
|
||||
DatabaseOptions opts;
|
||||
opts.require_create = true;
|
||||
opts.require_format = DatabaseFormat::SQLITE;
|
||||
DatabaseStatus db_status;
|
||||
std::unique_ptr<WalletDatabase> new_db = MakeDatabase(db_dir, opts, db_status, error);
|
||||
std::unique_ptr<WalletDatabase> new_db = MakeDatabase(wallet_path, opts, db_status, error);
|
||||
assert(new_db); // This is to prevent doing anything further with this wallet. The original file was deleted, but a backup exists.
|
||||
m_database.reset();
|
||||
m_database = std::move(new_db);
|
||||
|
||||
Reference in New Issue
Block a user