Blame SOURCES/0031-Add-support-for-group-upgrade-rollback-RhBug-2016070.patch

eb8139
From 7ba2cd6a86945e0ec6f9ed866e2ef6b6759ee092 Mon Sep 17 00:00:00 2001
eb8139
From: Jan Kolarik <jkolarik@redhat.com>
eb8139
Date: Thu, 25 Aug 2022 08:06:34 +0200
eb8139
Subject: [PATCH] Add support for group upgrade rollback (RhBug:2016070)
eb8139
eb8139
= changelog =
eb8139
type: bugfix
eb8139
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2016070
eb8139
---
eb8139
 dnf/db/group.py       |  8 +++++++-
eb8139
 dnf/transaction_sr.py | 24 ++++++++++++++++++++++++
eb8139
 2 files changed, 31 insertions(+), 1 deletion(-)
eb8139
eb8139
diff --git a/dnf/db/group.py b/dnf/db/group.py
eb8139
index 4dc8cb06..312e3b98 100644
eb8139
--- a/dnf/db/group.py
eb8139
+++ b/dnf/db/group.py
eb8139
@@ -34,14 +34,16 @@ class PersistorBase(object):
eb8139
         self._installed = {}
eb8139
         self._removed = {}
eb8139
         self._upgraded = {}
eb8139
+        self._downgraded = {}
eb8139
 
eb8139
     def __len__(self):
eb8139
-        return len(self._installed) + len(self._removed) + len(self._upgraded)
eb8139
+        return len(self._installed) + len(self._removed) + len(self._upgraded) + len(self._downgraded)
eb8139
 
eb8139
     def clean(self):
eb8139
         self._installed = {}
eb8139
         self._removed = {}
eb8139
         self._upgraded = {}
eb8139
+        self._downgraded = {}
eb8139
 
eb8139
     def _get_obj_id(self, obj):
eb8139
         raise NotImplementedError
eb8139
@@ -62,6 +64,10 @@ class PersistorBase(object):
eb8139
         self._upgraded[self._get_obj_id(obj)] = obj
eb8139
         self._add_to_history(obj, libdnf.transaction.TransactionItemAction_UPGRADE)
eb8139
 
eb8139
+    def downgrade(self, obj):
eb8139
+        self._downgraded[self._get_obj_id(obj)] = obj
eb8139
+        self._add_to_history(obj, libdnf.transaction.TransactionItemAction_DOWNGRADE)
eb8139
+
eb8139
     def new(self, obj_id, name, translated_name, pkg_types):
eb8139
         raise NotImplementedError
eb8139
 
eb8139
diff --git a/dnf/transaction_sr.py b/dnf/transaction_sr.py
eb8139
index dae8d300..5d403a3e 100644
eb8139
--- a/dnf/transaction_sr.py
eb8139
+++ b/dnf/transaction_sr.py
eb8139
@@ -416,6 +416,16 @@ class TransactionReplay(object):
eb8139
         if swdb_group is not None:
eb8139
             self._base.history.group.upgrade(swdb_group)
eb8139
 
eb8139
+    def _swdb_group_downgrade(self, group_id, pkg_types, pkgs):
eb8139
+        if not self._base.history.group.get(group_id):
eb8139
+            self._raise_or_warn(self._ignore_installed, _("Group id '%s' is not installed.") % group_id)
eb8139
+            return
eb8139
+
eb8139
+        swdb_group = self._create_swdb_group(group_id, pkg_types, pkgs)
eb8139
+
eb8139
+        if swdb_group is not None:
eb8139
+            self._base.history.group.downgrade(swdb_group)
eb8139
+
eb8139
     def _swdb_group_remove(self, group_id, pkg_types, pkgs):
eb8139
         if not self._base.history.group.get(group_id):
eb8139
             self._raise_or_warn(self._ignore_installed, _("Group id '%s' is not installed.") % group_id)
eb8139
@@ -482,6 +492,16 @@ class TransactionReplay(object):
eb8139
         if swdb_env is not None:
eb8139
             self._base.history.env.upgrade(swdb_env)
eb8139
 
eb8139
+    def _swdb_environment_downgrade(self, env_id, pkg_types, groups):
eb8139
+        if not self._base.history.env.get(env_id):
eb8139
+            self._raise_or_warn(self._ignore_installed, _("Environment id '%s' is not installed.") % env_id)
eb8139
+            return
eb8139
+
eb8139
+        swdb_env = self._create_swdb_environment(env_id, pkg_types, groups)
eb8139
+
eb8139
+        if swdb_env is not None:
eb8139
+            self._base.history.env.downgrade(swdb_env)
eb8139
+
eb8139
     def _swdb_environment_remove(self, env_id, pkg_types, groups):
eb8139
         if not self._base.history.env.get(env_id):
eb8139
             self._raise_or_warn(self._ignore_installed, _("Environment id '%s' is not installed.") % env_id)
eb8139
@@ -535,6 +555,8 @@ class TransactionReplay(object):
eb8139
                     self._swdb_group_install(group_id, pkg_types, group_data["packages"])
eb8139
                 elif action == "Upgrade":
eb8139
                     self._swdb_group_upgrade(group_id, pkg_types, group_data["packages"])
eb8139
+                elif action == "Downgraded":
eb8139
+                    self._swdb_group_downgrade(group_id, pkg_types, group_data["packages"])
eb8139
                 elif action == "Removed":
eb8139
                     self._swdb_group_remove(group_id, pkg_types, group_data["packages"])
eb8139
                 else:
eb8139
@@ -564,6 +586,8 @@ class TransactionReplay(object):
eb8139
                     self._swdb_environment_install(env_id, pkg_types, env_data["groups"])
eb8139
                 elif action == "Upgrade":
eb8139
                     self._swdb_environment_upgrade(env_id, pkg_types, env_data["groups"])
eb8139
+                elif action == "Downgraded":
eb8139
+                    self._swdb_environment_downgrade(env_id, pkg_types, env_data["groups"])
eb8139
                 elif action == "Removed":
eb8139
                     self._swdb_environment_remove(env_id, pkg_types, env_data["groups"])
eb8139
                 else:
eb8139
-- 
eb8139
2.37.1
eb8139