15 const size_t offset = wallet_dir.string().size() + (wallet_dir == wallet_dir.root_name() ? 0 : 1);
16 std::vector<fs::path> paths;
17 boost::system::error_code ec;
19 for (
auto it = fs::recursive_directory_iterator(wallet_dir, ec); it != fs::recursive_directory_iterator(); it.increment(ec)) {
21 if (fs::is_directory(*it)) {
23 LogPrintf(
"%s: %s %s -- skipping.\n", __func__, ec.message(), it->path().string());
25 LogPrintf(
"%s: %s %s\n", __func__, ec.message(), it->path().string());
33 const fs::path path = it->path().string().substr(offset);
35 if (it->status().type() == fs::directory_file &&
38 paths.emplace_back(path);
39 }
else if (it.level() == 0 && it->symlink_status().type() == fs::regular_file &&
IsBDBFile(it->path())) {
40 if (it->path().filename() ==
"wallet.dat") {
49 paths.emplace_back(path);
52 }
catch (
const std::exception& e) {
53 LogPrintf(
"%s: Error scanning %s: %s\n", __func__, it->path().string(), e.what());
63 if (fs::is_regular_file(wallet_path)) {
71 return wallet_path /
"wallet.dat";
77 return path /
"wallet.dat";
82 if (!fs::exists(path))
return false;
86 boost::system::error_code ec;
87 auto size = fs::file_size(path, ec);
88 if (ec)
LogPrintf(
"%s: %s %s\n", __func__, ec.message(), path.string());
89 if (size < 4096)
return false;
92 if (!file.is_open())
return false;
94 file.seekg(12, std::ios::beg);
96 file.read((
char*) &data,
sizeof(data));
102 return data == 0x00053162 || data == 0x62310500;
107 if (!fs::exists(path))
return false;
110 boost::system::error_code ec;
111 auto size = fs::file_size(path, ec);
112 if (ec)
LogPrintf(
"%s: %s %s\n", __func__, ec.message(), path.string());
113 if (size < 512)
return false;
116 if (!file.is_open())
return false;
120 file.read(magic, 16);
123 file.seekg(68, std::ios::beg);
125 file.read(app_id, 4);
130 std::string magic_str(magic, 16);
131 if (magic_str != std::string(
"SQLite format 3", 16)) {
136 return memcmp(
Params().MessageStart(), app_id, 4) == 0;
fs::path BDBDataFile(const fs::path &wallet_path)
bool IsSQLiteFile(const fs::path &path)
bool IsBDBFile(const fs::path &path)
const CChainParams & Params()
Return the currently selected parameters.
fs::path SQLiteDataFile(const fs::path &path)
std::vector< fs::path > ListDatabases(const fs::path &wallet_dir)
Recursively list database paths in directory.