Skip to content

Commit f78f6f1

Browse files
committed
wallettool: do not use fs::remove_all in createfromdump cleanup
1 parent c60f9cb commit f78f6f1

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/wallet/dump.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,17 @@ bool CreateFromDump(const ArgsManager& args, const std::string& name, const fs::
276276

277277
dump_file.close();
278278
}
279+
// On failure, gather the paths to remove
280+
std::vector<fs::path> paths_to_remove = wallet->GetDatabase().Files();
281+
if (!name.empty()) paths_to_remove.push_back(wallet_path);
282+
279283
wallet.reset(); // The pointer deleter will close the wallet for us.
280284

281285
// Remove the wallet dir if we have a failure
282286
if (!ret) {
283-
fs::remove_all(wallet_path);
287+
for (const auto& p : paths_to_remove) {
288+
fs::remove(p);
289+
}
284290
}
285291

286292
return ret;

test/functional/tool_wallet.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,12 @@ def test_dump_createfromdump(self):
319319
self.write_dump(dump_data, bad_sum_wallet_dump)
320320
self.assert_raises_tool_error('Error: Checksum is not the correct size', '-wallet=badload', '-dumpfile={}'.format(bad_sum_wallet_dump), 'createfromdump')
321321
assert not (self.nodes[0].wallets_path / "badload").is_dir()
322+
self.assert_raises_tool_error('Error: Checksum is not the correct size', '-wallet=', '-dumpfile={}'.format(bad_sum_wallet_dump), 'createfromdump')
323+
assert self.nodes[0].wallets_path.exists()
324+
assert not (self.nodes[0].wallets_path / "wallet.dat").exists()
325+
326+
self.log.info('Checking createfromdump with an unnamed wallet')
327+
self.do_tool_createfromdump("", "wallet.dump")
322328

323329
def test_chainless_conflicts(self):
324330
self.log.info("Test wallet tool when wallet contains conflicting transactions")

0 commit comments

Comments
 (0)