mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-05 20:49:19 +01:00
MOVEONLY: Move IsBDBFile, IsSQLiteFile, and ListWalletDir
This commit does not change to any code and behavior. It it is easily reviewed with the --color-moved=dimmed_zebra git diff option. Motivation for this change is to: - Consolidate redundant functions IsBDBFile /ExistsBerkeleyDatabase / SplitWalletPath, and IsSQLiteFile / ExistsSQLiteDatabase in the next commits - Detect SQLite wallets consistently regardless whether bitcoin is built with SQLite support in the next commits - Avoid attempting to open SQLite databases with the BDB library when bitcoin is built without SQLite support in the next commits
This commit is contained in:
@@ -839,28 +839,3 @@ std::unique_ptr<BerkeleyDatabase> MakeBerkeleyDatabase(const fs::path& path, con
|
||||
status = DatabaseStatus::SUCCESS;
|
||||
return db;
|
||||
}
|
||||
|
||||
bool IsBDBFile(const fs::path& path)
|
||||
{
|
||||
if (!fs::exists(path)) return false;
|
||||
|
||||
// A Berkeley DB Btree file has at least 4K.
|
||||
// This check also prevents opening lock files.
|
||||
boost::system::error_code ec;
|
||||
auto size = fs::file_size(path, ec);
|
||||
if (ec) LogPrintf("%s: %s %s\n", __func__, ec.message(), path.string());
|
||||
if (size < 4096) return false;
|
||||
|
||||
fsbridge::ifstream file(path, std::ios::binary);
|
||||
if (!file.is_open()) return false;
|
||||
|
||||
file.seekg(12, std::ios::beg); // Magic bytes start at offset 12
|
||||
uint32_t data = 0;
|
||||
file.read((char*) &data, sizeof(data)); // Read 4 bytes of file to compare against magic
|
||||
|
||||
// Berkeley DB Btree magic bytes, from:
|
||||
// https://github.com/file/file/blob/5824af38469ec1ca9ac3ffd251e7afe9dc11e227/magic/Magdir/database#L74-L75
|
||||
// - big endian systems - 00 05 31 62
|
||||
// - little endian systems - 62 31 05 00
|
||||
return data == 0x00053162 || data == 0x62310500;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user