Skip to content

Commit d50c996

Browse files
committed
Merge #14561: Remove fs::relative call and fix listwalletdir tests
ed2e183 Remove fs::relative call and fix listwalletdir tests (João Barbosa) Pull request description: The implementation of `fs::relative` resolves symlinks which is not intended in ListWalletDir. The replacement does what is required, and `listwalletdir` RPC tests are fixed accordingly. Also, `fs::recursive_directory_iterator` iteration is fixed to build with boost 1.47. Based on #14559 Tree-SHA512: 1da516226073f195285d10d9d9648c90cce0158c5d1eb9c31217bb4abb575cd37f07c00787c5a850554d6120bbc5a3cbc5cb47d4488b32ac6bcb52bc1882d600
2 parents 9d45415 + ed2e183 commit d50c996

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/wallet/walletutil.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,17 @@ static bool IsBerkeleyBtree(const fs::path& path)
5252
std::vector<fs::path> ListWalletDir()
5353
{
5454
const fs::path wallet_dir = GetWalletDir();
55+
const size_t offset = wallet_dir.string().size() + 1;
5556
std::vector<fs::path> paths;
5657

57-
for (auto it = fs::recursive_directory_iterator(wallet_dir); it != end(it); ++it) {
58+
for (auto it = fs::recursive_directory_iterator(wallet_dir); it != fs::recursive_directory_iterator(); ++it) {
59+
// Get wallet path relative to walletdir by removing walletdir from the wallet path.
60+
// This can be replaced by boost::filesystem::lexically_relative once boost is bumped to 1.60.
61+
const fs::path path = it->path().string().substr(offset);
62+
5863
if (it->status().type() == fs::directory_file && IsBerkeleyBtree(it->path() / "wallet.dat")) {
5964
// Found a directory which contains wallet.dat btree file, add it as a wallet.
60-
paths.emplace_back(fs::relative(it->path(), wallet_dir));
65+
paths.emplace_back(path);
6166
} else if (it.level() == 0 && it->symlink_status().type() == fs::regular_file && IsBerkeleyBtree(it->path())) {
6267
if (it->path().filename() == "wallet.dat") {
6368
// Found top-level wallet.dat btree file, add top level directory ""
@@ -68,7 +73,7 @@ std::vector<fs::path> ListWalletDir()
6873
// software will never create these files but will allow them to be
6974
// opened in a shared database environment for backwards compatibility.
7075
// Add it to the list of available wallets.
71-
paths.emplace_back(fs::relative(it->path(), wallet_dir));
76+
paths.emplace_back(path);
7277
}
7378
}
7479
}

test/functional/wallet_multiwallet.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def wallet_file(name):
7171
wallet_names = ['w1', 'w2', 'w3', 'w', 'sub/w5', os.path.join(self.options.tmpdir, 'extern/w6'), 'w7_symlink', 'w8', '']
7272
extra_args = ['-wallet={}'.format(n) for n in wallet_names]
7373
self.start_node(0, extra_args)
74-
assert_equal(set(map(lambda w: w['name'], self.nodes[0].listwalletdir()['wallets'])), set(['', 'w3', 'w2', os.path.join('sub', 'w5'), 'w7', 'w7', 'w1', 'w8', 'w']))
74+
assert_equal(sorted(map(lambda w: w['name'], self.nodes[0].listwalletdir()['wallets'])), ['', os.path.join('sub', 'w5'), 'w', 'w1', 'w2', 'w3', 'w7', 'w7_symlink', 'w8'])
7575

7676
assert_equal(set(node.listwallets()), set(wallet_names))
7777

@@ -144,7 +144,7 @@ def wallet_file(name):
144144

145145
self.restart_node(0, extra_args)
146146

147-
assert_equal(set(map(lambda w: w['name'], self.nodes[0].listwalletdir()['wallets'])), set(['', 'w3', 'w2', os.path.join('sub', 'w5'), 'w7', 'w7', 'w8_copy', 'w1', 'w8', 'w']))
147+
assert_equal(sorted(map(lambda w: w['name'], self.nodes[0].listwalletdir()['wallets'])), ['', os.path.join('sub', 'w5'), 'w', 'w1', 'w2', 'w3', 'w7', 'w7_symlink', 'w8', 'w8_copy'])
148148

149149
wallets = [wallet(w) for w in wallet_names]
150150
wallet_bad = wallet("bad")
@@ -291,7 +291,7 @@ def wallet_file(name):
291291
assert_equal(self.nodes[0].listwallets(), ['w1'])
292292
assert_equal(w1.getwalletinfo()['walletname'], 'w1')
293293

294-
assert_equal(set(map(lambda w: w['name'], self.nodes[0].listwalletdir()['wallets'])), set(['', 'w3', 'w2', os.path.join('sub', 'w5'), 'w7', 'w9', 'w7', 'w8_copy', 'w1', 'w8', 'w']))
294+
assert_equal(sorted(map(lambda w: w['name'], self.nodes[0].listwalletdir()['wallets'])), ['', os.path.join('sub', 'w5'), 'w', 'w1', 'w2', 'w3', 'w7', 'w7_symlink', 'w8', 'w8_copy', 'w9'])
295295

296296
# Test backing up and restoring wallets
297297
self.log.info("Test wallet backup")

0 commit comments

Comments
 (0)