From 0d29fb21da48066ed0cedf8c83ef3b002f61ba64 Mon Sep 17 00:00:00 2001 From: Icarus Sparry Date: Tue, 26 Sep 2017 12:44:55 -0700 Subject: [PATCH] Fix progress meters The denominator for the progress report is based on the length of the linked list to be processed, and the numerator is the number of elements processed. Most loops have short cut conditions, which invoke continue, which don't therefore update the numerator, and so loops end before the progress meter shows 100%. In particular the final file might be skipped. Update the numerator early in the loop, and add a final call to print_progress to force showing 100% if it has not already been done. Note this can force another dot to be output for the case where stdout is not connected to a terminal. Signed-off-by: Icarus Sparry --- src/bundle.c | 8 +++++--- src/packs.c | 6 ++++-- src/staging.c | 4 +++- src/update.c | 4 +++- src/verify.c | 10 ++++++---- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/bundle.c b/src/bundle.c index 2fd2caba..d9b8f639 100644 --- a/src/bundle.c +++ b/src/bundle.c @@ -761,6 +761,7 @@ download_subscribed_packs: while (iter) { file = iter->data; iter = iter->next; + complete++; if (file->is_deleted || file->do_not_update || ignore(file)) { continue; @@ -780,13 +781,14 @@ download_subscribed_packs: /* two loops are necessary, first to stage, then to rename. Total is * list_length * 2 */ - print_progress(++complete, list_length * 2); + print_progress(complete, list_length * 2); } iter = list_head(to_install_files); while (iter) { file = iter->data; iter = iter->next; + complete++; if (file->is_deleted || file->do_not_update || ignore(file)) { continue; @@ -799,9 +801,9 @@ download_subscribed_packs: rename_staged_file_to_final(file); // This is the second half of this process - print_progress(++complete, list_length * 2); + print_progress(complete, list_length * 2); } - + print_progress(list_length * 2, list_length * 2); /* Force out 100% complete */ printf("\n"); sync(); grabtime_stop(×); diff --git a/src/packs.c b/src/packs.c index 0fb632d4..facbf041 100644 --- a/src/packs.c +++ b/src/packs.c @@ -109,15 +109,16 @@ int download_subscribed_packs(struct list *subs, bool required) while (iter) { sub = iter->data; iter = iter->next; + complete++; if (sub->oldversion == sub->version) { // pack didn't change in this release continue; } err = download_pack(sub->oldversion, sub->version, sub->component); - print_progress(++complete, list_length); + print_progress(complete, list_length); if (err < 0) { - if (required) { + if (required) { /* Probably need printf("\n") here */ return err; } else { continue; @@ -125,6 +126,7 @@ int download_subscribed_packs(struct list *subs, bool required) } } + print_progress(list_length, list_length); /* Force out 100% */ printf("\n"); return 0; } diff --git a/src/staging.c b/src/staging.c index 7808cca1..7ddb0de6 100644 --- a/src/staging.c +++ b/src/staging.c @@ -311,6 +311,7 @@ int rename_all_files_to_final(struct list *updates) struct file *file; file = list->data; list = list->next; + complete++; if (file->do_not_update) { skip += 1; continue; @@ -323,9 +324,10 @@ int rename_all_files_to_final(struct list *updates) update_good += 1; } - print_progress(++complete, list_length); + print_progress(complete, list_length); } + print_progress(list_length, list_length); /* Force out 100% */ printf("\n"); return update_count - update_good - update_errs - (update_skip - skip); } diff --git a/src/update.c b/src/update.c index 90759eb9..7fcdd29b 100644 --- a/src/update.c +++ b/src/update.c @@ -74,14 +74,16 @@ static struct list *full_download_loop(struct list *updates, int isfailed) while (iter) { file = iter->data; iter = iter->next; + complete++; if (file->is_deleted) { continue; } full_download(file); - print_progress(++complete, list_length); + print_progress(complete, list_length); } + print_progress(list_length, list_length); /* Force out 100% */ printf("\n"); if (isfailed) { diff --git a/src/verify.c b/src/verify.c index 11a18d91..9705c4e4 100644 --- a/src/verify.c +++ b/src/verify.c @@ -290,6 +290,7 @@ static struct list *download_loop(struct list *files, int isfailed) file = iter->data; iter = iter->next; + complete++; if (file->is_deleted) { continue; @@ -321,9 +322,9 @@ static struct list *download_loop(struct list *files, int isfailed) file->do_not_update = 1; } free(fullname); - print_progress(++complete, list_length); + print_progress(complete, list_length); } - + print_progress(list_length, list_length); /* Force out 100% */ printf("\n"); if (isfailed) { list_free_list(files); @@ -405,6 +406,7 @@ static void add_missing_files(struct manifest *official_manifest) file = iter->data; iter = iter->next; + complete++; if ((file->is_deleted) || (file->do_not_update)) { @@ -461,9 +463,9 @@ static void add_missing_files(struct manifest *official_manifest) } } free(fullname); - print_progress(++complete, list_length); + print_progress(complete, list_length); } - + print_progress(list_length, list_length); printf("\n"); }