File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -182,13 +182,18 @@ bool WalletInit::Verify() const
182182
183183 if (gArgs .IsArgSet (" -walletdir" )) {
184184 fs::path wallet_dir = gArgs .GetArg (" -walletdir" , " " );
185- if (!fs::exists (wallet_dir)) {
185+ boost::system::error_code error;
186+ // The canonical path cleans the path, preventing >1 Berkeley environment instances for the same directory
187+ fs::path canonical_wallet_dir = fs::canonical (wallet_dir, error);
188+ if (error || !fs::exists (wallet_dir)) {
186189 return InitError (strprintf (_ (" Specified -walletdir \" %s\" does not exist" ), wallet_dir.string ()));
187190 } else if (!fs::is_directory (wallet_dir)) {
188191 return InitError (strprintf (_ (" Specified -walletdir \" %s\" is not a directory" ), wallet_dir.string ()));
192+ // The canonical path transforms relative paths into absolute ones, so we check the non-canonical version
189193 } else if (!wallet_dir.is_absolute ()) {
190194 return InitError (strprintf (_ (" Specified -walletdir \" %s\" is a relative path" ), wallet_dir.string ()));
191195 }
196+ gArgs .ForceSetArg (" -walletdir" , canonical_wallet_dir.string ());
192197 }
193198
194199 LogPrintf (" Using wallet directory %s\n " , GetWalletDir ().string ());
Original file line number Diff line number Diff line change @@ -55,4 +55,24 @@ BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_is_not_relative)
5555 BOOST_CHECK (result == false );
5656}
5757
58+ BOOST_AUTO_TEST_CASE (walletinit_verify_walletdir_no_trailing)
59+ {
60+ SetWalletDir (m_walletdir_path_cases[" trailing" ]);
61+ bool result = g_wallet_init_interface.Verify ();
62+ BOOST_CHECK (result == true );
63+ fs::path walletdir = gArgs .GetArg (" -walletdir" , " " );
64+ fs::path expected_path = fs::canonical (m_walletdir_path_cases[" default" ]);
65+ BOOST_CHECK (walletdir == expected_path);
66+ }
67+
68+ BOOST_AUTO_TEST_CASE (walletinit_verify_walletdir_no_trailing2)
69+ {
70+ SetWalletDir (m_walletdir_path_cases[" trailing2" ]);
71+ bool result = g_wallet_init_interface.Verify ();
72+ BOOST_CHECK (result == true );
73+ fs::path walletdir = gArgs .GetArg (" -walletdir" , " " );
74+ fs::path expected_path = fs::canonical (m_walletdir_path_cases[" default" ]);
75+ BOOST_CHECK (walletdir == expected_path);
76+ }
77+
5878BOOST_AUTO_TEST_SUITE_END ()
You can’t perform that action at this time.
0 commit comments