Skip to content

Commit

Permalink
goal: Do not add lower versions to upgrade jobs
Browse files Browse the repository at this point in the history
For UPGRADE* actions, do not add packages that are older than the
currently installed versions to the libsolv job. This decreases the
number of potential solutions and helps resolve some edge cases.

See https://issues.redhat.com/browse/RHEL-1448 for one of those edge
cases.
  • Loading branch information
m-blaha committed Sep 7, 2023
1 parent 93c18cf commit f62ab7f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions libdnf5/base/goal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,9 @@ GoalProblem Goal::Impl::add_specs_to_goal(base::Transaction & transaction) {
// Make the smallest possible upgrade
if (action == GoalAction::UPGRADE_ALL_MINIMAL) {
query.filter_earliest_evr();
} else {
// remove packages of lower version than installed
query.filter_upgrades();
}

libdnf5::solv::IdQueue upgrade_ids;
Expand Down Expand Up @@ -1458,8 +1461,13 @@ GoalProblem Goal::Impl::add_up_down_distrosync_to_goal(

switch (action) {
case GoalAction::UPGRADE_MINIMAL:
case GoalAction::UPGRADE:
case GoalAction::UPGRADE: {
query.filter_available();
// remove packages of lower version than installed. Substract downgrades
// instead of filter_upgrades() to keep obsoletes in the query.
rpm::PackageQuery tmp_downgrades(query);
tmp_downgrades.filter_downgrades();
query.difference(tmp_downgrades);
// Given that we use libsolv's targeted transactions, we need to ensure that the transaction contains both
// the new targeted version and also the current installed version (for the upgraded package). This is
// because if it only contained the new version, libsolv would decide to reinstall the package even if it
Expand All @@ -1480,7 +1488,7 @@ GoalProblem Goal::Impl::add_up_down_distrosync_to_goal(
query |= all_installed;
solv_map_to_id_queue(tmp_queue, *query.p_impl);
rpm_goal.add_upgrade(tmp_queue, best, clean_requirements_on_remove);
break;
} break;
case GoalAction::DISTRO_SYNC:
solv_map_to_id_queue(tmp_queue, *query.p_impl);
rpm_goal.add_distro_sync(tmp_queue, skip_broken, best, clean_requirements_on_remove);
Expand Down

0 comments on commit f62ab7f

Please sign in to comment.