summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Jones <nathanj@insightbb.com>2007-10-19 13:17:54 -0400
committerDan McGee <dan@archlinux.org>2007-10-19 19:30:06 -0500
commitf5b77eb9894ea92a08fac586ddf03e9ba70c3de8 (patch)
tree6cf3e2750522841f1e1fb39d4d5e9c953bd27644
parente472e80c084c5e94fdc15d2f6565c50e65854372 (diff)
downloadpacman-f5b77eb9894ea92a08fac586ddf03e9ba70c3de8.tar.xz
Add download size to target list.
This displays the download size, taking into account delta files and cached files. This closes FS#4182. Signed-off-by: Nathan Jones <nathanj@insightbb.com> Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--lib/libalpm/alpm.h2
-rw-r--r--lib/libalpm/sync.c34
-rw-r--r--src/pacman/query.c2
-rw-r--r--src/pacman/sync.c2
-rw-r--r--src/pacman/util.c12
-rw-r--r--src/pacman/util.h2
6 files changed, 47 insertions, 7 deletions
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index a4eaafa0..880bbeb0 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -215,6 +215,8 @@ alpm_list_t *alpm_pkg_get_files(pmpkg_t *pkg);
alpm_list_t *alpm_pkg_get_backup(pmpkg_t *pkg);
unsigned short alpm_pkg_has_scriptlet(pmpkg_t *pkg);
+unsigned long alpm_pkg_download_size(pmpkg_t *newpkg, pmdb_t *db_local);
+
/*
* Deltas
*/
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index d5f65001..3e12ffb5 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -749,6 +749,40 @@ static alpm_list_t *pkg_upgrade_delta_path(pmpkg_t *newpkg, pmdb_t *db_local)
return(ret);
}
+/** Returns the size of the files that will be downloaded to install a
+ * package.
+ *
+ * @param newpkg the new package to upgrade to
+ * @param db_local the local database
+ *
+ * @return the size of the download
+ */
+unsigned long SYMEXPORT alpm_pkg_download_size(pmpkg_t *newpkg, pmdb_t *db_local)
+{
+ char *fpath = _alpm_filecache_find(alpm_pkg_get_filename(newpkg));
+ unsigned long size = 0;
+
+ if(fpath) {
+ size = 0;
+ } else if(handle->usedelta) {
+ alpm_list_t *deltas = pkg_upgrade_delta_path(newpkg, db_local);
+
+ if(deltas) {
+ size = _alpm_delta_path_size_uncached(deltas);
+ } else {
+ size = alpm_pkg_get_size(newpkg);
+ }
+
+ alpm_list_free(deltas);
+ } else {
+ size = alpm_pkg_get_size(newpkg);
+ }
+
+ FREE(fpath);
+
+ return(size);
+}
+
/** Applies delta files to create an upgraded package file.
*
* All intermediate files are deleted, leaving only the starting and
diff --git a/src/pacman/query.c b/src/pacman/query.c
index 4e4002cf..8a01d829 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -219,7 +219,7 @@ static int query_upgrades(void)
printf(_("Checking for package upgrades... \n"));
if((syncpkgs = alpm_db_get_upgrades()) != NULL) {
- display_targets(syncpkgs);
+ display_targets(syncpkgs, db_local);
return(0);
}
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 6a7d50e7..bf6eed1b 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -601,7 +601,7 @@ int sync_trans(alpm_list_t *targets, int sync_only)
if(!(alpm_trans_get_flags() & PM_TRANS_FLAG_PRINTURIS)) {
int confirm;
- display_targets(packages);
+ display_targets(packages, db_local);
printf("\n");
if(config->op_s_downloadonly) {
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 48f3f1eb..78a359be 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -329,14 +329,15 @@ void list_display(const char *title, const alpm_list_t *list)
* retrieved from a transaction object
*/
/* TODO move to output.c? or just combine util and output */
-void display_targets(const alpm_list_t *syncpkgs)
+void display_targets(const alpm_list_t *syncpkgs, pmdb_t *db_local)
{
char *str;
const 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, dispsize = 0;
- double mbsize = 0.0, mbisize = 0.0, mbrsize = 0.0, mbdispsize = 0.0;
+ unsigned long size = 0, isize = 0, rsize = 0, dispsize = 0, dlsize = 0;
+ double mbsize = 0.0, mbisize = 0.0, mbrsize = 0.0, mbdispsize = 0.0,
+ mbdlsize = 0.0;
for(i = syncpkgs; i; i = alpm_list_next(i)) {
pmsyncpkg_t *sync = alpm_list_getdata(i);
@@ -361,6 +362,7 @@ void display_targets(const alpm_list_t *syncpkgs)
dispsize = alpm_pkg_get_size(pkg);
size += dispsize;
+ dlsize += alpm_pkg_download_size(pkg, db_local);
isize += alpm_pkg_get_isize(pkg);
/* print the package size with the output if ShowSize option set */
@@ -381,6 +383,7 @@ void display_targets(const alpm_list_t *syncpkgs)
mbsize = size / (1024.0 * 1024.0);
mbisize = isize / (1024.0 * 1024.0);
mbrsize = rsize / (1024.0 * 1024.0);
+ mbdlsize = dlsize / (1024.0 * 1024.0);
/* start displaying information */
printf("\n");
@@ -396,7 +399,8 @@ void display_targets(const alpm_list_t *syncpkgs)
list_display(_("Targets:"), targets);
printf("\n");
- printf(_("Total Package Size: %.2f MB\n"), mbsize);
+ printf(_("Total Package Size: %.2f MB\n"), mbsize);
+ printf(_("Total Download Size: %.2f MB\n"), mbdlsize);
/* TODO because all pkgs don't include isize, this is a crude hack */
if(mbisize > mbsize) {
diff --git a/src/pacman/util.h b/src/pacman/util.h
index f3171caf..876f8175 100644
--- a/src/pacman/util.h
+++ b/src/pacman/util.h
@@ -47,7 +47,7 @@ char *strtoupper(char *str);
char *strtrim(char *str);
char *strreplace(const char *str, const char *needle, const char *replace);
void list_display(const char *title, const alpm_list_t *list);
-void display_targets(const alpm_list_t *syncpkgs);
+void display_targets(const alpm_list_t *syncpkgs, pmdb_t *db_local);
int yesno(char *fmt, ...);
int pm_printf(pmloglevel_t level, const char *format, ...) __attribute__((format(printf,2,3)));
int pm_fprintf(FILE *stream, pmloglevel_t level, const char *format, ...) __attribute__((format(printf,3,4)));