filbranden / rpms / dnf

Forked from rpms/dnf 4 years ago
Clone
Blob Blame History Raw
From d53492bea1ed9c08710af75c54abea9a69f82757 Mon Sep 17 00:00:00 2001
From: Jaroslav Mracek <jmracek@redhat.com>
Date: Wed, 19 Jun 2019 12:42:31 +0200
Subject: [PATCH] Prevent switching modules in all cases (RhBug:1706215)

The test moved into cli/do_transaction() allows to apply the restriction
for all commands.

https://bugzilla.redhat.com/show_bug.cgi?id=1706215
---
 dnf/cli/cli.py             | 16 ++++++++++++++++
 dnf/cli/commands/module.py | 23 -----------------------
 2 files changed, 16 insertions(+), 23 deletions(-)

diff --git a/dnf/cli/cli.py b/dnf/cli/cli.py
index 09642d1..6ac18fa 100644
--- a/dnf/cli/cli.py
+++ b/dnf/cli/cli.py
@@ -142,6 +142,13 @@ def print_versions(pkgs, base, output):
         #                                    sm_ui_date(pkg.committime)))
 
 
+def report_module_switch(switchedModules):
+    msg1 = _("The operation would result in switching of module '{0}' stream '{1}' to "
+             "stream '{2}'")
+    for moduleName, streams in switchedModules.items():
+        logger.warning(msg1.format(moduleName, streams[0], streams[1]))
+
+
 class BaseCli(dnf.Base):
     """This is the base class for yum cli."""
 
@@ -157,6 +164,15 @@ class BaseCli(dnf.Base):
         :param display: `rpm.callback.TransactionProgress` object(s)
         :return: history database transaction ID or None
         """
+        if dnf.base.WITH_MODULES:
+            switchedModules = dict(self._moduleContainer.getSwitchedStreams())
+            if switchedModules:
+                report_module_switch(switchedModules)
+                msg = _("It is not possible to switch enabled streams of a module.\n"
+                        "It is recommended to remove all installed content from the module, and "
+                        "reset the module using 'dnf module reset <module_name>' command. After "
+                        "you reset the module, you can install the other stream.")
+                raise dnf.exceptions.Error(msg)
 
         trans = self.transaction
         pkg_str = self.output.list_transaction(trans)
diff --git a/dnf/cli/commands/module.py b/dnf/cli/commands/module.py
index 143bfaa..acaa42c 100644
--- a/dnf/cli/commands/module.py
+++ b/dnf/cli/commands/module.py
@@ -32,13 +32,6 @@ import dnf.module.module_base
 import dnf.exceptions
 
 
-def report_module_switch(switchedModules):
-    msg1 = _("The operation would result in switching of module '{0}' stream '{1}' to "
-             "stream '{2}'")
-    for moduleName, streams in switchedModules.items():
-        logger.warning(msg1.format(moduleName, streams[0], streams[1]))
-
-
 class ModuleCommand(commands.Command):
     class SubCommand(commands.Command):
 
@@ -122,14 +115,6 @@ class ModuleCommand(commands.Command):
                             libdnf.module.ModulePackageContainer.ModuleErrorType_ERROR_IN_DEFAULTS:
                         raise e
                 logger.error(str(e))
-            switchedModules = dict(self.base._moduleContainer.getSwitchedStreams())
-            if switchedModules:
-                report_module_switch(switchedModules)
-                msg = _("It is not possible to switch enabled streams of a module.\n"
-                        "It is recommended to remove all installed content from the module, and "
-                        "reset the module using 'dnf module reset <module_name>' command. After "
-                        "you reset the module, you can enable the other stream.")
-                raise dnf.exceptions.Error(msg)
 
     class DisableSubCommand(SubCommand):
 
@@ -193,14 +178,6 @@ class ModuleCommand(commands.Command):
                     if e.no_match_group_specs or e.error_group_specs:
                         raise e
                 logger.error(str(e))
-            switchedModules = dict(self.base._moduleContainer.getSwitchedStreams())
-            if switchedModules:
-                report_module_switch(switchedModules)
-                msg = _("It is not possible to switch enabled streams of a module.\n"
-                        "It is recommended to remove all installed content from the module, and "
-                        "reset the module using 'dnf module reset <module_name>' command. After "
-                        "you reset the module, you can install the other stream.")
-                raise dnf.exceptions.Error(msg)
 
     class UpdateSubCommand(SubCommand):
 
--
libgit2 0.28.2