summaryrefslogtreecommitdiffstats
path: root/src/import
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2024-10-29 21:32:28 +0100
committerLennart Poettering <lennart@poettering.net>2024-10-29 21:37:26 +0100
commit91d640435d0fd79fe74f6c558d69ffdcbdf86234 (patch)
treeff8c75d0c5c5c5b6d12e44d830a8b47e8f4d2de9 /src/import
parentpretty-print: rename draw_progress_bar_impl()→draw_progress_bar_unbuffered() (diff)
downloadsystemd-91d640435d0fd79fe74f6c558d69ffdcbdf86234.tar.xz
systemd-91d640435d0fd79fe74f6c558d69ffdcbdf86234.zip
pretty-print: add format-string version of draw_progress_bar()
We often format the prefix string via asprintf() before, let's hence add a helper for that.
Diffstat (limited to 'src/import')
-rw-r--r--src/import/export-raw.c19
-rw-r--r--src/import/export-tar.c19
-rw-r--r--src/import/import-raw.c19
-rw-r--r--src/import/import-tar.c19
4 files changed, 32 insertions, 44 deletions
diff --git a/src/import/export-raw.c b/src/import/export-raw.c
index 337d74706a..5e34fd372e 100644
--- a/src/import/export-raw.c
+++ b/src/import/export-raw.c
@@ -124,17 +124,14 @@ static void raw_export_report_progress(RawExport *e) {
sd_notifyf(false, "X_IMPORT_PROGRESS=%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
+ if (isatty_safe(STDERR_FILENO))
+ (void) draw_progress_barf(
+ percent,
+ "%s %s/%s",
+ special_glyph(SPECIAL_GLYPH_ARROW_RIGHT),
+ FORMAT_BYTES(e->written_uncompressed),
+ FORMAT_BYTES(e->st.st_size));
+ else
log_info("Exported %u%%.", percent);
e->last_percent = percent;
diff --git a/src/import/export-tar.c b/src/import/export-tar.c
index 42f3adee96..e025efe411 100644
--- a/src/import/export-tar.c
+++ b/src/import/export-tar.c
@@ -134,17 +134,14 @@ static void tar_export_report_progress(TarExport *e) {
sd_notifyf(false, "X_IMPORT_PROGRESS=%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
+ if (isatty_safe(STDERR_FILENO))
+ (void) draw_progress_barf(
+ percent,
+ "%s %s/%s",
+ special_glyph(SPECIAL_GLYPH_ARROW_RIGHT),
+ FORMAT_BYTES(e->written_uncompressed),
+ FORMAT_BYTES(e->quota_referenced));
+ else
log_info("Exported %u%%.", percent);
e->last_percent = percent;
diff --git a/src/import/import-raw.c b/src/import/import-raw.c
index 190a08a005..602d1f1ac3 100644
--- a/src/import/import-raw.c
+++ b/src/import/import-raw.c
@@ -151,17 +151,14 @@ static void raw_import_report_progress(RawImport *i) {
sd_notifyf(false, "X_IMPORT_PROGRESS=%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
+ if (isatty_safe(STDERR_FILENO))
+ (void) draw_progress_barf(
+ percent,
+ "%s %s/%s",
+ special_glyph(SPECIAL_GLYPH_ARROW_RIGHT),
+ FORMAT_BYTES(i->written_compressed),
+ FORMAT_BYTES(i->input_stat.st_size));
+ else
log_info("Imported %u%%.", percent);
i->last_percent = percent;
diff --git a/src/import/import-tar.c b/src/import/import-tar.c
index 6e6c720782..e82159cb52 100644
--- a/src/import/import-tar.c
+++ b/src/import/import-tar.c
@@ -152,17 +152,14 @@ static void tar_import_report_progress(TarImport *i) {
sd_notifyf(false, "X_IMPORT_PROGRESS=%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
+ if (isatty_safe(STDERR_FILENO))
+ (void) draw_progress_barf(
+ percent,
+ "%s %s/%s",
+ special_glyph(SPECIAL_GLYPH_ARROW_RIGHT),
+ FORMAT_BYTES(i->written_compressed),
+ FORMAT_BYTES(i->input_stat.st_size));
+ else
log_info("Imported %u%%.", percent);
i->last_percent = percent;