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 <icarus.w.sparry@intel.com>
This commit is contained in:
Icarus Sparry
2017-09-28 08:59:49 -07:00
committed by Matthew Johnson
parent 397d8758af
commit 0d29fb21da
5 changed files with 21 additions and 11 deletions
+5 -3
View File
@@ -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(&times);
+4 -2
View File
@@ -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;
}
+3 -1
View File
@@ -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);
}
+3 -1
View File
@@ -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) {
+6 -4
View File
@@ -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");
}