From 95bbc1817780298d90149c132f3f47408d03621d Mon Sep 17 00:00:00 2001 From: Filipe Brandenburger Date: Apr 03 2020 19:14:24 +0000 Subject: Backport fixes from PR #1611 add SOURCES/0005-Fix-behavior-of-install-n-command-and-friends.patch This patch includes all the fixes in the commits pushed in: https://github.com/rpm-software-management/dnf/pull/1611 These fixes cover some commands and aliases such as `install-n` and some similar `*-n` commands, also `localinstall` and `list-updateinfo`, in a way that they were behaving like the main command rather than the specific altered behavior from the aliased command. Tested this patched RPM on a CentOS 8 box and confirmed it fixed all the commands by testing it using the same test commands used in the upstream commits. --- diff --git a/SOURCES/0005-Fix-behavior-of-install-n-command-and-friends.patch b/SOURCES/0005-Fix-behavior-of-install-n-command-and-friends.patch new file mode 100644 index 0000000..5531247 --- /dev/null +++ b/SOURCES/0005-Fix-behavior-of-install-n-command-and-friends.patch @@ -0,0 +1,159 @@ +From 9c157b51af2eb2df8ee3d92e20847d4f191bca95 Mon Sep 17 00:00:00 2001 +From: Filipe Brandenburger +Date: Thu, 2 Apr 2020 11:10:13 -0700 +Subject: [PATCH] Fix behavior of `install-n` command and friends + +Commit de9643afbdf5bb (first shipped in dnf 4.2.8) changed opts.command +from a list to a simple string, but code in InstallCommand and other +similar command classes still handled it as if it was a list. + +This broke silently because Python will iterate over a string character +by character, so it never produced a syntax error or an exception that +would be noticed. + +But it broke behavior of the `install-n` form (and related forms on +other commands, many of the `-n` extensions and some other command +aliases or specializations), since they would no longer detect that +command to restrict search of packages. + +Before this commit, this command would (incorrectly) succeed: + $ dnf install-n joe-4.6 + +After this commit: + $ dnf install-n joe-4.6 + No match for argument: joe-4.6 + * Maybe you meant: joe + Error: Unable to find a match: joe-4.6 + +Similarly tested for other commands. + +Pushed upstream as: +https://github.com/rpm-software-management/dnf/pull/1611 + +This should first make it into dnf version 4.2.22 + +Closes: #1611 +Approved by: m-blaha +--- + dnf/cli/commands/autoremove.py | 5 +++-- + dnf/cli/commands/install.py | 16 ++++++++-------- + dnf/cli/commands/remove.py | 5 +++-- + dnf/cli/commands/repoquery.py | 6 ++---- + dnf/cli/commands/updateinfo.py | 4 ++-- + 5 files changed, 18 insertions(+), 18 deletions(-) + +diff --git a/dnf/cli/commands/autoremove.py b/dnf/cli/commands/autoremove.py +index 23603f52..5bd59f20 100644 +--- a/dnf/cli/commands/autoremove.py ++++ b/dnf/cli/commands/autoremove.py +@@ -65,8 +65,9 @@ class AutoremoveCommand(commands.Command): + + def run(self): + if any([self.opts.grp_specs, self.opts.pkg_specs, self.opts.filenames]): +- forms = [self.nevra_forms[command] for command in self.opts.command +- if command in list(self.nevra_forms.keys())] ++ forms = [] ++ if self.opts.command in self.nevra_forms: ++ forms = [self.nevra_forms[self.opts.command]] + + self.base.autoremove(forms, + self.opts.pkg_specs, +diff --git a/dnf/cli/commands/install.py b/dnf/cli/commands/install.py +index 56efef21..38a90b61 100644 +--- a/dnf/cli/commands/install.py ++++ b/dnf/cli/commands/install.py +@@ -74,12 +74,12 @@ class InstallCommand(commands.Command): + nevra_forms = self._get_nevra_forms_from_command() + + self.cli._populate_update_security_filter(self.opts, self.base.sack.query()) +- if self.opts.command == ['localinstall'] and (self.opts.grp_specs or self.opts.pkg_specs): ++ if self.opts.command == 'localinstall' and (self.opts.grp_specs or self.opts.pkg_specs): + self._log_not_valid_rpm_file_paths(self.opts.grp_specs) + if self.base.conf.strict: + raise dnf.exceptions.Error(_('Nothing to do.')) + skipped_grp_specs = [] +- if self.opts.grp_specs and self.opts.command != ['localinstall']: ++ if self.opts.grp_specs and self.opts.command != 'localinstall': + if dnf.base.WITH_MODULES: + try: + module_base = dnf.module.module_base.ModuleBase(self.base) +@@ -108,10 +108,10 @@ class InstallCommand(commands.Command): + self._inform_not_a_valid_combination(skipped_grp_specs) + if self.base.conf.strict: + raise dnf.exceptions.Error(_('Nothing to do.')) +- elif skipped_grp_specs and self.opts.command != ['localinstall']: ++ elif skipped_grp_specs and self.opts.command != 'localinstall': + self._install_groups(skipped_grp_specs) + +- if self.opts.command != ['localinstall']: ++ if self.opts.command != 'localinstall': + errs = self._install_packages(nevra_forms) + + if (len(errs) != 0 or len(err_pkgs) != 0 or error_module_specs) and self.base.conf.strict: +@@ -120,10 +120,10 @@ class InstallCommand(commands.Command): + packages=err_pkgs) + + def _get_nevra_forms_from_command(self): +- return [self.nevra_forms[command] +- for command in self.opts.command +- if command in list(self.nevra_forms.keys()) +- ] ++ if self.opts.command in self.nevra_forms: ++ return [self.nevra_forms[self.opts.command]] ++ else: ++ return [] + + def _log_not_valid_rpm_file_paths(self, grp_specs): + group_names = map(lambda g: '@' + g, grp_specs) +diff --git a/dnf/cli/commands/remove.py b/dnf/cli/commands/remove.py +index f8059e46..5760d758 100644 +--- a/dnf/cli/commands/remove.py ++++ b/dnf/cli/commands/remove.py +@@ -79,8 +79,9 @@ class RemoveCommand(commands.Command): + + def run(self): + +- forms = [self.nevra_forms[command] for command in self.opts.command +- if command in list(self.nevra_forms.keys())] ++ forms = [] ++ if self.opts.command in self.nevra_forms: ++ forms = [self.nevra_forms[self.opts.command]] + + # local pkgs not supported in erase command + self.opts.pkg_specs += self.opts.filenames +diff --git a/dnf/cli/commands/repoquery.py b/dnf/cli/commands/repoquery.py +index f5cb36fe..214abbb2 100644 +--- a/dnf/cli/commands/repoquery.py ++++ b/dnf/cli/commands/repoquery.py +@@ -417,10 +417,8 @@ class RepoQueryCommand(commands.Command): + ) + if self.opts.key: + kwark = {} +- forms = [self.nevra_forms[command] for command in self.opts.command +- if command in list(self.nevra_forms.keys())] +- if forms: +- kwark["forms"] = forms ++ if self.opts.command in self.nevra_forms: ++ kwark["forms"] = [self.nevra_forms[self.opts.command]] + pkgs = [] + query_results = q.filter(empty=True) + for key in self.opts.key: +diff --git a/dnf/cli/commands/updateinfo.py b/dnf/cli/commands/updateinfo.py +index 77923bd8..946398d5 100644 +--- a/dnf/cli/commands/updateinfo.py ++++ b/dnf/cli/commands/updateinfo.py +@@ -112,9 +112,9 @@ class UpdateInfoCommand(commands.Command): + self.cli.demands.available_repos = True + self.cli.demands.sack_activation = True + +- if self.opts.command[0] in self.direct_commands: ++ if self.opts.command in self.direct_commands: + # we were called with direct command +- self.opts.spec_action = self.direct_commands[self.opts.command[0]] ++ self.opts.spec_action = self.direct_commands[self.opts.command] + else: + if self.opts._spec_action: + self.opts.spec_action = self.opts._spec_action +-- +2.25.1 + diff --git a/SPECS/dnf.spec b/SPECS/dnf.spec index 0589b2b..488dd35 100644 --- a/SPECS/dnf.spec +++ b/SPECS/dnf.spec @@ -82,7 +82,7 @@ It supports RPMs, modules and comps groups & environments. Name: dnf Version: 4.2.17 -Release: 3%{?dist} +Release: 4%{?dist} Summary: %{pkg_summary} # For a breakdown of the licensing, see PACKAGE-LICENSING License: GPLv2+ and GPLv2 and GPL @@ -92,6 +92,7 @@ Patch1: 0001-Do-a-substitution-of-variables-in-repo_id-RhBug1748841.patc Patch2: 0002-Fix-and-document-order-of-config-files-in-aliasesd-RhBug1680489.patch Patch3: 0003-doc-Remove-note-about-whitelist.patch Patch4: 0004-Fix-detection-of-the-latest-module-RhBug1781769.patch +Patch5: 0005-Fix-behavior-of-install-n-command-and-friends.patch BuildArch: noarch BuildRequires: cmake @@ -509,6 +510,10 @@ ln -sr %{buildroot}%{confdir}/vars %{buildroot}%{_sysconfdir}/yum/vars %endif %changelog +* Fri Apr 03 2020 Filipe Brandenburger - 4.2.17-4 +- Backport fixes for `install-n` and friends. + Upstream PR #1611: https://github.com/rpm-software-management/dnf/pull/1611 + * Thu Dec 12 2019 Pavla Kratochvilova - 4.2.17-3 - Do a substitution of variables in repo_id (RhBug:1748841) - Respect order of config files in aliases.d (RhBug:1680489)