static HyRepo config_repo(const char *name, const char *md_repo, const char *md_primary_xml, const char *md_filelists) { HyRepo repo = hy_repo_create(name); hy_repo_set_string(repo, HY_REPO_MD_FN, md_repo); hy_repo_set_string(repo, HY_REPO_PRIMARY_FN, md_primary_xml); hy_repo_set_string(repo, HY_REPO_FILELISTS_FN, md_filelists); return repo; }
static PyObject * repo_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { _RepoObject *self = (_RepoObject *)type->tp_alloc(type, 0); if (self) { self->repo = hy_repo_create("(default)"); if (self->repo == NULL) { Py_DECREF(self); return NULL; } } return (PyObject *) self; }
END_TEST START_TEST(test_load_repo_err) { HySack sack = hy_sack_create(test_globals.tmpdir, NULL, NULL, NULL, HY_MAKE_CACHE_DIR); HyRepo repo = hy_repo_create("crabalocker"); hy_repo_set_string(repo, HY_REPO_MD_FN, "/non/existing"); fail_unless(hy_sack_load_repo(sack, repo, 0) == HY_E_FAILED); fail_unless(hy_get_errno() == HY_E_IO); hy_repo_free(repo); hy_sack_free(sack); }
END_TEST START_TEST(test_load_repo_err) { g_autoptr(GError) error = NULL; HifSack *sack = hif_sack_new(); hif_sack_set_cachedir(sack, test_globals.tmpdir); fail_unless(hif_sack_setup(sack, HIF_SACK_SETUP_FLAG_MAKE_CACHE_DIR, &error)); g_assert(sack != NULL); HyRepo repo = hy_repo_create("crabalocker"); g_assert(repo != NULL); hy_repo_set_string(repo, HY_REPO_MD_FN, "/non/existing"); fail_unless(!hif_sack_load_repo(sack, repo, 0, &error)); fail_unless(g_error_matches (error, HIF_ERROR, HIF_ERROR_FILE_INVALID)); hy_repo_free(repo); g_object_unref(sack); }
ModulePackageContainer::ModulePackageContainer(bool allArch, std::string installRoot, const char * arch) : pImpl(new Impl) { if (allArch) { dnf_sack_set_all_arch(pImpl->moduleSack, TRUE); } else { dnf_sack_set_arch(pImpl->moduleSack, arch, NULL); } Pool * pool = dnf_sack_get_pool(pImpl->moduleSack); HyRepo hrepo = hy_repo_create("available"); auto repoImpl = libdnf::repoGetImpl(hrepo); LibsolvRepo *repo = repo_create(pool, "available"); repo->appdata = hrepo; repoImpl->libsolvRepo = repo; repoImpl->needs_internalizing = 1; pImpl->installRoot = installRoot; }
int load_repo(Pool *pool, const char *name, const char *path, int installed) { HyRepo hrepo = hy_repo_create(name); Repo *r = repo_create(pool, name); hrepo->libsolv_repo = r; r->appdata = hrepo; FILE *fp = fopen(path, "r"); if (!fp) return 1; testcase_add_testtags(r, fp, 0); if (installed) pool_set_installed(pool, r); fclose(fp); return 0; }
HyRepo glob_for_repofiles(Pool *pool, const char *repo_name, const char *path) { HyRepo repo = hy_repo_create(repo_name); const char *tmpl; wordexp_t word_vector; tmpl = pool_tmpjoin(pool, path, "/repomd.xml", NULL); if (wordexp(tmpl, &word_vector, 0) || word_vector.we_wordc < 1) goto fail; hy_repo_set_string(repo, HY_REPO_MD_FN, word_vector.we_wordv[0]); tmpl = pool_tmpjoin(pool, path, "/*primary.xml.gz", NULL); if (wordexp(tmpl, &word_vector, WRDE_REUSE) || word_vector.we_wordc < 1) goto fail; hy_repo_set_string(repo, HY_REPO_PRIMARY_FN, word_vector.we_wordv[0]); tmpl = pool_tmpjoin(pool, path, "/*filelists.xml.gz", NULL); if (wordexp(tmpl, &word_vector, WRDE_REUSE) || word_vector.we_wordc < 1) goto fail; hy_repo_set_string(repo, HY_REPO_FILELISTS_FN, word_vector.we_wordv[0]); tmpl = pool_tmpjoin(pool, path, "/*prestodelta.xml.gz", NULL); if (wordexp(tmpl, &word_vector, WRDE_REUSE) || word_vector.we_wordc < 1) goto fail; hy_repo_set_string(repo, HY_REPO_PRESTO_FN, word_vector.we_wordv[0]); tmpl = pool_tmpjoin(pool, path, "/*updateinfo.xml.gz", NULL); if (wordexp(tmpl, &word_vector, WRDE_REUSE) || word_vector.we_wordc < 1) goto fail; hy_repo_set_string(repo, HY_REPO_UPDATEINFO_FN, word_vector.we_wordv[0]); wordfree(&word_vector); return repo; fail: wordfree(&word_vector); hy_repo_free(repo); return NULL; }
//Download repo metadata and initialize uint32_t TDNFInitRepo( PTDNF pTdnf, PTDNF_REPO_DATA pRepoData, HyRepo* phRepo ) { uint32_t dwError = 0; gboolean bRet = 0; LrHandle* hLibRepo = NULL; LrResult* pResult = NULL; LrYumRepo* pRepo = NULL; int nLocalOnly = 0; char* pszRepoCacheDir = NULL; char* pszRepoDataDir = NULL; char* pszUserPass = NULL; char* ppszRepoUrls[] = {NULL, NULL}; char* ppszLocalUrls[] = {NULL, NULL}; char* ppszDownloadList[] = {"primary", "filelists", "updateinfo", NULL}; PTDNF_CONF pConf = NULL; HyRepo hRepo = NULL; if(!pTdnf || !pTdnf->pConf || !pRepoData || !phRepo) { dwError = ERROR_TDNF_INVALID_PARAMETER; BAIL_ON_TDNF_ERROR(dwError); } pConf = pTdnf->pConf; pszRepoCacheDir = g_build_path( G_DIR_SEPARATOR_S, pConf->pszCacheDir, pRepoData->pszId, NULL); if(!pszRepoCacheDir) { dwError = ERROR_TDNF_INVALID_PARAMETER; BAIL_ON_TDNF_ERROR(dwError); } pszRepoDataDir = g_build_path( G_DIR_SEPARATOR_S, pszRepoCacheDir, TDNF_REPODATA_DIR_NAME, NULL); if(!pszRepoDataDir) { dwError = ERROR_TDNF_INVALID_PARAMETER; BAIL_ON_TDNF_ERROR(dwError); } ppszRepoUrls[0] = pRepoData->pszBaseUrl; ppszLocalUrls[0] = pszRepoCacheDir; hLibRepo = lr_handle_init(); if(!hLibRepo) { dwError = ERROR_TDNF_INVALID_PARAMETER; BAIL_ON_TDNF_ERROR(dwError); } pResult = lr_result_init(); if(!pResult) { dwError = ERROR_TDNF_INVALID_PARAMETER; BAIL_ON_TDNF_ERROR(dwError); } //Look for repodata dir - this is auto created //during last refresh so skip download if present if(!access(pszRepoDataDir, F_OK)) { nLocalOnly = 1; lr_handle_setopt(hLibRepo, NULL, LRO_URLS, ppszLocalUrls); lr_handle_setopt(hLibRepo, NULL, LRO_IGNOREMISSING, 1); } else { //Look for the repo root cache dir. If not there, //try to create and download into it. if(access(pszRepoCacheDir, F_OK)) { if(errno != ENOENT) { dwError = errno; } BAIL_ON_TDNF_SYSTEM_ERROR(dwError); if(mkdir(pszRepoCacheDir, 755)) { dwError = errno; BAIL_ON_TDNF_SYSTEM_ERROR(dwError); } } lr_handle_setopt(hLibRepo, NULL, LRO_URLS, ppszRepoUrls); lr_handle_setopt(hLibRepo, NULL, LRO_SSLVERIFYPEER, 1); lr_handle_setopt(hLibRepo, NULL, LRO_SSLVERIFYHOST, 2); lr_handle_setopt(hLibRepo, NULL, LRO_DESTDIR, pszRepoCacheDir); lr_handle_setopt(hLibRepo, NULL, LRO_YUMDLIST, ppszDownloadList); if(!IsNullOrEmptyString(pRepoData->pszUser) && !IsNullOrEmptyString(pRepoData->pszPass)) { dwError = TDNFAllocateStringPrintf( &pszUserPass, "%s:%s", pRepoData->pszUser, pRepoData->pszPass); BAIL_ON_TDNF_ERROR(dwError); lr_handle_setopt( hLibRepo, NULL, LRO_USERPWD, pszUserPass); } } lr_handle_setopt(hLibRepo, NULL, LRO_REPOTYPE, LR_YUMREPO); lr_handle_setopt(hLibRepo, NULL, LRO_LOCAL, nLocalOnly); bRet = lr_handle_perform(hLibRepo, pResult, NULL); if(!bRet) { dwError = ERROR_TDNF_REPO_PERFORM; BAIL_ON_TDNF_ERROR(dwError); } bRet = lr_result_getinfo(pResult, NULL, LRR_YUM_REPO, &pRepo); if(!bRet) { dwError = ERROR_TDNF_REPO_GETINFO; BAIL_ON_TDNF_ERROR(dwError); } //Create and set repo properties hRepo = hy_repo_create(pRepoData->pszId); if(!hRepo) { dwError = ERROR_TDNF_HAWKEY_FAILED; BAIL_ON_TDNF_ERROR(dwError); } dwError = TDNFInitRepoFromMetaData(hRepo, pRepo); BAIL_ON_TDNF_ERROR(dwError); *phRepo = hRepo; cleanup: if(pszRepoDataDir) { g_free(pszRepoDataDir); } if(pszRepoCacheDir) { g_free(pszRepoCacheDir); } if(pResult) { lr_result_free(pResult); } if(hLibRepo) { lr_handle_free(hLibRepo); } return dwError; error: //If there is an error during init, log the error //remove any cache data that could be potentially corrupt. if(pRepoData) { fprintf( stderr, "Error: Failed to synchronize cache for repo '%s' from '%s'\n", pRepoData->pszName, pRepoData->pszBaseUrl); if(pTdnf) { TDNFRepoRemoveCache(pTdnf, pRepoData->pszId); } } if(phRepo) { *phRepo = NULL; } if(hRepo) { hy_repo_free(hRepo); } goto cleanup; }
int main(int argc, const char **argv) { HifSack *sack = hif_sack_new (); HyRepo repo; char *md_repo; char *md_primary_xml; char *md_filelists; char *md_repo_updates; char *md_primary_updates_xml; char *md_filelists_updates; int ret; g_autoptr(GError) error = NULL; if (!hif_sack_setup(sack, HIF_SACK_SETUP_FLAG_MAKE_CACHE_DIR, NULL)) return 1; if (read_repopaths(&md_repo, &md_primary_xml, &md_filelists, &md_repo_updates, &md_primary_updates_xml, &md_filelists_updates)) { fprintf(stderr, "This is hawkey testing hack, it needs a readable %s file " "containing the following paths on separate lines:\n" "<main repomd.xml path>\n" "<main primary.xml.gz path>\n" "<main filelist.xml.gz path>\n" "<updates repomd.xml path>\n" "<updates primary.xml.gz path>\n" "<updates filelists.xml.gz path>\n", CFG_FILE); return 1; } int load_flags = HIF_SACK_LOAD_FLAG_BUILD_CACHE; /* rpmdb */ repo = hy_repo_create(HY_SYSTEM_REPO_NAME); hif_sack_load_system_repo(sack, NULL, load_flags, &error); hy_repo_free(repo); if (need_filelists(argc, argv)) load_flags |= HIF_SACK_LOAD_FLAG_USE_FILELISTS; /* Fedora repo */ repo = config_repo("Fedora", md_repo, md_primary_xml, md_filelists); ret = hif_sack_load_repo(sack, repo, load_flags, &error); assert(ret == 0); (void)ret; hy_repo_free(repo); /* Fedora updates repo */ repo = config_repo("updates", md_repo_updates, md_primary_updates_xml, md_filelists_updates); ret = hif_sack_load_repo(sack, repo, load_flags, &error); assert(ret == 0); (void)ret; hy_repo_free(repo); free(md_repo); free(md_primary_xml); free(md_filelists); free(md_repo_updates); free(md_primary_updates_xml); free(md_filelists_updates); hif_sack_set_installonly(sack, installonly); hif_sack_set_installonly_limit(sack, 3); if (argc == 2 && !strcmp(argv[1], "-o")) { obsoletes(sack); } else if (argc == 2) { search_and_print(sack, argv[1]); } else if (argc == 3 && !strcmp(argv[1], "-f")) { search_filter_files(sack, argv[2]); } else if (argc == 3 && !strcmp(argv[1], "-r")) { search_filter_repos(sack, argv[2]); } else if (argc == 3 && !strcmp(argv[1], "-u")) { updatables_query_name(sack, argv[2]); } else if (argc == 3 && !strcmp(argv[1], "-ul")) { update_local(sack, argv[2]); } else if (argc == 3 && !strcmp(argv[1], "-ur")) { update_remote(sack, argv[2]); } else if (argc == 3 && !strcmp(argv[1], "-e")) { erase(sack, argv[2]); } else if (argc == 3) { search_anded(sack, argv[1], argv[2]); } else if (argc == 4 && !strcmp(argv[1], "-p")) { search_provides(sack, argv[2], argv[3]); } g_object_unref(sack); return 0; }
Id ModulePackage::createPlatformSolvable(DnfSack * sack, DnfSack * moduleSack, const std::vector<std::string> & osReleasePaths, const std::string install_root, const char * platformModule) { std::pair<std::string, std::string> parsedPlatform; std::string name; std::string stream; if (platformModule) { parsedPlatform = parsePlatform(platformModule); if (!parsedPlatform.first.empty() && !parsedPlatform.second.empty()) { name = parsedPlatform.first; stream = parsedPlatform.second; } else { throw std::runtime_error( tfm::format(_("Invalid format of Platform module: %s"), platformModule)); } } else if (sack) { Query baseQuery(sack); baseQuery.addFilter(HY_PKG_PROVIDES, HY_EQ, "system-release"); baseQuery.addFilter(HY_PKG_LATEST, HY_EQ, 1); baseQuery.apply(); Query availableQuery(baseQuery); availableQuery.addFilter(HY_PKG_REPONAME, HY_NEQ, HY_SYSTEM_REPO_NAME); auto platform = availableQuery.getStringsFromProvide("base-module"); auto platformSize = platform.size(); if (platformSize == 1) { parsedPlatform = parsePlatform(*platform.begin()); } else if (platformSize > 1) { auto logger(Log::getLogger()); logger->debug(_("Multiple module platforms provided by available packages\n")); } if (!parsedPlatform.first.empty() && !parsedPlatform.second.empty()) { name = parsedPlatform.first; stream = parsedPlatform.second; } else { baseQuery.addFilter(HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME); platform = baseQuery.getStringsFromProvide("base-module"); platformSize = platform.size(); if (platformSize == 1) { parsedPlatform = parsePlatform(*platform.begin()); } else if (platformSize > 1) { auto logger(Log::getLogger()); logger->debug(_("Multiple module platforms provided by installed packages\n")); } if (!parsedPlatform.first.empty() && !parsedPlatform.second.empty()) { name = parsedPlatform.first; stream = parsedPlatform.second; } } } if (name.empty() || stream.empty()) { for (auto & osReleasePath: osReleasePaths) { std::string path; if (install_root == "/") { path = osReleasePath; } else { if (install_root.back() == '/') { path = install_root.substr(0, install_root.size() -1); } else { path = install_root; } path += osReleasePath; } std::pair<std::string, std::string> platform; try { platform = getPlatformStream(path); } catch (const std::exception & except) { auto logger(Log::getLogger()); logger->debug(tfm::format(_("Detection of Platform Module in %s failed: %s"), osReleasePath, std::string(except.what()))); } if (!platform.first.empty() && !platform.second.empty()) { name = platform.first; stream = platform.second; break; } else { auto logger(Log::getLogger()); logger->debug(tfm::format(_("Missing PLATFORM_ID in %s"), osReleasePath)); } } } if (name.empty() || stream.empty()) { throw std::runtime_error(_("No valid Platform ID detected")); } std::string version = "0"; std::string context = "00000000"; Pool * pool = dnf_sack_get_pool(moduleSack); HyRepo hrepo = hy_repo_create(HY_SYSTEM_REPO_NAME); auto repoImpl = libdnf::repoGetImpl(hrepo); LibsolvRepo *repo = repo_create(pool, HY_SYSTEM_REPO_NAME); repo->appdata = hrepo; repoImpl->libsolvRepo = repo; repoImpl->needs_internalizing = 1; Id id = repo_add_solvable(repo); Solvable *solvable = pool_id2solvable(pool, id); setSovable(pool, solvable, name, stream, version, context, "noarch"); repoImpl->needs_internalizing = 1; dnf_sack_set_provides_not_ready(moduleSack); dnf_sack_set_considered_to_update(moduleSack); pool_set_installed(pool, repo); return id; }