From: Daan De Meyer Date: Fri, 25 Oct 2024 15:03:37 +0000 (+0200) Subject: import: Draw progress bars X-Git-Tag: v257-rc1~113 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3dd0389ba0261ac7fffba3c5cf9961857452d440;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/import/export-raw.c b/src/import/export-raw.c index f4253962615..337d74706a5 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); } diff --git a/src/import/export-tar.c b/src/import/export-tar.c index 9e92badfef3..42f3adee963 100644 --- a/src/import/export-tar.c +++ b/src/import/export-tar.c @@ -7,6 +7,7 @@ #include "export-tar.h" #include "fd-util.h" #include "import-common.h" +#include "pretty-print.h" #include "process-util.h" #include "ratelimit.h" #include "string-util.h" @@ -132,7 +133,19 @@ static void tar_export_report_progress(TarExport *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->quota_referenced)) < 0) + return; + + draw_progress_bar(s, percent); + } else + log_info("Exported %u%%.", percent); e->last_percent = percent; } @@ -229,6 +242,9 @@ static int tar_export_process(TarExport *e) { return 0; finish: + if (r >= 0 && isatty_safe(STDERR_FILENO)) + clear_progress_bar(/* prefix= */ NULL); + if (e->on_finished) e->on_finished(e, r, e->userdata); else diff --git a/src/import/import-raw.c b/src/import/import-raw.c index 78775b96d67..190a08a005a 100644 --- a/src/import/import-raw.c +++ b/src/import/import-raw.c @@ -20,6 +20,7 @@ #include "machine-pool.h" #include "mkdir-label.h" #include "path-util.h" +#include "pretty-print.h" #include "qcow2-util.h" #include "ratelimit.h" #include "rm-rf.h" @@ -149,7 +150,19 @@ static void raw_import_report_progress(RawImport *i) { return; sd_notifyf(false, "X_IMPORT_PROGRESS=%u%%", percent); - log_info("Imported %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(i->written_compressed), + FORMAT_BYTES(i->input_stat.st_size)) < 0) + return; + + draw_progress_bar(s, percent); + } else + log_info("Imported %u%%.", percent); i->last_percent = percent; } @@ -459,6 +472,9 @@ static int raw_import_process(RawImport *i) { return 0; complete: + if (isatty_safe(STDERR_FILENO)) + clear_progress_bar(/* prefix= */ NULL); + r = raw_import_finish(i); finish: diff --git a/src/import/import-tar.c b/src/import/import-tar.c index 976c9182461..6e6c720782a 100644 --- a/src/import/import-tar.c +++ b/src/import/import-tar.c @@ -20,6 +20,7 @@ #include "machine-pool.h" #include "mkdir-label.h" #include "path-util.h" +#include "pretty-print.h" #include "process-util.h" #include "qcow2-util.h" #include "ratelimit.h" @@ -150,7 +151,19 @@ static void tar_import_report_progress(TarImport *i) { return; sd_notifyf(false, "X_IMPORT_PROGRESS=%u%%", percent); - log_info("Imported %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(i->written_compressed), + FORMAT_BYTES(i->input_stat.st_size)) < 0) + return; + + draw_progress_bar(s, percent); + } else + log_info("Imported %u%%.", percent); i->last_percent = percent; } @@ -322,6 +335,9 @@ static int tar_import_process(TarImport *i) { return 0; finish: + if (r >= 0 && isatty_safe(STDERR_FILENO)) + clear_progress_bar(/* prefix= */ NULL); + if (i->on_finished) i->on_finished(i, r, i->userdata); else