From 1a73b93d63eafdd4b6e1e4e91c839a4ab5832418 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Wed, 25 Jan 2012 04:56:54 +0100 Subject: [PATCH] Calculate properly required/freed size in transactions. --- bin/xbps-bin/transaction.c | 2 +- lib/transaction_dictionary.c | 67 ++++++++++++++++++------------------ 2 files changed, 35 insertions(+), 34 deletions(-) diff --git a/bin/xbps-bin/transaction.c b/bin/xbps-bin/transaction.c index c931b873..9b0826b7 100644 --- a/bin/xbps-bin/transaction.c +++ b/bin/xbps-bin/transaction.c @@ -185,7 +185,7 @@ show_transaction_sizes(struct transaction *trans) "%s\n", strerror(errno)); return -1; } - printf("Total removed size:\t%6s\n", size); + printf("Total freed size:\t%6s\n", size); } printf("\n"); diff --git a/lib/transaction_dictionary.c b/lib/transaction_dictionary.c index 965d0785..f240483c 100644 --- a/lib/transaction_dictionary.c +++ b/lib/transaction_dictionary.c @@ -75,7 +75,9 @@ compute_transaction_stats(prop_dictionary_t transd) * Count number of pkgs to be removed, configured, * installed and updated. */ + prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname); prop_dictionary_get_cstring_nocopy(obj, "transaction", &tract); + if (strcmp(tract, "install") == 0) inst_pkgcnt++; else if (strcmp(tract, "update") == 0) @@ -84,38 +86,7 @@ compute_transaction_stats(prop_dictionary_t transd) cf_pkgcnt++; else if (strcmp(tract, "remove") == 0) rm_pkgcnt++; - } - if (inst_pkgcnt && - !prop_dictionary_set_uint32(transd, "total-install-pkgs", - inst_pkgcnt)) { - rv = EINVAL; - goto out; - } - if (up_pkgcnt && - !prop_dictionary_set_uint32(transd, "total-update-pkgs", - up_pkgcnt)) { - rv = EINVAL; - goto out; - } - if (cf_pkgcnt && - !prop_dictionary_set_uint32(transd, "total-configure-pkgs", - cf_pkgcnt)) { - rv = EINVAL; - goto out; - } - if (rm_pkgcnt && - !prop_dictionary_set_uint32(transd, "total-remove-pkgs", - rm_pkgcnt)) { - rv = EINVAL; - goto out; - } - - prop_object_iterator_reset(iter); - - while ((obj = prop_object_iterator_next(iter)) != NULL) { - prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname); - prop_dictionary_get_cstring_nocopy(obj, "transaction", &tract); /* * Only process pkgs to be installed or updated. */ @@ -146,9 +117,39 @@ compute_transaction_stats(prop_dictionary_t transd) dlsize += tsize; } } - /* installed - removed */ - if (rmsize > 0 && instsize > 0) + + if (inst_pkgcnt && + !prop_dictionary_set_uint32(transd, "total-install-pkgs", + inst_pkgcnt)) { + rv = EINVAL; + goto out; + } + if (up_pkgcnt && + !prop_dictionary_set_uint32(transd, "total-update-pkgs", + up_pkgcnt)) { + rv = EINVAL; + goto out; + } + if (cf_pkgcnt && + !prop_dictionary_set_uint32(transd, "total-configure-pkgs", + cf_pkgcnt)) { + rv = EINVAL; + goto out; + } + if (rm_pkgcnt && + !prop_dictionary_set_uint32(transd, "total-remove-pkgs", + rm_pkgcnt)) { + rv = EINVAL; + goto out; + } + + if (instsize > rmsize) { instsize -= rmsize; + rmsize = 0; + } else if (rmsize > instsize) { + rmsize -= instsize; + instsize = 0; + } /* * Add object in transaction dictionary with total installed * size that it will take.