summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNagy Gabor <ngaba@bibl.u-szeged.hu>2008-07-08 10:17:19 +0200
committerDan McGee <dan@archlinux.org>2008-07-13 16:15:07 +0200
commitf724fb27022551e536496f8f99bc4be33b4ce3b7 (patch)
tree085a8636d9564ff04185ed60f1336e1d540d8c8d
parent1d9d47d62c8dab07bbd411ed0c1919ad4149cd43 (diff)
downloadpacman-f724fb27022551e536496f8f99bc4be33b4ce3b7.tar.gz
pacman-f724fb27022551e536496f8f99bc4be33b4ce3b7.tar.xz
remove_addtarget rework (in front-end)
Now "pacman -R foo" first searches for literal, and then for group. This is faster in most cases, see: http://www.archlinux.org/pipermail/pacman-dev/2008-July/012311.html "-R group" implementation was broken, since alpm_grp_get_pkgs returns with an pmpkg_t list, not a string list. Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--src/pacman/remove.c92
1 files changed, 46 insertions, 46 deletions
diff --git a/src/pacman/remove.c b/src/pacman/remove.c
index 4fe9bc81..83947cae 100644
--- a/src/pacman/remove.c
+++ b/src/pacman/remove.c
@@ -42,55 +42,59 @@ extern pmdb_t *db_local;
*/
int pacman_remove(alpm_list_t *targets)
{
- alpm_list_t *i, *data = NULL, *finaltargs = NULL;
int retval = 0;
+ alpm_list_t *i, *data = NULL;
if(targets == NULL) {
pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
return(1);
}
- /* If the target is a group, ask if its packages should be removed
- * (the library can't remove groups for now)
- */
- for(i = targets; i; i = alpm_list_next(i)) {
- pmgrp_t *grp = alpm_db_readgrp(db_local, alpm_list_getdata(i));
- if(grp) {
- int all;
- const alpm_list_t *p, *pkgnames = alpm_grp_get_pkgs(grp);
-
- printf(_(":: group %s:\n"), alpm_grp_get_name(grp));
- list_display(" ", pkgnames);
- all = yesno(1, _(" Remove whole content?"));
-
- for(p = pkgnames; p; p = alpm_list_next(p)) {
- char *pkg = alpm_list_getdata(p);
- if(all || yesno(1, _(":: Remove %s from group %s?"), pkg, (char *)alpm_list_getdata(i))) {
- finaltargs = alpm_list_add(finaltargs, strdup(pkg));
- }
- }
- } else {
- /* not a group, so add it to the final targets */
- finaltargs = alpm_list_add(finaltargs, strdup(alpm_list_getdata(i)));
- }
- }
-
- /* Step 1: create a new transaction */
+ /* Step 0: create a new transaction */
if(trans_init(PM_TRANS_TYPE_REMOVE, config->flags) == -1) {
- FREELIST(finaltargs);
return(1);
}
- /* add targets to the created transaction */
- printf(_("loading package data...\n"));
- for(i = finaltargs; i; i = alpm_list_next(i)) {
+ /* Step 1: add targets to the created transaction */
+ for(i = targets; i; i = alpm_list_next(i)) {
char *targ = alpm_list_getdata(i);
if(alpm_trans_addtarget(targ) == -1) {
- pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n",
- targ, alpm_strerrorlast());
- trans_release();
- FREELIST(finaltargs);
- return(1);
+ if(pm_errno == PM_ERR_PKG_NOT_FOUND) {
+ printf(_("%s not found, searching for group...\n"), targ);
+ pmgrp_t *grp = alpm_db_readgrp(db_local, targ);
+ if(grp == NULL) {
+ pm_fprintf(stderr, PM_LOG_ERROR, _("'%s': not found in local db\n"), targ);
+ retval = 1;
+ goto cleanup;
+ } else {
+ alpm_list_t *p, *pkgnames = NULL;
+ /* convert packages to package names */
+ for(p = alpm_grp_get_pkgs(grp); p; p = alpm_list_next(p)) {
+ pmpkg_t *pkg = alpm_list_getdata(p);
+ pkgnames = alpm_list_add(pkgnames, (void *)alpm_pkg_get_name(pkg));
+ }
+ printf(_(":: group %s:\n"), targ);
+ list_display(" ", pkgnames);
+ int all = yesno(1, _(" Remove whole content?"));
+ for(p = pkgnames; p; p = alpm_list_next(p)) {
+ char *pkgn = alpm_list_getdata(p);
+ if(all || yesno(1, _(":: Remove %s from group %s?"), pkgn, targ)) {
+ if(alpm_trans_addtarget(pkgn) == -1) {
+ pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", targ,
+ alpm_strerrorlast());
+ retval = 1;
+ alpm_list_free(pkgnames);
+ goto cleanup;
+ }
+ }
+ }
+ alpm_list_free(pkgnames);
+ }
+ } else {
+ pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", targ, alpm_strerrorlast());
+ retval = 1;
+ goto cleanup;
+ }
}
}
@@ -113,9 +117,8 @@ int pacman_remove(alpm_list_t *targets)
default:
break;
}
- trans_release();
- FREELIST(finaltargs);
- return(1);
+ retval = 1;
+ goto cleanup;
}
/* Warn user in case of dangerous operation */
@@ -133,9 +136,8 @@ int pacman_remove(alpm_list_t *targets)
FREELIST(lst);
/* get confirmation */
if(yesno(1, _("\nDo you want to remove these packages?")) == 0) {
- trans_release();
- FREELIST(finaltargs);
- return(1);
+ retval = 1;
+ goto cleanup;
}
printf("\n");
}
@@ -144,16 +146,14 @@ int pacman_remove(alpm_list_t *targets)
if(alpm_trans_commit(NULL) == -1) {
pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"),
alpm_strerrorlast());
- trans_release();
- FREELIST(finaltargs);
- return(1);
+ retval = 1;
}
/* Step 4: release transaction resources */
+cleanup:
if(trans_release() == -1) {
retval = 1;
}
- FREELIST(finaltargs);
return(retval);
}