Skip to content

Commit

Permalink
wallet: Fix backupwallet for multiwallets
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
domob1812 authored and furszy committed Jul 21, 2021
1 parent 351d2c8 commit 7aa251d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/wallet/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 7 additions & 4 deletions test/functional/wallet_multiwallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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()

0 comments on commit 7aa251d

Please sign in to comment.