From b17230354de4d0834b9af4c65b502e9c357dd117 Mon Sep 17 00:00:00 2001 From: Evan Goode Date: Mon, 17 Jul 2023 20:37:46 +0000 Subject: [PATCH] Allow obsoletion of protected packages This is the libdnf5 companion to https://github.com/rpm-software-management/libdnf/pull/1610; if we change DNF 4, then we should also change DNF 5. There should be some mechanism for replacing even protected packages, e.g. to upgrade DNF to DNF 5. We unprotected dnf to allow this upgrade, but that solution isn't perfect; DNF 5 should be able to remove python3-dnf[1] and DNF 4 should not be able to remove DNF without installing DNF 5. @m-blaha proposed "implementing a hard-coded self-protection for each package manager", i.e. adding back the hardcoded protection of dnf and python3-dnf in DNF 4 and adding a protection of dnf5 in DNF 5. So if we want to do this, it seems we would need to allow obsoletion of protected packages to allow DNF 4 to obsolete dnf with dnf5. --- libdnf5/rpm/solv/goal_private.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/libdnf5/rpm/solv/goal_private.cpp b/libdnf5/rpm/solv/goal_private.cpp index 12cc29cc3..89da492ca 100644 --- a/libdnf5/rpm/solv/goal_private.cpp +++ b/libdnf5/rpm/solv/goal_private.cpp @@ -571,8 +571,7 @@ libdnf5::GoalProblem GoalPrivate::protected_in_removals() { return ret; } auto removes = list_removes(); - auto obsoleted = list_obsoleted(); - if (removes.empty() && obsoleted.empty()) { + if (removes.empty()) { removal_of_protected.reset(); return ret; } @@ -580,11 +579,8 @@ libdnf5::GoalProblem GoalPrivate::protected_in_removals() { auto & pool = get_rpm_pool(); libdnf5::solv::SolvMap pkg_remove_list(pool->nsolvables); - for (auto index = 0; index < removes.size(); ++index) { - pkg_remove_list.add_unsafe(removes[index]); - } - for (auto index = 0; index < obsoleted.size(); ++index) { - pkg_remove_list.add_unsafe(obsoleted[index]); + for (const auto & remove : removes) { + pkg_remove_list.add_unsafe(remove); } libdnf5::solv::SolvMap protected_pkgs(pool->nsolvables);