[pacman-dev] [PATCH] Show used/freed space when syncing (FR FS#12566)

Hugo Chargois hugo.chargois at free.fr
Sun Jan 10 21:46:56 EST 2010


Shows the "Total Used/Freed Size" after "Total Download Size" and
"Total Installed Size" when syncing packages. It is the difference of
installation size between packages to be updated and the installation
size of the older version of these packages on disk. For exemple, if
uploading to a new version of a package that has an installed size of
60 and the old version has an installed size of 50, this will show 10.
Negative numbers represent space actually freed.

Signed-off-by: Hugo Chargois <hugo.chargois at free.fr>
---
 src/pacman/util.c |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/pacman/util.c b/src/pacman/util.c
index 14a0f6c..e1e0064 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -44,6 +44,7 @@
 #include "conf.h"
 #include "callback.h"

+extern pmdb_t db_local;

 int trans_init(pmtransflag_t flags)
 {
@@ -498,8 +499,8 @@ void display_targets(const alpm_list_t *pkgs, int install)
 {
       char *str;
       const alpm_list_t *i;
-       off_t isize = 0, dlsize = 0;
-       double mbisize = 0.0, mbdlsize = 0.0;
+       off_t isize = 0, dlsize = 0, localsize = 0;
+       double mbisize = 0.0, mbdlsize = 0.0, mbdeltasize = 0.0;
       alpm_list_t *targets = NULL;

       if(!pkgs) {
@@ -510,8 +511,14 @@ void display_targets(const alpm_list_t *pkgs, int install)
       for(i = pkgs; i; i = alpm_list_next(i)) {
               pmpkg_t *pkg = alpm_list_getdata(i);

+               char *name = alpm_pkg_get_name(pkg);
+               pmpkg_t *local_pkg = alpm_db_get_pkg(db_local, name);
+
               dlsize += alpm_pkg_download_size(pkg);
               isize += alpm_pkg_get_isize(pkg);
+               if(local_pkg != NULL){
+                       localsize += alpm_pkg_get_isize(local_pkg);
+               }

               /* print the package size with the output if ShowSize
option set */
               if(config->showsize) {
@@ -527,9 +534,10 @@ void display_targets(const alpm_list_t *pkgs, int install)
               targets = alpm_list_add(targets, str);
       }

-       /* Convert byte sizes to MB */
+       /* Convert byte sizes to MB and calculate delta size*/
       mbdlsize = dlsize / (1024.0 * 1024.0);
       mbisize = isize / (1024.0 * 1024.0);
+       mbdeltasize = (isize - localsize) / (1024.0 * 1024.0);

       if(install) {
               asprintf(&str, _("Targets (%d):"), alpm_list_count(targets));
@@ -539,6 +547,7 @@ void display_targets(const alpm_list_t *pkgs, int install)

               printf(_("Total Download Size:    %.2f MB\n"), mbdlsize);
               printf(_("Total Installed Size:   %.2f MB\n"), mbisize);
+               printf(_("Total Size Used/Freed: % .2f MB\n"), mbdeltasize);
       } else {
               asprintf(&str, _("Remove (%d):"), alpm_list_count(targets));
               list_display(str, targets);
--
1.6.3.3


More information about the pacman-dev mailing list