Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Jones <nathanj@insightbb.com>2007-05-14 01:21:42 -0400
committerDan McGee <dan@archlinux.org>2007-05-14 01:22:15 -0400
commit5c930c318e7b80af3a322ddc7ddf9fe100e9c16b (patch)
treef0a5480fe7d324f8c66041ed36699c9168259f58
parent14c768365cc32659d0adf0887f93c39d340089fc (diff)
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>
-rw-r--r--src/pacman/conf.h1
-rw-r--r--src/pacman/pacman.c6
-rw-r--r--src/pacman/query.c12
-rw-r--r--src/pacman/sync.c15
-rw-r--r--src/pacman/util.c24
5 files changed, 47 insertions, 11 deletions
diff --git a/src/pacman/conf.h b/src/pacman/conf.h
index 4fff0abb..11aa41be 100644
--- a/src/pacman/conf.h
+++ b/src/pacman/conf.h
@@ -54,6 +54,7 @@ typedef struct __config_t {
pmtransflag_t flags;
unsigned short noask;
unsigned int ask;
+ unsigned short showsize;
} config_t;
config_t *config_new(void);
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 1f5c5aed..fe70ea10 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -131,6 +131,7 @@ static void usage(int op, char *myname)
printf(_(" -p, --file <package> query a package file instead of the database\n"));
printf(_(" -s, --search <regex> search locally-installed packages for matching strings\n"));
printf(_(" -u, --upgrades list all packages that can be upgraded\n"));
+ printf(_(" -z, --showsize display installed size of each package\n"));
} else if(op == PM_OP_SYNC) {
printf("%s: %s {-S --sync} [%s] [%s]\n", str_usg, myname, str_opt, str_pkg);
printf("%s:\n", str_opt);
@@ -146,6 +147,7 @@ static void usage(int op, char *myname)
printf(_(" -u, --sysupgrade upgrade all packages that are out of date\n"));
printf(_(" -w, --downloadonly download packages but do not install/upgrade anything\n"));
printf(_(" -y, --refresh download fresh package databases from the server\n"));
+ printf(_(" -z, --showsize display download size of each package\n"));
printf(_(" --ignore <pkg> ignore a package upgrade (can be used more than once)\n"));
}
printf(_(" --config <path> set an alternate configuration file\n"));
@@ -291,6 +293,7 @@ static int parseargs(int argc, char *argv[])
{"verbose", no_argument, 0, 'v'},
{"downloadonly", no_argument, 0, 'w'},
{"refresh", no_argument, 0, 'y'},
+ {"showsize", no_argument, 0, 'z'},
{"noconfirm", no_argument, 0, 1000},
{"config", required_argument, 0, 1001},
{"ignore", required_argument, 0, 1002},
@@ -304,7 +307,7 @@ static int parseargs(int argc, char *argv[])
struct stat st;
unsigned short logmask;
- while((opt = getopt_long(argc, argv, "ARUFQSTr:b:vkhscVfmnoldepiuwyg", opts, &option_index))) {
+ while((opt = getopt_long(argc, argv, "ARUFQSTr:b:vkhscVfmnoldepiuwygz", opts, &option_index))) {
if(opt < 0) {
break;
}
@@ -423,6 +426,7 @@ static int parseargs(int argc, char *argv[])
config->flags |= PM_TRANS_FLAG_NOCONFLICTS;
break;
case 'y': (config->op_s_sync)++; break;
+ case 'z': config->showsize = 1; break;
case '?': return(1);
default: return(1);
}
diff --git a/src/pacman/query.c b/src/pacman/query.c
index dcb7c6bb..bb4cfb9d 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -146,7 +146,17 @@ int pacman_query(alpm_list_t *targets)
alpm_list_t *grp;
pmpkg_t *pkg = alpm_list_getdata(i);
- printf("local/%s %s", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
+ /* print the package size with the output if -z option passed */
+ if(config->showsize) {
+ /* Convert byte size to MB */
+ double mbsize = alpm_pkg_get_size(pkg) / (1024.0 * 1024.0);
+
+ printf("local/%s %s [%.2f MB]", alpm_pkg_get_name(pkg),
+ alpm_pkg_get_version(pkg), mbsize);
+ } else {
+ printf("local/%s %s", alpm_pkg_get_name(pkg),
+ alpm_pkg_get_version(pkg));
+ }
if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
group = alpm_list_getdata(grp);
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 1b629429..4f11bb4c 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -251,8 +251,19 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets)
alpm_list_t *grp;
pmpkg_t *pkg = alpm_list_getdata(j);
- printf("%s/%s %s", alpm_db_get_name(db), alpm_pkg_get_name(pkg),
- alpm_pkg_get_version(pkg));
+ /* print the package size with the output if -z option passed */
+ if(config->showsize) {
+ /* Convert byte size to MB */
+ double mbsize = alpm_pkg_get_size(pkg) / (1024.0 * 1024.0);
+
+ printf("%s/%s %s [%.2f MB]", alpm_db_get_name(db),
+ alpm_pkg_get_name(pkg),
+ alpm_pkg_get_version(pkg), mbsize);
+ } else {
+ printf("%s/%s %s", alpm_db_get_name(db),
+ alpm_pkg_get_name(pkg),
+ alpm_pkg_get_version(pkg));
+ }
if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
group = alpm_list_getdata(grp);
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");