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); }
uint32_t TDNFLoadYumRepo( HySack hSack, HyRepo hRepo, int nFlags ) { uint32_t dwError = 0; if(!hSack || !hRepo) { dwError = ERROR_TDNF_INVALID_PARAMETER; BAIL_ON_TDNF_ERROR(dwError); } dwError = hy_sack_load_yum_repo(hSack, hRepo, nFlags); BAIL_ON_TDNF_HAWKEY_ERROR(dwError); cleanup: return dwError; error: if(hSack) { hy_sack_free(hSack); } goto cleanup; }
END_TEST START_TEST(test_sack_create) { fail_unless(hy_get_errno() == 0); HySack sack = hy_sack_create(test_globals.tmpdir, NULL, NULL, NULL, HY_MAKE_CACHE_DIR); fail_if(sack == NULL, NULL); fail_if(sack_pool(sack) == NULL, NULL); hy_sack_free(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); }
uint32_t TDNFRefreshCache( PTDNF pTdnf ) { uint32_t dwError = 0; HySack hSack = NULL; if(!pTdnf) { dwError = ERROR_TDNF_INVALID_PARAMETER; BAIL_ON_TDNF_ERROR(dwError); } //Creating a new sack without removing the //old one did not work well. Remove first, then //create if(pTdnf->hSack) { hy_sack_free(pTdnf->hSack); pTdnf->hSack = NULL; } //init with cache dwError = TDNFInitSack(pTdnf, &hSack, HY_LOAD_FILELISTS); BAIL_ON_TDNF_ERROR(dwError); //Do the same for all enabled repos if(pTdnf->pRepos) { PTDNF_REPO_DATA pRepo = pTdnf->pRepos; while(pRepo) { if(pRepo->nEnabled) { hy_repo_free(pRepo->hRepo); pRepo->hRepo = NULL; dwError = TDNFInitRepo(pTdnf, pRepo, &pRepo->hRepo); BAIL_ON_TDNF_ERROR(dwError); } pRepo = pRepo->pNext; } } pTdnf->hSack = hSack; cleanup: return dwError; error: if(hSack) { hy_sack_free(hSack); } if(pTdnf->hSack) { hy_sack_free(pTdnf->hSack); pTdnf->hSack = NULL; } goto cleanup; }
void teardown(void) { hy_sack_free(test_globals.sack); test_globals.sack = NULL; }
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; }
uint32_t TDNFRefreshSack( PTDNF pTdnf, int nCleanMetadata ) { uint32_t dwError = 0; HyRepo hRepo = NULL; int nYumFlags = HY_LOAD_FILELISTS | HY_LOAD_UPDATEINFO; if(!pTdnf) { dwError = ERROR_TDNF_INVALID_PARAMETER; BAIL_ON_TDNF_ERROR(dwError); } if(pTdnf->hSack) { hy_sack_free(pTdnf->hSack); pTdnf->hSack = NULL; } dwError = TDNFInitSack(pTdnf, &pTdnf->hSack, HY_LOAD_FILELISTS); BAIL_ON_TDNF_ERROR(dwError); //If there is an empty repo directory, do nothing if(pTdnf->pRepos) { PTDNF_REPO_DATA pTempRepo = pTdnf->pRepos; while(pTempRepo) { if(pTempRepo->nEnabled) { if(nCleanMetadata) { fprintf(stdout, "Refreshing metadata for: '%s'\n", pTempRepo->pszName); dwError = TDNFRepoRemoveCache(pTdnf, pTempRepo->pszId); if(dwError == ERROR_TDNF_FILE_NOT_FOUND) { dwError = 0;//Ignore non existent folders } BAIL_ON_TDNF_ERROR(dwError); } dwError = TDNFInitRepo(pTdnf, pTempRepo, &hRepo); if(dwError) { if(pTempRepo->nSkipIfUnavailable) { pTempRepo->nEnabled = 0; fprintf(stdout, "Disabling Repo: '%s'\n", pTempRepo->pszName); dwError = 0; } } BAIL_ON_TDNF_ERROR(dwError); if(pTempRepo->nEnabled) { if(pTempRepo->hRepo) { hy_repo_free(pTempRepo->hRepo); pTempRepo->hRepo = NULL; } pTempRepo->hRepo = hRepo; dwError = TDNFLoadYumRepo(pTdnf->hSack, hRepo, nYumFlags); BAIL_ON_TDNF_ERROR(dwError); } } pTempRepo = pTempRepo->pNext; } } cleanup: return dwError; error: goto cleanup; }