Skip to content

Commit

Permalink
dnf5daemon: Add skipped packages to transaction table
Browse files Browse the repository at this point in the history
  • Loading branch information
m-blaha authored and kontura committed May 10, 2024
1 parent d4a144d commit 388e253
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 10 deletions.
17 changes: 12 additions & 5 deletions dnf5daemon-client/wrappers/dbus_goal_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,24 @@ DbusGoalWrapper::DbusGoalWrapper(std::vector<dnfdaemon::DbusTransactionItem> tra
std::map<int, size_t> transaction_packages_by_id;

for (const auto & ti : transaction) {
auto object_type = libdnf5::transaction::transaction_item_type_from_string(std::get<0>(ti));
if (object_type == libdnf5::transaction::TransactionItemType::PACKAGE) {
auto object_type = std::get<0>(ti);
if (object_type == "Package") {
transaction_packages.push_back(DbusTransactionPackageWrapper(ti));
transaction_packages_by_id.emplace(
transaction_packages.back().get_package().get_id(), transaction_packages.size() - 1);
} else if (object_type == libdnf5::transaction::TransactionItemType::GROUP) {
} else if (object_type == "Group") {
transaction_groups.push_back(DbusTransactionGroupWrapper(ti));
} else if (object_type == libdnf5::transaction::TransactionItemType::ENVIRONMENT) {
} else if (object_type == "Environment") {
transaction_environments.push_back(DbusTransactionEnvironmentWrapper(ti));
} else if (object_type == libdnf5::transaction::TransactionItemType::MODULE) {
} else if (object_type == "Module") {
transaction_modules.push_back(DbusTransactionModuleWrapper(ti));
} else if (object_type == "Skipped") {
auto trans_item_attrs = std::get<3>(ti);
if (key_value_map_get<std::string>(trans_item_attrs, "reason_skipped", "conflict") == "conflict") {
conflicting_packages.emplace_back(std::get<4>(ti));
} else {
broken_dependency_packages.emplace_back(std::get<4>(ti));
}
}
}
// set "replaces" for transaction_packages. Since transaction_package contains only
Expand Down
5 changes: 5 additions & 0 deletions dnf5daemon-client/wrappers/dbus_goal_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,16 @@ class DbusGoalWrapper {
std::vector<std::string> get_resolve_logs_as_strings() const { return resolve_logs; }
void set_resolve_logs(std::vector<std::string> logs) { resolve_logs = logs; }

std::vector<DbusPackageWrapper> get_conflicting_packages() const { return conflicting_packages; }
std::vector<DbusPackageWrapper> get_broken_dependency_packages() const { return broken_dependency_packages; }

private:
std::vector<DbusTransactionPackageWrapper> transaction_packages;
std::vector<DbusTransactionGroupWrapper> transaction_groups;
std::vector<DbusTransactionEnvironmentWrapper> transaction_environments;
std::vector<DbusTransactionModuleWrapper> transaction_modules;
std::vector<DbusPackageWrapper> conflicting_packages;
std::vector<DbusPackageWrapper> broken_dependency_packages;
std::vector<std::string> resolve_logs;
};

Expand Down
4 changes: 3 additions & 1 deletion dnf5daemon-server/dbus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ using KeyValueMapList = std::vector<KeyValueMap>;
enum class RepoStatus { NOT_READY, PENDING, READY, ERROR };
enum class ResolveResult { NO_PROBLEM, WARNING, ERROR };

enum class DbusTransactionItemType : int { PACKAGE, GROUP, ENVIRONMENT, MODULE, SKIPPED };

using DbusTransactionItem = sdbus::Struct<
std::string, // libdnf5::transaction::TransactionItemType
std::string, // DbusTransactionItemType
std::string, // libdnf5::transaction::TransactionItemAction
std::string, // libdnf5::transaction::TransactionItemReason
KeyValueMap, // other transaction item attributes - e.g. group id for REASON_CHANGE to GROUP,
Expand Down
45 changes: 41 additions & 4 deletions dnf5daemon-server/services/goal/goal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
} \
})

