From e3a37a1543ed2767148d0c75ad2367cc410dcba2 Mon Sep 17 00:00:00 2001 From: chenhaixing123 Date: Tue, 30 Jan 2024 11:11:25 +0800 Subject: [PATCH] Fix history rollback command does not meet the expected result --- dnf/cli/commands/history.py | 17 +++++++++++------ dnf/transaction_sr.py | 7 +++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/dnf/cli/commands/history.py b/dnf/cli/commands/history.py index 21d04a1a65..267d6e4d3d 100644 --- a/dnf/cli/commands/history.py +++ b/dnf/cli/commands/history.py @@ -209,21 +209,26 @@ def _hcmd_rollback(self, extcmds): else: merged_trans.merge(trans) + tm = dnf.util.normalize_time(old.beg_timestamp) + print("Rollback to transaction %u, from %s" % (old.tid, tm)) + print(self.output.fmtKeyValFill(" Undoing the following transactions: ", + ", ".join((str(x) for x in merged_trans.tids())))) + self.output.historyInfoCmdPkgsAltered(merged_trans) self._revert_transaction(merged_trans) def _revert_transaction(self, trans): action_map = { "Install": "Removed", "Removed": "Install", - "Upgrade": "Downgraded", + "Upgrade": None, "Upgraded": "Downgrade", - "Downgrade": "Upgraded", + "Downgrade": None, "Downgraded": "Upgrade", - "Reinstalled": "Reinstall", - "Reinstall": "Reinstalled", + "Reinstalled": None, + "Reinstall": None, "Obsoleted": "Install", - "Obsolete": "Obsoleted", - "Reason Change": "Reason Change", + "Obsolete": None, + "Reason Change": None, } data = serialize_transaction(trans) diff --git a/dnf/transaction_sr.py b/dnf/transaction_sr.py index b389f1522a..4067adf32b 100644 --- a/dnf/transaction_sr.py +++ b/dnf/transaction_sr.py @@ -536,6 +536,9 @@ def run(self): for pkg_data in self._rpms: try: + action = pkg_data["action"] + if action is None: + continue self._replay_pkg_action(pkg_data) except TransactionError as e: errors.append(e) @@ -543,6 +546,8 @@ def run(self): for group_data in self._groups: try: action = group_data["action"] + if action is None: + continue group_id = group_data["id"] try: @@ -576,6 +581,8 @@ def run(self): for env_data in self._environments: try: action = env_data["action"] + if action is None: + continue env_id = env_data["id"] try: