Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

history: Support operations on modules #1688

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 42 additions & 3 deletions dnf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,11 +798,17 @@ def do_transaction(self, display=()):
display = \
[dnf.yum.rpmtrans.LoggingTransactionDisplay()] + list(display)

# save changed stream states into history database
modules_changed = self._moduleContainer.saveHistory(self.history._swdb)

# save module states on disk right before entering rpm transaction,
# because we want system in recoverable state if transaction gets interrupted
self._moduleContainer.save()
self._moduleContainer.updateFailSafeData()

if not self.transaction:
# packages are not changed, but comps and modules changes need to be committed
self._moduleContainer.save()
self._moduleContainer.updateFailSafeData()
if self._history and (self._history.group or self._history.env):
if self._history and (self._history.group or self._history.env or modules_changed):
cmdline = None
if hasattr(self, 'args') and self.args:
cmdline = ' '.join(self.args)
Expand Down Expand Up @@ -2219,6 +2225,7 @@ def _history_undo_operations(self, operations, first_trans, rollback=False, stri
:param rollback: True if transaction is performing a rollback
:param strict: if True, raise an exception on any errors
"""
module_base = dnf.module.module_base.ModuleBase(self)

# map actions to their opposites
action_map = {
Expand All @@ -2234,9 +2241,17 @@ def _history_undo_operations(self, operations, first_trans, rollback=False, stri
libdnf.transaction.TransactionItemAction_UPGRADE: None,
libdnf.transaction.TransactionItemAction_UPGRADED: libdnf.transaction.TransactionItemAction_DOWNGRADE,
libdnf.transaction.TransactionItemAction_REASON_CHANGE: None,

libdnf.transaction.TransactionItemAction_ENABLE_OUT: libdnf.transaction.TransactionItemAction_ENABLE,
libdnf.transaction.TransactionItemAction_ENABLE: None,
libdnf.transaction.TransactionItemAction_DISABLE_OUT: libdnf.transaction.TransactionItemAction_DISABLE,
libdnf.transaction.TransactionItemAction_DISABLE: None,
libdnf.transaction.TransactionItemAction_RESET_OUT: libdnf.transaction.TransactionItemAction_RESET,
libdnf.transaction.TransactionItemAction_RESET: None,
}

failed = False

for ti in operations.packages():
try:
action = action_map[ti.action]
Expand All @@ -2246,6 +2261,30 @@ def _history_undo_operations(self, operations, first_trans, rollback=False, stri
if action is None:
continue

if action == libdnf.transaction.TransactionItemAction_ENABLE:
module_base.enable([str(ti)])
continue

if action == libdnf.transaction.TransactionItemAction_DISABLE:
module_base.disable([str(ti)])
continue

if action == libdnf.transaction.TransactionItemAction_RESET:
module_base.reset([str(ti)])
continue

if ti._item.getCompsGroupItem() or ti._item.getCompsEnvironmentItem():
if action == libdnf.transaction.TransactionItemAction_REMOVE:
if ti._item.getCompsGroupItem():
self.read_comps(arch_filter=True)
self.group_remove(str(ti).lstrip("@"))
elif ti._item.getCompsEnvironmentItem():
self.read_comps(arch_filter=True)
self.env_group_remove([str(ti).lstrip("@")])
else:
self.install_specs([str(ti)], [])
continue

if action == libdnf.transaction.TransactionItemAction_REMOVE:
query = self.sack.query().installed().filterm(nevra_strict=str(ti))
if not query:
Expand Down
2 changes: 1 addition & 1 deletion dnf/cli/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -1564,7 +1564,7 @@ def _history_uiactions(self, hpkgs):
actions_short = set()
count = 0
for pkg in hpkgs:
if pkg.action in (libdnf.transaction.TransactionItemAction_UPGRADED, libdnf.transaction.TransactionItemAction_DOWNGRADED):
if pkg.action != libdnf.transaction.TransactionItemAction_REMOVE and pkg.action in dnf.transaction.BACKWARD_ACTIONS:
# skip states we don't want to display in user input
continue
actions.add(pkg.action_name)
Expand Down
3 changes: 3 additions & 0 deletions dnf/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
libdnf.transaction.TransactionItemAction_OBSOLETED,
libdnf.transaction.TransactionItemAction_UPGRADED,
libdnf.transaction.TransactionItemAction_REMOVE,
libdnf.transaction.TransactionItemAction_ENABLE_OUT,
libdnf.transaction.TransactionItemAction_DISABLE_OUT,
libdnf.transaction.TransactionItemAction_RESET_OUT,
# TODO: REINSTALLED may and may not belong here; the same NEVRA is in FORWARD_ACTIONS already
# libdnf.transaction.TransactionItemAction_REINSTALLED,
]
Expand Down