autoremove: warn and skip dangling protected dependencies

Resolves: RHEL-76112
This commit is contained in:
Aleš Matěj 2026-02-11 16:26:20 +01:00
parent 409d0252fa
commit b978806b7d
2 changed files with 50 additions and 2 deletions

View File

@ -0,0 +1,43 @@
From bffb669be6d49bd570c3a898aebc3a6dd28abf30 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
Date: Mon, 26 Jan 2026 12:29:11 +0100
Subject: [PATCH] autoremove: warn and skip dangling protected dependencies
Requires new libdnf 0.76.0 API.
---
dnf/base.py | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/dnf/base.py b/dnf/base.py
index 7d3dfdee..a20c18ee 100644
--- a/dnf/base.py
+++ b/dnf/base.py
@@ -2308,9 +2308,23 @@ class Base(object):
logger.warning(_('No packages marked for removal.'))
else:
- pkgs = self.sack.query()._unneeded(self.history.swdb,
+ unneeded_pkgs = self.sack.query()._unneeded(self.history.swdb,
debug_solver=self.conf.debug_solver)
- for pkg in pkgs:
+
+ protected = self.sack.query().installed().filterm(name=self.conf.protected_packages)
+ protected_found = False
+ for pkg in protected:
+ if pkg in unneeded_pkgs:
+ msg = _('Unneeded protected package: %s (and its dependencies) cannot be removed, '
+ 'either mark it as user-installed or change protected_packages configuration option.')
+ logger.warning(msg, pkg)
+ protected_found = True
+
+ if protected_found:
+ unneeded_pkgs = self.sack.query()._unneeded_extra_userinstalled(self.history.swdb, protected,
+ debug_solver=self.conf.debug_solver)
+
+ for pkg in unneeded_pkgs:
self.package_remove(pkg)
def remove(self, pkg_spec, reponame=None, forms=None):
--
2.53.0

View File

@ -22,7 +22,7 @@
%endif
%if 0%{?rhel} == 9
%global hawkey_version 0.69.0-16
%global hawkey_version 0.69.0-18
%endif
# override dependencies for fedora 26
@ -73,7 +73,7 @@ It supports RPMs, modules and comps groups & environments.
Name: dnf
Version: 4.14.0
Release: 32%{?dist}
Release: 33%{?dist}
Summary: %{pkg_summary}
# For a breakdown of the licensing, see PACKAGE-LICENSING
License: GPLv2+
@ -147,6 +147,7 @@ Patch65: 0065-tests-Patch-detect_releasevers-not-detect_releasever.patch
Patch66: 0066-Document-how-releasever-releasever_-major-minor-affe.patch
Patch67: 0067-Move-releasever_minor-setter-docstring-to-the-correc.patch
Patch68: 0068-automatic-Expand-email_to-in-command_email-emitter-t.patch
Patch69: 0069-autoremove-warn-and-skip-dangling-protected-dependen.patch
BuildArch: noarch
BuildRequires: cmake
@ -453,6 +454,10 @@ popd
# bootc subpackage does not include any files
%changelog
* Wed Feb 11 2026 Ales Matej <amatej@redhat.com> - 4.14.0-33
- autoremove: when a dangling protected dependency is found produce a wanrning
and skip it (RHEL-76112)
* Fri Jan 09 2026 Petr Pisar <ppisar@redhat.com> - 4.14.0-32
- automatic: Expand email_to in command_email emitter to individual arguments
(RHEL-94321)