| 16 | |
| 17 | namespace wallet { |
| 18 | std::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 | |
| 63 | fs::path BDBDataFile(const fs::path& wallet_path) |
| 64 | { |
no test coverage detected