Skip to content

Commit

Permalink
offline: Use 90-99 part of the progress bar for scriptlets
Browse files Browse the repository at this point in the history
This is definitely not exact (since there is no way to get the exact
number of scriptlets going to be executed), but is should at least show
some progress bar changes during the scriptlets execution.
  • Loading branch information
m-blaha committed Feb 28, 2025
1 parent bb98f76 commit 969d19a
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion dnf5/commands/offline/offline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ class PlymouthTransCB : public RpmTransCB {
void elem_progress(const libdnf5::base::TransactionPackage & item, uint64_t amount, uint64_t total) override {
RpmTransCB::elem_progress(item, amount, total);

plymouth.progress(static_cast<int>(100 * static_cast<double>(amount) / static_cast<double>(total)));
if (total != 0) {
// reserve the last 10 percent of the progress for post-transaction callbacks
plymouth.progress(static_cast<int>(90 * static_cast<double>(amount) / static_cast<double>(total)));
}

std::string action;
switch (item.get_action()) {
Expand Down Expand Up @@ -187,10 +190,29 @@ class PlymouthTransCB : public RpmTransCB {
const auto message = fmt::format(
"Running {} scriptlet: {}...", script_type_to_string(type), to_full_nevra_string(nevra).c_str());
plymouth.message(message);

if (type == ScriptType::POST_TRANSACTION) {
// Post-transaction scriptlets take considerable amount of time and
// there was no indication to the user that the process did not stuck.
// Let's try to utilize 90-99 % part of the progress bar for them.
if (post_trans_scriptlets_count < post_trans_scriptlets_total) {
++post_trans_scriptlets_count;
}
plymouth.progress(
90 + static_cast<int>(
9 * static_cast<double>(post_trans_scriptlets_count) /
static_cast<double>(post_trans_scriptlets_total)));
}
}

private:
PlymouthOutput plymouth;
// Total assumed number of post-transaction scriptlets during the system-upgrade
// (based on F41 observation)
// There is no way how to get the exact number of scriptlets that are going
// to be executed.
const int post_trans_scriptlets_total = 40;
int post_trans_scriptlets_count = 0;
};

void OfflineCommand::pre_configure() {
Expand Down

0 comments on commit 969d19a

Please sign in to comment.