diff --git a/libdnf5/base/goal.cpp b/libdnf5/base/goal.cpp index c42875ad7f..69b8f42a82 100644 --- a/libdnf5/base/goal.cpp +++ b/libdnf5/base/goal.cpp @@ -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; @@ -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 @@ -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);