6#include <chainparams.h>
16#include <system_error>
20bool operator<(
BytePrefix a, std::span<const std::byte> b) {
return std::ranges::lexicographical_compare(
a.prefix, b.subspan(0, std::min(
a.prefix.size(), b.size()))); }
25 std::vector<std::pair<fs::path, std::string>>
paths;
28 for (
auto it = fs::recursive_directory_iterator(
wallet_dir,
ec); it != fs::recursive_directory_iterator(); it.increment(
ec)) {
31 const fs::path path{it->path().lexically_relative(
wallet_dir)};
33 if (it->status().type() == fs::file_type::directory) {
36 paths.emplace_back(path,
"bdb");
39 paths.emplace_back(path,
"sqlite");
41 }
else if (it.depth() == 0 && it->symlink_status().type() == fs::file_type::regular && it->path().extension() !=
".bak") {
42 if (it->path().filename() ==
"wallet.dat") {
46 paths.emplace_back(fs::path(),
"bdb");
48 paths.emplace_back(fs::path(),
"sqlite");
55 paths.emplace_back(path,
"bdb");
58 }
catch (
const std::exception&
e) {
60 it.disable_recursion_pending();
91 return path /
"wallet.dat";
101 auto size = fs::file_size(path,
ec);
103 if (size < 4096)
return false;
105 std::ifstream file{path.std_path(), std::ios::binary};
106 if (!file.is_open())
return false;
108 file.seekg(12, std::ios::beg);
110 file.read((
char*) &data,
sizeof(data));
116 return data == 0x00053162 || data == 0x62310500;
125 auto size = fs::file_size(path,
ec);
127 if (size < 512)
return false;
129 std::ifstream file{path.std_path(), std::ios::binary};
130 if (!file.is_open())
return false;
134 file.read(magic, 16);
137 file.seekg(68, std::ios::beg);
145 if (
magic_str != std::string{
"SQLite format 3\000", 16}) {
const CChainParams & Params()
Return the currently selected parameters.
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
static bool exists(const path &p)
static std::string PathToString(const path &path)
Convert path object to a byte string.
void ReadDatabaseArgs(const ArgsManager &args, DatabaseOptions &options)
bool operator<(BytePrefix a, std::span< const std::byte > b)
fs::path SQLiteDataFile(const fs::path &path)
bool IsBDBFile(const fs::path &path)
fs::path BDBDataFile(const fs::path &wallet_path)
bool IsSQLiteFile(const fs::path &path)
std::vector< std::pair< fs::path, std::string > > ListDatabases(const fs::path &wallet_dir)
Recursively list database paths in directory.
std::span< const std::byte > prefix
bool use_unsafe_sync
Disable file sync for faster performance.
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.