From 5a05773dfcfbd317e082a8a58edc391d53bed845 Mon Sep 17 00:00:00 2001 From: Marek Blaha Date: Thu, 2 Jul 2020 14:30:34 +0200 Subject: [PATCH 5/5] [debug] Do not remove install-only packages (RhBug:1844533) Running debug-restore command may result in an attempt to remove the running kernel (in case the running kernel package is not present in the dump file). Newly the install-only packages are not removed, only the versions mentioned in the dump file are marked for installation (the decision on what versions to keep on the system is done according to installonly_limit config option). New option `--remove-installonly` to force removal of those versions of install-only packages that are not present in the dump file is introduced. https://bugzilla.redhat.com/show_bug.cgi?id=1844533 --- doc/debug.rst | 18 +++++++++++++++++- plugins/debug.py | 13 +++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/doc/debug.rst b/doc/debug.rst index ee9860f..2f8418f 100644 --- a/doc/debug.rst +++ b/doc/debug.rst @@ -23,7 +23,18 @@ DNF debug Plugin Description ----------- -Writes system RPM configuration to a dump file and restore it. +The plugin provides two dnf commands: + +``debug-dump`` + Writes system RPM configuration to a dump file + +``debug-restore`` + Restore the installed packages to the versions written in the dump file. By + default, it does not remove already installed versions of install-only + packages and only marks those versions that are mentioned in the dump file + for installation. The final decision on which versions to keep on the + system is left to dnf and can be fine-tuned using the `installonly_limit` + (see :manpage:`dnf.conf(5)`) configuration option. .. note:: DNF and Yum debug files are not compatible and thus can't be used by the other program. @@ -70,3 +81,8 @@ All general DNF options are accepted, see `Options` in :manpage:`dnf(8)` for det ``--output`` Only output list of packages which will be installed or removed. No actuall changes are done. + +``--remove-installonly`` + Allow removal of install-only packages. Using this option may result in an + attempt to remove the running kernel version (in situations when the currently + running kernel version is not part of the dump file). diff --git a/plugins/debug.py b/plugins/debug.py index efe6bea..ad136a9 100644 --- a/plugins/debug.py +++ b/plugins/debug.py @@ -194,6 +194,10 @@ class DebugRestoreCommand(dnf.cli.Command): "--filter-types", metavar="[install, remove, replace]", default="install, remove, replace", help=_("limit to specified type")) + parser.add_argument( + "--remove-installonly", action="store_true", + help=_('Allow removing of install-only packages. Using this option may ' + 'result in an attempt to remove the running kernel.')) parser.add_argument( "filename", nargs=1, help=_("name of dump file")) @@ -238,10 +242,11 @@ class DebugRestoreCommand(dnf.cli.Command): # package should not be installed pkg_remove = True if pkg_remove and "remove" in opts.filter_types: - if opts.output: - print("remove %s" % spec) - else: - self.base.package_remove(pkg) + if pkg not in installonly_pkgs or opts.remove_installonly: + if opts.output: + print("remove %s" % spec) + else: + self.base.package_remove(pkg) def process_dump(self, dump_pkgs, opts): for (n, a) in sorted(dump_pkgs.keys()): -- 2.25.4