Esempio n. 1
0
File: hth.c Progetto: Tojaj/hawkey
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);
}
Esempio n. 2
0
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);
}
Esempio n. 3
0
File: hth.c Progetto: Tojaj/hawkey
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);
}
Esempio n. 4
0
static void
erase(HifSack *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);

    GPtrArray *plist = hy_query_run(q);
    if (plist->len < 1) {
        printf("No installed package to erase found.\n");
        goto finish;
    }
    if (plist->len > 1)
        printf("(more than one updatables found, selecting the first one)\n");

    HyGoal goal = hy_goal_create(sack);
    hy_goal_erase(goal, g_ptr_array_index(plist, 0));

    if (hy_goal_run(goal)) {
        dump_goal_errors(goal);
        hy_goal_free(goal);
        goto finish;
    }
    g_ptr_array_unref(plist);
    plist = hy_goal_list_erasures(goal, NULL);
    printf("erasure count: %d\n", plist->len);
    for (unsigned int i = 0; i < plist->len; ++i) {
        HifPackage *pkg = g_ptr_array_index(plist, i);
        const char *nvra = hif_package_get_nevra(pkg);

        printf("erasing %s\n", nvra);
    }

    hy_goal_free(goal);
finish:
    g_ptr_array_unref(plist);
    hy_query_free(q);
}