Skip to content

Commit d216bc8

Browse files
committed
Re-enable walletinit_verify_walletdir_no_trailing2 test disabled in #20744
This should also fix an init error if a -walletdir with a trailing slash is used on windows. This appears to be a real error and regression introduced with #20744. On windows (or at least wine), fs calls that actuallly access the filesystem like fs::equivalent or fs::exists seem to treat directory paths with trailing slashes as not existing, so it's necessary to normalize these paths before using them. This change passes canonical paths to fs calls validating the -walletdir path to fix this.
1 parent 80cd64e commit d216bc8

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/wallet/load.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ bool VerifyWallets(WalletContext& context)
3131
fs::path wallet_dir = fs::PathFromString(args.GetArg("-walletdir", ""));
3232
std::error_code error;
3333
// The canonical path cleans the path, preventing >1 Berkeley environment instances for the same directory
34+
// It also lets the fs::exists and fs::is_directory checks below pass on windows, since they return false
35+
// if a path has trailing slashes, and it strips trailing slashes.
3436
fs::path canonical_wallet_dir = fs::canonical(wallet_dir, error);
35-
if (error || !fs::exists(wallet_dir)) {
37+
if (error || !fs::exists(canonical_wallet_dir)) {
3638
chain.initError(strprintf(_("Specified -walletdir \"%s\" does not exist"), fs::PathToString(wallet_dir)));
3739
return false;
38-
} else if (!fs::is_directory(wallet_dir)) {
40+
} else if (!fs::is_directory(canonical_wallet_dir)) {
3941
chain.initError(strprintf(_("Specified -walletdir \"%s\" is not a directory"), fs::PathToString(wallet_dir)));
4042
return false;
4143
// The canonical path transforms relative paths into absolute ones, so we check the non-canonical version

src/wallet/test/init_tests.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_no_trailing)
7373
BOOST_CHECK_EQUAL(walletdir, expected_path);
7474
}
7575

76-
#ifndef WIN32
77-
// Windows does not consider "datadir/wallets//" to be a valid directory path.
7876
BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_no_trailing2)
7977
{
8078
SetWalletDir(m_walletdir_path_cases["trailing2"]);
@@ -84,7 +82,6 @@ BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_no_trailing2)
8482
fs::path expected_path = fs::canonical(m_walletdir_path_cases["default"]);
8583
BOOST_CHECK_EQUAL(walletdir, expected_path);
8684
}
87-
#endif
8885

8986
BOOST_AUTO_TEST_SUITE_END()
9087
} // namespace wallet

0 commit comments

Comments
 (0)