static GPtrArray * query_all_packages_in_sack (RpmOstreeRefSack *rsack) { HyQuery hquery = NULL; g_autoptr(GPtrArray) pkglist = NULL; GPtrArray *result; int i, c; hquery = hy_query_create (rsack->sack); hy_query_filter (hquery, HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME); pkglist = hy_query_run (hquery); result = g_ptr_array_new_with_free_func (g_object_unref); c = pkglist->len; for (i = 0; i < c; i++) { DnfPackage *pkg = pkglist->pdata[i]; g_ptr_array_add (result, _rpm_ostree_package_new (rsack, pkg)); } if (hquery) hy_query_free (hquery); return g_steal_pointer (&result); }
END_TEST START_TEST(test_query_apply) { HySack sack = test_globals.sack; HyQuery q; HyPackageList plist; q = hy_query_create(sack); hy_query_filter(q, HY_PKG_NAME, HY_NOT | HY_GLOB, "j*"); struct _HyQuery _q = *q; fail_unless(_q.result == NULL); ck_assert_int_gt(_q.nfilters, 0); ck_assert_int_eq(_q.applied, 0); hy_query_apply(q); _q = *q; fail_unless(_q.result != NULL); ck_assert_int_eq(_q.nfilters, 0); ck_assert_int_eq(_q.applied, 1); hy_query_filter(q, HY_PKG_NAME, HY_NOT | HY_GLOB, "p*"); _q = *q; fail_unless(_q.result != NULL); ck_assert_int_gt(_q.nfilters, 0); ck_assert_int_eq(_q.applied, 0); plist = hy_query_run(q); ck_assert_int_eq(hy_packagelist_count(plist), 6); hy_packagelist_free(plist); hy_query_free(q); }
uint32_t TDNFQueryTermsHelper( HyPackageList hAccumPkgList, HyQuery hQuery, int nKeyId, const char* pszMatch ) { HyPackageList hPkgList = NULL; HyPackage hPkg = NULL; uint32_t unError = 0; int nIndex = 0; if(!hAccumPkgList || !hQuery || !pszMatch) { unError = ERROR_TDNF_INVALID_PARAMETER; goto error; } unError = hy_query_filter( hQuery, nKeyId, HY_GLOB | HY_ICASE, pszMatch); BAIL_ON_TDNF_HAWKEY_ERROR(unError); hPkgList = hy_query_run(hQuery); if(!hPkgList) { unError = HY_E_IO; BAIL_ON_TDNF_HAWKEY_ERROR(unError); } FOR_PACKAGELIST(hPkg, hPkgList, nIndex) { if (!hy_packagelist_has(hAccumPkgList, hPkg)) { hy_packagelist_push(hAccumPkgList, hy_package_link(hPkg)); } } cleanup: if (hPkgList != NULL) { hy_packagelist_free(hPkgList); } if (hQuery != NULL) { hy_query_clear(hQuery); } return unError; error: goto cleanup; }
static void execute_print(HySack sack, HyQuery q, int show_obsoletes) { HyPackageList plist; plist = hy_query_run(q); const int count = hy_packagelist_count(plist); for (int i = 0; i < count; ++i) { HyPackage pkg = hy_packagelist_get(plist, i); char *nvra = hy_package_get_nevra(pkg); const char *reponame = hy_package_get_reponame(pkg); printf("found package: %s [%s]\n", nvra, reponame); if (strcmp(reponame, HY_SYSTEM_REPO_NAME) == 0) { int type; const unsigned char * hdrid = hy_package_get_hdr_chksum(pkg, &type); char *str = hy_chksum_str(hdrid, type); printf("\tsha1 header id: %s\n", str); hy_free(str); } if (show_obsoletes) { HyReldepList obsoletes = hy_package_get_obsoletes(pkg); HyQuery qobs = hy_query_create(sack); hy_query_filter(qobs, HY_PKG_REPONAME, HY_NEQ, HY_SYSTEM_REPO_NAME); hy_query_filter_reldep_in(qobs, HY_PKG_PROVIDES, obsoletes); HyPackageList olist = hy_query_run(qobs); const int ocount = hy_packagelist_count(olist); for (int j = 0; j < ocount; ++j) { HyPackage opkg = hy_packagelist_get(olist, j); char *onvra = hy_package_get_nevra(opkg); printf("obsoleting: %s\n", onvra); hy_free(onvra); } hy_packagelist_free(olist); hy_query_free(qobs); hy_reldeplist_free(obsoletes); } hy_free(nvra); } hy_packagelist_free(plist); }
END_TEST START_TEST(test_filter_files) { HyQuery q = hy_query_create(test_globals.sack); hy_query_filter(q, HY_PKG_FILE, HY_EQ, "/etc/takeyouaway"); HyPackageList plist = hy_query_run(q); fail_unless(hy_packagelist_count(plist) == 1); HyPackage pkg = hy_packagelist_get(plist, 0); fail_if(strcmp(hy_package_get_name(pkg), "tour")); hy_packagelist_free(plist); hy_query_free(q); q = hy_query_create(test_globals.sack); hy_query_filter(q, HY_PKG_FILE, HY_GLOB, "/usr/*"); plist = hy_query_run(q); fail_unless(hy_packagelist_count(plist) == 2); hy_packagelist_free(plist); hy_query_free(q); }
END_TEST START_TEST(test_filter_latest_archs) { HyQuery q = hy_query_create(test_globals.sack); hy_query_filter(q, HY_PKG_NAME, HY_EQ, "penny-lib"); hy_query_filter_latest_per_arch(q, 1); HyPackageList plist = hy_query_run(q); fail_unless(hy_packagelist_count(plist) == 2); /* both architectures */ hy_query_free(q); hy_packagelist_free(plist); }
static void execute_print(HifSack *sack, HyQuery q, int show_obsoletes) { GPtrArray *plist; plist = hy_query_run(q); const int count = plist->len; for (int i = 0; i < count; ++i) { HifPackage *pkg = g_ptr_array_index(plist, i); const char *nvra = hif_package_get_nevra(pkg); const char *reponame = hif_package_get_reponame(pkg); printf("found package: %s [%s]\n", nvra, reponame); if (strcmp(reponame, HY_SYSTEM_REPO_NAME) == 0) { int type; const unsigned char * hdrid = hif_package_get_hdr_chksum(pkg, &type); char *str = hy_chksum_str(hdrid, type); printf("\tsha1 header id: %s\n", str); g_free(str); } if (show_obsoletes) { HifReldepList *obsoletes = hif_package_get_obsoletes(pkg); HyQuery qobs = hy_query_create(sack); hy_query_filter(qobs, HY_PKG_REPONAME, HY_NEQ, HY_SYSTEM_REPO_NAME); hy_query_filter_reldep_in(qobs, HY_PKG_PROVIDES, obsoletes); GPtrArray *olist = hy_query_run(qobs); const int ocount = olist->len; for (int j = 0; j < ocount; ++j) { HifPackage *opkg = g_ptr_array_index(olist, j); const char *onvra = hif_package_get_nevra(opkg); printf("obsoleting: %s\n", onvra); } g_ptr_array_unref(olist); hy_query_free(qobs); g_object_unref(obsoletes); } } g_ptr_array_unref(plist); }
static DnfPackage * get_available_pkg(DnfSack *sack, const char *name) { HyQuery q = hy_query_create(sack); hy_query_filter(q, HY_PKG_NAME, HY_EQ, name); hy_query_filter(q, HY_PKG_REPONAME, HY_NEQ, HY_SYSTEM_REPO_NAME); GPtrArray *plist = hy_query_run(q); fail_unless(plist->len == 1); DnfPackage *pkg = g_object_ref(g_ptr_array_index(plist, 0)); hy_query_free(q); g_ptr_array_unref(plist); return pkg; }
static HyPackage get_available_pkg(HySack sack, const char *name) { HyQuery q = hy_query_create(sack); hy_query_filter(q, HY_PKG_NAME, HY_EQ, name); hy_query_filter(q, HY_PKG_REPONAME, HY_NEQ, HY_SYSTEM_REPO_NAME); HyPackageList plist = hy_query_run(q); fail_unless(hy_packagelist_count(plist) == 1); HyPackage pkg = hy_packagelist_get_clone(plist, 0); hy_query_free(q); hy_packagelist_free(plist); return pkg; }
END_TEST START_TEST(test_query_provides_in_not_found) { HyPackageList plist; char* provides[] = { "thisisnotgoingtoexist", NULL }; HyQuery q = hy_query_create(test_globals.sack); hy_query_filter_provides_in(q, provides); plist = hy_query_run(q); fail_unless(hy_packagelist_count(plist) == 0); hy_packagelist_free(plist); hy_query_free(q); }
FOR_PACKAGELIST(pkg, new_pkglist, i) { _cleanup_hyquery_ HyQuery query = NULL; _cleanup_hypackagelist_ HyPackageList pkglist = NULL; query = hy_query_create (orig_sack->sack); hy_query_filter (query, HY_PKG_NAME, HY_EQ, hy_package_get_name (pkg)); hy_query_filter (query, HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME); pkglist = hy_query_run (query); if (hy_packagelist_count (pkglist) == 0) g_ptr_array_add (ret_added, _rpm_ostree_package_new (new_sack, pkg)); }
END_TEST START_TEST(test_query_enhances) { HyPackageList plist; HyPackage pkg; HyQuery q = hy_query_create(test_globals.sack); hy_query_filter(q, HY_PKG_ENHANCES, HY_EQ, "flying"); plist = hy_query_run(q); pkg = hy_packagelist_get(plist, 0); ck_assert_str_eq(hy_package_get_name(pkg), "walrus"); hy_query_free(q); hy_packagelist_free(plist); }
END_TEST START_TEST(test_downgrade) { HyQuery q = hy_query_create(test_globals.sack); hy_query_filter(q, HY_PKG_NAME, HY_EQ, "jay"); hy_query_filter_downgrades(q, 1); HyPackageList plist = hy_query_run(q); fail_unless(hy_packagelist_count(plist) == 1); HyPackage pkg = hy_packagelist_get(plist, 0); ck_assert_str_eq(hy_package_get_evr(pkg), "4.9-0"); hy_query_free(q); hy_packagelist_free(plist); }
END_TEST START_TEST(test_upgrade_already_installed) { /* if pkg is installed in two versions and the later is available in repos, it shouldn't show as a possible update. */ HyQuery q = hy_query_create(test_globals.sack); hy_query_filter(q, HY_PKG_NAME, HY_EQ, "jay"); hy_query_filter_upgrades(q, 1); HyPackageList plist = hy_query_run(q); fail_unless(hy_packagelist_count(plist) == 0); hy_query_free(q); hy_packagelist_free(plist); }
END_TEST START_TEST(test_query_supplements) { HyPackageList plist; HyPackage pkg; HyQuery q = hy_query_create(test_globals.sack); hy_query_filter(q, HY_PKG_SUPPLEMENTS, HY_EQ, "flying"); plist = hy_query_run(q); pkg = hy_packagelist_get(plist, 0); ck_assert_str_eq(hy_package_get_name(pkg), "baby"); hy_query_free(q); hy_packagelist_free(plist); }
/* make Sack think k-1-1 is the running kernel */ static Id mock_running_kernel(DnfSack *sack) { HyQuery q = hy_query_create(sack); hy_query_filter(q, HY_PKG_NAME, HY_EQ, "k"); hy_query_filter(q, HY_PKG_EVR, HY_EQ, "1-1"); GPtrArray *plist = hy_query_run(q); fail_unless(plist->len == 1); DnfPackage *pkg = g_object_ref(g_ptr_array_index(plist, 0)); hy_query_free(q); g_ptr_array_unref(plist); Id id = dnf_package_get_id(pkg); g_object_unref(pkg); return id; }
/* make Sack think k-1-1 is the running kernel */ static Id mock_running_kernel(HySack sack) { HyQuery q = hy_query_create(sack); hy_query_filter(q, HY_PKG_NAME, HY_EQ, "k"); hy_query_filter(q, HY_PKG_EVR, HY_EQ, "1-1"); HyPackageList plist = hy_query_run(q); fail_unless(hy_packagelist_count(plist) == 1); HyPackage pkg = hy_packagelist_get_clone(plist, 0); hy_query_free(q); hy_packagelist_free(plist); Id id = package_id(pkg); hy_package_free(pkg); return id; }
static HyPackage get_latest_pkg(HySack sack, const char *name) { HyQuery q = hy_query_create(sack); hy_query_filter(q, HY_PKG_NAME, HY_EQ, name); hy_query_filter(q, HY_PKG_REPONAME, HY_NEQ, HY_SYSTEM_REPO_NAME); hy_query_filter_latest_per_arch(q, 1); HyPackageList plist = hy_query_run(q); fail_unless(hy_packagelist_count(plist) == 1, "get_latest_pkg() failed finding '%s'.", name); HyPackage pkg = hy_packagelist_get_clone(plist, 0); hy_query_free(q); hy_packagelist_free(plist); return pkg; }
END_TEST START_TEST(test_filter_latest) { HyQuery q = hy_query_create(test_globals.sack); hy_query_filter(q, HY_PKG_NAME, HY_EQ, "fool"); hy_query_filter_latest_per_arch(q, 1); HyPackageList plist = hy_query_run(q); fail_unless(hy_packagelist_count(plist) == 1); HyPackage pkg = hy_packagelist_get(plist, 0); fail_if(strcmp(hy_package_get_name(pkg), "fool")); fail_if(strcmp(hy_package_get_evr(pkg), "1-5")); hy_query_free(q); hy_packagelist_free(plist); }
END_TEST START_TEST(test_query_multiple_flags) { HySack sack = test_globals.sack; HyQuery q; HyPackageList plist; q = hy_query_create(sack); hy_query_filter(q, HY_PKG_NAME, HY_NOT | HY_GLOB, "p*"); plist = hy_query_run(q); ck_assert_int_eq(hy_packagelist_count(plist), 8); hy_packagelist_free(plist); hy_query_free(q); }
static void userinstalled(HySack sack, HyGoal goal, const char *name) { HyQuery q = hy_query_create(sack); hy_query_filter(q, HY_PKG_NAME, HY_EQ, name); hy_query_filter(q, HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME); HyPackageList plist = hy_query_run(q); HyPackage pkg; int i; FOR_PACKAGELIST(pkg, plist, i) hy_goal_userinstalled(goal, pkg); hy_packagelist_free(plist); hy_query_free(q); }
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 gboolean print_rpmdb_diff (GFile *oldroot, GFile *newroot, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; _cleanup_hysack_ HySack old_sack = NULL; _cleanup_hypackagelist_ HyPackageList old_pkglist = NULL; _cleanup_hysack_ HySack new_sack = NULL; _cleanup_hypackagelist_ HyPackageList new_pkglist = NULL; guint i; HyPackage pkg; gboolean printed_header = FALSE; if (!rpmostree_get_pkglist_for_root (oldroot, &old_sack, &old_pkglist, cancellable, error)) goto out; if (!rpmostree_get_pkglist_for_root (newroot, &new_sack, &new_pkglist, cancellable, error)) goto out; printed_header = FALSE; FOR_PACKAGELIST(pkg, new_pkglist, i) { _cleanup_hyquery_ HyQuery query = NULL; _cleanup_hypackagelist_ HyPackageList pkglist = NULL; query = hy_query_create (old_sack); hy_query_filter (query, HY_PKG_NAME, HY_EQ, hy_package_get_name (pkg)); hy_query_filter (query, HY_PKG_EVR, HY_NEQ, hy_package_get_evr (pkg)); hy_query_filter (query, HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME); pkglist = hy_query_run (query); if (hy_packagelist_count (pkglist) > 0) { gs_free char *nevra = hy_package_get_nevra (pkg); if (!printed_header) { g_print ("Changed:\n"); printed_header = TRUE; } g_print (" %s\n", nevra); } }
static void userinstalled(DnfSack *sack, HyGoal goal, const char *name) { HyQuery q = hy_query_create(sack); hy_query_filter(q, HY_PKG_NAME, HY_EQ, name); hy_query_filter(q, HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME); GPtrArray *plist = hy_query_run(q); DnfPackage *pkg; guint i; for(i = 0; i < plist->len; i++) { pkg = g_ptr_array_index (plist, i); hy_goal_userinstalled(goal, pkg); } g_ptr_array_unref(plist); hy_query_free(q); }
END_TEST START_TEST(test_query_nevra) { HySack sack = test_globals.sack; HyQuery q; HyPackageList plist; q = hy_query_create(sack); hy_query_filter(q, HY_PKG_NEVRA, HY_EQ, "penny-4-1.noarch"); plist = hy_query_run(q); ck_assert_int_eq(hy_packagelist_count(plist), 1); HyPackage pkg1 = hy_packagelist_get(plist, 0); char *nevra1 = hy_package_get_nevra(pkg1); ck_assert_str_eq(nevra1, "penny-4-1.noarch"); solv_free(nevra1); hy_packagelist_free(plist); hy_query_free(q); }
FOR_PACKAGELIST(pkg, new_pkglist, i) { _cleanup_hyquery_ HyQuery query = NULL; _cleanup_hypackagelist_ HyPackageList pkglist = NULL; query = hy_query_create (old_sack); hy_query_filter (query, HY_PKG_NAME, HY_EQ, hy_package_get_name (pkg)); hy_query_filter (query, HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME); pkglist = hy_query_run (query); if (hy_packagelist_count (pkglist) == 0) { gs_free char *nevra = hy_package_get_nevra (pkg); if (!printed_header) { g_print ("Added:\n"); printed_header = TRUE; } g_print (" %s\n", nevra); } }
static void update_remote(HySack sack, const char *name) { HyQuery q = hy_query_create(sack); HyPackageList plist; hy_query_filter(q, HY_PKG_NAME, HY_EQ, name); hy_query_filter(q, HY_PKG_REPONAME, HY_NEQ, HY_SYSTEM_REPO_NAME); hy_query_filter_latest_per_arch(q, 1); plist = hy_query_run(q); if (hy_packagelist_count(plist) == 0) { printf("no updatables found\n"); goto finish; } if (hy_packagelist_count(plist) > 1) printf("(more than one updatables found, selecting the first one)\n"); update(sack, hy_packagelist_get(plist, 0)); finish: hy_packagelist_free(plist); hy_query_free(q); }
static void update_remote(HifSack *sack, const char *name) { HyQuery q = hy_query_create(sack); GPtrArray *plist; hy_query_filter(q, HY_PKG_NAME, HY_EQ, name); hy_query_filter(q, HY_PKG_REPONAME, HY_NEQ, HY_SYSTEM_REPO_NAME); hy_query_filter_latest_per_arch(q, 1); plist = hy_query_run(q); if (plist->len == 0) { printf("no updatables found\n"); goto finish; } if (plist->len > 1) printf("(more than one updatables found, selecting the first one)\n"); update(sack, g_ptr_array_index(plist, 0)); finish: g_ptr_array_unref(plist); hy_query_free(q); }
END_TEST START_TEST(test_query_provides_in) { HyPackage pkg; HyPackageList plist; char* pkg_names[] = { "P", "fool <= 2.0", "fool-lib > 3-3", NULL }; HyQuery q = hy_query_create(test_globals.sack); hy_query_filter_provides_in(q, pkg_names); plist = hy_query_run(q); pkg = hy_packagelist_get(plist, 0); ck_assert_str_eq(hy_package_get_name(pkg), "fool"); ck_assert_str_eq(hy_package_get_evr(pkg), "1-3"); pkg = hy_packagelist_get(plist, 1); ck_assert_str_eq(hy_package_get_name(pkg), "penny"); pkg = hy_packagelist_get(plist, 2); ck_assert_str_eq(hy_package_get_name(pkg), "fool"); ck_assert_str_eq(hy_package_get_evr(pkg), "1-5"); fail_unless(size_and_free(q) == 3); hy_packagelist_free(plist); }
static void erase(HySack sack, const char *name) { HyQuery q = hy_query_create(sack); hy_query_filter(q, HY_PKG_NAME, HY_EQ, name); hy_query_filter(q, HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME); HyPackageList plist = hy_query_run(q); if (hy_packagelist_count(plist) < 1) { printf("No installed package to erase found.\n"); goto finish; } if (hy_packagelist_count(plist) > 1) printf("(more than one updatables found, selecting the first one)\n"); HyGoal goal = hy_goal_create(sack); hy_goal_erase(goal, hy_packagelist_get(plist, 0)); if (hy_goal_run(goal)) { dump_goal_errors(goal); hy_goal_free(goal); goto finish; } hy_packagelist_free(plist); plist = hy_goal_list_erasures(goal); printf("erasure count: %d\n", hy_packagelist_count(plist)); for (int i = 0; i < hy_packagelist_count(plist); ++i) { HyPackage pkg = hy_packagelist_get(plist, i); char *nvra = hy_package_get_nevra(pkg); printf("erasing %s\n", nvra); hy_free(nvra); } hy_goal_free(goal); finish: hy_packagelist_free(plist); hy_query_free(q); }