Skip to content

Commit 3ddbdd1

Browse files
committed
wallet: Ignore .bak files when listing wallet files
Migration creates backup files in the wallet directory with .bak as the extension. This pollutes the output of listwalletdir with backup files that most users should not need to care about.
1 parent b1ba1b1 commit 3ddbdd1

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/wallet/db.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ std::vector<fs::path> ListDatabases(const fs::path& wallet_dir)
4242
(IsBDBFile(BDBDataFile(it->path())) || IsSQLiteFile(SQLiteDataFile(it->path())))) {
4343
// Found a directory which contains wallet.dat btree file, add it as a wallet.
4444
paths.emplace_back(path);
45-
} else if (it.depth() == 0 && it->symlink_status().type() == fs::file_type::regular && IsBDBFile(it->path())) {
45+
} else if (it.depth() == 0 && it->symlink_status().type() == fs::file_type::regular && IsBDBFile(it->path()) && it->path().extension() != ".bak") {
4646
if (it->path().filename() == "wallet.dat") {
4747
// Found top-level wallet.dat btree file, add top level directory ""
4848
// as a wallet.

test/functional/wallet_migration.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,10 +538,14 @@ def test_default_wallet(self):
538538
assert_equal(info["descriptors"], True)
539539
assert_equal(info["format"], "sqlite")
540540

541+
walletdir_list = wallet.listwalletdir()
542+
541543
# Check backup existence and its non-empty wallet filename
542-
backup_path = self.nodes[0].wallets_path / f'default_wallet_{curr_time}.legacy.bak'
544+
backup_filename = f"default_wallet_{curr_time}.legacy.bak"
545+
backup_path = self.nodes[0].wallets_path / backup_filename
543546
assert backup_path.exists()
544547
assert_equal(str(backup_path), res['backup_path'])
548+
assert {"name": backup_filename} not in walletdir_list["wallets"]
545549

546550
def test_direct_file(self):
547551
self.log.info("Test migration of a wallet that is not in a wallet directory")

0 commit comments

Comments
 (0)