mirror of
https://github.com/moparisthebest/pacman
synced 2025-02-28 17:31:52 -05:00
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>
This commit is contained in:
parent
e472e80c08
commit
f5b77eb989
@ -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
|
||||
*/
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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)));
|
||||
|
Loading…
x
Reference in New Issue
Block a user