Skip to content

Commit

Permalink
modules: Add switching module streams as a possible transaction action
Browse files Browse the repository at this point in the history
  • Loading branch information
pkratoch committed Mar 13, 2024
1 parent 379913d commit d5a10c9
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ void TransactionCallbacksSimple::install_start(
case libdnf5::transaction::TransactionItemAction::ENABLE:
case libdnf5::transaction::TransactionItemAction::DISABLE:
case libdnf5::transaction::TransactionItemAction::RESET:
case libdnf5::transaction::TransactionItemAction::SWITCH:
auto & logger = *context.base.get_logger();
logger.warning(
"Unexpected action in TransactionPackage: {}",
Expand Down
1 change: 1 addition & 0 deletions dnf5/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ class RpmTransCB : public libdnf5::rpm::TransactionCallbacks {
case libdnf5::transaction::TransactionItemAction::ENABLE:
case libdnf5::transaction::TransactionItemAction::DISABLE:
case libdnf5::transaction::TransactionItemAction::RESET:
case libdnf5::transaction::TransactionItemAction::SWITCH:
auto & logger = *context.base.get_logger();
logger.warning(
"Unexpected action in TransactionPackage: {}",
Expand Down
1 change: 1 addition & 0 deletions dnf5daemon-server/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ RpmTransactionItemActions transaction_package_to_action(const libdnf5::base::Tra
case libdnf5::base::TransactionPackage::Action::ENABLE:
case libdnf5::base::TransactionPackage::Action::DISABLE:
case libdnf5::base::TransactionPackage::Action::RESET:
case libdnf5::base::TransactionPackage::Action::SWITCH:
// TODO(lukash) handle cases
libdnf_throw_assertion(
"Unexpected action in RpmTransactionItem: {}",
Expand Down
6 changes: 6 additions & 0 deletions include/libdnf5-cli/output/transaction_table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ static const char * action_color(libdnf5::transaction::TransactionItemAction act
case libdnf5::transaction::TransactionItemAction::REINSTALL:
case libdnf5::transaction::TransactionItemAction::REASON_CHANGE:
case libdnf5::transaction::TransactionItemAction::ENABLE:
case libdnf5::transaction::TransactionItemAction::SWITCH:
return "green";
case libdnf5::transaction::TransactionItemAction::DOWNGRADE:
case libdnf5::transaction::TransactionItemAction::RESET:
Expand Down Expand Up @@ -121,6 +122,7 @@ class ActionHeaderPrinter {
case libdnf5::transaction::TransactionItemAction::ENABLE:
case libdnf5::transaction::TransactionItemAction::DISABLE:
case libdnf5::transaction::TransactionItemAction::RESET:
case libdnf5::transaction::TransactionItemAction::SWITCH:
libdnf_throw_assertion(
"Unexpected action in print_transaction_table: {}", libdnf5::utils::to_underlying(action));
}
Expand Down Expand Up @@ -271,6 +273,9 @@ class ActionHeaderPrinterModule {
case libdnf5::transaction::TransactionItemAction::RESET:
text = "Resetting modules";
break;
case libdnf5::transaction::TransactionItemAction::SWITCH:
text = "Switching module streams";
break;
default:
libdnf_throw_assertion(
"Unexpected action in print_transaction_table: {}", libdnf5::utils::to_underlying(action));
Expand Down Expand Up @@ -323,6 +328,7 @@ class TransactionSummary {
case libdnf5::transaction::TransactionItemAction::ENABLE:
case libdnf5::transaction::TransactionItemAction::DISABLE:
case libdnf5::transaction::TransactionItemAction::RESET:
case libdnf5::transaction::TransactionItemAction::SWITCH:
// Only package change counts are reported.
break;
}
Expand Down
3 changes: 2 additions & 1 deletion include/libdnf5/transaction/transaction_item_action.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ enum class TransactionItemAction : int {
REASON_CHANGE = 7, // a package is being kept on the system but its reason is changing
ENABLE = 8, // module enable
DISABLE = 9, // module disable
RESET = 10 // module reset
RESET = 10, // module reset
SWITCH = 11 // module switch
};


Expand Down
9 changes: 9 additions & 0 deletions libdnf5/base/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,15 @@ void Transaction::Impl::set_transaction(
name, "", "", transaction::TransactionItemAction::RESET, transaction::TransactionItemReason::USER);
modules.emplace_back(std::move(tsmodule));
}
for (auto & name_streams : module_db->get_all_newly_switched_streams()) {
TransactionModule tsmodule(
name_streams.first,
name_streams.second.second,
name_streams.second.first,
transaction::TransactionItemAction::SWITCH,
transaction::TransactionItemReason::USER);
modules.emplace_back(std::move(tsmodule));
}

// Add reason change actions to the transaction
for (auto & [pkg, reason, group_id] : solved_goal.list_reason_changes()) {
Expand Down
1 change: 1 addition & 0 deletions libdnf5/rpm/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ void Transaction::fill(const base::Transaction & transaction) {
case libdnf5::transaction::TransactionItemAction::ENABLE:
case libdnf5::transaction::TransactionItemAction::DISABLE:
case libdnf5::transaction::TransactionItemAction::RESET:
case libdnf5::transaction::TransactionItemAction::SWITCH:
break;
}
}
Expand Down
5 changes: 5 additions & 0 deletions libdnf5/transaction/transaction_item_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ std::string transaction_item_action_to_string(TransactionItemAction action) {
return "Disable";
case TransactionItemAction::RESET:
return "Reset";
case TransactionItemAction::SWITCH:
return "Switch";
}
return "";
}
Expand All @@ -76,6 +78,8 @@ TransactionItemAction transaction_item_action_from_string(const std::string & ac
return TransactionItemAction::DISABLE;
} else if (action == "Reset") {
return TransactionItemAction::RESET;
} else if (action == "Switch") {
return TransactionItemAction::SWITCH;
}

throw InvalidTransactionItemAction(action);
Expand Down Expand Up @@ -104,6 +108,7 @@ std::string transaction_item_action_to_letter(TransactionItemAction action) {
case TransactionItemAction::ENABLE:
case TransactionItemAction::DISABLE:
case TransactionItemAction::RESET:
case TransactionItemAction::SWITCH:
// TODO(pkratoch): Add letters for ENABLE, DISABLE and RESET
return "";
}
Expand Down

0 comments on commit d5a10c9

Please sign in to comment.