Skip to content

Commit

Permalink
wallet: introduce method to return all db created files
Browse files Browse the repository at this point in the history
  • Loading branch information
furszy committed Feb 14, 2025
1 parent 5769481 commit a48d810
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/wallet/bdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ class BerkeleyDatabase : public WalletDatabase

/** Return path to main database filename */
std::string Filename() override { return fs::PathToString(env->Directory() / m_filename); }
/** Return paths to all database created files */
std::vector<fs::path> Files() override
{
std::vector<fs::path> files;
files.emplace_back(env->Directory() / m_filename);
files.emplace_back(env->Directory() / "database");
files.emplace_back(env->Directory() / "db.log");
files.emplace_back(env->Directory() / ".walletlock");
return files;
}

std::string Format() override { return "bdb"; }
/**
Expand Down
3 changes: 3 additions & 0 deletions src/wallet/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ class WalletDatabase
/** Return path to main database file for logs and error messages. */
virtual std::string Filename() = 0;

/** Return paths to all database created files */
virtual std::vector<fs::path> Files() = 0;

virtual std::string Format() = 0;

std::atomic<unsigned int> nUpdateCounter;
Expand Down
1 change: 1 addition & 0 deletions src/wallet/migrate.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class BerkeleyRODatabase : public WalletDatabase

/** Return path to main database file for logs and error messages. */
std::string Filename() override { return fs::PathToString(m_filepath); }
std::vector<fs::path> Files() override { return {m_filepath}; }

std::string Format() override { return "bdb_ro"; }

Expand Down
1 change: 1 addition & 0 deletions src/wallet/salvage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class DummyDatabase : public WalletDatabase
void IncrementUpdateCounter() override { ++nUpdateCounter; }
void ReloadDbEnv() override {}
std::string Filename() override { return "dummy"; }
std::vector<fs::path> Files() override { return {}; }
std::string Format() override { return "dummy"; }
std::unique_ptr<DatabaseBatch> MakeBatch(bool flush_on_close = true) override { return std::make_unique<DummyBatch>(); }
};
Expand Down
8 changes: 8 additions & 0 deletions src/wallet/sqlite.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ class SQLiteDatabase : public WalletDatabase
void IncrementUpdateCounter() override { ++nUpdateCounter; }

std::string Filename() override { return m_file_path; }
/** Return paths to all database created files */
std::vector<fs::path> Files() override
{
std::vector<fs::path> files;
files.emplace_back(m_dir_path / fs::PathFromString(m_file_path));
files.emplace_back(m_dir_path / fs::PathFromString(m_file_path + "-journal"));
return files;
}
std::string Format() override { return "sqlite"; }

/** Make a SQLiteBatch connected to this database */
Expand Down
1 change: 1 addition & 0 deletions src/wallet/test/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class MockableDatabase : public WalletDatabase
void ReloadDbEnv() override {}

std::string Filename() override { return "mockable"; }
std::vector<fs::path> Files() override { return {}; }
std::string Format() override { return "mock"; }
std::unique_ptr<DatabaseBatch> MakeBatch(bool flush_on_close = true) override { return std::make_unique<MockableBatch>(m_records, m_pass); }
};
Expand Down

0 comments on commit a48d810

Please sign in to comment.