dcavalca / rpms / dnf

Forked from rpms/dnf 2 years ago
Clone

Blame SOURCES/0007-Not-allow-direct-module-switch-RhBug1669491.patch

0f2fcc
From 25d7c0129c7a5490f2c735cd927555c043e04ff6 Mon Sep 17 00:00:00 2001
0f2fcc
From: Jaroslav Mracek <jmracek@redhat.com>
0f2fcc
Date: Wed, 13 Feb 2019 16:27:39 +0100
0f2fcc
Subject: [PATCH] Not allow direct module switch (RhBug:1669491)
0f2fcc
0f2fcc
---
0f2fcc
 dnf/cli/commands/module.py | 24 ++++++++++++++++++++++++
0f2fcc
 1 file changed, 24 insertions(+)
0f2fcc
0f2fcc
diff --git a/dnf/cli/commands/module.py b/dnf/cli/commands/module.py
0f2fcc
index edb3dfd..6d23bd2 100644
0f2fcc
--- a/dnf/cli/commands/module.py
0f2fcc
+++ b/dnf/cli/commands/module.py
0f2fcc
@@ -31,6 +31,14 @@ import libdnf
0f2fcc
 import dnf.module.module_base
0f2fcc
 import dnf.exceptions
0f2fcc
 
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
+
0f2fcc
 class ModuleCommand(commands.Command):
0f2fcc
     class SubCommand(commands.Command):
0f2fcc
 
0f2fcc
@@ -115,6 +123,14 @@ class ModuleCommand(commands.Command):
0f2fcc
                             libdnf.module.ModulePackageContainer.ModuleErrorType_ERROR_IN_DEFAULTS:
0f2fcc
                         raise e
0f2fcc
                 logger.error(str(e))
0f2fcc
+            switchedModules = dict(self.base._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 "
0f2fcc
+                        "you reset the module, you can enable the other stream.")
0f2fcc
+                raise dnf.exceptions.Error(msg)
0f2fcc
 
0f2fcc
     class DisableSubCommand(SubCommand):
0f2fcc
 
0f2fcc
@@ -178,6 +194,14 @@ class ModuleCommand(commands.Command):
0f2fcc
                     if e.no_match_group_specs or e.error_group_specs:
0f2fcc
                         raise e
0f2fcc
                 logger.error(str(e))
0f2fcc
+            switchedModules = dict(self.base._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 "
0f2fcc
+                        "you reset the module, you can install the other stream.")
0f2fcc
+                raise dnf.exceptions.Error(msg)
0f2fcc
 
0f2fcc
     class UpdateSubCommand(SubCommand):
0f2fcc
 
0f2fcc
--
0f2fcc
libgit2 0.27.7
0f2fcc