mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-22 07:48:50 -05:00
Combine add and removal package list display
There was no real reason for these to be done separately. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
40a264478e
commit
bd83c8e756
@ -156,7 +156,7 @@ int pacman_remove(alpm_list_t *targets)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* print targets and ask user confirmation */
|
/* print targets and ask user confirmation */
|
||||||
display_targets(pkglist, 0);
|
display_targets();
|
||||||
printf("\n");
|
printf("\n");
|
||||||
if(yesno(_("Do you want to remove these packages?")) == 0) {
|
if(yesno(_("Do you want to remove these packages?")) == 0) {
|
||||||
retval = 1;
|
retval = 1;
|
||||||
|
@ -820,8 +820,7 @@ int sync_prepare_execute(void)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
display_targets(alpm_trans_get_remove(config->handle), 0);
|
display_targets();
|
||||||
display_targets(alpm_trans_get_add(config->handle), 1);
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
int confirm;
|
int confirm;
|
||||||
|
@ -744,7 +744,7 @@ void signature_display(const char *title, alpm_siglist_t *siglist)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* creates a header row for use with table_display */
|
/* creates a header row for use with table_display */
|
||||||
static alpm_list_t *create_verbose_header(int install)
|
static alpm_list_t *create_verbose_header(void)
|
||||||
{
|
{
|
||||||
alpm_list_t *res = NULL;
|
alpm_list_t *res = NULL;
|
||||||
char *str;
|
char *str;
|
||||||
@ -753,10 +753,8 @@ static alpm_list_t *create_verbose_header(int install)
|
|||||||
res = alpm_list_add(res, str);
|
res = alpm_list_add(res, str);
|
||||||
str = _("Old Version");
|
str = _("Old Version");
|
||||||
res = alpm_list_add(res, str);
|
res = alpm_list_add(res, str);
|
||||||
if(install) {
|
str = _("New Version");
|
||||||
str = _("New Version");
|
res = alpm_list_add(res, str);
|
||||||
res = alpm_list_add(res, str);
|
|
||||||
}
|
|
||||||
str = _("Size");
|
str = _("Size");
|
||||||
res = alpm_list_add(res, str);
|
res = alpm_list_add(res, str);
|
||||||
|
|
||||||
@ -764,125 +762,169 @@ static alpm_list_t *create_verbose_header(int install)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* returns package info as list of strings */
|
/* returns package info as list of strings */
|
||||||
static alpm_list_t *create_verbose_row(alpm_pkg_t *pkg, int install)
|
static alpm_list_t *create_verbose_row(pm_target_t *target)
|
||||||
{
|
{
|
||||||
char *str;
|
char *str;
|
||||||
double size;
|
off_t size = 0;
|
||||||
|
double human_size;
|
||||||
const char *label;
|
const char *label;
|
||||||
alpm_list_t *ret = NULL;
|
alpm_list_t *ret = NULL;
|
||||||
alpm_db_t *ldb = alpm_option_get_localdb(config->handle);
|
|
||||||
|
|
||||||
/* a row consists of the package name, */
|
/* a row consists of the package name, */
|
||||||
pm_asprintf(&str, "%s", alpm_pkg_get_name(pkg));
|
if(target->install) {
|
||||||
|
pm_asprintf(&str, "%s", alpm_pkg_get_name(target->install));
|
||||||
|
} else {
|
||||||
|
pm_asprintf(&str, "%s", alpm_pkg_get_name(target->remove));
|
||||||
|
}
|
||||||
ret = alpm_list_add(ret, str);
|
ret = alpm_list_add(ret, str);
|
||||||
|
|
||||||
/* old and new versions */
|
/* old and new versions */
|
||||||
if(install) {
|
pm_asprintf(&str, "%s",
|
||||||
alpm_pkg_t *oldpkg = alpm_db_get_pkg(ldb, alpm_pkg_get_name(pkg));
|
target->remove != NULL ? alpm_pkg_get_version(target->remove) : "");
|
||||||
pm_asprintf(&str, "%s",
|
ret = alpm_list_add(ret, str);
|
||||||
oldpkg != NULL ? alpm_pkg_get_version(oldpkg) : "");
|
|
||||||
ret = alpm_list_add(ret, str);
|
|
||||||
}
|
|
||||||
|
|
||||||
pm_asprintf(&str, "%s", alpm_pkg_get_version(pkg));
|
pm_asprintf(&str, "%s",
|
||||||
|
target->install != NULL ? alpm_pkg_get_version(target->install) : "");
|
||||||
ret = alpm_list_add(ret, str);
|
ret = alpm_list_add(ret, str);
|
||||||
|
|
||||||
/* and size */
|
/* and size */
|
||||||
size = humanize_size(alpm_pkg_get_size(pkg), 'M', &label);
|
size -= target->remove ? alpm_pkg_get_isize(target->remove) : 0;
|
||||||
pm_asprintf(&str, "%.2f %s", size, label);
|
size += target->install ? alpm_pkg_get_isize(target->install) : 0;
|
||||||
|
human_size = humanize_size(size, 'M', &label);
|
||||||
|
pm_asprintf(&str, "%.2f %s", human_size, label);
|
||||||
ret = alpm_list_add(ret, str);
|
ret = alpm_list_add(ret, str);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* prepare a list of pkgs to display */
|
/* prepare a list of pkgs to display */
|
||||||
void display_targets(const alpm_list_t *pkgs, int install)
|
static void _display_targets(alpm_list_t *targets)
|
||||||
{
|
{
|
||||||
char *str;
|
char *str;
|
||||||
const char *title, *label;
|
const char *label;
|
||||||
double size;
|
double size;
|
||||||
const alpm_list_t *i;
|
|
||||||
off_t isize = 0, rsize = 0, dlsize = 0;
|
off_t isize = 0, rsize = 0, dlsize = 0;
|
||||||
alpm_list_t *j, *lp, *header = NULL, *targets = NULL;
|
alpm_list_t *i, *header = NULL, *rows = NULL;
|
||||||
alpm_db_t *db_local = alpm_option_get_localdb(config->handle);
|
|
||||||
|
|
||||||
if(!pkgs) {
|
if(!targets) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* gather pkg infos */
|
/* gather package info */
|
||||||
for(i = pkgs; i; i = alpm_list_next(i)) {
|
for(i = targets; i; i = alpm_list_next(i)) {
|
||||||
alpm_pkg_t *pkg = alpm_list_getdata(i);
|
pm_target_t *target = alpm_list_getdata(i);
|
||||||
|
|
||||||
if(install) {
|
if(target->install) {
|
||||||
alpm_pkg_t *lpkg = alpm_db_get_pkg(db_local, alpm_pkg_get_name(pkg));
|
dlsize += alpm_pkg_download_size(target->install);
|
||||||
dlsize += alpm_pkg_download_size(pkg);
|
isize += alpm_pkg_get_isize(target->install);
|
||||||
if(lpkg) {
|
}
|
||||||
/* add up size of all removed packages */
|
if(target->remove) {
|
||||||
rsize += alpm_pkg_get_isize(lpkg);
|
/* add up size of all removed packages */
|
||||||
}
|
rsize += alpm_pkg_get_isize(target->remove);
|
||||||
}
|
}
|
||||||
isize += alpm_pkg_get_isize(pkg);
|
|
||||||
|
|
||||||
if(config->verbosepkglists) {
|
if(config->verbosepkglists) {
|
||||||
targets = alpm_list_add(targets, create_verbose_row(pkg, install));
|
rows = alpm_list_add(rows, create_verbose_row(target));
|
||||||
} else {
|
} else {
|
||||||
pm_asprintf(&str, "%s-%s", alpm_pkg_get_name(pkg),
|
if(target->install) {
|
||||||
alpm_pkg_get_version(pkg));
|
pm_asprintf(&str, "%s-%s", alpm_pkg_get_name(target->install),
|
||||||
targets = alpm_list_add(targets, str);
|
alpm_pkg_get_version(target->install));
|
||||||
|
} else {
|
||||||
|
pm_asprintf(&str, "%s-%s [removal]", alpm_pkg_get_name(target->remove),
|
||||||
|
alpm_pkg_get_version(target->remove));
|
||||||
|
}
|
||||||
|
rows = alpm_list_add(rows, str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* print to screen */
|
/* print to screen */
|
||||||
title = install ? _("Targets (%d):") : _("Remove (%d):");
|
pm_asprintf(&str, _("Targets (%d):"), alpm_list_count(targets));
|
||||||
pm_asprintf(&str, title, alpm_list_count(pkgs));
|
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
if(config->verbosepkglists) {
|
if(config->verbosepkglists) {
|
||||||
header = create_verbose_header(install);
|
header = create_verbose_header();
|
||||||
if(table_display(str, header, targets) != 0) {
|
if(table_display(str, header, rows) != 0) {
|
||||||
config->verbosepkglists = 0;
|
config->verbosepkglists = 0;
|
||||||
display_targets(pkgs, install);
|
_display_targets(targets);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
list_display(str, targets);
|
list_display(str, rows);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
if(install) {
|
if(dlsize > 0) {
|
||||||
size = humanize_size(dlsize, 'M', &label);
|
size = humanize_size(dlsize, 'M', &label);
|
||||||
printf(_("Total Download Size: %.2f %s\n"), size, label);
|
printf(_("Total Download Size: %.2f %s\n"), size, label);
|
||||||
if(!(config->flags & ALPM_TRANS_FLAG_DOWNLOADONLY)) {
|
}
|
||||||
|
if(!(config->flags & ALPM_TRANS_FLAG_DOWNLOADONLY)) {
|
||||||
|
if(isize > 0) {
|
||||||
size = humanize_size(isize, 'M', &label);
|
size = humanize_size(isize, 'M', &label);
|
||||||
printf(_("Total Installed Size: %.2f %s\n"), size, label);
|
printf(_("Total Installed Size: %.2f %s\n"), size, label);
|
||||||
/* only show this net value if different from raw installed size */
|
|
||||||
if(rsize > 0) {
|
|
||||||
size = humanize_size(isize - rsize, 'M', &label);
|
|
||||||
printf(_("Net Upgrade Size: %.2f %s\n"), size, label);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
if(rsize > 0) {
|
||||||
size = humanize_size(isize, 'M', &label);
|
size = humanize_size(rsize, 'M', &label);
|
||||||
printf(_("Total Removed Size: %.2f %s\n"), size, label);
|
printf(_("Total Removed Size: %.2f %s\n"), size, label);
|
||||||
|
}
|
||||||
|
/* only show this net value if different from raw installed size */
|
||||||
|
if(isize > 0 && rsize > 0) {
|
||||||
|
size = humanize_size(isize - rsize, 'M', &label);
|
||||||
|
printf(_("Net Upgrade Size: %.2f %s\n"), size, label);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
/* cleanup */
|
/* cleanup */
|
||||||
if(config->verbosepkglists) {
|
if(config->verbosepkglists) {
|
||||||
/* targets is a list of lists of strings, free inner lists here */
|
/* rows is a list of lists of strings, free inner lists here */
|
||||||
for(j = targets; j; j = alpm_list_next(j)) {
|
for(i = rows; i; i = alpm_list_next(i)) {
|
||||||
lp = alpm_list_getdata(j);
|
alpm_list_t *lp = alpm_list_getdata(i);
|
||||||
FREELIST(lp);
|
FREELIST(lp);
|
||||||
}
|
}
|
||||||
alpm_list_free(targets);
|
|
||||||
alpm_list_free(header);
|
alpm_list_free(header);
|
||||||
} else {
|
} else {
|
||||||
FREELIST(targets);
|
FREELIST(rows);
|
||||||
}
|
}
|
||||||
free(str);
|
free(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int target_cmp(const void *p1, const void *p2)
|
||||||
|
{
|
||||||
|
const pm_target_t *targ1 = p1;
|
||||||
|
const pm_target_t *targ2 = p2;
|
||||||
|
const char *name1 = targ1->install ?
|
||||||
|
alpm_pkg_get_name(targ1->install) : alpm_pkg_get_name(targ1->remove);
|
||||||
|
const char *name2 = targ2->install ?
|
||||||
|
alpm_pkg_get_name(targ2->install) : alpm_pkg_get_name(targ2->remove);
|
||||||
|
return strcmp(name1, name2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void display_targets(void)
|
||||||
|
{
|
||||||
|
alpm_list_t *i, *targets = NULL;
|
||||||
|
alpm_db_t *db_local = alpm_option_get_localdb(config->handle);
|
||||||
|
|
||||||
|
for(i = alpm_trans_get_add(config->handle); i; i = alpm_list_next(i)) {
|
||||||
|
alpm_pkg_t *pkg = alpm_list_getdata(i);
|
||||||
|
pm_target_t *targ = calloc(1, sizeof(pm_target_t));
|
||||||
|
if(!targ) return;
|
||||||
|
targ->install = pkg;
|
||||||
|
targ->remove = alpm_db_get_pkg(db_local, alpm_pkg_get_name(pkg));
|
||||||
|
targets = alpm_list_add(targets, targ);
|
||||||
|
}
|
||||||
|
for(i = alpm_trans_get_remove(config->handle); i; i = alpm_list_next(i)) {
|
||||||
|
alpm_pkg_t *pkg = alpm_list_getdata(i);
|
||||||
|
pm_target_t *targ = calloc(1, sizeof(pm_target_t));
|
||||||
|
if(!targ) return;
|
||||||
|
targ->remove = pkg;
|
||||||
|
targets = alpm_list_add(targets, targ);
|
||||||
|
}
|
||||||
|
|
||||||
|
targets = alpm_list_msort(targets, alpm_list_count(targets), target_cmp);
|
||||||
|
_display_targets(targets);
|
||||||
|
FREELIST(targets);
|
||||||
|
}
|
||||||
|
|
||||||
static off_t pkg_get_size(alpm_pkg_t *pkg)
|
static off_t pkg_get_size(alpm_pkg_t *pkg)
|
||||||
{
|
{
|
||||||
switch(config->op) {
|
switch(config->op) {
|
||||||
|
@ -39,6 +39,11 @@
|
|||||||
/* update speed for the fill_progress based functions */
|
/* update speed for the fill_progress based functions */
|
||||||
#define UPDATE_SPEED_SEC 0.2f
|
#define UPDATE_SPEED_SEC 0.2f
|
||||||
|
|
||||||
|
typedef struct _pm_target_t {
|
||||||
|
alpm_pkg_t *remove;
|
||||||
|
alpm_pkg_t *install;
|
||||||
|
} pm_target_t;
|
||||||
|
|
||||||
void trans_init_error(void);
|
void trans_init_error(void);
|
||||||
int trans_init(alpm_transflag_t flags, int check_valid);
|
int trans_init(alpm_transflag_t flags, int check_valid);
|
||||||
int trans_release(void);
|
int trans_release(void);
|
||||||
@ -59,7 +64,7 @@ int table_display(const char *title, const alpm_list_t *header, const alpm_list_
|
|||||||
void list_display(const char *title, const alpm_list_t *list);
|
void list_display(const char *title, const alpm_list_t *list);
|
||||||
void list_display_linebreak(const char *title, const alpm_list_t *list);
|
void list_display_linebreak(const char *title, const alpm_list_t *list);
|
||||||
void signature_display(const char *title, alpm_siglist_t *siglist);
|
void signature_display(const char *title, alpm_siglist_t *siglist);
|
||||||
void display_targets(const alpm_list_t *pkgs, int install);
|
void display_targets(void);
|
||||||
int str_cmp(const void *s1, const void *s2);
|
int str_cmp(const void *s1, const void *s2);
|
||||||
void display_new_optdepends(alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg);
|
void display_new_optdepends(alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg);
|
||||||
void display_optdepends(alpm_pkg_t *pkg);
|
void display_optdepends(alpm_pkg_t *pkg);
|
||||||
|
Loading…
Reference in New Issue
Block a user