filbranden / rpms / dnf

Forked from rpms/dnf 4 years ago
Clone

Blame SOURCES/0005-Fix-behavior-of-install-n-command-and-friends.patch

95bbc1
From 9c157b51af2eb2df8ee3d92e20847d4f191bca95 Mon Sep 17 00:00:00 2001
95bbc1
From: Filipe Brandenburger <filbranden@fb.com>
95bbc1
Date: Thu, 2 Apr 2020 11:10:13 -0700
95bbc1
Subject: [PATCH] Fix behavior of `install-n` command and friends
95bbc1
95bbc1
Commit de9643afbdf5bb (first shipped in dnf 4.2.8) changed opts.command
95bbc1
from a list to a simple string, but code in InstallCommand and other
95bbc1
similar command classes still handled it as if it was a list.
95bbc1
95bbc1
This broke silently because Python will iterate over a string character
95bbc1
by character, so it never produced a syntax error or an exception that
95bbc1
would be noticed.
95bbc1
95bbc1
But it broke behavior of the `install-n` form (and related forms on
95bbc1
other commands, many of the `-n` extensions and some other command
95bbc1
aliases or specializations), since they would no longer detect that
95bbc1
command to restrict search of packages.
95bbc1
95bbc1
Before this commit, this command would (incorrectly) succeed:
95bbc1
  $ dnf install-n joe-4.6
95bbc1
95bbc1
After this commit:
95bbc1
  $ dnf install-n joe-4.6
95bbc1
  No match for argument: joe-4.6
95bbc1
    * Maybe you meant: joe
95bbc1
  Error: Unable to find a match: joe-4.6
95bbc1
95bbc1
Similarly tested for other commands.
95bbc1
95bbc1
Pushed upstream as:
95bbc1
https://github.com/rpm-software-management/dnf/pull/1611
95bbc1
95bbc1
This should first make it into dnf version 4.2.22
95bbc1
95bbc1
Closes: #1611
95bbc1
Approved by: m-blaha
95bbc1
---
95bbc1
 dnf/cli/commands/autoremove.py |  5 +++--
95bbc1
 dnf/cli/commands/install.py    | 16 ++++++++--------
95bbc1
 dnf/cli/commands/remove.py     |  5 +++--
95bbc1
 dnf/cli/commands/repoquery.py  |  6 ++----
95bbc1
 dnf/cli/commands/updateinfo.py |  4 ++--
95bbc1
 5 files changed, 18 insertions(+), 18 deletions(-)
95bbc1
95bbc1
diff --git a/dnf/cli/commands/autoremove.py b/dnf/cli/commands/autoremove.py
95bbc1
index 23603f52..5bd59f20 100644
95bbc1
--- a/dnf/cli/commands/autoremove.py
95bbc1
+++ b/dnf/cli/commands/autoremove.py
95bbc1
@@ -65,8 +65,9 @@ class AutoremoveCommand(commands.Command):
95bbc1
 
95bbc1
     def run(self):
95bbc1
         if any([self.opts.grp_specs, self.opts.pkg_specs, self.opts.filenames]):
95bbc1
-            forms = [self.nevra_forms[command] for command in self.opts.command
95bbc1
-                     if command in list(self.nevra_forms.keys())]
95bbc1
+            forms = []
95bbc1
+            if self.opts.command in self.nevra_forms:
95bbc1
+                forms = [self.nevra_forms[self.opts.command]]
95bbc1
 
95bbc1
             self.base.autoremove(forms,
95bbc1
                                  self.opts.pkg_specs,
95bbc1
diff --git a/dnf/cli/commands/install.py b/dnf/cli/commands/install.py
95bbc1
index 56efef21..38a90b61 100644
95bbc1
--- a/dnf/cli/commands/install.py
95bbc1
+++ b/dnf/cli/commands/install.py
95bbc1
@@ -74,12 +74,12 @@ class InstallCommand(commands.Command):
95bbc1
         nevra_forms = self._get_nevra_forms_from_command()
95bbc1
 
95bbc1
         self.cli._populate_update_security_filter(self.opts, self.base.sack.query())
95bbc1
-        if self.opts.command == ['localinstall'] and (self.opts.grp_specs or self.opts.pkg_specs):
95bbc1
+        if self.opts.command == 'localinstall' and (self.opts.grp_specs or self.opts.pkg_specs):
95bbc1
             self._log_not_valid_rpm_file_paths(self.opts.grp_specs)
95bbc1
             if self.base.conf.strict:
95bbc1
                 raise dnf.exceptions.Error(_('Nothing to do.'))
95bbc1
         skipped_grp_specs = []
95bbc1
-        if self.opts.grp_specs and self.opts.command != ['localinstall']:
95bbc1
+        if self.opts.grp_specs and self.opts.command != 'localinstall':
95bbc1
             if dnf.base.WITH_MODULES:
95bbc1
                 try:
95bbc1
                     module_base = dnf.module.module_base.ModuleBase(self.base)
95bbc1
@@ -108,10 +108,10 @@ class InstallCommand(commands.Command):
95bbc1
             self._inform_not_a_valid_combination(skipped_grp_specs)
95bbc1
             if self.base.conf.strict:
95bbc1
                 raise dnf.exceptions.Error(_('Nothing to do.'))
95bbc1
-        elif skipped_grp_specs and self.opts.command != ['localinstall']:
95bbc1
+        elif skipped_grp_specs and self.opts.command != 'localinstall':
95bbc1
             self._install_groups(skipped_grp_specs)
95bbc1
 
95bbc1
-        if self.opts.command != ['localinstall']:
95bbc1
+        if self.opts.command != 'localinstall':
95bbc1
             errs = self._install_packages(nevra_forms)
95bbc1
 
95bbc1
         if (len(errs) != 0 or len(err_pkgs) != 0 or error_module_specs) and self.base.conf.strict:
95bbc1
@@ -120,10 +120,10 @@ class InstallCommand(commands.Command):
95bbc1
                                                            packages=err_pkgs)
