Esempio n. 1
0
DnfPackageSet *
pyseq_to_packageset(PyObject *obj, DnfSack *sack)
{
    PyObject *sequence = PySequence_Fast(obj, "Expected a sequence.");
    if (sequence == NULL)
        return NULL;
    DnfPackageSet *pset = dnf_packageset_new(sack);

    const unsigned count = PySequence_Size(sequence);
    for (unsigned int i = 0; i < count; ++i) {
        PyObject *item = PySequence_Fast_GET_ITEM(sequence, i);
        if (item == NULL)
            goto fail;
        DnfPackage *pkg = packageFromPyObject(item);
        if (pkg == NULL)
            goto fail;
        dnf_packageset_add(pset, pkg);
    }

    Py_DECREF(sequence);
    return pset;
 fail:
    g_object_unref(pset);
    Py_DECREF(sequence);
    return NULL;
}
Esempio n. 2
0
END_TEST

START_TEST(test_goal_protected)
{
    DnfSack *sack = test_globals.sack;
    DnfPackageSet *protected = dnf_packageset_new(sack);
    DnfPackage *pkg = by_name_repo(sack, "penny-lib", HY_SYSTEM_REPO_NAME);
    DnfPackage *pp = by_name_repo(sack, "flying", HY_SYSTEM_REPO_NAME);
    const char *expected;
    g_autofree gchar *problem;

    // when protected_packages set is empty it should remove both packages
    HyGoal goal = hy_goal_create(sack);
    DnfPackageSet *empty = dnf_packageset_new(sack);
    dnf_goal_set_protected(goal, empty);
    g_object_unref(empty);
    hy_goal_erase(goal, pkg);
    fail_if(hy_goal_run_flags(goal, DNF_ALLOW_UNINSTALL));
    assert_iueo(goal, 0, 0, 2, 0);
    hy_goal_free(goal);

    // fails to uninstall penny-lib because flying is protected
    goal = hy_goal_create(sack);
    dnf_packageset_add(protected, pp);
    dnf_goal_set_protected(goal, protected);
    hy_goal_erase(goal, pkg);
    fail_unless(hy_goal_run_flags(goal, DNF_ALLOW_UNINSTALL));
    hy_goal_free(goal);

    // removal of protected package explicitly should trigger error
    goal = hy_goal_create(sack);
    dnf_goal_set_protected(goal, protected);
    hy_goal_erase(goal, pp);
    fail_unless(hy_goal_run(goal));
    fail_unless(hy_goal_count_problems(goal) == 1);
    problem = hy_goal_describe_problem(goal, 0);
    expected = "The operation would result in removing "
        "the following protected packages: flying";
    fail_if(g_strcmp0(problem, expected));
    hy_goal_free(goal);

    g_object_unref(protected);
    g_object_unref(pkg);
    g_object_unref(pp);
}