diff options
author | Lennart Poettering <lennart@poettering.net> | 2024-10-29 21:32:28 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2024-10-29 21:37:26 +0100 |
commit | 91d640435d0fd79fe74f6c558d69ffdcbdf86234 (patch) | |
tree | ff8c75d0c5c5c5b6d12e44d830a8b47e8f4d2de9 /src/partition | |
parent | pretty-print: rename draw_progress_bar_impl()→draw_progress_bar_unbuffered() (diff) | |
download | systemd-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/partition')
-rw-r--r-- | src/partition/repart.c | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/src/partition/repart.c b/src/partition/repart.c index 1acd5af38c..5427e0a69f 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -5085,21 +5085,19 @@ static int partition_format_verity_sig(Context *context, Partition *p) { static int progress_bytes(uint64_t n_bytes, void *userdata) { Partition *p = ASSERT_PTR(userdata); - _cleanup_free_ char *s = NULL; p->copy_blocks_done += n_bytes; - if (asprintf(&s, "%s %s %s %s/%s", - strna(p->copy_blocks_path), - special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), - strna(p->definition_path), - FORMAT_BYTES(p->copy_blocks_done), - FORMAT_BYTES(p->copy_blocks_size)) < 0) - return log_oom(); + (void) draw_progress_barf( + p->copy_blocks_done >= p->copy_blocks_size ? 100.0 : /* catch division be zero */ + 100.0 * (double) p->copy_blocks_done / (double) p->copy_blocks_size, + "%s %s %s %s/%s", + strna(p->copy_blocks_path), + special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), + strna(p->definition_path), + FORMAT_BYTES(p->copy_blocks_done), + FORMAT_BYTES(p->copy_blocks_size)); - draw_progress_bar(s, - p->copy_blocks_done >= p->copy_blocks_size ? 100.0 : /* catch division be zero */ - 100.0 * (double) p->copy_blocks_done / (double) p->copy_blocks_size); return 0; } |