END_TEST START_TEST(test_sack_create) { fail_unless(hy_get_errno() == 0); HySack sack = hy_sack_create(test_globals.tmpdir, NULL, NULL, HY_MAKE_CACHE_DIR); fail_if(sack == NULL, NULL); fail_if(sack_pool(sack) == NULL, NULL); hy_sack_free(sack); sack = hy_sack_create(test_globals.tmpdir, "", NULL, HY_MAKE_CACHE_DIR); fail_unless(sack == NULL); fail_unless(hy_get_errno() == HY_E_ARCH); }
END_TEST START_TEST(test_two_sacks) { /* This clumsily mimics create_ut_sack() and setup_with() to * create a second HySack. */ char *tmpdir = solv_dupjoin(test_globals.tmpdir, "/tmp", NULL); HySack sack1 = hy_sack_create(tmpdir, TEST_FIXED_ARCH, NULL, NULL, HY_MAKE_CACHE_DIR); Pool *pool1 = sack_pool(sack1); const char *path = pool_tmpjoin(pool1, test_globals.repo_dir, "change.repo", NULL); fail_if(load_repo(pool1, "change", path, 0)); HyPackage pkg1 = by_name(sack1, "penny-lib"); fail_if(pkg1 == NULL); HySack sack2 = test_globals.sack; Pool *pool2 = sack_pool(sack2); HyPackage pkg2 = by_name(sack2, "penny-lib"); fail_if(pkg2 == NULL); /* "penny-lib" is in both pools but at different offsets */ Solvable *s1 = pool_id2solvable(pool1, pkg1->id); Solvable *s2 = pool_id2solvable(pool2, pkg2->id); fail_if(s1->name == s2->name); fail_if(hy_package_cmp(pkg1, pkg2) != 0); hy_package_free(pkg1); hy_package_free(pkg2); hy_sack_free(sack1); solv_free(tmpdir); }
gboolean rpmostree_get_pkglist_for_root (GFile *root, HySack *out_sack, HyPackageList *out_pkglist, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; int rc; _cleanup_hysack_ HySack sack = NULL; _cleanup_hyquery_ HyQuery query = NULL; _cleanup_hypackagelist_ HyPackageList pkglist = NULL; #if BUILDOPT_HAWKEY_SACK_CREATE2 sack = hy_sack_create (NULL, NULL, gs_file_get_path_cached (root), NULL, HY_MAKE_CACHE_DIR); #else sack = hy_sack_create (NULL, NULL, gs_file_get_path_cached (root), HY_MAKE_CACHE_DIR); #endif if (sack == NULL) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Failed to create sack cache"); goto out; } rc = hy_sack_load_system_repo (sack, NULL, 0); if (!hif_error_set_from_hawkey (rc, error)) { g_prefix_error (error, "Failed to load system repo: "); goto out; } query = hy_query_create (sack); hy_query_filter (query, HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME); pkglist = hy_query_run (query); ret = TRUE; gs_transfer_out_value (out_sack, &sack); gs_transfer_out_value (out_pkglist, &pkglist); out: return ret; }
static HySack create_ut_sack(void) { HySack sack = hy_sack_create(test_globals.tmpdir, TEST_FIXED_ARCH, NULL, NULL, HY_MAKE_CACHE_DIR); test_globals.sack = sack; HY_LOG_INFO("HySack for UT created: %p", sack); return sack; }
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_presto_from_cache) { HySack sack = hy_sack_create(test_globals.tmpdir, TEST_FIXED_ARCH, NULL, NULL, HY_MAKE_CACHE_DIR); setup_yum_sack(sack, YUM_REPO_NAME); HyRepo repo = hrepo_by_name(sack, YUM_REPO_NAME); fail_unless(repo->state_presto == _HY_LOADED_CACHE); check_prestoinfo(sack_pool(sack)); hy_sack_free(sack); }
END_TEST START_TEST(test_list_arches) { HySack sack = hy_sack_create(test_globals.tmpdir, TEST_FIXED_ARCH, NULL, NULL, HY_MAKE_CACHE_DIR); const char ** arches = hy_sack_list_arches(sack); /* noarch, x86_64, athlon, i686, i586, i486, i386 */ fail_unless(count_nullt_array(arches), 7); ck_assert_str_eq(arches[3], "i686"); hy_free(arches); hy_sack_free(sack); }
END_TEST START_TEST(test_give_cache_fn) { HySack sack = hy_sack_create(test_globals.tmpdir, NULL, NULL, NULL, HY_MAKE_CACHE_DIR); char *path = hy_sack_give_cache_fn(sack, "rain", NULL); fail_if(strstr(path, "rain.solv") == NULL); hy_free(path); path = hy_sack_give_cache_fn(sack, "rain", HY_EXT_FILENAMES); fail_if(strstr(path, "rain-filenames.solvx") == NULL); hy_free(path); hy_sack_free(sack); }
uint32_t TDNFInitSack( PTDNF pTdnf, HySack* phSack, int nFlags ) { uint32_t dwError = 0; HySack hSack = NULL; char* pszHawkeyCacheDir = NULL; if(!pTdnf || !pTdnf->pConf || !phSack) { dwError = ERROR_TDNF_INVALID_PARAMETER; BAIL_ON_TDNF_ERROR(dwError); } pszHawkeyCacheDir = pTdnf->pConf->pszCacheDir; hSack = hy_sack_create(pszHawkeyCacheDir, NULL, "/", 0); if(!hSack) { dwError = ERROR_TDNF_INVALID_PARAMETER; BAIL_ON_TDNF_ERROR(dwError); } dwError = hy_sack_load_system_repo(hSack, NULL, nFlags); BAIL_ON_TDNF_HAWKEY_ERROR(dwError); *phSack = hSack; cleanup: return dwError; error: if(hSack) { hy_sack_free(hSack); } if(phSack) { *phSack = NULL; } goto cleanup; }
END_TEST START_TEST(test_repo_written) { HySack sack = hy_sack_create(test_globals.tmpdir, NULL, NULL, NULL, HY_MAKE_CACHE_DIR); char *filename = hy_sack_give_cache_fn(sack, "test_sack_written", NULL); fail_unless(access(filename, R_OK|W_OK)); setup_yum_sack(sack, "test_sack_written"); HyRepo repo = hrepo_by_name(sack, "test_sack_written"); fail_if(repo == NULL); fail_unless(repo->state_main == _HY_WRITTEN); fail_unless(repo->state_filelists == _HY_WRITTEN); fail_unless(repo->state_presto == _HY_WRITTEN); fail_if(access(filename, R_OK|W_OK)); hy_free(filename); hy_sack_free(sack); }
//check a local rpm folder for dependency issues. uint32_t TDNFCheckLocalPackages( PTDNF pTdnf, const char* pszLocalPath ) { uint32_t dwError = 0; int i = 0; char* pszRPMPath = NULL; const char* pszFile = NULL; GDir* pDir = NULL; HySack hSack = NULL; HyPackage hPkg = NULL; HyGoal hGoal = NULL; HyPackageList hPkgList = NULL; if(!pTdnf || !pszLocalPath) { dwError = ERROR_TDNF_INVALID_PARAMETER; BAIL_ON_TDNF_ERROR(dwError); } pDir = g_dir_open(pszLocalPath, 0, NULL); if(!pDir) { dwError = errno; BAIL_ON_TDNF_SYSTEM_ERROR(dwError); } fprintf(stdout, "Checking all packages from: %s\n", pszLocalPath); hSack = hy_sack_create(NULL, NULL, NULL, 0); if(!hSack) { dwError = ERROR_TDNF_INVALID_PARAMETER; BAIL_ON_TDNF_ERROR(dwError); } hy_sack_create_cmdline_repo(hSack); hPkgList = hy_packagelist_create(); if(!hPkgList) { dwError = ERROR_TDNF_INVALID_PARAMETER; BAIL_ON_TDNF_ERROR(dwError); } while ((pszFile = g_dir_read_name (pDir)) != NULL) { if (!g_str_has_suffix (pszFile, TDNF_RPM_EXT)) { continue; } pszRPMPath = g_build_filename(pszLocalPath, pszFile, NULL); hPkg = hy_sack_add_cmdline_package(hSack, pszRPMPath); g_free(pszRPMPath); pszRPMPath = NULL; if(!hPkg) { dwError = ERROR_TDNF_INVALID_PARAMETER; BAIL_ON_TDNF_ERROR(dwError); } hy_packagelist_push(hPkgList, hPkg); hPkg = NULL; } fprintf(stdout, "Found %d packages\n", hy_packagelist_count(hPkgList)); hGoal = hy_goal_create(hSack); if(!hGoal) { dwError = ERROR_TDNF_INVALID_PARAMETER; BAIL_ON_TDNF_ERROR(dwError); } FOR_PACKAGELIST(hPkg, hPkgList, i) { dwError = hy_goal_install(hGoal, hPkg); BAIL_ON_TDNF_HAWKEY_ERROR(dwError); }
int main(int argc, const char **argv) { HySack sack = hy_sack_create(NULL, NULL, NULL, HY_MAKE_CACHE_DIR); 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; 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 = HY_BUILD_CACHE; /* rpmdb */ repo = hy_repo_create(HY_SYSTEM_REPO_NAME); hy_sack_load_system_repo(sack, NULL, load_flags); hy_repo_free(repo); if (need_filelists(argc, argv)) load_flags |= HY_LOAD_FILELISTS; /* Fedora repo */ repo = config_repo("Fedora", md_repo, md_primary_xml, md_filelists); ret = hy_sack_load_yum_repo(sack, repo, load_flags); 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 = hy_sack_load_yum_repo(sack, repo, load_flags); 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); hy_sack_set_installonly(sack, installonly); hy_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]); } hy_sack_free(sack); return 0; }