summaryrefslogtreecommitdiffstats
path: root/src/pacman/util.c
diff options
context:
space:
mode:
authorNathan Jones <nathanj@insightbb.com>2007-05-14 07:21:42 +0200
committerDan McGee <dan@archlinux.org>2007-05-14 07:22:15 +0200
commit5c930c318e7b80af3a322ddc7ddf9fe100e9c16b (patch)
treef0a5480fe7d324f8c66041ed36699c9168259f58 /src/pacman/util.c
parent14c768365cc32659d0adf0887f93c39d340089fc (diff)
downloadpacman-5c930c318e7b80af3a322ddc7ddf9fe100e9c16b.tar.gz
pacman-5c930c318e7b80af3a322ddc7ddf9fe100e9c16b.tar.xz
Display size for packages
This patch adds a -z|--showsize option to the -Q and -S commands. The option displays the size of individual packages. This is something that I have wanted for a while, and there is a feature request for it. Signed-off-by: Nathan Jones <nathanj@insightbb.com> Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'src/pacman/util.c')
-rw-r--r--src/pacman/util.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 780434cd..0057a85b 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -266,8 +266,8 @@ void display_targets(alpm_list_t *syncpkgs)
alpm_list_t *i, *j;
alpm_list_t *targets = NULL, *to_remove = NULL;
/* TODO these are some messy variable names */
- unsigned long size = 0, isize = 0, rsize = 0;
- double mbsize = 0.0, mbisize = 0.0, mbrsize = 0.0;
+ unsigned long size = 0, isize = 0, rsize = 0, dispsize = 0;
+ double mbsize = 0.0, mbisize = 0.0, mbrsize = 0.0, mbdispsize = 0.0;
for(i = syncpkgs; i; i = alpm_list_next(i)) {
pmsyncpkg_t *sync = alpm_list_getdata(i);
@@ -290,17 +290,27 @@ void display_targets(alpm_list_t *syncpkgs)
}
}
- size += alpm_pkg_get_size(pkg);
+ dispsize = alpm_pkg_get_size(pkg);
+ size += dispsize;
isize += alpm_pkg_get_isize(pkg);
- asprintf(&str, "%s-%s", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
+ if(config->showsize) {
+ /* Convert byte size to MB */
+ mbdispsize = dispsize / (1024.0 * 1024.0);
+
+ asprintf(&str, "%s-%s [%.1f MB]", alpm_pkg_get_name(pkg),
+ alpm_pkg_get_version(pkg), (mbdispsize < 0.1 ? 0.1 : mbdispsize));
+ } else {
+ asprintf(&str, "%s-%s", alpm_pkg_get_name(pkg),
+ alpm_pkg_get_version(pkg));
+ }
targets = alpm_list_add(targets, str);
}
/* Convert byte sizes to MB */
- mbsize = (double)(size) / (1024.0 * 1024.0);
- mbisize = (double)(isize) / (1024.0 * 1024.0);
- mbrsize = (double)(rsize) / (1024.0 * 1024.0);
+ mbsize = size / (1024.0 * 1024.0);
+ mbisize = isize / (1024.0 * 1024.0);
+ mbrsize = rsize / (1024.0 * 1024.0);
/* start displaying information */
printf("\n");