From e7aa6bd5863c29ebfb083210365bdadd49e8fea6 Mon Sep 17 00:00:00 2001 From: random-zebra Date: Wed, 21 Jul 2021 02:03:19 +0200 Subject: [PATCH] [Refactor] First load all wallets, then back em --- src/wallet/init.cpp | 15 +++++++++------ test/functional/wallet_multiwallet.py | 5 ++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/wallet/init.cpp b/src/wallet/init.cpp index c2ac22ec133ed..5d88ba4124ae4 100644 --- a/src/wallet/init.cpp +++ b/src/wallet/init.cpp @@ -219,19 +219,22 @@ bool InitLoadWallet() return false; } - // automatic backup + // add to wallets in use + vpwallets.emplace_back(pwallet); + } + + // automatic backup + // do this after loading all wallets, so unique fileids are checked properly + for (CWallet* pwallet: vpwallets) { std::string strWarning, strError; if (!AutoBackupWallet(*pwallet, strWarning, strError)) { if (!strWarning.empty()) { - UIWarning(strprintf("%s: %s", walletFile, strWarning)); + UIWarning(strprintf("%s: %s", pwallet->GetName(), strWarning)); } if (!strError.empty()) { - return UIError(strprintf("%s: %s", walletFile, strError)); + return UIError(strprintf("%s: %s", pwallet->GetName(), strError)); } } - - // add to wallets in use - vpwallets.emplace_back(pwallet); } return true; diff --git a/test/functional/wallet_multiwallet.py b/test/functional/wallet_multiwallet.py index 6bb349a59c377..0f3803c08e767 100755 --- a/test/functional/wallet_multiwallet.py +++ b/test/functional/wallet_multiwallet.py @@ -74,10 +74,9 @@ def wallet_file(name): # should not initialize if there are duplicate wallets self.assert_start_raises_init_error(0, ['-wallet=w1', '-wallet=w1'], 'Error loading wallet w1. Duplicate -wallet filename specified.') - # !TODO: automatic backup changes the environment, fix in the next commit # should not initialize if one wallet is a copy of another - # shutil.copyfile(wallet_dir('w8'), wallet_dir('w8_copy')) - # self.assert_start_raises_init_error(0, ['-wallet=w8', '-wallet=w8_copy'], 'duplicates fileid') + shutil.copyfile(wallet_dir('w8'), wallet_dir('w8_copy')) + self.assert_start_raises_init_error(0, ['-wallet=w8', '-wallet=w8_copy'], 'duplicates fileid') # should not initialize if wallet file is a symlink os.symlink('w8', wallet_dir('w8_symlink'))