2005-03-14 20:51:43 -05:00
|
|
|
/*
|
|
|
|
* remove.c
|
2007-11-16 21:18:45 -05:00
|
|
|
*
|
2011-01-05 23:45:15 -05:00
|
|
|
* Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>
|
2009-07-01 03:08:33 -04:00
|
|
|
* Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
|
2007-11-16 21:18:45 -05:00
|
|
|
*
|
2005-03-14 20:51:43 -05:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2007-12-10 23:55:22 -05:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2005-03-14 20:51:43 -05:00
|
|
|
*/
|
|
|
|
|
2007-03-05 17:13:33 -05:00
|
|
|
#include "config.h"
|
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <alpm.h>
|
2007-01-19 04:28:44 -05:00
|
|
|
#include <alpm_list.h>
|
2007-03-05 17:13:33 -05:00
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
/* pacman */
|
2007-04-25 02:21:12 -04:00
|
|
|
#include "pacman.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
#include "util.h"
|
2005-10-28 08:20:40 -04:00
|
|
|
#include "conf.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2011-06-01 18:11:45 -04:00
|
|
|
static int remove_target(const char *target)
|
2010-10-17 05:18:01 -04:00
|
|
|
{
|
2011-07-29 16:35:59 -04:00
|
|
|
alpm_pkg_t *pkg;
|
2011-06-28 00:11:43 -04:00
|
|
|
alpm_db_t *db_local = alpm_option_get_localdb(config->handle);
|
2010-10-17 05:18:01 -04:00
|
|
|
alpm_list_t *p;
|
|
|
|
|
2011-07-29 16:35:59 -04:00
|
|
|
if((pkg = alpm_db_get_pkg(db_local, target)) != NULL) {
|
|
|
|
if(alpm_remove_pkg(config->handle, pkg) == -1) {
|
2011-07-01 12:01:38 -04:00
|
|
|
pm_fprintf(stderr, ALPM_LOG_ERROR, "'%s': %s\n", target,
|
2011-06-07 17:06:16 -04:00
|
|
|
alpm_strerror(alpm_errno(config->handle)));
|
2011-03-20 20:45:57 -04:00
|
|
|
return -1;
|
2010-10-17 05:18:01 -04:00
|
|
|
}
|
2011-07-29 16:35:59 -04:00
|
|
|
config->explicit_removes = alpm_list_add(config->explicit_removes, pkg);
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2010-10-17 05:18:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* fallback to group */
|
2011-06-29 01:46:49 -04:00
|
|
|
alpm_group_t *grp = alpm_db_readgroup(db_local, target);
|
2010-10-17 05:18:01 -04:00
|
|
|
if(grp == NULL) {
|
2011-07-01 12:01:38 -04:00
|
|
|
pm_fprintf(stderr, ALPM_LOG_ERROR, "'%s': target not found\n", target);
|
2011-03-20 20:45:57 -04:00
|
|
|
return -1;
|
2010-10-17 05:18:01 -04:00
|
|
|
}
|
2011-06-16 12:55:26 -04:00
|
|
|
for(p = grp->packages; p; p = alpm_list_next(p)) {
|
2011-07-29 16:35:59 -04:00
|
|
|
pkg = alpm_list_getdata(p);
|
2011-06-09 17:00:55 -04:00
|
|
|
if(alpm_remove_pkg(config->handle, pkg) == -1) {
|
2011-07-01 12:01:38 -04:00
|
|
|
pm_fprintf(stderr, ALPM_LOG_ERROR, "'%s': %s\n", target,
|
2011-06-07 17:06:16 -04:00
|
|
|
alpm_strerror(alpm_errno(config->handle)));
|
2011-03-20 20:45:57 -04:00
|
|
|
return -1;
|
2010-10-17 05:18:01 -04:00
|
|
|
}
|
2011-07-29 16:35:59 -04:00
|
|
|
config->explicit_removes = alpm_list_add(config->explicit_removes, pkg);
|
2010-10-17 05:18:01 -04:00
|
|
|
}
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2010-10-17 05:18:01 -04:00
|
|
|
}
|
|
|
|
|
2007-04-25 04:08:49 -04:00
|
|
|
/**
|
|
|
|
* @brief Remove a specified list of packages.
|
|
|
|
*
|
|
|
|
* @param targets a list of packages (as strings) to remove from the system
|
|
|
|
*
|
|
|
|
* @return 0 on success, 1 on failure
|
|
|
|
*/
|
2007-01-19 04:28:44 -05:00
|
|
|
int pacman_remove(alpm_list_t *targets)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2006-01-26 15:46:48 -05:00
|
|
|
int retval = 0;
|
2008-07-08 04:17:19 -04:00
|
|
|
alpm_list_t *i, *data = NULL;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
if(targets == NULL) {
|
2011-07-01 12:01:38 -04:00
|
|
|
pm_printf(ALPM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
|
2011-03-20 20:45:57 -04:00
|
|
|
return 1;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2008-07-08 04:17:19 -04:00
|
|
|
/* Step 0: create a new transaction */
|
2011-06-08 00:08:06 -04:00
|
|
|
if(trans_init(config->flags, 0) == -1) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return 1;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2007-04-25 04:08:49 -04:00
|
|
|
|
2008-07-08 04:17:19 -04:00
|
|
|
/* Step 1: add targets to the created transaction */
|
|
|
|
for(i = targets; i; i = alpm_list_next(i)) {
|
2009-07-16 08:55:45 -04:00
|
|
|
char *target = alpm_list_getdata(i);
|
|
|
|
char *targ = strchr(target, '/');
|
|
|
|
if(targ && strncmp(target, "local", 5) == 0) {
|
|
|
|
targ++;
|
|
|
|
} else {
|
|
|
|
targ = target;
|
|
|
|
}
|
2010-10-17 05:18:01 -04:00
|
|
|
if(remove_target(targ) == -1) {
|
2009-07-16 08:55:45 -04:00
|
|
|
retval = 1;
|
|
|
|
goto cleanup;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-25 04:08:49 -04:00
|
|
|
/* Step 2: prepare the transaction based on its type, targets and flags */
|
2011-06-07 14:29:05 -04:00
|
|
|
if(alpm_trans_prepare(config->handle, &data) == -1) {
|
2011-06-28 00:50:48 -04:00
|
|
|
enum _alpm_errno_t err = alpm_errno(config->handle);
|
2011-07-01 12:01:38 -04:00
|
|
|
pm_fprintf(stderr, ALPM_LOG_ERROR, _("failed to prepare transaction (%s)\n"),
|
2011-06-07 17:06:16 -04:00
|
|
|
alpm_strerror(err));
|
|
|
|
switch(err) {
|
2011-07-01 12:01:39 -04:00
|
|
|
case ALPM_ERR_PKG_INVALID_ARCH:
|
2009-08-19 11:58:03 -04:00
|
|
|
for(i = data; i; i = alpm_list_next(i)) {
|
|
|
|
char *pkg = alpm_list_getdata(i);
|
|
|
|
printf(_(":: package %s does not have a valid architecture\n"), pkg);
|
|
|
|
}
|
|
|
|
break;
|
2011-07-01 12:01:39 -04:00
|
|
|
case ALPM_ERR_UNSATISFIED_DEPS:
|
2007-01-19 04:28:44 -05:00
|
|
|
for(i = data; i; i = alpm_list_next(i)) {
|
2011-06-28 00:32:09 -04:00
|
|
|
alpm_depmissing_t *miss = alpm_list_getdata(i);
|
2011-06-16 12:42:10 -04:00
|
|
|
char *depstring = alpm_dep_compute_string(miss->depend);
|
|
|
|
printf(_(":: %s: requires %s\n"), miss->target, depstring);
|
2007-10-24 20:31:28 -04:00
|
|
|
free(depstring);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2007-04-25 04:08:49 -04:00
|
|
|
break;
|
2005-03-14 20:51:43 -05:00
|
|
|
default:
|
2007-04-25 04:08:49 -04:00
|
|
|
break;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2011-06-03 12:37:15 -04:00
|
|
|
FREELIST(data);
|
2008-07-08 04:17:19 -04:00
|
|
|
retval = 1;
|
|
|
|
goto cleanup;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2008-08-24 17:24:53 -04:00
|
|
|
/* Search for holdpkg in target list */
|
|
|
|
int holdpkg = 0;
|
2011-06-07 14:29:05 -04:00
|
|
|
for(i = alpm_trans_get_remove(config->handle); i; i = alpm_list_next(i)) {
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *pkg = alpm_list_getdata(i);
|
2008-08-24 17:24:53 -04:00
|
|
|
if(alpm_list_find_str(config->holdpkg, alpm_pkg_get_name(pkg))) {
|
2011-07-01 12:01:38 -04:00
|
|
|
pm_printf(ALPM_LOG_WARNING, _("%s is designated as a HoldPkg.\n"),
|
2008-08-24 17:24:53 -04:00
|
|
|
alpm_pkg_get_name(pkg));
|
|
|
|
holdpkg = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(holdpkg && (noyes(_("HoldPkg was found in target list. Do you want to continue?")) == 0)) {
|
|
|
|
retval = 1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2009-09-15 06:30:32 -04:00
|
|
|
/* Step 3: actually perform the removal */
|
2011-06-07 14:29:05 -04:00
|
|
|
alpm_list_t *pkglist = alpm_trans_get_remove(config->handle);
|
2009-09-15 06:30:32 -04:00
|
|
|
if(pkglist == NULL) {
|
2010-01-19 15:35:13 -05:00
|
|
|
printf(_(" there is nothing to do\n"));
|
2009-09-15 06:30:32 -04:00
|
|
|
goto cleanup; /* we are done */
|
|
|
|
}
|
2009-07-19 05:15:11 -04:00
|
|
|
|
|
|
|
if(config->print) {
|
|
|
|
print_packages(pkglist);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2009-09-15 06:30:32 -04:00
|
|
|
/* print targets and ask user confirmation */
|
2011-07-22 13:01:58 -04:00
|
|
|
display_targets();
|
2009-09-15 06:30:32 -04:00
|
|
|
printf("\n");
|
|
|
|
if(yesno(_("Do you want to remove these packages?")) == 0) {
|
|
|
|
retval = 1;
|
|
|
|
goto cleanup;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2011-06-03 12:37:15 -04:00
|
|
|
if(alpm_trans_commit(config->handle, &data) == -1) {
|
2011-07-01 12:01:38 -04:00
|
|
|
pm_fprintf(stderr, ALPM_LOG_ERROR, _("failed to commit transaction (%s)\n"),
|
2011-06-07 17:06:16 -04:00
|
|
|
alpm_strerror(alpm_errno(config->handle)));
|
2008-07-08 04:17:19 -04:00
|
|
|
retval = 1;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2011-06-03 12:37:15 -04:00
|
|
|
FREELIST(data);
|
|
|
|
|
2007-04-25 04:08:49 -04:00
|
|
|
/* Step 4: release transaction resources */
|
2008-07-08 04:17:19 -04:00
|
|
|
cleanup:
|
2008-04-26 05:30:49 -04:00
|
|
|
if(trans_release() == -1) {
|
|
|
|
retval = 1;
|
|
|
|
}
|
2011-03-20 20:45:57 -04:00
|
|
|
return retval;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* vim: set ts=2 sw=2 noet: */
|