std::vector<fs::path> ListWalletDir() { const fs::path wallet_dir = GetWalletDir(); const size_t offset = wallet_dir.string().size() + 1; std::vector<fs::path> paths; for (auto it = fs::recursive_directory_iterator(wallet_dir); it != fs::recursive_directory_iterator(); ++it) { // Get wallet path relative to walletdir by removing walletdir from the wallet path. // This can be replaced by boost::filesystem::lexically_relative once boost is bumped to 1.60. const fs::path path = it->path().string().substr(offset); if (it->status().type() == fs::directory_file && IsBerkeleyBtree(it->path() / "wallet.dat")) { // Found a directory which contains wallet.dat btree file, add it as a wallet. paths.emplace_back(path); } else if (it.level() == 0 && it->symlink_status().type() == fs::regular_file && IsBerkeleyBtree(it->path())) { if (it->path().filename() == "wallet.dat") { // Found top-level wallet.dat btree file, add top level directory "" // as a wallet. paths.emplace_back(); } else { // Found top-level btree file not called wallet.dat. Current bitcoin // software will never create these files but will allow them to be // opened in a shared database environment for backwards compatibility. // Add it to the list of available wallets. paths.emplace_back(path); } } } return paths; }
QueryData genPythonPackages(QueryContext& context) { QueryData results; std::set<std::string> paths; if (context.constraints.count("directory") > 0 && context.constraints.at("directory").exists(EQUALS)) { paths = context.constraints["directory"].getAll(EQUALS); } else { paths = kPythonPath; } for (const auto& key : paths) { genSiteDirectories(key, results); } if (isPlatform(PlatformType::TYPE_OSX)) { for (const auto& dir : kDarwinPythonPath) { std::vector<std::string> versions; if (!listDirectoriesInDirectory(dir, versions, false).ok()) { continue; } for (const auto& version : versions) { // macOS will link older versions to 2.6. auto version_path = fs::path(version).parent_path(); if (fs::is_symlink(symlink_status(version_path))) { continue; } auto complete = version + "lib/python" + version_path.filename().string() + "/site-packages/"; genSiteDirectories(complete, results); } } } else if (isPlatform(PlatformType::TYPE_WINDOWS)) { // Enumerate any system installed python packages auto installPathKey = "HKEY_LOCAL_MACHINE\\" + kWinPythonInstallKey; genWinPythonPackages(installPathKey, results); // Enumerate any user installed python packages installPathKey = "HKEY_USERS\\%\\" + kWinPythonInstallKey; genWinPythonPackages(installPathKey, results); } return results; }