END_TEST START_TEST(test_goal_distupgrade_all_keep_arch) { HyGoal goal = hy_goal_create(test_globals.sack); fail_if(hy_goal_distupgrade_all(goal)); fail_if(hy_goal_run(goal)); assert_iueo(goal, 0, 5, 0, 1); HyPackageList plist = hy_goal_list_upgrades(goal); // gun pkg is not upgraded to latest version of different arch assert_nevra_eq(hy_packagelist_get(plist, 0), "dog-1-2.x86_64"); assert_nevra_eq(hy_packagelist_get(plist, 1), "pilchard-1.2.4-1.i686"); assert_nevra_eq(hy_packagelist_get(plist, 2), "pilchard-1.2.4-1.x86_64"); assert_nevra_eq(hy_packagelist_get(plist, 3), "flying-3.1-0.x86_64"); assert_nevra_eq(hy_packagelist_get(plist, 4), "fool-1-5.noarch"); hy_packagelist_free(plist); plist = hy_goal_list_obsoleted(goal); fail_unless(hy_packagelist_count(plist) == 1); assert_nevra_eq(hy_packagelist_get(plist, 0), "penny-4-1.noarch"); hy_packagelist_free(plist); plist = hy_goal_list_downgrades(goal); fail_unless(hy_packagelist_count(plist) == 1); assert_nevra_eq(hy_packagelist_get(plist, 0), "baby-6:4.9-3.x86_64"); hy_packagelist_free(plist); hy_goal_free(goal); }
END_TEST START_TEST(test_goal_downgrade) { HySack sack = test_globals.sack; HyPackage to_be_pkg = get_available_pkg(sack, "baby"); HyGoal goal = hy_goal_create(sack); hy_goal_downgrade_to(goal, to_be_pkg); fail_if(hy_goal_run(goal)); assert_iueo(goal, 0, 0, 0, 0); HyPackageList plist = hy_goal_list_downgrades(goal); fail_unless(hy_packagelist_count(plist) == 1); HyPackage pkg = hy_packagelist_get(plist, 0); ck_assert_str_eq(hy_package_get_evr(pkg), "6:4.9-3"); HyPackageList obsoleted = hy_goal_list_obsoleted_by_package(goal, pkg); fail_unless(hy_packagelist_count(obsoleted) == 1); HyPackage old_pkg = hy_packagelist_get(obsoleted, 0); ck_assert_str_eq(hy_package_get_evr(old_pkg), "6:5.0-11"); hy_packagelist_free(obsoleted); hy_packagelist_free(plist); hy_goal_free(goal); hy_package_free(to_be_pkg); }
static void update(HySack sack, HyPackage pkg) { HyGoal goal = hy_goal_create(sack); if (hy_goal_upgrade_to_flags(goal, pkg, HY_CHECK_INSTALLED)) { printf("no package of that name installed, trying install\n"); hy_goal_install(goal, pkg); } if (hy_goal_run(goal)) { dump_goal_errors(goal); // handle errors goto finish; } // handle upgrades HyPackageList plist = hy_goal_list_upgrades(goal); printf("upgrade 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); char *location = hy_package_get_location(pkg); HyPackageList obsoleted = hy_goal_list_obsoleted_by_package(goal, pkg); HyPackage installed = hy_packagelist_get(obsoleted, 0); char *nvra_installed = hy_package_get_nevra(installed); printf("upgrading: %s using %s\n", nvra, location); printf("\tfrom: %s\n", nvra_installed); printf("\tsize: %lld kB\n", hy_package_get_size(pkg) / 1024); hy_free(nvra_installed); hy_packagelist_free(obsoleted); hy_free(location); hy_free(nvra); } hy_packagelist_free(plist); // handle installs plist = hy_goal_list_installs(goal); printf("install 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); char *location = hy_package_get_location(pkg); printf("installing: %s using %s\n", nvra, location); printf("\tsize: %lld kB\n", hy_package_get_size(pkg) / 1024); hy_free(location); hy_free(nvra); } hy_packagelist_free(plist); finish: hy_goal_free(goal); }
END_TEST START_TEST(test_goal_unneeded) { HySack sack = test_globals.sack; HyGoal goal = hy_goal_create(sack); userinstalled(sack, goal, "baby"); userinstalled(sack, goal, "dog"); userinstalled(sack, goal, "fool"); userinstalled(sack, goal, "gun"); userinstalled(sack, goal, "jay"); userinstalled(sack, goal, "penny"); userinstalled(sack, goal, "pilchard"); hy_goal_run(goal); HyPackageList plist = hy_goal_list_unneeded(goal); ck_assert_int_eq(hy_packagelist_count(plist), 4); HyPackage pkg = hy_packagelist_get(plist, 0); assert_nevra_eq(pkg, "flying-2-9.noarch"); pkg = hy_packagelist_get(plist, 1); assert_nevra_eq(pkg, "penny-lib-4-1.x86_64"); hy_packagelist_free(plist); hy_goal_free(goal); }
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); }
static int size_and_free(HyPackageList plist) { int c = hy_packagelist_count(plist); hy_packagelist_free(plist); return c; }
END_TEST START_TEST(test_goal_selector_upgrade) { HySelector sltr = hy_selector_create(test_globals.sack); HyGoal goal = hy_goal_create(test_globals.sack); fail_if(hy_selector_set(sltr, HY_PKG_NAME, HY_EQ, "dog")); fail_if(hy_selector_set(sltr, HY_PKG_EVR, HY_EQ, "1-2")); fail_if(hy_goal_upgrade_to_selector(goal, sltr)); fail_if(hy_goal_run(goal)); HyPackageList plist = hy_goal_list_upgrades(goal); fail_unless(hy_packagelist_count(plist) == 1); assert_nevra_eq(hy_packagelist_get(plist, 0), "dog-1-2.x86_64"); hy_packagelist_free(plist); hy_goal_free(goal); hy_selector_free(sltr); sltr = hy_selector_create(test_globals.sack); goal = hy_goal_create(test_globals.sack); fail_if(hy_selector_set(sltr, HY_PKG_NAME, HY_EQ, "pilchard")); fail_if(hy_goal_upgrade_to_selector(goal, sltr)); fail_if(hy_goal_run(goal)); assert_iueo(goal, 0, 2, 0, 0); hy_goal_free(goal); hy_selector_free(sltr); }
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); }
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); }
END_TEST START_TEST(test_sltr_provides_glob) { HySelector sltr = hy_selector_create(test_globals.sack); fail_if(hy_selector_set(sltr, HY_PKG_PROVIDES, HY_GLOB, "*alru*")); HyPackageList plist = hy_selector_matches(sltr); fail_unless(hy_packagelist_count(plist) == 2); hy_packagelist_free(plist); hy_selector_free(sltr); }
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); }
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); }
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; }
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)); }
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); }
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_sltr_version) { HySelector sltr = hy_selector_create(test_globals.sack); fail_if(hy_selector_set(sltr, HY_PKG_NAME, HY_EQ, "jay")); fail_if(hy_selector_set(sltr, HY_PKG_VERSION, HY_EQ, "5.0")); HyPackageList plist = hy_selector_matches(sltr); fail_unless(hy_packagelist_count(plist) == 2); hy_packagelist_free(plist); hy_selector_free(sltr); }
END_TEST START_TEST(test_sltr_reponame_nonexistent) { HySelector sltr = hy_selector_create(test_globals.sack); fail_if(hy_selector_set(sltr, HY_PKG_NAME, HY_GLOB, "*")); fail_if(hy_selector_set(sltr, HY_PKG_REPONAME, HY_EQ, "non-existent")); HyPackageList plist = hy_selector_matches(sltr); fail_unless(hy_packagelist_count(plist) == 0); hy_packagelist_free(plist); hy_selector_free(sltr); }
END_TEST START_TEST(test_sltr_reponame) { HySelector sltr = hy_selector_create(test_globals.sack); fail_if(hy_selector_set(sltr, HY_PKG_NAME, HY_EQ, "penny")); fail_if(hy_selector_set(sltr, HY_PKG_REPONAME, HY_EQ, "main")); HyPackageList plist = hy_selector_matches(sltr); fail_unless(hy_packagelist_count(plist) == 1); hy_packagelist_free(plist); hy_selector_free(sltr); }
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); }
/* 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; }
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); }
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_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); }
END_TEST START_TEST(test_goal_distupgrade_selector_nothing) { HyGoal goal = hy_goal_create(test_globals.sack); HySelector sltr = hy_selector_create(test_globals.sack); hy_selector_set(sltr, HY_PKG_NAME, HY_EQ, "P-lib"); fail_if(hy_goal_distupgrade_selector(goal, sltr)); fail_if(hy_goal_run(goal)); assert_iueo(goal, 0, 0, 0, 0); HyPackageList plist = hy_goal_list_downgrades(goal); fail_unless(hy_packagelist_count(plist) == 0); hy_packagelist_free(plist); hy_goal_free(goal); hy_selector_free(sltr); }
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); } }
END_TEST static void assert_list_names(HyPackageList plist, ...) { va_list names; char *name; int count = hy_packagelist_count(plist), i = 0; va_start(names, plist); while ((name = va_arg(names, char *)) != NULL) { if (i >= count) fail("assert_list_names(): list too short"); HyPackage pkg = hy_packagelist_get(plist, i++); ck_assert_str_eq(hy_package_get_name(pkg), name); } fail_unless(i == count, "assert_list_names(): too many items in the list"); va_end(names); }
END_TEST START_TEST(test_goal_distupgrade_all) { HyGoal goal = hy_goal_create(test_globals.sack); fail_if(hy_goal_distupgrade_all(goal)); fail_if(hy_goal_run(goal)); assert_iueo(goal, 0, 1, 0, 0); HyPackageList plist = hy_goal_list_upgrades(goal); assert_nevra_eq(hy_packagelist_get(plist, 0), "flying-3-0.noarch"); hy_packagelist_free(plist); plist = hy_goal_list_downgrades(goal); fail_unless(hy_packagelist_count(plist) == 1); assert_nevra_eq(hy_packagelist_get(plist, 0), "baby-6:4.9-3.x86_64"); hy_packagelist_free(plist); hy_goal_free(goal); }
END_TEST START_TEST(test_goal_distupgrade_selector_downgrade) { HyGoal goal = hy_goal_create(test_globals.sack); HySelector sltr = hy_selector_create(test_globals.sack); hy_selector_set(sltr, HY_PKG_NAME, HY_EQ, "baby"); fail_if(hy_goal_distupgrade_selector(goal, sltr)); fail_if(hy_goal_run(goal)); assert_iueo(goal, 0, 0, 0, 0); HyPackageList plist = hy_goal_list_downgrades(goal); fail_unless(hy_packagelist_count(plist) == 1); assert_nevra_eq(hy_packagelist_get(plist, 0), "baby-6:4.9-3.x86_64"); hy_packagelist_free(plist); hy_goal_free(goal); hy_selector_free(sltr); }