Skip to content

Commit

Permalink
dnf5: Print rpm scriptlets outputs to the user
Browse files Browse the repository at this point in the history
If a scriptlet fails, its output is displayed to the user in addition to
being written to the log. For scriptlets that complete successfully, the
output is only logged.
  • Loading branch information
m-blaha committed Aug 28, 2024
1 parent b11e7aa commit e2794e2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 17 additions & 1 deletion dnf5/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,17 @@ void RpmTransCB::cpio_error(const libdnf5::rpm::TransactionItem & item) {
multi_progress_bar.print();
}

void RpmTransCB::script_output_to_progress(const libdnf5::cli::progressbar::MessageType message_type) {
auto transaction = context.get_transaction();
auto output = transaction->get_last_script_output();
if (!output.empty()) {
active_progress_bar->add_message(message_type, "Scriptlet output:");
for (auto & line : libdnf5::utils::string::split(output, "\n")) {
active_progress_bar->add_message(message_type, line);
}
}
}

void RpmTransCB::script_error(
[[maybe_unused]] const libdnf5::rpm::TransactionItem * item,
libdnf5::rpm::Nevra nevra,
Expand All @@ -855,6 +866,7 @@ void RpmTransCB::script_error(
script_type_to_string(type),
to_full_nevra_string(nevra),
return_code));
script_output_to_progress(libdnf5::cli::progressbar::MessageType::ERROR);
multi_progress_bar.print();
}

Expand Down Expand Up @@ -883,7 +895,11 @@ void RpmTransCB::script_stop(
// Print the error message here.
active_progress_bar->add_message(
libdnf5::cli::progressbar::MessageType::WARNING,
fmt::format("Error in {} scriptlet: {}", script_type_to_string(type), to_full_nevra_string(nevra)));
fmt::format(
"Non-critical error in {} scriptlet: {}",
script_type_to_string(type),
to_full_nevra_string(nevra)));
script_output_to_progress(libdnf5::cli::progressbar::MessageType::WARNING);
[[fallthrough]];
default:
active_progress_bar->add_message(
Expand Down
2 changes: 2 additions & 0 deletions dnf5/include/dnf5/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ class DNF_API RpmTransCB : public libdnf5::rpm::TransactionCallbacks {

DNF_LOCAL static std::chrono::time_point<std::chrono::steady_clock> prev_print_time;

DNF_LOCAL void script_output_to_progress(libdnf5::cli::progressbar::MessageType message_type);

libdnf5::cli::progressbar::MultiProgressBar multi_progress_bar;
libdnf5::cli::progressbar::DownloadProgressBar * active_progress_bar{nullptr};
Context & context;
Expand Down

0 comments on commit e2794e2

Please sign in to comment.