95bbc1
 
95bbc1
     def _get_nevra_forms_from_command(self):
95bbc1
-        return [self.nevra_forms[command]
95bbc1
-                for command in self.opts.command
95bbc1
-                if command in list(self.nevra_forms.keys())
95bbc1
-                ]
95bbc1
+        if self.opts.command in self.nevra_forms:
95bbc1
+            return [self.nevra_forms[self.opts.command]]
95bbc1
+        else:
95bbc1
+            return []
95bbc1
 
95bbc1
     def _log_not_valid_rpm_file_paths(self, grp_specs):
95bbc1
         group_names = map(lambda g: '@' + g, grp_specs)
95bbc1
diff --git a/dnf/cli/commands/remove.py b/dnf/cli/commands/remove.py
95bbc1
index f8059e46..5760d758 100644
95bbc1
--- a/dnf/cli/commands/remove.py
95bbc1
+++ b/dnf/cli/commands/remove.py
95bbc1
@@ -79,8 +79,9 @@ class RemoveCommand(commands.Command):
95bbc1
 
95bbc1
     def run(self):
95bbc1
 
95bbc1
-        forms = [self.nevra_forms[command] for command in self.opts.command
95bbc1
-                 if command in list(self.nevra_forms.keys())]
95bbc1
+        forms = []
95bbc1
+        if self.opts.command in self.nevra_forms:
95bbc1
+            forms = [self.nevra_forms[self.opts.command]]
95bbc1
 
95bbc1
         # local pkgs not supported in erase command
95bbc1
         self.opts.pkg_specs += self.opts.filenames
95bbc1
diff --git a/dnf/cli/commands/repoquery.py b/dnf/cli/commands/repoquery.py
95bbc1
index f5cb36fe..214abbb2 100644
95bbc1
--- a/dnf/cli/commands/repoquery.py
95bbc1
+++ b/dnf/cli/commands/repoquery.py
95bbc1
@@ -417,10 +417,8 @@ class RepoQueryCommand(commands.Command):
95bbc1
         )
95bbc1
         if self.opts.key:
95bbc1
             kwark = {}
95bbc1
-            forms = [self.nevra_forms[command] for command in self.opts.command
95bbc1
-                     if command in list(self.nevra_forms.keys())]
95bbc1
-            if forms:
95bbc1
-                kwark["forms"] = forms
95bbc1
+            if self.opts.command in self.nevra_forms:
95bbc1
+                kwark["forms"] = [self.nevra_forms[self.opts.command]]
95bbc1
             pkgs = []
95bbc1
             query_results = q.filter(empty=True)
95bbc1
             for key in self.opts.key:
95bbc1
diff --git a/dnf/cli/commands/updateinfo.py b/dnf/cli/commands/updateinfo.py
95bbc1
index 77923bd8..946398d5 100644
95bbc1
--- a/dnf/cli/commands/updateinfo.py
95bbc1
+++ b/dnf/cli/commands/updateinfo.py
95bbc1
@@ -112,9 +112,9 @@ class UpdateInfoCommand(commands.Command):
95bbc1
         self.cli.demands.available_repos = True
95bbc1
         self.cli.demands.sack_activation = True
95bbc1
 
95bbc1
-        if self.opts.command[0] in self.direct_commands:
95bbc1
+        if self.opts.command in self.direct_commands:
95bbc1
             # we were called with direct command
95bbc1
-            self.opts.spec_action = self.direct_commands[self.opts.command[0]]
95bbc1
+            self.opts.spec_action = self.direct_commands[self.opts.command]
95bbc1
         else:
95bbc1
             if self.opts._spec_action:
95bbc1
                 self.opts.spec_action = self.opts._spec_action
95bbc1
-- 
95bbc1
2.25.1
95bbc1