From 028990d5760b3d978db7daebfb011385b73fb571 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Fri, 26 Feb 2010 13:27:09 +0000 Subject: state: write status for each package change prints like: (1/12) Installing... (2/12) Installing... etc... --- src/state.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/state.c b/src/state.c index 1d95f53..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); } } @@ -726,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) @@ -781,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)) { -- cgit v1.2.3