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
182
182
183
183
if (gArgs .IsArgSet (" -walletdir" )) {
184
184
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)) {
186
189
return InitError (strprintf (_ (" Specified -walletdir \" %s\" does not exist" ), wallet_dir.string ()));
187
190
} else if (!fs::is_directory (wallet_dir)) {
188
191
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
189
193
} else if (!wallet_dir.is_absolute ()) {
190
194
return InitError (strprintf (_ (" Specified -walletdir \" %s\" is a relative path" ), wallet_dir.string ()));
191
195
}
196
+ gArgs .ForceSetArg (" -walletdir" , canonical_wallet_dir.string ());
192
197
}
193
198
194
199
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)
55
55
BOOST_CHECK (result == false );
56
56
}
57
57
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
+
58
78
BOOST_AUTO_TEST_SUITE_END ()
You can’t perform that action at this time.
0 commit comments