From e10dc249769a62e7c2a50dab875b438164a07df6 Mon Sep 17 00:00:00 2001 From: Marek Blaha Date: Fri, 2 Aug 2024 13:27:28 +0200 Subject: [PATCH] dnf5: Reduce the noise around running scriptlets If the scriptlet finishes successfully, do not print the "Running scriptlet..." / "Stop scriptlet..." pair of messages in the transaction progress bar. The "Running scriptlet" message is displayed during the scriptlet execution to inform the user that a time-consuming operation is in progress. If the scriptlet completes successfully, the message is removed. If it fails, the message remains, and an error/warning message and the "Stop scriptlet" message is printed to enable debugging. --- dnf5/context.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/dnf5/context.cpp b/dnf5/context.cpp index b3addd9fb..cdf35b627 100644 --- a/dnf5/context.cpp +++ b/dnf5/context.cpp @@ -41,6 +41,7 @@ along with libdnf. If not, see . #include #include #include +#include #include #include @@ -871,10 +872,24 @@ void RpmTransCB::script_stop( [[maybe_unused]] const libdnf5::rpm::TransactionItem * item, libdnf5::rpm::Nevra nevra, libdnf5::rpm::TransactionCallbacks::ScriptType type, - [[maybe_unused]] uint64_t return_code) { - active_progress_bar->add_message( - libdnf5::cli::progressbar::MessageType::INFO, - fmt::format("Stop {} scriptlet: {}", script_type_to_string(type), to_full_nevra_string(nevra))); + uint64_t return_code) { + switch (return_code) { + case RPMRC_OK: + // remove the script_start message in case the script finished successfully + active_progress_bar->pop_message(); + break; + case RPMRC_NOTFOUND: + // Non-critical rpm scriptlet errors do not call script_error callback. + // 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))); + [[fallthrough]]; + default: + active_progress_bar->add_message( + libdnf5::cli::progressbar::MessageType::INFO, + fmt::format("Stop {} scriptlet: {}", script_type_to_string(type), to_full_nevra_string(nevra))); + } multi_progress_bar.print(); }