diff options
author | Adrian Vovk <adrianvovk@gmail.com> | 2024-08-31 03:57:07 +0200 |
---|---|---|
committer | Adrian Vovk <adrianvovk@gmail.com> | 2024-08-31 04:50:23 +0200 |
commit | ca7490c5ad180614926d1d126333ec6632b31180 (patch) | |
tree | 418d606319ec9d76eb99a5fcaf30ea392b0176ab /src/sysupdate/updatectl.c | |
parent | updatectl: Ensure we clear the progress bar (diff) | |
download | systemd-ca7490c5ad180614926d1d126333ec6632b31180.tar.xz systemd-ca7490c5ad180614926d1d126333ec6632b31180.zip |
updatectl: Improve behavior of progress logging
This applies a couple of aesthetic changes to the way updatectl renders
progress information
1. We invert from "ICON TARGET MESSAGE" to "TARGET: ICON MESSAGE" to
better fit in with the systemd progress bars, which look like
"TARGET [==========---------] XX%". The original version of the
sysupdated PR implemented its own progress bars that were oriented
differently: "[==========---------] TARGET XX%". When we swapped
the progress bar we didn't swap the status messages
2. When a target finishes updating, instead of leaving a 100% progress
bar on screen for potentially extended periods of time (which implies
to the user that the update isn't actually done...), we show a status
message saying the target is done updating.
3. Fixed a minor bug where an extra newline would be printed after the
total progress bar. At the top of the rendering function, we scroll
the terminal's scroll-back just enough to fit a line for each target,
and one for the total. This means that we should not print an
additional line after the total, or else it'll scroll the terminal's
buffer by an additional character. This bug was introduced at some
point during review
4. Clears the Total progress bar before quitting. By the time we're
quitting, that progress bar will be showing no useful status for the
user. Also, the fix in point 3 will cause the shell's prompt to
appear on the same line as the Total progress bar, partially
overwriting it and leaving the shell in a glitchy state.
Diffstat (limited to '')
-rw-r--r-- | src/sysupdate/updatectl.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/sysupdate/updatectl.c b/src/sysupdate/updatectl.c index 8f1e4e72db..400e521c1b 100644 --- a/src/sysupdate/updatectl.c +++ b/src/sysupdate/updatectl.c @@ -775,6 +775,7 @@ static int verb_check(int argc, char **argv, void *userdata) { } #define UPDATE_PROGRESS_FAILED INT_MIN +#define UPDATE_PROGRESS_DONE INT_MAX /* Make sure it doesn't overlap w/ errno values */ assert_cc(UPDATE_PROGRESS_FAILED < -ERRNO_MAX); @@ -809,15 +810,19 @@ static int update_render_progress(sd_event_source *source, void *userdata) { if (progress == UPDATE_PROGRESS_FAILED) { clear_progress_bar(target); - fprintf(stderr, "%s %s\n", RED_CROSS_MARK(), target); + fprintf(stderr, "%s: %s Unknown failure\n", target, RED_CROSS_MARK()); total += 100; } else if (progress == -EALREADY) { clear_progress_bar(target); - fprintf(stderr, "%s %s (Already up-to-date)\n", GREEN_CHECK_MARK(), target); + fprintf(stderr, "%s: %s Already up-to-date\n", target, GREEN_CHECK_MARK()); n--; /* Don't consider this target in the total */ } else if (progress < 0) { clear_progress_bar(target); - fprintf(stderr, "%s %s (%s)\n", RED_CROSS_MARK(), target, STRERROR(progress)); + fprintf(stderr, "%s: %s %s\n", target, RED_CROSS_MARK(), STRERROR(progress)); + total += 100; + } else if (progress == UPDATE_PROGRESS_DONE) { + clear_progress_bar(target); + fprintf(stderr, "%s: %s Done\n", target, GREEN_CHECK_MARK()); total += 100; } else { draw_progress_bar(target, progress); @@ -827,8 +832,13 @@ static int update_render_progress(sd_event_source *source, void *userdata) { } if (n > 1) { - draw_progress_bar("TOTAL", (double) total / n); - fputs("\n", stderr); + if (exiting) + clear_progress_bar(target); + else { + draw_progress_bar("Total", (double) total / n); + if (terminal_is_dumb()) + fputs("\n", stderr); + } } if (!terminal_is_dumb()) { @@ -898,7 +908,7 @@ static int update_finished(sd_bus_message *m, void *userdata, sd_bus_error *erro } if (status == 0) /* success */ - status = 100; + status = UPDATE_PROGRESS_DONE; else if (status > 0) /* exit status without errno */ status = UPDATE_PROGRESS_FAILED; /* i.e. EXIT_FAILURE */ /* else errno */ |