aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Falbesoner <sebastian.falbesoner@gmail.com>2022-12-23 02:56:03 +0100
committerSebastian Falbesoner <sebastian.falbesoner@gmail.com>2022-12-23 03:24:36 +0100
commit8c7222bda3f7136f312a6e57b76d6a2d0a114f68 (patch)
tree58d87d55b99b091e0738734aaff2aac9fc24c742
parentf3bc1a72825fe2b51f4bc20e004cef464f05b965 (diff)
downloadbitcoin-8c7222bda3f7136f312a6e57b76d6a2d0a114f68.tar.xz
wallet: fix GUI crash on cross-chain legacy wallet restore
Restoring a wallet backup from another chain should obviously result in a dedicated error message (we have "Wallet files should not be reused across chains. Restart bitcoind with -walletcrosschain to override." for that). Unfortunately this is currently not the case for legacy wallet restores, as in the course of cleaning up the newly created wallet directory a `filesystem_error` exception is thrown due to the directory not being empty; the wallet database did indeed load successfully (otherwise we wouldn't know that the chain doesn't match) and hence BDB-related files and directories are created in the wallet directory. For bitcoind, this leads to a very confusing error message: ``` $ ./src/bitcoin-cli restorewallet test123 ~/.bitcoin/regtest/wallets/regtest_wallet/wallet.dat error code: -1 error message: filesystem error: in remove: Directory not empty ["/home/thestack/.bitcoin/wallets/test123"] ``` Even worse, the GUI crashes in such a scenario: ``` libc++abi: terminating with uncaught exception of type std::__1::__fs::filesystem::filesystem_error: filesystem error: in remove: Directory not empty ["/home/thestack/.bitcoin/wallets/foobar"] Abort trap (core dumped) ``` Fix this by simply deleting the whole folder via `fs::remove_all`.
-rw-r--r--src/wallet/wallet.cpp3
1 files changed, 1 insertions, 2 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 2c0ce89929..d7ab511e9a 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -472,8 +472,7 @@ std::shared_ptr<CWallet> RestoreWallet(WalletContext& context, const fs::path& b
error += strprintf(Untranslated("Unexpected exception: %s"), e.what());
}
if (!wallet) {
- fs::remove(wallet_file);
- fs::remove(wallet_path);
+ fs::remove_all(wallet_path);
}
return wallet;