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>
|
2006-10-15 15:31:03 -04:00
|
|
|
* Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
|
|
|
|
* Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu>
|
|
|
|
* Copyright (c) 2006 by David Kimpe <dnaku@frugalware.org>
|
|
|
|
* Copyright (c) 2005, 2006 by Miklos Vajna <vmiklos@frugalware.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
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2007-03-05 17:13:33 -05:00
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
2006-03-02 14:02:35 -05:00
|
|
|
#include <limits.h>
|
2007-01-18 11:04:05 -05:00
|
|
|
#include <unistd.h>
|
2007-08-23 20:47:40 -04:00
|
|
|
#include <sys/stat.h>
|
2007-03-05 17:13:33 -05:00
|
|
|
|
|
|
|
/* libalpm */
|
|
|
|
#include "remove.h"
|
2007-01-19 04:28:44 -05:00
|
|
|
#include "alpm_list.h"
|
2011-04-15 19:53:51 -04:00
|
|
|
#include "alpm.h"
|
2006-10-15 15:31:03 -04:00
|
|
|
#include "trans.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
#include "util.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "backup.h"
|
|
|
|
#include "package.h"
|
|
|
|
#include "db.h"
|
|
|
|
#include "deps.h"
|
|
|
|
#include "handle.h"
|
2011-06-16 14:16:49 -04:00
|
|
|
#include "conflict.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
int SYMEXPORT alpm_remove_pkg(alpm_handle_t *handle, alpm_pkg_t *pkg)
|
2010-10-17 05:14:43 -04:00
|
|
|
{
|
|
|
|
const char *pkgname;
|
2011-06-28 09:27:16 -04:00
|
|
|
alpm_trans_t *trans;
|
2011-08-19 12:06:55 -04:00
|
|
|
alpm_pkg_t *copy;
|
2010-10-17 05:14:43 -04:00
|
|
|
|
|
|
|
/* Sanity checks */
|
2011-06-14 11:01:08 -04:00
|
|
|
CHECK_HANDLE(handle, return -1);
|
2011-07-01 12:01:39 -04:00
|
|
|
ASSERT(pkg != NULL, RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1));
|
|
|
|
ASSERT(handle == pkg->handle, RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1));
|
2011-06-09 17:00:55 -04:00
|
|
|
trans = handle->trans;
|
2011-07-01 12:01:39 -04:00
|
|
|
ASSERT(trans != NULL, RET_ERR(handle, ALPM_ERR_TRANS_NULL, -1));
|
2010-10-17 05:14:43 -04:00
|
|
|
ASSERT(trans->state == STATE_INITIALIZED,
|
2011-07-01 12:01:39 -04:00
|
|
|
RET_ERR(handle, ALPM_ERR_TRANS_NOT_INITIALIZED, -1));
|
2010-10-17 05:14:43 -04:00
|
|
|
|
2011-04-21 23:09:57 -04:00
|
|
|
pkgname = pkg->name;
|
2010-10-17 05:14:43 -04:00
|
|
|
|
|
|
|
if(_alpm_pkg_find(trans->remove, pkgname)) {
|
2011-07-01 12:01:39 -04:00
|
|
|
RET_ERR(handle, ALPM_ERR_TRANS_DUP_TARGET, -1);
|
2010-10-17 05:14:43 -04:00
|
|
|
}
|
|
|
|
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "adding package %s to the transaction remove list\n",
|
2011-04-21 23:09:57 -04:00
|
|
|
pkgname);
|
2011-08-19 12:06:55 -04:00
|
|
|
if(_alpm_pkg_dup(pkg, ©) == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
trans->remove = alpm_list_add(trans->remove, copy);
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2010-10-17 05:14:43 -04:00
|
|
|
}
|
|
|
|
|
2011-08-19 12:06:55 -04:00
|
|
|
static int remove_prepare_cascade(alpm_handle_t *handle, alpm_list_t *lp)
|
2008-04-04 23:02:23 -04:00
|
|
|
{
|
2011-06-28 09:27:16 -04:00
|
|
|
alpm_trans_t *trans = handle->trans;
|
2011-06-07 15:05:42 -04:00
|
|
|
|
2008-04-04 23:02:23 -04:00
|
|
|
while(lp) {
|
|
|
|
alpm_list_t *i;
|
|
|
|
for(i = lp; i; i = i->next) {
|
2011-07-06 10:18:59 -04:00
|
|
|
alpm_depmissing_t *miss = i->data;
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *info = _alpm_db_get_pkgfromcache(handle->db_local, miss->target);
|
2008-04-04 23:02:23 -04:00
|
|
|
if(info) {
|
2011-08-19 12:06:55 -04:00
|
|
|
alpm_pkg_t *copy;
|
2011-08-18 00:25:19 -04:00
|
|
|
if(!_alpm_pkg_find(trans->remove, info->name)) {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "pulling %s in target list\n",
|
2011-08-18 00:25:19 -04:00
|
|
|
info->name);
|
2011-08-19 12:06:55 -04:00
|
|
|
if(_alpm_pkg_dup(info, ©) == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
trans->remove = alpm_list_add(trans->remove, copy);
|
2008-04-04 23:02:23 -04:00
|
|
|
}
|
|
|
|
} else {
|
2011-08-19 12:06:55 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_ERROR,
|
|
|
|
_("could not find %s in database -- skipping\n"), miss->target);
|
2008-04-04 23:02:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
alpm_list_free_inner(lp, (alpm_list_fn_free)_alpm_depmiss_free);
|
|
|
|
alpm_list_free(lp);
|
2011-06-07 15:05:42 -04:00
|
|
|
lp = alpm_checkdeps(handle, _alpm_db_get_pkgcache(handle->db_local),
|
|
|
|
trans->remove, NULL, 1);
|
2008-04-04 23:02:23 -04:00
|
|
|
}
|
2011-08-19 12:06:55 -04:00
|
|
|
return 0;
|
2008-04-04 23:02:23 -04:00
|
|
|
}
|
|
|
|
|
2011-06-28 00:04:00 -04:00
|
|
|
static void remove_prepare_keep_needed(alpm_handle_t *handle, alpm_list_t *lp)
|
2008-04-04 23:02:23 -04:00
|
|
|
{
|
2011-06-28 09:27:16 -04:00
|
|
|
alpm_trans_t *trans = handle->trans;
|
2011-06-07 15:05:42 -04:00
|
|
|
|
2009-09-16 20:03:23 -04:00
|
|
|
/* Remove needed packages (which break dependencies) from target list */
|
2008-04-04 23:02:23 -04:00
|
|
|
while(lp != NULL) {
|
|
|
|
alpm_list_t *i;
|
|
|
|
for(i = lp; i; i = i->next) {
|
2011-07-06 10:18:59 -04:00
|
|
|
alpm_depmissing_t *miss = i->data;
|
2008-04-04 23:02:23 -04:00
|
|
|
void *vpkg;
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *pkg = _alpm_pkg_find(trans->remove, miss->causingpkg);
|
2008-07-16 09:27:37 -04:00
|
|
|
if(pkg == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
2009-07-15 13:14:01 -04:00
|
|
|
trans->remove = alpm_list_remove(trans->remove, pkg, _alpm_pkg_cmp,
|
Cleanup usages of alpm_list_find and alpm_list_remove.
* remove obsolete and unused *_cmp helper functions like deppkg_cmp and
_alpm_grp_cmp
* new alpm_list_remove_str function, used 6 times in handle.c
* remove _alpm_prov_cmp / _alpm_db_whatprovides and replace them by
a more general alpm_find_pkg_satisfiers with a cleaner implementation.
before: alpm_db_whatprovides(db, targ)
after: alpm_find_pkg_satisfiers(alpm_db_getpkgcache(db), targ)
* remove satisfycmp and replace alpm_list_find + satisfycmp usage by
_alpm_find_dep_satisfiers.
before : alpm_list_find(_alpm_db_get_pkgcache(db), dep, satisfycmp)
after : _alpm_find_dep_satisfiers(_alpm_db_get_pkgcache(db), dep)
* remove _alpm_pkgname_pkg_cmp, which was used with alpm_list_remove, and
use _alpm_pkg_find + alpm_list_remove with _alpm_pkg_cmp instead.
This commit actually get rids of all complicated and asymmetric _cmp
functions. I first thought these functions were worth it, be caused it
allowed us to reuse list_find and list_remove. But this was at the detriment
of the clarity and also the ease of use of these functions, dangerous
because of their asymmetricity.
Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
2008-05-10 12:47:42 -04:00
|
|
|
&vpkg);
|
2008-04-04 23:02:23 -04:00
|
|
|
pkg = vpkg;
|
|
|
|
if(pkg) {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_WARNING, _("removing %s from target list\n"),
|
2011-08-18 00:25:19 -04:00
|
|
|
pkg->name);
|
2008-04-04 23:02:23 -04:00
|
|
|
_alpm_pkg_free(pkg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
alpm_list_free_inner(lp, (alpm_list_fn_free)_alpm_depmiss_free);
|
|
|
|
alpm_list_free(lp);
|
2011-06-07 15:05:42 -04:00
|
|
|
lp = alpm_checkdeps(handle, _alpm_db_get_pkgcache(handle->db_local),
|
|
|
|
trans->remove, NULL, 1);
|
2008-04-04 23:02:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-09 10:04:18 -04:00
|
|
|
/** Transaction preparation for remove actions.
|
|
|
|
* This functions takes a pointer to a alpm_list_t which will be
|
2011-06-28 00:32:09 -04:00
|
|
|
* filled with a list of alpm_depmissing_t* objects representing
|
2011-04-09 10:04:18 -04:00
|
|
|
* the packages blocking the transaction.
|
2011-06-03 13:53:53 -04:00
|
|
|
* @param handle the context handle
|
2011-04-09 10:04:18 -04:00
|
|
|
* @param data a pointer to an alpm_list_t* to fill
|
2011-08-19 12:06:55 -04:00
|
|
|
* @return 0 on success, -1 on error
|
2011-04-09 10:04:18 -04:00
|
|
|
*/
|
2011-06-28 00:04:00 -04:00
|
|
|
int _alpm_remove_prepare(alpm_handle_t *handle, alpm_list_t **data)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2007-01-19 04:28:44 -05:00
|
|
|
alpm_list_t *lp;
|
2011-06-28 09:27:16 -04:00
|
|
|
alpm_trans_t *trans = handle->trans;
|
2011-06-28 00:11:43 -04:00
|
|
|
alpm_db_t *db = handle->db_local;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2011-08-11 00:28:57 -04:00
|
|
|
if((trans->flags & ALPM_TRANS_FLAG_RECURSE)
|
|
|
|
&& !(trans->flags & ALPM_TRANS_FLAG_CASCADE)) {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "finding removable dependencies\n");
|
2011-08-19 12:06:55 -04:00
|
|
|
if(_alpm_recursedeps(db, trans->remove,
|
|
|
|
trans->flags & ALPM_TRANS_FLAG_RECURSEALL)) {
|
|
|
|
return -1;
|
|
|
|
}
|
2008-04-19 16:31:22 -04:00
|
|
|
}
|
|
|
|
|
2011-07-01 12:01:39 -04:00
|
|
|
if(!(trans->flags & ALPM_TRANS_FLAG_NODEPS)) {
|
2011-09-01 18:35:50 -04:00
|
|
|
EVENT(handle, ALPM_EVENT_CHECKDEPS_START, NULL, NULL);
|
2008-01-11 20:03:50 -05:00
|
|
|
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "looking for unsatisfied dependencies\n");
|
2011-06-07 15:05:42 -04:00
|
|
|
lp = alpm_checkdeps(handle, _alpm_db_get_pkgcache(db), trans->remove, NULL, 1);
|
2006-01-15 10:55:16 -05:00
|
|
|
if(lp != NULL) {
|
2008-04-04 23:02:23 -04:00
|
|
|
|
2011-07-01 12:01:39 -04:00
|
|
|
if(trans->flags & ALPM_TRANS_FLAG_CASCADE) {
|
2011-08-19 12:06:55 -04:00
|
|
|
if(remove_prepare_cascade(handle, lp)) {
|
|
|
|
return -1;
|
|
|
|
}
|
2011-07-01 12:01:39 -04:00
|
|
|
} else if(trans->flags & ALPM_TRANS_FLAG_UNNEEDED) {
|
2008-04-04 23:02:23 -04:00
|
|
|
/* Remove needed packages (which would break dependencies)
|
2009-09-16 20:03:23 -04:00
|
|
|
* from target list */
|
2011-06-07 15:05:42 -04:00
|
|
|
remove_prepare_keep_needed(handle, lp);
|
2005-03-14 20:51:43 -05:00
|
|
|
} else {
|
2006-01-07 13:25:28 -05:00
|
|
|
if(data) {
|
|
|
|
*data = lp;
|
2006-01-15 10:55:16 -05:00
|
|
|
} else {
|
2007-11-18 12:45:46 -05:00
|
|
|
alpm_list_free_inner(lp, (alpm_list_fn_free)_alpm_depmiss_free);
|
|
|
|
alpm_list_free(lp);
|
2006-01-07 13:25:28 -05:00
|
|
|
}
|
2011-07-01 12:01:39 -04:00
|
|
|
RET_ERR(handle, ALPM_ERR_UNSATISFIED_DEPS, -1);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
2007-07-12 07:49:23 -04:00
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-11-16 21:18:45 -05:00
|
|
|
/* re-order w.r.t. dependencies */
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "sorting by dependencies\n");
|
2011-06-07 17:13:58 -04:00
|
|
|
lp = _alpm_sortbydeps(handle, trans->remove, 1);
|
2007-07-12 07:49:23 -04:00
|
|
|
/* free the old alltargs */
|
2009-07-15 13:14:01 -04:00
|
|
|
alpm_list_free(trans->remove);
|
|
|
|
trans->remove = lp;
|
2005-03-25 17:09:14 -05:00
|
|
|
|
2008-04-19 16:31:22 -04:00
|
|
|
/* -Rcs == -Rc then -Rs */
|
2011-08-11 00:28:57 -04:00
|
|
|
if((trans->flags & ALPM_TRANS_FLAG_CASCADE)
|
|
|
|
&& (trans->flags & ALPM_TRANS_FLAG_RECURSE)) {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "finding removable dependencies\n");
|
2011-08-19 12:06:55 -04:00
|
|
|
if(_alpm_recursedeps(db, trans->remove,
|
|
|
|
trans->flags & ALPM_TRANS_FLAG_RECURSEALL)) {
|
|
|
|
return -1;
|
|
|
|
}
|
2007-11-14 06:42:15 -05:00
|
|
|
}
|
|
|
|
|
2011-07-01 12:01:39 -04:00
|
|
|
if(!(trans->flags & ALPM_TRANS_FLAG_NODEPS)) {
|
2011-09-01 18:35:50 -04:00
|
|
|
EVENT(handle, ALPM_EVENT_CHECKDEPS_DONE, NULL, NULL);
|
2008-01-12 08:51:01 -05:00
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2011-06-16 14:16:49 -04:00
|
|
|
static int can_remove_file(alpm_handle_t *handle, const alpm_file_t *file,
|
2011-06-14 10:30:46 -04:00
|
|
|
alpm_list_t *skip_remove)
|
2007-02-08 03:09:34 -05:00
|
|
|
{
|
2011-06-16 14:16:49 -04:00
|
|
|
char filepath[PATH_MAX];
|
2007-02-08 03:09:34 -05:00
|
|
|
|
2011-09-19 14:17:16 -04:00
|
|
|
if(alpm_list_find_str(skip_remove, file->name)) {
|
2007-02-19 21:14:27 -05:00
|
|
|
/* return success because we will never actually remove this file */
|
2011-03-20 20:45:57 -04:00
|
|
|
return 1;
|
2007-02-08 03:09:34 -05:00
|
|
|
}
|
2011-09-19 14:17:16 -04:00
|
|
|
|
|
|
|
snprintf(filepath, PATH_MAX, "%s%s", handle->root, file->name);
|
2007-02-08 03:09:34 -05:00
|
|
|
/* If we fail write permissions due to a read-only filesystem, abort.
|
|
|
|
* Assume all other possible failures are covered somewhere else */
|
2011-07-06 12:26:56 -04:00
|
|
|
if(_alpm_access(handle, NULL, filepath, W_OK) == -1) {
|
2011-06-16 14:16:49 -04:00
|
|
|
if(errno != EACCES && errno != ETXTBSY && access(filepath, F_OK) == 0) {
|
2007-03-09 00:33:06 -05:00
|
|
|
/* only return failure if the file ACTUALLY exists and we can't write to
|
|
|
|
* it - ignore "chmod -w" simple permission failures */
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_ERROR, _("cannot remove file '%s': %s\n"),
|
2011-06-16 14:16:49 -04:00
|
|
|
filepath, strerror(errno));
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2007-02-08 03:09:34 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return 1;
|
2007-02-08 03:09:34 -05:00
|
|
|
}
|
|
|
|
|
2007-01-16 23:47:19 -05:00
|
|
|
/* Helper function for iterating through a package's file and deleting them
|
2007-09-23 16:44:40 -04:00
|
|
|
* Used by _alpm_remove_commit. */
|
2011-08-08 13:24:43 -04:00
|
|
|
static int unlink_file(alpm_handle_t *handle, alpm_pkg_t *info,
|
2011-06-16 14:16:49 -04:00
|
|
|
const alpm_file_t *fileobj, alpm_list_t *skip_remove, int nosave)
|
2007-01-16 23:47:19 -05:00
|
|
|
{
|
2007-01-18 11:04:05 -05:00
|
|
|
struct stat buf;
|
2011-06-09 14:41:08 -04:00
|
|
|
char file[PATH_MAX];
|
2007-01-18 11:04:05 -05:00
|
|
|
|
2011-06-16 14:16:49 -04:00
|
|
|
snprintf(file, PATH_MAX, "%s%s", handle->root, fileobj->name);
|
2007-06-27 19:20:30 -04:00
|
|
|
|
2009-07-15 13:14:01 -04:00
|
|
|
/* check the remove skip list before removing the file.
|
|
|
|
* see the big comment block in db_find_fileconflicts() for an
|
|
|
|
* explanation. */
|
2011-06-16 14:16:49 -04:00
|
|
|
if(alpm_list_find_str(skip_remove, fileobj->name)) {
|
2011-07-16 11:07:25 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
|
|
|
"%s is in skip_remove, skipping removal\n", file);
|
2011-08-08 13:24:43 -04:00
|
|
|
return 1;
|
2007-01-18 11:04:05 -05:00
|
|
|
}
|
2007-02-17 03:55:05 -05:00
|
|
|
|
2007-12-22 11:47:19 -05:00
|
|
|
/* we want to do a lstat here, and not a _alpm_lstat.
|
|
|
|
* if a directory in the package is actually a directory symlink on the
|
|
|
|
* filesystem, we want to work with the linked directory instead of the
|
|
|
|
* actual symlink */
|
|
|
|
if(lstat(file, &buf)) {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "file %s does not exist\n", file);
|
2011-08-08 13:24:43 -04:00
|
|
|
return 1;
|
2007-01-18 11:04:05 -05:00
|
|
|
}
|
2007-11-16 21:18:45 -05:00
|
|
|
|
2007-02-08 03:09:34 -05:00
|
|
|
if(S_ISDIR(buf.st_mode)) {
|
2011-07-16 11:07:25 -04:00
|
|
|
ssize_t files = _alpm_files_in_directory(handle, file, 0);
|
|
|
|
/* if we have files, no need to remove the directory */
|
|
|
|
if(files > 0) {
|
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "keeping directory %s (contains files)\n",
|
|
|
|
file);
|
|
|
|
} else if(files < 0) {
|
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
|
|
|
"keeping directory %s (could not count files)\n", file);
|
2007-01-18 11:04:05 -05:00
|
|
|
} else {
|
2011-07-16 11:07:25 -04:00
|
|
|
/* one last check- does any other package own this file? */
|
|
|
|
alpm_list_t *local, *local_pkgs;
|
|
|
|
int found = 0;
|
|
|
|
local_pkgs = _alpm_db_get_pkgcache(handle->db_local);
|
|
|
|
for(local = local_pkgs; local && !found; local = local->next) {
|
|
|
|
alpm_pkg_t *local_pkg = local->data;
|
Convert package filelists to an array instead of linked list
This accomplishes quite a few things with one rather invasive change.
1. Iteration is much more performant, due to a reduction in pointer
chasing and linear item access.
2. Data structures are smaller- we no longer have the overhead of the
linked list as the file struts are now laid out consecutively in
memory.
3. Memory allocation has been massively reworked. Before, we would
allocate three different pieces of memory per file item- the list
struct, the file struct, and the copied filename. What this resulted
in was massive fragmentation of memory when loading filelists since
the memory allocator had to leave holes all over the place. The new
situation here now removes the need for any list item allocation;
allocates the file structs in contiguous memory (and reallocs as
necessary), leaving only the strings as individually allocated. Tests
using valgrind (massif) show some pretty significant memory
reductions on the worst case `pacman -Ql > /dev/null` (366387 files
on my machine):
Before:
Peak heap: 54,416,024 B
Useful heap: 36,840,692 B
Extra heap: 17,575,332 B
After:
Peak heap: 38,004,352 B
Useful heap: 28,101,347 B
Extra heap: 9,903,005 B
Several small helper methods have been introduced, including a list to
array conversion helper as well as a filelist merge sort that works
directly on arrays.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-19 05:47:29 -04:00
|
|
|
alpm_filelist_t *filelist;
|
2011-07-16 11:07:25 -04:00
|
|
|
|
|
|
|
/* we duplicated the package when we put it in the removal list, so we
|
|
|
|
* so we can't use direct pointer comparison here. */
|
|
|
|
if(_alpm_pkg_cmp(info, local_pkg) == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
Convert package filelists to an array instead of linked list
This accomplishes quite a few things with one rather invasive change.
1. Iteration is much more performant, due to a reduction in pointer
chasing and linear item access.
2. Data structures are smaller- we no longer have the overhead of the
linked list as the file struts are now laid out consecutively in
memory.
3. Memory allocation has been massively reworked. Before, we would
allocate three different pieces of memory per file item- the list
struct, the file struct, and the copied filename. What this resulted
in was massive fragmentation of memory when loading filelists since
the memory allocator had to leave holes all over the place. The new
situation here now removes the need for any list item allocation;
allocates the file structs in contiguous memory (and reallocs as
necessary), leaving only the strings as individually allocated. Tests
using valgrind (massif) show some pretty significant memory
reductions on the worst case `pacman -Ql > /dev/null` (366387 files
on my machine):
Before:
Peak heap: 54,416,024 B
Useful heap: 36,840,692 B
Extra heap: 17,575,332 B
After:
Peak heap: 38,004,352 B
Useful heap: 28,101,347 B
Extra heap: 9,903,005 B
Several small helper methods have been introduced, including a list to
array conversion helper as well as a filelist merge sort that works
directly on arrays.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-19 05:47:29 -04:00
|
|
|
filelist = alpm_pkg_get_files(local_pkg);
|
|
|
|
if(_alpm_filelist_contains(filelist, fileobj->name)) {
|
2011-07-16 11:07:25 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
|
|
|
"keeping directory %s (owned by %s)\n", file, local_pkg->name);
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!found) {
|
|
|
|
if(rmdir(file)) {
|
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
|
|
|
"directory removal of %s failed: %s\n", file, strerror(errno));
|
2011-08-08 13:24:43 -04:00
|
|
|
return -1;
|
2011-07-16 11:07:25 -04:00
|
|
|
} else {
|
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
|
|
|
"removed directory %s (no remaining owners)\n", file);
|
|
|
|
}
|
|
|
|
}
|
2007-01-18 11:04:05 -05:00
|
|
|
}
|
|
|
|
} else {
|
2009-07-19 13:49:59 -04:00
|
|
|
/* if the file needs backup and has been modified, back it up to .pacsave */
|
2011-07-14 16:32:03 -04:00
|
|
|
alpm_backup_t *backup = _alpm_needbackup(fileobj->name, info);
|
2011-06-16 14:15:11 -04:00
|
|
|
if(backup) {
|
2009-07-15 13:14:01 -04:00
|
|
|
if(nosave) {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "transaction is set to NOSAVE, not backing up '%s'\n", file);
|
2009-07-19 13:49:59 -04:00
|
|
|
} else {
|
|
|
|
char *filehash = alpm_compute_md5sum(file);
|
2011-06-16 14:15:11 -04:00
|
|
|
int cmp = filehash ? strcmp(filehash, backup->hash) : 0;
|
2009-07-19 13:49:59 -04:00
|
|
|
FREE(filehash);
|
|
|
|
if(cmp != 0) {
|
2011-09-28 05:45:30 -04:00
|
|
|
char *newpath;
|
|
|
|
size_t len = strlen(file) + 8 + 1;
|
|
|
|
MALLOC(newpath, len, RET_ERR(handle, ALPM_ERR_MEMORY, -1));
|
|
|
|
snprintf(newpath, len, "%s.pacsave", file);
|
2011-08-08 13:24:43 -04:00
|
|
|
if(rename(file, newpath)) {
|
|
|
|
_alpm_log(handle, ALPM_LOG_ERROR, _("could not rename %s to %s (%s)\n"),
|
|
|
|
file, newpath, strerror(errno));
|
|
|
|
alpm_logaction(handle, "error: could not rename %s to %s (%s)\n",
|
|
|
|
file, newpath, strerror(errno));
|
2011-09-28 05:45:30 -04:00
|
|
|
free(newpath);
|
2011-08-08 13:24:43 -04:00
|
|
|
return -1;
|
|
|
|
}
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_WARNING, _("%s saved as %s\n"), file, newpath);
|
2011-06-07 13:41:33 -04:00
|
|
|
alpm_logaction(handle, "warning: %s saved as %s\n", file, newpath);
|
2011-09-28 05:45:30 -04:00
|
|
|
free(newpath);
|
2011-08-08 13:24:43 -04:00
|
|
|
return 0;
|
2009-07-19 13:49:59 -04:00
|
|
|
}
|
2007-02-17 03:55:05 -05:00
|
|
|
}
|
2007-02-21 01:44:14 -05:00
|
|
|
}
|
2009-07-19 13:49:59 -04:00
|
|
|
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "unlinking %s\n", file);
|
2007-01-23 11:05:21 -05:00
|
|
|
|
2007-02-21 01:44:14 -05:00
|
|
|
if(unlink(file) == -1) {
|
2011-08-08 13:24:43 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_ERROR, _("cannot remove %s (%s)\n"),
|
2011-06-16 14:16:49 -04:00
|
|
|
file, strerror(errno));
|
2011-08-08 13:24:43 -04:00
|
|
|
alpm_logaction(handle, "error: cannot remove %s (%s)\n",
|
|
|
|
file, strerror(errno));
|
|
|
|
return -1;
|
2007-01-18 11:04:05 -05:00
|
|
|
}
|
|
|
|
}
|
2011-08-08 13:24:43 -04:00
|
|
|
return 0;
|
2007-01-16 23:47:19 -05:00
|
|
|
}
|
|
|
|
|
2011-07-06 10:18:59 -04:00
|
|
|
int _alpm_remove_single_package(alpm_handle_t *handle,
|
|
|
|
alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg,
|
|
|
|
size_t targ_count, size_t pkg_count)
|
2009-07-15 13:14:01 -04:00
|
|
|
{
|
Convert package filelists to an array instead of linked list
This accomplishes quite a few things with one rather invasive change.
1. Iteration is much more performant, due to a reduction in pointer
chasing and linear item access.
2. Data structures are smaller- we no longer have the overhead of the
linked list as the file struts are now laid out consecutively in
memory.
3. Memory allocation has been massively reworked. Before, we would
allocate three different pieces of memory per file item- the list
struct, the file struct, and the copied filename. What this resulted
in was massive fragmentation of memory when loading filelists since
the memory allocator had to leave holes all over the place. The new
situation here now removes the need for any list item allocation;
allocates the file structs in contiguous memory (and reallocs as
necessary), leaving only the strings as individually allocated. Tests
using valgrind (massif) show some pretty significant memory
reductions on the worst case `pacman -Ql > /dev/null` (366387 files
on my machine):
Before:
Peak heap: 54,416,024 B
Useful heap: 36,840,692 B
Extra heap: 17,575,332 B
After:
Peak heap: 38,004,352 B
Useful heap: 28,101,347 B
Extra heap: 9,903,005 B
Several small helper methods have been introduced, including a list to
array conversion helper as well as a filelist merge sort that works
directly on arrays.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-19 05:47:29 -04:00
|
|
|
alpm_list_t *skip_remove;
|
2011-07-06 10:18:59 -04:00
|
|
|
size_t filenum = 0, position = 0;
|
|
|
|
const char *pkgname = oldpkg->name;
|
|
|
|
const char *pkgver = oldpkg->version;
|
Convert package filelists to an array instead of linked list
This accomplishes quite a few things with one rather invasive change.
1. Iteration is much more performant, due to a reduction in pointer
chasing and linear item access.
2. Data structures are smaller- we no longer have the overhead of the
linked list as the file struts are now laid out consecutively in
memory.
3. Memory allocation has been massively reworked. Before, we would
allocate three different pieces of memory per file item- the list
struct, the file struct, and the copied filename. What this resulted
in was massive fragmentation of memory when loading filelists since
the memory allocator had to leave holes all over the place. The new
situation here now removes the need for any list item allocation;
allocates the file structs in contiguous memory (and reallocs as
necessary), leaving only the strings as individually allocated. Tests
using valgrind (massif) show some pretty significant memory
reductions on the worst case `pacman -Ql > /dev/null` (366387 files
on my machine):
Before:
Peak heap: 54,416,024 B
Useful heap: 36,840,692 B
Extra heap: 17,575,332 B
After:
Peak heap: 38,004,352 B
Useful heap: 28,101,347 B
Extra heap: 9,903,005 B
Several small helper methods have been introduced, including a list to
array conversion helper as well as a filelist merge sort that works
directly on arrays.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-19 05:47:29 -04:00
|
|
|
alpm_filelist_t *filelist;
|
|
|
|
size_t i;
|
2011-07-06 10:18:59 -04:00
|
|
|
|
|
|
|
if(newpkg) {
|
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "removing old package first (%s-%s)\n",
|
|
|
|
pkgname, pkgver);
|
|
|
|
} else {
|
2011-09-01 18:35:50 -04:00
|
|
|
EVENT(handle, ALPM_EVENT_REMOVE_START, oldpkg, NULL);
|
2011-07-06 10:18:59 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "removing package %s-%s\n",
|
|
|
|
pkgname, pkgver);
|
|
|
|
|
|
|
|
/* run the pre-remove scriptlet if it exists */
|
|
|
|
if(alpm_pkg_has_scriptlet(oldpkg) &&
|
|
|
|
!(handle->trans->flags & ALPM_TRANS_FLAG_NOSCRIPTLET)) {
|
2011-09-28 05:43:23 -04:00
|
|
|
char *scriptlet = _alpm_local_db_pkgpath(handle->db_local,
|
|
|
|
oldpkg, "install");
|
2011-09-28 04:45:46 -04:00
|
|
|
_alpm_runscriptlet(handle, scriptlet, "pre_remove", pkgver, NULL, 0);
|
2011-09-28 05:43:23 -04:00
|
|
|
free(scriptlet);
|
2011-07-06 10:18:59 -04:00
|
|
|
}
|
|
|
|
}
|
2009-07-15 13:14:01 -04:00
|
|
|
|
2011-07-01 12:01:39 -04:00
|
|
|
if(handle->trans->flags & ALPM_TRANS_FLAG_DBONLY) {
|
2010-10-11 18:42:04 -04:00
|
|
|
goto db;
|
|
|
|
}
|
|
|
|
|
2011-07-06 10:18:59 -04:00
|
|
|
if(newpkg) {
|
Convert package filelists to an array instead of linked list
This accomplishes quite a few things with one rather invasive change.
1. Iteration is much more performant, due to a reduction in pointer
chasing and linear item access.
2. Data structures are smaller- we no longer have the overhead of the
linked list as the file struts are now laid out consecutively in
memory.
3. Memory allocation has been massively reworked. Before, we would
allocate three different pieces of memory per file item- the list
struct, the file struct, and the copied filename. What this resulted
in was massive fragmentation of memory when loading filelists since
the memory allocator had to leave holes all over the place. The new
situation here now removes the need for any list item allocation;
allocates the file structs in contiguous memory (and reallocs as
necessary), leaving only the strings as individually allocated. Tests
using valgrind (massif) show some pretty significant memory
reductions on the worst case `pacman -Ql > /dev/null` (366387 files
on my machine):
Before:
Peak heap: 54,416,024 B
Useful heap: 36,840,692 B
Extra heap: 17,575,332 B
After:
Peak heap: 38,004,352 B
Useful heap: 28,101,347 B
Extra heap: 9,903,005 B
Several small helper methods have been introduced, including a list to
array conversion helper as well as a filelist merge sort that works
directly on arrays.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-19 05:47:29 -04:00
|
|
|
alpm_filelist_t *newfiles;
|
|
|
|
alpm_list_t *b;
|
2011-07-06 10:18:59 -04:00
|
|
|
skip_remove = alpm_list_join(
|
|
|
|
alpm_list_strdup(handle->trans->skip_remove),
|
|
|
|
alpm_list_strdup(handle->noupgrade));
|
|
|
|
/* Add files in the NEW backup array to the skip_remove array
|
|
|
|
* so this removal operation doesn't kill them */
|
|
|
|
/* old package backup list */
|
|
|
|
newfiles = alpm_pkg_get_files(newpkg);
|
|
|
|
for(b = alpm_pkg_get_backup(newpkg); b; b = b->next) {
|
|
|
|
const alpm_backup_t *backup = b->data;
|
|
|
|
/* safety check (fix the upgrade026 pactest) */
|
|
|
|
if(!_alpm_filelist_contains(newfiles, backup->name)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "adding %s to the skip_remove array\n",
|
|
|
|
backup->name);
|
|
|
|
skip_remove = alpm_list_add(skip_remove, strdup(backup->name));
|
2009-07-15 13:14:01 -04:00
|
|
|
}
|
2011-07-06 10:18:59 -04:00
|
|
|
} else {
|
|
|
|
skip_remove = alpm_list_strdup(handle->trans->skip_remove);
|
2009-07-15 13:14:01 -04:00
|
|
|
}
|
|
|
|
|
Convert package filelists to an array instead of linked list
This accomplishes quite a few things with one rather invasive change.
1. Iteration is much more performant, due to a reduction in pointer
chasing and linear item access.
2. Data structures are smaller- we no longer have the overhead of the
linked list as the file struts are now laid out consecutively in
memory.
3. Memory allocation has been massively reworked. Before, we would
allocate three different pieces of memory per file item- the list
struct, the file struct, and the copied filename. What this resulted
in was massive fragmentation of memory when loading filelists since
the memory allocator had to leave holes all over the place. The new
situation here now removes the need for any list item allocation;
allocates the file structs in contiguous memory (and reallocs as
necessary), leaving only the strings as individually allocated. Tests
using valgrind (massif) show some pretty significant memory
reductions on the worst case `pacman -Ql > /dev/null` (366387 files
on my machine):
Before:
Peak heap: 54,416,024 B
Useful heap: 36,840,692 B
Extra heap: 17,575,332 B
After:
Peak heap: 38,004,352 B
Useful heap: 28,101,347 B
Extra heap: 9,903,005 B
Several small helper methods have been introduced, including a list to
array conversion helper as well as a filelist merge sort that works
directly on arrays.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-19 05:47:29 -04:00
|
|
|
filelist = alpm_pkg_get_files(oldpkg);
|
|
|
|
for(i = 0; i < filelist->count; i++) {
|
|
|
|
alpm_file_t *file = filelist->files + i;
|
|
|
|
if(!can_remove_file(handle, file, skip_remove)) {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
2011-06-16 14:15:11 -04:00
|
|
|
"not removing package '%s', can't remove all files\n", pkgname);
|
2011-07-01 12:01:39 -04:00
|
|
|
RET_ERR(handle, ALPM_ERR_PKG_CANT_REMOVE, -1);
|
2009-07-15 13:14:01 -04:00
|
|
|
}
|
2011-06-24 18:28:28 -04:00
|
|
|
filenum++;
|
2009-07-15 13:14:01 -04:00
|
|
|
}
|
|
|
|
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "removing %ld files\n", (unsigned long)filenum);
|
Fix double filelist issue when upgrading a package
Due to the way we funk around with package data loading, we had a condition
where the filelist got doubled up because it was loaded twice.
Packages are originally loaded with INFRQ_BASE. In an upgrade/sync, the
package is checked for file conflicts next, leaving us in an "INFRQ_BASE |
INFRQ_FILES" state. Later, when committing a single package, we have an
explicit call to _alpm_local_db_read() with INFRQ_ALL as the level. Because
the package's level did not match this, we skipped over our previous "does
the incoming level match where I'm at" shortcut, and continued to load
things again, because of a lack of fine-grained checking for each of DESC,
FILES, and INSTALL.
The end result is we loaded the filelist twice, causing our remove logic to
iterate twice over the installed files, spewing a bunch of "cannot find file
X" messages.
Fix the problem by doing a bit more bitmasking logic throughout the load
method, and also fix the sanity check at the beginning of the function- this
should *only* be used for local packages as opposed to the "not a package"
check that was there before.
A debug log message was added to upgraderemove as well to match the one
already in the normal remove codepath.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-01-11 19:46:10 -05:00
|
|
|
|
2011-07-06 10:18:59 -04:00
|
|
|
if(!newpkg) {
|
|
|
|
/* init progress bar, but only on true remove transactions */
|
2011-09-01 18:35:50 -04:00
|
|
|
PROGRESS(handle, ALPM_PROGRESS_REMOVE_START, pkgname, 0,
|
2011-07-06 10:18:59 -04:00
|
|
|
pkg_count, targ_count);
|
|
|
|
}
|
|
|
|
|
2009-07-15 13:14:01 -04:00
|
|
|
/* iterate through the list backwards, unlinking files */
|
Convert package filelists to an array instead of linked list
This accomplishes quite a few things with one rather invasive change.
1. Iteration is much more performant, due to a reduction in pointer
chasing and linear item access.
2. Data structures are smaller- we no longer have the overhead of the
linked list as the file struts are now laid out consecutively in
memory.
3. Memory allocation has been massively reworked. Before, we would
allocate three different pieces of memory per file item- the list
struct, the file struct, and the copied filename. What this resulted
in was massive fragmentation of memory when loading filelists since
the memory allocator had to leave holes all over the place. The new
situation here now removes the need for any list item allocation;
allocates the file structs in contiguous memory (and reallocs as
necessary), leaving only the strings as individually allocated. Tests
using valgrind (massif) show some pretty significant memory
reductions on the worst case `pacman -Ql > /dev/null` (366387 files
on my machine):
Before:
Peak heap: 54,416,024 B
Useful heap: 36,840,692 B
Extra heap: 17,575,332 B
After:
Peak heap: 38,004,352 B
Useful heap: 28,101,347 B
Extra heap: 9,903,005 B
Several small helper methods have been introduced, including a list to
array conversion helper as well as a filelist merge sort that works
directly on arrays.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-19 05:47:29 -04:00
|
|
|
for(i = filelist->count; i > 0; i--) {
|
|
|
|
alpm_file_t *file = filelist->files + i - 1;
|
2011-07-06 10:18:59 -04:00
|
|
|
int percent;
|
2011-08-08 13:24:43 -04:00
|
|
|
/* TODO: check return code and handle accordingly */
|
Convert package filelists to an array instead of linked list
This accomplishes quite a few things with one rather invasive change.
1. Iteration is much more performant, due to a reduction in pointer
chasing and linear item access.
2. Data structures are smaller- we no longer have the overhead of the
linked list as the file struts are now laid out consecutively in
memory.
3. Memory allocation has been massively reworked. Before, we would
allocate three different pieces of memory per file item- the list
struct, the file struct, and the copied filename. What this resulted
in was massive fragmentation of memory when loading filelists since
the memory allocator had to leave holes all over the place. The new
situation here now removes the need for any list item allocation;
allocates the file structs in contiguous memory (and reallocs as
necessary), leaving only the strings as individually allocated. Tests
using valgrind (massif) show some pretty significant memory
reductions on the worst case `pacman -Ql > /dev/null` (366387 files
on my machine):
Before:
Peak heap: 54,416,024 B
Useful heap: 36,840,692 B
Extra heap: 17,575,332 B
After:
Peak heap: 38,004,352 B
Useful heap: 28,101,347 B
Extra heap: 9,903,005 B
Several small helper methods have been introduced, including a list to
array conversion helper as well as a filelist merge sort that works
directly on arrays.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-19 05:47:29 -04:00
|
|
|
unlink_file(handle, oldpkg, file, skip_remove,
|
2011-07-06 10:18:59 -04:00
|
|
|
handle->trans->flags & ALPM_TRANS_FLAG_NOSAVE);
|
|
|
|
|
|
|
|
if(!newpkg) {
|
|
|
|
/* update progress bar after each file */
|
|
|
|
percent = (position * 100) / filenum;
|
2011-09-01 18:35:50 -04:00
|
|
|
PROGRESS(handle, ALPM_PROGRESS_REMOVE_START, pkgname,
|
2011-07-06 10:18:59 -04:00
|
|
|
percent, pkg_count, targ_count);
|
|
|
|
}
|
|
|
|
position++;
|
2009-07-15 13:14:01 -04:00
|
|
|
}
|
|
|
|
FREELIST(skip_remove);
|
|
|
|
|
2011-07-06 10:18:59 -04:00
|
|
|
if(!newpkg) {
|
|
|
|
/* set progress to 100% after we finish unlinking files */
|
2011-09-01 18:35:50 -04:00
|
|
|
PROGRESS(handle, ALPM_PROGRESS_REMOVE_START, pkgname, 100,
|
2011-07-06 10:18:59 -04:00
|
|
|
pkg_count, targ_count);
|
|
|
|
|
|
|
|
/* run the post-remove script if it exists */
|
|
|
|
if(alpm_pkg_has_scriptlet(oldpkg) &&
|
|
|
|
!(handle->trans->flags & ALPM_TRANS_FLAG_NOSCRIPTLET)) {
|
2011-09-28 05:43:23 -04:00
|
|
|
char *scriptlet = _alpm_local_db_pkgpath(handle->db_local,
|
|
|
|
oldpkg, "install");
|
2011-09-28 04:45:46 -04:00
|
|
|
_alpm_runscriptlet(handle, scriptlet, "post_remove", pkgver, NULL, 0);
|
2011-09-28 05:43:23 -04:00
|
|
|
free(scriptlet);
|
2011-07-06 10:18:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-11 18:42:04 -04:00
|
|
|
db:
|
2009-07-15 13:14:01 -04:00
|
|
|
/* remove the package from the database */
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "updating database\n");
|
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "removing database entry '%s'\n", pkgname);
|
2010-10-13 04:04:07 -04:00
|
|
|
if(_alpm_local_db_remove(handle->db_local, oldpkg) == -1) {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_ERROR, _("could not remove database entry %s-%s\n"),
|
2011-07-06 10:18:59 -04:00
|
|
|
pkgname, pkgver);
|
2009-07-15 13:14:01 -04:00
|
|
|
}
|
|
|
|
/* remove the package from the cache */
|
|
|
|
if(_alpm_db_remove_pkgfromcache(handle->db_local, oldpkg) == -1) {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_ERROR, _("could not remove entry '%s' from cache\n"),
|
2009-07-15 13:14:01 -04:00
|
|
|
pkgname);
|
|
|
|
}
|
|
|
|
|
2011-07-06 10:18:59 -04:00
|
|
|
if(!newpkg) {
|
|
|
|
/* TODO: awesome! we're passing invalid pointers. */
|
2011-09-01 18:35:50 -04:00
|
|
|
EVENT(handle, ALPM_EVENT_REMOVE_DONE, oldpkg, NULL);
|
2011-07-06 10:18:59 -04:00
|
|
|
}
|
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2009-07-15 13:14:01 -04:00
|
|
|
}
|
|
|
|
|
2011-09-19 14:18:42 -04:00
|
|
|
int _alpm_remove_packages(alpm_handle_t *handle, int run_ldconfig)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2011-07-06 10:18:59 -04:00
|
|
|
alpm_list_t *targ;
|
|
|
|
size_t pkg_count, targ_count;
|
2011-06-28 09:27:16 -04:00
|
|
|
alpm_trans_t *trans = handle->trans;
|
2011-07-06 10:18:59 -04:00
|
|
|
int ret = 0;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2009-07-15 13:14:01 -04:00
|
|
|
pkg_count = alpm_list_count(trans->remove);
|
2011-07-06 10:18:59 -04:00
|
|
|
targ_count = 1;
|
2007-09-23 16:44:40 -04:00
|
|
|
|
2009-07-15 13:14:01 -04:00
|
|
|
for(targ = trans->remove; targ; targ = targ->next) {
|
2011-07-06 10:18:59 -04:00
|
|
|
alpm_pkg_t *pkg = targ->data;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2011-06-03 13:53:53 -04:00
|
|
|
if(trans->state == STATE_INTERRUPTED) {
|
2011-09-19 14:18:42 -04:00
|
|
|
return ret;
|
2006-07-14 19:15:07 -04:00
|
|
|
}
|
|
|
|
|
2011-07-06 10:18:59 -04:00
|
|
|
if(_alpm_remove_single_package(handle, pkg, NULL,
|
|
|
|
targ_count, pkg_count) == -1) {
|
|
|
|
handle->pm_errno = ALPM_ERR_TRANS_ABORT;
|
2011-09-19 14:18:42 -04:00
|
|
|
/* running ldconfig at this point could possibly screw system */
|
|
|
|
run_ldconfig = 0;
|
2011-07-06 10:18:59 -04:00
|
|
|
ret = -1;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2011-07-06 10:18:59 -04:00
|
|
|
targ_count++;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2011-09-19 14:18:42 -04:00
|
|
|
if(run_ldconfig) {
|
|
|
|
/* run ldconfig if it exists */
|
|
|
|
_alpm_ldconfig(handle);
|
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2011-07-06 10:18:59 -04:00
|
|
|
return ret;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* vim: set ts=2 sw=2 noet: */
|