Skip to content

Commit

Permalink
dnf5: Reduce the noise around running scriptlets
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
m-blaha committed Aug 2, 2024
1 parent b3163df commit d1ffe89
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions dnf5/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#include <libdnf5/utils/bgettext/bgettext-mark-domain.h>
#include <libdnf5/utils/fs/file.hpp>
#include <libdnf5/utils/patterns.hpp>
#include <rpm/rpmtypes.h>

#include <algorithm>
#include <cctype>
Expand Down Expand Up @@ -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 0:
// remove the script_start message in case the script finished successfully
active_progress_bar->pop_message();
break;
case 1:
// Non-critical rpm scriptlet errors does 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();
}

Expand Down

0 comments on commit d1ffe89

Please sign in to comment.