From 7aa251d1311264aacf400f57bb25394bb4b1c856 Mon Sep 17 00:00:00 2001 From: Daniel Kraft Date: Sun, 15 Jul 2018 11:17:50 +0200 Subject: [PATCH] wallet: Fix backupwallet for multiwallets backupwallet was broken for multiwallets in their own directories (i.e. something like DATADIR/wallets/mywallet/wallet.dat). In this case, the backup would use DATADIR/wallets/wallet.dat as source file and not take the specific wallet's directory into account. This led to either an error during the backup (if the wrong source file was not present) or would silently back up the wrong wallet; especially the latter behaviour can be quite bad for users. --- src/wallet/db.cpp | 2 +- test/functional/wallet_multiwallet.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp index 5c26fa1ab70fe..047df48fd4c7d 100644 --- a/src/wallet/db.cpp +++ b/src/wallet/db.cpp @@ -763,7 +763,7 @@ bool CWalletDBWrapper::Backup(const std::string& strDest) env->mapFileUseCount.erase(strFile); // Copy wallet file - fs::path pathSrc = GetWalletDir() / strFile; + fs::path pathSrc = env->Directory() / strFile; fs::path pathDest(strDest); if (fs::is_directory(pathDest)) pathDest /= strFile; diff --git a/test/functional/wallet_multiwallet.py b/test/functional/wallet_multiwallet.py index 52a0abc4a2aff..304c0a8d5bb6c 100755 --- a/test/functional/wallet_multiwallet.py +++ b/test/functional/wallet_multiwallet.py @@ -28,6 +28,11 @@ def run_test(self): wallet_dir = lambda *p: data_dir('wallets', *p) wallet = lambda name: node.get_wallet_rpc(name) + def wallet_file(name): + if os.path.isdir(wallet_dir(name)): + return wallet_dir(name, "wallet.dat") + return wallet_dir(name) + # check wallet.dat is created self.stop_nodes() assert_equal(os.path.isfile(wallet_dir('wallet.dat')), True) @@ -57,10 +62,7 @@ def run_test(self): # check that all requested wallets were created self.stop_node(0) for wallet_name in wallet_names: - if os.path.isdir(wallet_dir(wallet_name)): - assert_equal(os.path.isfile(wallet_dir(wallet_name, "wallet.dat")), True) - else: - assert_equal(os.path.isfile(wallet_dir(wallet_name)), True) + assert_equal(os.path.isfile(wallet_file(wallet_name)), True) # should not initialize if wallet path can't be created self.assert_start_raises_init_error(0, ['-wallet=wallet.dat/bad'], 'Not a directory') @@ -159,5 +161,6 @@ def run_test(self): assert_equal(batch[0]["result"]["chain"], "regtest") #assert_equal(batch[1]["result"]["walletname"], "w1") + if __name__ == '__main__': MultiWalletTest().main()