static std::string dbus_transaction_item_type_to_string(dnfdaemon::DbusTransactionItemType type) {
switch (type) {
case dnfdaemon::DbusTransactionItemType::PACKAGE:
return "Package";
case dnfdaemon::DbusTransactionItemType::GROUP:
return "Group";
case dnfdaemon::DbusTransactionItemType::ENVIRONMENT:
return "Environment";
case dnfdaemon::DbusTransactionItemType::MODULE:
return "Module";
case dnfdaemon::DbusTransactionItemType::SKIPPED:
return "Skipped";
}
return "";
}

void Goal::dbus_register() {
auto dbus_object = session.get_dbus_object();
// TODO(mblaha) Adjust resolve method to accommodate also groups, environments,
Expand Down Expand Up @@ -119,7 +135,8 @@ sdbus::MethodReply Goal::resolve(sdbus::MethodCall & call) {
"download_size",
"install_size",
"evr",
"reason"};
"reason",
"full_nevra"};
for (auto & tspkg : transaction.get_transaction_packages()) {
dnfdaemon::KeyValueMap trans_item_attrs{};
if (tspkg.get_reason_change_group_id()) {
Expand All @@ -134,7 +151,7 @@ sdbus::MethodReply Goal::resolve(sdbus::MethodCall & call) {
trans_item_attrs.emplace("replaces", replaces_ids);
}
dbus_transaction.push_back(dnfdaemon::DbusTransactionItem(
transaction_item_type_to_string(libdnf5::transaction::TransactionItemType::PACKAGE),
dbus_transaction_item_type_to_string(dnfdaemon::DbusTransactionItemType::PACKAGE),
transaction_item_action_to_string(tspkg.get_action()),
transaction_item_reason_to_string(tspkg.get_reason()),
trans_item_attrs,
Expand All @@ -144,15 +161,15 @@ sdbus::MethodReply Goal::resolve(sdbus::MethodCall & call) {
dnfdaemon::KeyValueMap trans_item_attrs{};
for (auto & tsgrp : transaction.get_transaction_groups()) {
dbus_transaction.push_back(dnfdaemon::DbusTransactionItem(
transaction_item_type_to_string(libdnf5::transaction::TransactionItemType::GROUP),
dbus_transaction_item_type_to_string(dnfdaemon::DbusTransactionItemType::GROUP),
transaction_item_action_to_string(tsgrp.get_action()),
transaction_item_reason_to_string(tsgrp.get_reason()),
trans_item_attrs,
group_to_map(tsgrp.get_group(), grp_attrs)));
}
for (auto & tsenv : transaction.get_transaction_environments()) {
dbus_transaction.push_back(dnfdaemon::DbusTransactionItem(
transaction_item_type_to_string(libdnf5::transaction::TransactionItemType::ENVIRONMENT),
dbus_transaction_item_type_to_string(dnfdaemon::DbusTransactionItemType::ENVIRONMENT),
transaction_item_action_to_string(tsenv.get_action()),
transaction_item_reason_to_string(tsenv.get_reason()),
trans_item_attrs,
Expand All @@ -165,6 +182,26 @@ sdbus::MethodReply Goal::resolve(sdbus::MethodCall & call) {
} else {
overall_result = dnfdaemon::ResolveResult::NO_PROBLEM;
}
for (const auto & pkg : transaction.get_conflicting_packages()) {
dnfdaemon::KeyValueMap trans_item_attrs{};
trans_item_attrs.emplace("reason_skipped", "conflict");
dbus_transaction.emplace_back(
dbus_transaction_item_type_to_string(dnfdaemon::DbusTransactionItemType::SKIPPED),
"",
"",
trans_item_attrs,
package_to_map(pkg, pkg_attrs));
}
for (const auto & pkg : transaction.get_broken_dependency_packages()) {
dnfdaemon::KeyValueMap trans_item_attrs{};
trans_item_attrs.emplace("reason_skipped", "broken_dependency");
dbus_transaction.emplace_back(
dbus_transaction_item_type_to_string(dnfdaemon::DbusTransactionItemType::SKIPPED),
"",
"",
trans_item_attrs,
package_to_map(pkg, pkg_attrs));
}
}

auto reply = call.createReply();
Expand Down

0 comments on commit 388e253

Please sign in to comment.