MCPcopy Create free account
hub / github.com/ElementsProject/elements / ListDatabases

Function ListDatabases

src/wallet/db.cpp:18–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16
17namespace wallet {
18std::vector<fs::path> ListDatabases(const fs::path& wallet_dir)
19{
20 std::vector<fs::path> paths;
21 std::error_code ec;
22
23 for (auto it = fs::recursive_directory_iterator(wallet_dir, ec); it != fs::recursive_directory_iterator(); it.increment(ec)) {
24 if (ec) {
25 if (fs::is_directory(*it)) {
26 it.disable_recursion_pending();
27 LogPrintf("%s: %s %s -- skipping.\n", __func__, ec.message(), fs::PathToString(it->path()));
28 } else {
29 LogPrintf("%s: %s %s\n", __func__, ec.message(), fs::PathToString(it->path()));
30 }
31 continue;
32 }
33
34 try {
35 const fs::path path{it->path().lexically_relative(wallet_dir)};
36
37 if (it->status().type() == fs::file_type::directory &&
38 (IsBDBFile(BDBDataFile(it->path())) || IsSQLiteFile(SQLiteDataFile(it->path())))) {
39 // Found a directory which contains wallet.dat btree file, add it as a wallet.
40 paths.emplace_back(path);
41 } else if (it.depth() == 0 && it->symlink_status().type() == fs::file_type::regular && IsBDBFile(it->path())) {
42 if (it->path().filename() == "wallet.dat") {
43 // Found top-level wallet.dat btree file, add top level directory ""
44 // as a wallet.
45 paths.emplace_back();
46 } else {
47 // Found top-level btree file not called wallet.dat. Current bitcoin
48 // software will never create these files but will allow them to be
49 // opened in a shared database environment for backwards compatibility.
50 // Add it to the list of available wallets.
51 paths.emplace_back(path);
52 }
53 }
54 } catch (const std::exception& e) {
55 LogPrintf("%s: Error scanning %s: %s\n", __func__, fs::PathToString(it->path()), e.what());
56 it.disable_recursion_pending();
57 }
58 }
59
60 return paths;
61}
62
63fs::path BDBDataFile(const fs::path& wallet_path)
64{

Callers 2

listWalletDirMethod · 0.85
listwalletdirFunction · 0.85

Calls 11

PathToStringFunction · 0.85
IsBDBFileFunction · 0.85
BDBDataFileFunction · 0.85
IsSQLiteFileFunction · 0.85
SQLiteDataFileFunction · 0.85
pathMethod · 0.80
typeMethod · 0.80
emplace_backMethod · 0.80
filenameMethod · 0.80
messageMethod · 0.45
statusMethod · 0.45

Tested by

no test coverage detected