diff options
-rw-r--r-- | src/state.c | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/src/state.c b/src/state.c index 1bd29bf..731e3d1 100644 --- a/src/state.c +++ b/src/state.c @@ -529,11 +529,16 @@ int apk_state_lock_name(struct apk_state *state, static void apk_print_change(struct apk_database *db, struct apk_package *oldpkg, - struct apk_package *newpkg) + struct apk_package *newpkg, + int num, int total) { const char *msg = NULL; int r; struct apk_name *name; + char status[64]; + + snprintf(status, sizeof(status), "(%i/%i)", num, total); + status[sizeof(status) - 1] = '\0'; if (oldpkg != NULL) name = oldpkg->name; @@ -541,11 +546,11 @@ static void apk_print_change(struct apk_database *db, name = newpkg->name; if (oldpkg == NULL) { - apk_message("Installing %s (%s)", - name->name, newpkg->version); + apk_message("%s Installing %s (%s)", + status, name->name, newpkg->version); } else if (newpkg == NULL) { - apk_message("Purging %s (%s)", - name->name, oldpkg->version); + apk_message("%s Purging %s (%s)", + status, name->name, oldpkg->version); } else { r = apk_pkg_version_compare(newpkg, oldpkg); switch (r) { @@ -559,8 +564,8 @@ static void apk_print_change(struct apk_database *db, msg = "Upgrading"; break; } - apk_message("%s %s (%s -> %s)", - msg, name->name, oldpkg->version, + apk_message("%s %s %s (%s -> %s)", + status, msg, name->name, oldpkg->version, newpkg->version); } } @@ -580,18 +585,21 @@ static void apk_count_change(struct apk_change *change, struct apk_stats *stats) stats->packages ++; } -static inline void apk_draw_progress(int x, int last) +static inline void apk_draw_progress(int percent, int last) { - char tmp[] = - "-[ ]- " - "\b\b\b\b\b\b\b\b\b\b\b\b\b" - "\b\b\b\b\b\b\b\b\b\b\b\b"; + char tmp[128]; + char reset[128]; int i; - for (i = 0; i < x; i++) + snprintf(tmp, sizeof(tmp), "-[ ]- %3i%%", percent); + for (i = 0; (i < (percent/5)) && (i < (sizeof(tmp)-2)); i++) tmp[2+i] = '#'; - - fwrite(tmp, last ? 25 : sizeof(tmp)-1, 1, stderr); + memset(reset, '\b', strlen(tmp)); + fwrite(tmp, strlen(tmp), 1, stderr); + if (!last) + fwrite(reset, strlen(tmp), 1, stderr); + else if (apk_verbosity > 0) + fwrite("\n", 1, 1, stderr); fflush(stderr); } @@ -610,7 +618,7 @@ static void progress_cb(void *ctx, size_t progress) if (prog->pkg != NULL) partial = muldiv(progress, prog->pkg->installed_size, APK_PROGRESS_SCALE); - count = muldiv(20, prog->done.bytes + prog->done.packages + partial, + count = muldiv(100, prog->done.bytes + prog->done.packages + partial, prog->total.bytes + prog->total.packages); if (prog->count != count) @@ -723,10 +731,12 @@ int apk_state_commit(struct apk_state *state, struct progress prog; struct apk_change *change; int r = 0, size_diff = 0, toplevel = FALSE, deleteonly = TRUE; + int n = 0, numpkg = 0; /* Count what needs to be done */ memset(&prog, 0, sizeof(prog)); list_for_each_entry(change, &state->change_list_head, change_list) { + numpkg++; if (change->newpkg == NULL) { apk_state_autoclean(state, change->oldpkg); if (change->oldpkg->name->flags & APK_NAME_TOPLEVEL) @@ -778,8 +788,10 @@ int apk_state_commit(struct apk_state *state, /* Go through changes */ r = 0; + n = 0; list_for_each_entry(change, &state->change_list_head, change_list) { - apk_print_change(db, change->oldpkg, change->newpkg); + n++; + apk_print_change(db, change->oldpkg, change->newpkg, n, numpkg); prog.pkg = change->newpkg; if (!(apk_flags & APK_SIMULATE)) { @@ -801,7 +813,7 @@ int apk_state_commit(struct apk_state *state, apk_count_change(change, &prog.done); } if (apk_flags & APK_PROGRESS) - apk_draw_progress(20, 1); + apk_draw_progress(100, 1); update_state: apk_db_run_triggers(db); |