1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-10 05:18:17 +03:00

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.
This commit is contained in:
Adrian Vovk 2024-08-30 21:57:07 -04:00
parent 2aff6efe67
commit ca7490c5ad
No known key found for this signature in database
GPG Key ID: 90A7B546533E15FB

View File

@ -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 */