#1 Backport fixes from PR #1611
Closed 3 years ago by carlwgeorge. Opened 4 years ago by filbranden.
rpms/ filbranden/dnf fix-install-n  into  c8s

@@ -0,0 +1,159 @@ 

+ From 9c157b51af2eb2df8ee3d92e20847d4f191bca95 Mon Sep 17 00:00:00 2001

+ From: Filipe Brandenburger <filbranden@fb.com>

+ 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

+ 

file modified
+6 -1
@@ -82,7 +82,7 @@ 

  

  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 @@ 

  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 @@ 

  %endif

  

  %changelog

+ * Fri Apr 03 2020 Filipe Brandenburger <filbranden@gmail.com> - 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 <pkratoch@redhat.com> - 4.2.17-3

  - Do a substitution of variables in repo_id (RhBug:1748841)

  - Respect order of config files in aliases.d (RhBug:1680489)

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.

Thanks for submitting this Filipe. We won't be able to merge this directly here, but I've opened rhbz#1821524 to get the dnf maintainers attention on the matter.

Thanks Carl! cc'd myself to that bug, I'll follow the progress over there. Feel free to close the PR if you like.

Pull-Request has been closed by arrfab

4 years ago

Pull-Request has been reopened by bstinson

4 years ago

Reopening this to wait on a potential build in CentOS Stream

@filbranden We're going to keep this open for reference until we get the appropriate fix released into CentOS Stream. Sorry for the confusion.

This was fixed in dnf-4.2.23-1.el8 internally and has been available in CentOS Stream since dnf-4.2.23-2.el8 was released back in July.

Pull-Request has been closed by carlwgeorge

3 years ago