Skip to content

Commit 01c04d3

Browse files
furszyachow101
authored andcommitted
wallet: introduce method to return all db created files
Github-Pull: #31423 Rebased-From: 1de423e
1 parent abaf1e3 commit 01c04d3

File tree

6 files changed

+29
-0
lines changed

6 files changed

+29
-0
lines changed

src/wallet/bdb.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,21 @@ class BerkeleyDatabase : public WalletDatabase
132132
/** Return path to main database filename */
133133
std::string Filename() override { return fs::PathToString(env->Directory() / m_filename); }
134134

135+
std::vector<fs::path> Files() override
136+
{
137+
std::vector<fs::path> files;
138+
files.emplace_back(env->Directory() / m_filename);
139+
if (env->m_databases.size() == 1) {
140+
files.emplace_back(env->Directory() / "db.log");
141+
files.emplace_back(env->Directory() / ".walletlock");
142+
files.emplace_back(env->Directory() / "database" / "log.0000000001");
143+
files.emplace_back(env->Directory() / "database");
144+
// Note that this list is not exhaustive as BDB may create more log files, and possibly other ones too
145+
// However it should be good enough for the only calls to Files()
146+
}
147+
return files;
148+
}
149+
135150
std::string Format() override { return "bdb"; }
136151
/**
137152
* Pointer to shared database environment.

src/wallet/db.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ class WalletDatabase
170170
/** Return path to main database file for logs and error messages. */
171171
virtual std::string Filename() = 0;
172172

173+
/** Return paths to all database created files */
174+
virtual std::vector<fs::path> Files() = 0;
175+
173176
virtual std::string Format() = 0;
174177

175178
std::atomic<unsigned int> nUpdateCounter;

src/wallet/migrate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class BerkeleyRODatabase : public WalletDatabase
6565

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

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

src/wallet/salvage.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class DummyDatabase : public WalletDatabase
6363
void IncrementUpdateCounter() override { ++nUpdateCounter; }
6464
void ReloadDbEnv() override {}
6565
std::string Filename() override { return "dummy"; }
66+
std::vector<fs::path> Files() override { return {}; }
6667
std::string Format() override { return "dummy"; }
6768
std::unique_ptr<DatabaseBatch> MakeBatch(bool flush_on_close = true) override { return std::make_unique<DummyBatch>(); }
6869
};

src/wallet/sqlite.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,14 @@ class SQLiteDatabase : public WalletDatabase
166166
void IncrementUpdateCounter() override { ++nUpdateCounter; }
167167

168168
std::string Filename() override { return m_file_path; }
169+
/** Return paths to all database created files */
170+
std::vector<fs::path> Files() override
171+
{
172+
std::vector<fs::path> files;
173+
files.emplace_back(m_dir_path / fs::PathFromString(m_file_path));
174+
files.emplace_back(m_dir_path / fs::PathFromString(m_file_path + "-journal"));
175+
return files;
176+
}
169177
std::string Format() override { return "sqlite"; }
170178

171179
/** Make a SQLiteBatch connected to this database */

src/wallet/test/util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ class MockableDatabase : public WalletDatabase
123123
void ReloadDbEnv() override {}
124124

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

0 commit comments

Comments
 (0)