dcavalca / rpms / dnf

Forked from rpms/dnf 2 years ago
Clone

Blame SOURCES/0004-Prevent-switching-modules-in-all-cases-RhBug1706215.patch

1f580a
From d53492bea1ed9c08710af75c54abea9a69f82757 Mon Sep 17 00:00:00 2001
0f2fcc
From: Jaroslav Mracek <jmracek@redhat.com>
1f580a
Date: Wed, 19 Jun 2019 12:42:31 +0200
1f580a
Subject: [PATCH] Prevent switching modules in all cases (RhBug:1706215)
0f2fcc
1f580a
The test moved into cli/do_transaction() allows to apply the restriction
1f580a
for all commands.
1f580a
1f580a
https://bugzilla.redhat.com/show_bug.cgi?id=1706215
0f2fcc
---
1f580a
 dnf/cli/cli.py             | 16 ++++++++++++++++
1f580a
 dnf/cli/commands/module.py | 23 -----------------------
1f580a
 2 files changed, 16 insertions(+), 23 deletions(-)
0f2fcc
1f580a
diff --git a/dnf/cli/cli.py b/dnf/cli/cli.py
1f580a
index 09642d1..6ac18fa 100644
1f580a
--- a/dnf/cli/cli.py
1f580a
+++ b/dnf/cli/cli.py
1f580a
@@ -142,6 +142,13 @@ def print_versions(pkgs, base, output):
1f580a
         #                                    sm_ui_date(pkg.committime)))
1f580a
 
0f2fcc
 
0f2fcc
+def report_module_switch(switchedModules):
0f2fcc
+    msg1 = _("The operation would result in switching of module '{0}' stream '{1}' to "
0f2fcc
+             "stream '{2}'")
0f2fcc
+    for moduleName, streams in switchedModules.items():
0f2fcc
+        logger.warning(msg1.format(moduleName, streams[0], streams[1]))
0f2fcc
+
0f2fcc
+
1f580a
 class BaseCli(dnf.Base):
1f580a
     """This is the base class for yum cli."""
0f2fcc
 
1f580a
@@ -157,6 +164,15 @@ class BaseCli(dnf.Base):
1f580a
         :param display: `rpm.callback.TransactionProgress` object(s)
1f580a
         :return: history database transaction ID or None
1f580a
         """
1f580a
+        if dnf.base.WITH_MODULES:
1f580a
+            switchedModules = dict(self._moduleContainer.getSwitchedStreams())
0f2fcc
+            if switchedModules:
0f2fcc
+                report_module_switch(switchedModules)
0f2fcc
+                msg = _("It is not possible to switch enabled streams of a module.\n"
0f2fcc
+                        "It is recommended to remove all installed content from the module, and "
0f2fcc
+                        "reset the module using 'dnf module reset <module_name>' command. After "
1f580a
+                        "you reset the module, you can install the other stream.")
0f2fcc
+                raise dnf.exceptions.Error(msg)
0f2fcc
 
1f580a
         trans = self.transaction
1f580a
         pkg_str = self.output.list_transaction(trans)
1f580a
diff --git a/dnf/cli/commands/module.py b/dnf/cli/commands/module.py
1f580a
index 143bfaa..acaa42c 100644
1f580a
--- a/dnf/cli/commands/module.py
1f580a
+++ b/dnf/cli/commands/module.py
1f580a
@@ -32,13 +32,6 @@ import dnf.module.module_base
1f580a
 import dnf.exceptions
1f580a
 
1f580a
 
1f580a
-def report_module_switch(switchedModules):
1f580a
-    msg1 = _("The operation would result in switching of module '{0}' stream '{1}' to "
1f580a
-             "stream '{2}'")
1f580a
-    for moduleName, streams in switchedModules.items():
1f580a
-        logger.warning(msg1.format(moduleName, streams[0], streams[1]))
1f580a
-
1f580a
-
1f580a
 class ModuleCommand(commands.Command):
1f580a
     class SubCommand(commands.Command):
1f580a
 
1f580a
@@ -122,14 +115,6 @@ class ModuleCommand(commands.Command):
1f580a
                             libdnf.module.ModulePackageContainer.ModuleErrorType_ERROR_IN_DEFAULTS:
1f580a
                         raise e
1f580a
                 logger.error(str(e))
1f580a
-            switchedModules = dict(self.base._moduleContainer.getSwitchedStreams())
1f580a
-            if switchedModules:
1f580a
-                report_module_switch(switchedModules)
1f580a
-                msg = _("It is not possible to switch enabled streams of a module.\n"
1f580a
-                        "It is recommended to remove all installed content from the module, and "
1f580a
-                        "reset the module using 'dnf module reset <module_name>' command. After "
1f580a
-                        "you reset the module, you can enable the other stream.")
1f580a
-                raise dnf.exceptions.Error(msg)
1f580a
 
0f2fcc
     class DisableSubCommand(SubCommand):
0f2fcc
 
1f580a
@@ -193,14 +178,6 @@ class ModuleCommand(commands.Command):
0f2fcc
                     if e.no_match_group_specs or e.error_group_specs:
0f2fcc
                         raise e
0f2fcc
                 logger.error(str(e))
1f580a
-            switchedModules = dict(self.base._moduleContainer.getSwitchedStreams())
1f580a
-            if switchedModules:
1f580a
-                report_module_switch(switchedModules)
1f580a
-                msg = _("It is not possible to switch enabled streams of a module.\n"
1f580a
-                        "It is recommended to remove all installed content from the module, and "
1f580a
-                        "reset the module using 'dnf module reset <module_name>' command. After "
1f580a
-                        "you reset the module, you can install the other stream.")
1f580a
-                raise dnf.exceptions.Error(msg)
0f2fcc
 
0f2fcc
     class UpdateSubCommand(SubCommand):
0f2fcc
 
0f2fcc
--
1f580a
libgit2 0.28.2
0f2fcc