dcavalca / rpms / dnf

Forked from rpms/dnf 2 years ago
Clone

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

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