Skip to content

Commit

Permalink
goal: Better handling of obsoleted pkg installation
Browse files Browse the repository at this point in the history
In situation where a package exists in multiple versions and some older
version is being obsoleted, any of obsoleters was considered a valid
solution.

The result could be really misleading. For example let's have this package set:

systemd-udev-1.0

systemd-udev-2.0
Obsoletes: systemd-udev < 2

systemd-boot-unsigned-2.0
Obsoletes: systemd-udev < 2

In this case `dnf install systemd-udev` may lead to installation of
systemd-boot-unsigned which is probably not what the user expected. The
reason is the split in the upgrade-path created by obsolete and both
branches - systemd-udev-2.0 and systemd-boot-unsigned-2.0 are considered
valid.

With this patch install command takes into account only obsoleters of
the best version of the package so the `dnf install systemd-udev`
results in correct installation of systemd-udev-2.0 package.
  • Loading branch information
m-blaha authored and j-mracek committed Mar 21, 2023
1 parent 5bc0353 commit fef4d28
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion libdnf/base/goal.cpp
Expand Up @@ -45,8 +45,25 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
namespace {

void add_obsoletes_to_data(const libdnf::rpm::PackageQuery & base_query, libdnf::rpm::PackageSet & data) {
libdnf::rpm::PackageQuery data_query(data);

// In case there is an installed package in the `data` behave consistently
// with upgrade and add all the obsoleters.
libdnf::rpm::PackageQuery installed_data(data_query);
installed_data.filter_installed();

if (installed_data.empty()) {
// If there is no installed package in the `data`, add only obsoleters
// of the latest versions. This should prevent unexpected results in
// case a package has multiple versions and some older version is being
// obsoleted.
// See also https://bugzilla.redhat.com/show_bug.cgi?id=2176263
data_query.filter_priority();
data_query.filter_latest_evr();
}

libdnf::rpm::PackageQuery obsoletes_query(base_query);
obsoletes_query.filter_obsoletes(data);
obsoletes_query.filter_obsoletes(data_query);
data |= obsoletes_query;
}

Expand Down

0 comments on commit fef4d28

Please sign in to comment.