/** * hif_package_get_filename: * @pkg: a #HifPackage *instance. * * Gets the package filename. * * Returns: absolute filename, or %NULL * * Since: 0.1.0 **/ const gchar * hif_package_get_filename(HifPackage *pkg) { HifPackagePrivate *priv; priv = hif_package_get_priv(pkg); if (priv == NULL) return NULL; if (hif_package_installed(pkg)) return NULL; /* default cache filename location */ if (priv->filename == NULL && priv->repo != NULL) { priv->filename = g_build_filename(hif_repo_get_location(priv->repo), hif_package_get_location(pkg), NULL); /* set the filename to cachedir for non-local repos */ if (!hif_repo_is_local(priv->repo) || !g_file_test(priv->filename, G_FILE_TEST_EXISTS)) { g_autofree gchar *basename = NULL; basename = g_path_get_basename(hif_package_get_location(pkg)); g_free(priv->filename); priv->filename = g_build_filename(hif_repo_get_packages(priv->repo), basename, NULL); } } return priv->filename; }
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_add_cmdline_package) { HifSack *sack = hif_sack_new(); hif_sack_set_cachedir(sack, test_globals.tmpdir); char *path_mystery = solv_dupjoin(TESTDATADIR, "/hawkey/yum/mystery-devel-19.67-1.noarch.rpm", NULL); HifPackage *pkg_mystery = hif_sack_add_cmdline_package(sack, path_mystery); char *location_mystery = hif_package_get_location(pkg_mystery); ck_assert_str_eq(path_mystery, location_mystery); char *path_tour = solv_dupjoin(TESTDATADIR, "/hawkey/yum/tour-4-6.noarch.rpm", NULL); HifPackage *pkg_tour = hif_sack_add_cmdline_package(sack, path_tour); char *location_tour = hif_package_get_location(pkg_tour); ck_assert_str_eq(path_tour, location_tour); g_free(path_mystery); g_free(location_mystery); g_free(path_tour); g_free(location_tour); g_object_unref(sack); }