Skip to content

Commit

Permalink
Add support of exclude_from_weak into Goal
Browse files Browse the repository at this point in the history
Exclude_from_weak only prevents packages to be used to satisfy
recommend and supplement dependencies.

= changelog =
msg: Add support for excluding packages to be installed as weak dependencies
type: enhancement
related: https://bugzilla.redhat.com/show_bug.cgi?id=1699672
  • Loading branch information
j-mracek authored and pkratoch committed Sep 30, 2021
1 parent d8d2703 commit e53dc41
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
2 changes: 1 addition & 1 deletion libdnf.spec
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%global libsolv_version 0.7.17
%global libsolv_version 0.7.20
%global libmodulemd_version 2.13.0
%global librepo_version 1.13.1
%global dnf_conflict 4.3.0
Expand Down
2 changes: 2 additions & 0 deletions libdnf/goal/Goal-private.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "Goal.hpp"
#include "IdQueue.hpp"
#include "../sack/packageset.hpp"

namespace libdnf {

Expand All @@ -37,6 +38,7 @@ class Goal::Impl {

DnfSack *sack;
Queue staging;
PackageSet exclude_from_weak;
Solver *solv{nullptr};
::Transaction *trans{nullptr};
DnfGoalActions actions{DNF_NONE};
Expand Down
22 changes: 20 additions & 2 deletions libdnf/goal/Goal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ erase_flags2libsolv(int flags)
Goal::Goal(const Goal & goal_src) : pImpl(new Impl(*goal_src.pImpl)) {}

Goal::Impl::Impl(const Goal::Impl & goal_src)
: sack(goal_src.sack)
: sack(goal_src.sack), exclude_from_weak(goal_src.exclude_from_weak)
{
queue_init_clone(&staging, const_cast<Queue *>(&goal_src.staging));

Expand All @@ -649,7 +649,7 @@ Goal::Impl::Impl(const Goal::Impl & goal_src)
}

Goal::Impl::Impl(DnfSack *sack)
: sack(sack)
: sack(sack), exclude_from_weak(sack)
{
queue_init(&staging);
}
Expand Down Expand Up @@ -793,6 +793,18 @@ Goal::favor(DnfPackage *pkg)
queue_push2(&pImpl->staging, SOLVER_SOLVABLE|SOLVER_FAVOR, dnf_package_get_id(pkg));
}

void
Goal::add_exclude_from_weak(const DnfPackageSet & pset)
{
pImpl->exclude_from_weak += pset;
}

void
Goal::reset_exclude_from_weak()
{
pImpl->exclude_from_weak.clear();
}

void
Goal::disfavor(DnfPackage *pkg)
{
Expand Down Expand Up @@ -1261,6 +1273,12 @@ Goal::Impl::constructJob(DnfGoalActions flags)
elements[i] |= SOLVER_FORCEBEST;
}

// Add weak excludes to the job
Id id = -1;
while ((id = exclude_from_weak.next(id)) != -1) {
job->pushBack(SOLVER_SOLVABLE|SOLVER_EXCLUDEFROMWEAK, id);
}

/* turn off implicit obsoletes for installonly packages */
for (int i = 0; i < (int) dnf_sack_get_installonly(sack)->count; i++)
job->pushBack(SOLVER_MULTIVERSION|SOLVER_SOLVABLE_PROVIDES,
Expand Down
2 changes: 2 additions & 0 deletions libdnf/goal/Goal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ struct Goal {
void install(DnfPackage *new_pkg, bool optional);
void lock(DnfPackage *new_pkg);
void favor(DnfPackage *new_pkg);
void add_exclude_from_weak(const DnfPackageSet & pset);
void reset_exclude_from_weak();
void disfavor(DnfPackage *new_pkg);

/**
Expand Down
21 changes: 21 additions & 0 deletions python/hawkey/goal-py.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,25 @@ add_protected(_GoalObject *self, PyObject *seq) try
Py_RETURN_NONE;
} CATCH_TO_PYTHON

static PyObject *
add_exclude_from_weak(_GoalObject *self, PyObject *seq) try
{
HyGoal goal = self->goal;
auto pset = pyseq_to_packageset(seq, hy_goal_get_sack(goal));
if (!pset)
return NULL;
goal->add_exclude_from_weak(*(pset.get()));
Py_RETURN_NONE;
} CATCH_TO_PYTHON

static PyObject *
reset_exclude_from_weak(_GoalObject *self, PyObject *unused) try
{
HyGoal goal = self->goal;
goal->reset_exclude_from_weak();
Py_RETURN_NONE;
} CATCH_TO_PYTHON

static PyObject *
run(_GoalObject *self, PyObject *args, PyObject *kwds) try
{
Expand Down Expand Up @@ -597,6 +616,8 @@ static struct PyMethodDef goal_methods[] = {
NULL},
{"add_protected", (PyCFunction)add_protected, METH_O,
NULL},
{"add_exclude_from_weak", (PyCFunction)add_exclude_from_weak, METH_O, NULL},
{"reset_exclude_from_weak", (PyCFunction)reset_exclude_from_weak, METH_NOARGS, NULL},
{"distupgrade_all", (PyCFunction)distupgrade_all, METH_NOARGS, NULL},
{"distupgrade", (PyCFunction)distupgrade,
METH_VARARGS | METH_KEYWORDS, NULL},
Expand Down

0 comments on commit e53dc41

Please sign in to comment.