diff options
author | Daan De Meyer <daan.j.demeyer@gmail.com> | 2024-10-25 17:03:37 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2024-10-29 21:11:26 +0100 |
commit | 3dd0389ba0261ac7fffba3c5cf9961857452d440 (patch) | |
tree | a51b0a2ec8af5f95a0f893ee972d45baa94e3dd6 /src/import/export-raw.c | |
parent | progress-bar: issue Windows Terminal progress indicating ANSI sequences (#34929) (diff) | |
download | systemd-3dd0389ba0261ac7fffba3c5cf9961857452d440.tar.xz systemd-3dd0389ba0261ac7fffba3c5cf9961857452d440.zip |
import: Draw progress bars
Currently every progress update results in a new progress message
which is extremely verbose. Instead, let's use the progress bar infra
to draw a proper progress bar similar to what we do in systemd-repart
now.
Diffstat (limited to 'src/import/export-raw.c')
-rw-r--r-- | src/import/export-raw.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/import/export-raw.c b/src/import/export-raw.c index f425396261..337d74706a 100644 --- a/src/import/export-raw.c +++ b/src/import/export-raw.c @@ -9,9 +9,11 @@ #include "copy.h" #include "export-raw.h" #include "fd-util.h" +#include "format-util.h" #include "fs-util.h" #include "import-common.h" #include "missing_fcntl.h" +#include "pretty-print.h" #include "ratelimit.h" #include "stat-util.h" #include "string-util.h" @@ -121,7 +123,19 @@ static void raw_export_report_progress(RawExport *e) { return; sd_notifyf(false, "X_IMPORT_PROGRESS=%u%%", percent); - log_info("Exported %u%%.", percent); + + if (isatty_safe(STDERR_FILENO)) { + _cleanup_free_ char *s = NULL; + + if (asprintf(&s, "%s %s/%s", + special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), + FORMAT_BYTES(e->written_uncompressed), + FORMAT_BYTES(e->st.st_size)) < 0) + return; + + draw_progress_bar(s, percent); + } else + log_info("Exported %u%%.", percent); e->last_percent = percent; } @@ -215,6 +229,9 @@ static int raw_export_process(RawExport *e) { finish: if (r >= 0) { + if (isatty_safe(STDERR_FILENO)) + clear_progress_bar(/* prefix= */ NULL); + (void) copy_times(e->input_fd, e->output_fd, COPY_CRTIME); (void) copy_xattr(e->input_fd, NULL, e->output_fd, NULL, 0); } |