6 #include <chainparams.h>
15 #include <system_error>
24 std::vector<fs::path> paths;
27 for (
auto it = fs::recursive_directory_iterator(wallet_dir, ec); it != fs::recursive_directory_iterator(); it.increment(ec)) {
29 if (fs::is_directory(*it)) {
30 it.disable_recursion_pending();
39 const fs::path path{it->
path().lexically_relative(wallet_dir)};
41 if (it->status().type() == fs::file_type::directory &&
44 paths.emplace_back(path);
45 }
else if (it.depth() == 0 && it->symlink_status().type() == fs::file_type::regular &&
IsBDBFile(it->path())) {
46 if (it->path().filename() ==
"wallet.dat") {
55 paths.emplace_back(path);
58 }
catch (
const std::exception& e) {
60 it.disable_recursion_pending();
69 if (fs::is_regular_file(wallet_path)) {
77 return wallet_path /
"wallet.dat";
83 return path /
"wallet.dat";
93 auto size = fs::file_size(path, ec);
95 if (size < 4096)
return false;
97 std::ifstream file{path, std::ios::binary};
98 if (!file.is_open())
return false;
100 file.seekg(12, std::ios::beg);
102 file.read((
char*) &data,
sizeof(data));
108 return data == 0x00053162 || data == 0x62310500;
117 auto size = fs::file_size(path, ec);
119 if (size < 512)
return false;
121 std::ifstream file{path, std::ios::binary};
122 if (!file.is_open())
return false;
126 file.read(magic, 16);
129 file.seekg(68, std::ios::beg);
131 file.read(app_id, 4);
136 std::string magic_str(magic, 16);
137 if (magic_str != std::string{
"SQLite format 3\000", 16}) {
142 return memcmp(
Params().MessageStart().data(), app_id, 4) == 0;
const CChainParams & Params()
Return the currently selected parameters.
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
constexpr std::size_t size() const noexcept
CONSTEXPR_IF_NOT_DEBUG Span< C > subspan(std::size_t offset) const noexcept
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
path(std::filesystem::path path)
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)
fs::path SQLiteDataFile(const fs::path &path)
std::vector< fs::path > ListDatabases(const fs::path &wallet_dir)
Recursively list database paths in directory.
bool IsBDBFile(const fs::path &path)
fs::path BDBDataFile(const fs::path &wallet_path)
bool operator<(BytePrefix a, Span< const std::byte > b)
bool IsSQLiteFile(const fs::path &path)
Span< const std::byte > prefix
bool use_shared_memory
Let other processes access the database.
bool use_unsafe_sync
Disable file sync for faster performance.
int64_t max_log_mb
Max log size to allow before consolidating.