Skip to content

Commit

Permalink
Fix history rollback command does not meet the expected result
Browse files Browse the repository at this point in the history
  • Loading branch information
chenhaixing123 committed Jan 30, 2024
1 parent 0e40047 commit e3a37a1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
17 changes: 11 additions & 6 deletions dnf/cli/commands/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions dnf/transaction_sr.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,13 +536,18 @@ 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)

for group_data in self._groups:
try:
action = group_data["action"]
if action is None:
continue
group_id = group_data["id"]

try:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit e3a37a1

Please sign in to comment.