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_upgrade) { DnfPackage *pkg = get_latest_pkg(test_globals.sack, "fool"); HyGoal goal = hy_goal_create(test_globals.sack); fail_if(hy_goal_upgrade_to_flags(goal, pkg, HY_CHECK_INSTALLED)); g_object_unref(pkg); fail_if(hy_goal_run(goal)); assert_iueo(goal, 0, 1, 0, 1); hy_goal_free(goal); }
END_TEST START_TEST(test_goal_update_impossible) { DnfPackage *pkg = get_latest_pkg(test_globals.sack, "walrus"); fail_if(pkg == NULL); HyGoal goal = hy_goal_create(test_globals.sack); // can not try an update, walrus is not installed: fail_unless(hy_goal_upgrade_to_flags(goal, pkg, HY_CHECK_INSTALLED)); g_object_unref(pkg); hy_goal_free(goal); }
static void update(HifSack *sack, HifPackage *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 GPtrArray *plist = hy_goal_list_upgrades(goal, NULL); printf("upgrade count: %d\n", plist->len); for (unsigned int i = 0; i < plist->len; ++i) { HifPackage *upkg = g_ptr_array_index(plist, i); const char *nvra = hif_package_get_nevra(upkg); char *location = hif_package_get_location(upkg); GPtrArray *obsoleted = hy_goal_list_obsoleted_by_package(goal, upkg); HifPackage *installed = g_ptr_array_index(obsoleted, 0); const char *nvra_installed = hif_package_get_nevra(installed); printf("upgrading: %s using %s\n", nvra, location); printf("\tfrom: %s\n", nvra_installed); printf("\tsize: %lu kB\n", hif_package_get_size(upkg) / 1024); g_ptr_array_unref(obsoleted); g_free(location); } g_ptr_array_unref(plist); // handle installs plist = hy_goal_list_installs(goal, NULL); printf("install count: %d\n", plist->len); for (unsigned int i = 0; i < plist->len; ++i) { HifPackage *ipkg = g_ptr_array_index(plist, i); const char *nvra = hif_package_get_nevra(ipkg); char *location = hif_package_get_location(ipkg); printf("installing: %s using %s\n", nvra, location); printf("\tsize: %lu kB\n", hif_package_get_size(ipkg) / 1024); g_free(location); } g_ptr_array_unref(plist); finish: hy_goal_free(goal); }
END_TEST START_TEST(test_goal_installonly) { const char *installonly[] = {"fool", NULL}; DnfSack *sack = test_globals.sack; dnf_sack_set_installonly(sack, installonly); dnf_sack_set_installonly_limit(sack, 2); DnfPackage *pkg = get_latest_pkg(sack, "fool"); HyGoal goal = hy_goal_create(sack); fail_if(hy_goal_upgrade_to_flags(goal, pkg, HY_CHECK_INSTALLED)); g_object_unref(pkg); fail_if(hy_goal_run(goal)); assert_iueo(goal, 1, 0, 1, 0); hy_goal_free(goal); }
static PyObject * upgrade_to(_GoalObject *self, PyObject *args, PyObject *kwds) { HifPackage *pkg = NULL; HySelector sltr = NULL; int ret; int flags = 0; if (!args_pkg_sltr_parse(args, kwds, &pkg, &sltr, &flags, HY_CHECK_INSTALLED)) return NULL; if (sltr) { ret = hy_goal_upgrade_to_selector(self->goal, sltr); return op_ret2exc(ret); } ret = hy_goal_upgrade_to_flags(self->goal, pkg, flags); return op_ret2exc(ret); }