2005-03-14 20:51:43 -05:00
|
|
|
/*
|
|
|
|
* remove.c
|
2007-11-16 21:18:45 -05:00
|
|
|
*
|
2015-01-21 01:31:20 -05:00
|
|
|
* Copyright (c) 2006-2015 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 <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
2006-03-02 14:02:35 -05:00
|
|
|
#include <limits.h>
|
2012-08-01 11:34:37 -04:00
|
|
|
#include <dirent.h>
|
|
|
|
#include <regex.h>
|
2007-01-18 11:04:05 -05:00
|
|
|
#include <unistd.h>
|
2007-08-23 20:47:40 -04:00
|
|
|
#include <sys/stat.h>
|
2012-08-01 11:34:37 -04:00
|
|
|
#include <sys/types.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"
|
2012-07-12 16:29:59 -04:00
|
|
|
#include "filelist.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2012-05-21 00:30:19 -04:00
|
|
|
/**
|
|
|
|
* @brief Add a package removal action to the transaction.
|
|
|
|
*
|
|
|
|
* @param handle the context handle
|
|
|
|
* @param pkg the package to uninstall
|
|
|
|
*
|
|
|
|
* @return 0 on success, -1 on error
|
|
|
|
*/
|
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));
|
2014-02-07 13:04:58 -05:00
|
|
|
ASSERT(pkg->origin == ALPM_PKG_FROM_LOCALDB,
|
|
|
|
RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1));
|
2011-07-01 12:01:39 -04:00
|
|
|
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
|
|
|
|
2012-08-12 06:48:53 -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
|
|
|
}
|
|
|
|
|
2012-05-21 00:30:19 -04:00
|
|
|
/**
|
|
|
|
* @brief Add dependencies to the removal transaction for cascading.
|
|
|
|
*
|
|
|
|
* @param handle the context handle
|
|
|
|
* @param lp list of missing dependencies caused by the removal transaction
|
|
|
|
*
|
|
|
|
* @return 0 on success, -1 on error
|
|
|
|
*/
|
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;
|
2012-08-12 06:48:53 -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
|
|
|
}
|
|
|
|
}
|
2014-02-03 12:09:18 -05:00
|
|
|
alpm_list_free_inner(lp, (alpm_list_fn_free)alpm_depmissing_free);
|
2008-04-04 23:02:23 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-05-21 00:30:19 -04:00
|
|
|
/**
|
|
|
|
* @brief Remove needed packages from the removal transaction.
|
|
|
|
*
|
|
|
|
* @param handle the context handle
|
|
|
|
* @param lp list of missing dependencies caused by the removal transaction
|
|
|
|
*/
|
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;
|
2012-08-12 06:48:53 -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);
|
|
|
|
}
|
|
|
|
}
|
2014-02-03 12:09:18 -05:00
|
|
|
alpm_list_free_inner(lp, (alpm_list_fn_free)alpm_depmissing_free);
|
2008-04-04 23:02:23 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-11 02:07:44 -04:00
|
|
|
/**
|
|
|
|
* @brief Send a callback for any optdepend being removed.
|
|
|
|
*
|
|
|
|
* @param handle the context handle
|
|
|
|
* @param lp list of packages to be removed
|
|
|
|
*/
|
|
|
|
static void remove_notify_needed_optdepends(alpm_handle_t *handle, alpm_list_t *lp)
|
|
|
|
{
|
|
|
|
alpm_list_t *i;
|
|
|
|
|
|
|
|
for(i = _alpm_db_get_pkgcache(handle->db_local); i; i = alpm_list_next(i)) {
|
|
|
|
alpm_pkg_t *pkg = i->data;
|
|
|
|
alpm_list_t *optdeps = alpm_pkg_get_optdepends(pkg);
|
|
|
|
|
2012-08-12 06:48:53 -04:00
|
|
|
if(optdeps && !alpm_pkg_find(lp, pkg->name)) {
|
2012-08-11 02:07:44 -04:00
|
|
|
alpm_list_t *j;
|
|
|
|
for(j = optdeps; j; j = alpm_list_next(j)) {
|
|
|
|
alpm_depend_t *optdep = j->data;
|
2012-08-12 06:48:53 -04:00
|
|
|
if(alpm_pkg_find(lp, optdep->name)) {
|
2014-01-10 10:25:14 -05:00
|
|
|
alpm_event_optdep_removal_t event = {
|
|
|
|
.type = ALPM_EVENT_OPTDEP_REMOVAL,
|
|
|
|
.pkg = pkg,
|
|
|
|
.optdep = optdep
|
|
|
|
};
|
|
|
|
EVENT(handle, &event);
|
2012-08-11 02:07:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-21 00:30:19 -04:00
|
|
|
/**
|
|
|
|
* @brief Transaction preparation for remove actions.
|
|
|
|
*
|
2011-04-09 10:04:18 -04:00
|
|
|
* 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.
|
2012-05-21 00:30:19 -04:00
|
|
|
*
|
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
|
2012-05-21 00:30:19 -04:00
|
|
|
*
|
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;
|
2014-01-10 10:25:14 -05:00
|
|
|
alpm_event_t event;
|
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");
|
2013-10-25 23:20:24 -04:00
|
|
|
if(_alpm_recursedeps(db, &trans->remove,
|
2011-08-19 12:06:55 -04:00
|
|
|
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)) {
|
2014-01-10 10:25:14 -05:00
|
|
|
event.type = ALPM_EVENT_CHECKDEPS_START;
|
|
|
|
EVENT(handle, &event);
|
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 {
|
2014-02-03 12:09:18 -05:00
|
|
|
alpm_list_free_inner(lp,
|
|
|
|
(alpm_list_fn_free)alpm_depmissing_free);
|
2007-11-18 12:45:46 -05:00
|
|
|
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
|
|
|
|
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");
|
2013-10-25 23:20:24 -04:00
|
|
|
if(_alpm_recursedeps(db, &trans->remove,
|
2011-08-19 12:06:55 -04:00
|
|
|
trans->flags & ALPM_TRANS_FLAG_RECURSEALL)) {
|
|
|
|
return -1;
|
|
|
|
}
|
2007-11-14 06:42:15 -05:00
|
|
|
}
|
|
|
|
|
2012-08-11 02:07:44 -04:00
|
|
|
/* Note packages being removed that are optdepends for installed packages */
|
2015-07-05 03:33:07 -04:00
|
|
|
if(!(trans->flags & ALPM_TRANS_FLAG_NODEPS)) {
|
|
|
|
remove_notify_needed_optdepends(handle, trans->remove);
|
|
|
|
}
|
2012-08-11 02:07:44 -04:00
|
|
|
|
2011-07-01 12:01:39 -04:00
|
|
|
if(!(trans->flags & ALPM_TRANS_FLAG_NODEPS)) {
|
2014-01-10 10:25:14 -05:00
|
|
|
event.type = ALPM_EVENT_CHECKDEPS_DONE;
|
|
|
|
EVENT(handle, &event);
|
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
|
|
|
}
|
|
|
|
|
2013-07-04 06:36:20 -04:00
|
|
|
/**
|
|
|
|
* @brief Test if a directory is being used as a mountpoint.
|
|
|
|
*
|
|
|
|
* @param handle context handle
|
|
|
|
* @param directory path to test, must be absolute and include trailing '/'
|
|
|
|
* @param stbuf stat result for @a directory, may be NULL
|
|
|
|
*
|
|
|
|
* @return 0 if @a directory is not a mountpoint or on error, 1 if @a directory
|
|
|
|
* is a mountpoint
|
|
|
|
*/
|
2013-01-06 19:08:00 -05:00
|
|
|
static int dir_is_mountpoint(alpm_handle_t *handle, const char *directory,
|
|
|
|
const struct stat *stbuf)
|
|
|
|
{
|
|
|
|
char parent_dir[PATH_MAX];
|
|
|
|
struct stat parent_stbuf;
|
|
|
|
dev_t dir_st_dev;
|
|
|
|
|
|
|
|
if(stbuf == NULL) {
|
|
|
|
struct stat dir_stbuf;
|
|
|
|
if(stat(directory, &dir_stbuf) < 0) {
|
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
2013-03-10 16:42:58 -04:00
|
|
|
"failed to stat directory %s: %s\n",
|
2013-01-06 19:08:00 -05:00
|
|
|
directory, strerror(errno));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
dir_st_dev = dir_stbuf.st_dev;
|
|
|
|
} else {
|
|
|
|
dir_st_dev = stbuf->st_dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(parent_dir, PATH_MAX, "%s..", directory);
|
|
|
|
if(stat(parent_dir, &parent_stbuf) < 0) {
|
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
2013-03-10 16:42:58 -04:00
|
|
|
"failed to stat parent of %s: %s: %s\n",
|
2013-01-06 19:08:00 -05:00
|
|
|
directory, parent_dir, strerror(errno));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dir_st_dev != parent_stbuf.st_dev;
|
|
|
|
}
|
|
|
|
|
2012-05-21 00:30:19 -04:00
|
|
|
/**
|
|
|
|
* @brief Check if alpm can delete a file.
|
|
|
|
*
|
|
|
|
* @param handle the context handle
|
|
|
|
* @param file file to be removed
|
|
|
|
*
|
|
|
|
* @return 1 if the file can be deleted, 0 if it cannot be deleted
|
|
|
|
*/
|
2014-11-29 18:02:57 -05:00
|
|
|
static int can_remove_file(alpm_handle_t *handle, const alpm_file_t *file)
|
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
|
|
|
|
2013-07-04 06:36:20 -04:00
|
|
|
snprintf(filepath, PATH_MAX, "%s%s", handle->root, file->name);
|
|
|
|
|
2013-01-06 19:08:00 -05:00
|
|
|
if(file->name[strlen(file->name) - 1] == '/' &&
|
2013-07-04 06:36:20 -04:00
|
|
|
dir_is_mountpoint(handle, filepath, NULL)) {
|
2013-01-06 19:08:00 -05:00
|
|
|
/* we do not remove mountpoints */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-08-01 11:34:37 -04:00
|
|
|
static void shift_pacsave(alpm_handle_t *handle, const char *file)
|
|
|
|
{
|
|
|
|
DIR *dir = NULL;
|
|
|
|
struct dirent *ent;
|
|
|
|
struct stat st;
|
|
|
|
regex_t reg;
|
|
|
|
|
|
|
|
const char *basename;
|
|
|
|
char *dirname;
|
|
|
|
char oldfile[PATH_MAX];
|
|
|
|
char newfile[PATH_MAX];
|
|
|
|
char regstr[PATH_MAX];
|
|
|
|
|
|
|
|
unsigned long log_max = 0;
|
|
|
|
size_t basename_len;
|
|
|
|
|
|
|
|
dirname = mdirname(file);
|
|
|
|
if(!dirname) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
basename = mbasename(file);
|
|
|
|
basename_len = strlen(basename);
|
|
|
|
|
|
|
|
snprintf(regstr, PATH_MAX, "^%s\\.pacsave\\.([[:digit:]]+)$", basename);
|
|
|
|
if(regcomp(®, regstr, REG_EXTENDED | REG_NEWLINE) != 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
dir = opendir(dirname);
|
|
|
|
if(dir == NULL) {
|
|
|
|
_alpm_log(handle, ALPM_LOG_ERROR, _("could not open directory: %s: %s\n"),
|
|
|
|
dirname, strerror(errno));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
while((ent = readdir(dir)) != NULL) {
|
|
|
|
if(strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(regexec(®, ent->d_name, 0, 0, 0) == 0) {
|
|
|
|
unsigned long cur_log;
|
|
|
|
cur_log = strtoul(ent->d_name + basename_len + strlen(".pacsave."), NULL, 10);
|
|
|
|
if(cur_log > log_max) {
|
|
|
|
log_max = cur_log;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Shift pacsaves */
|
|
|
|
unsigned long i;
|
|
|
|
for(i = log_max + 1; i > 1; i--) {
|
|
|
|
snprintf(oldfile, PATH_MAX, "%s.pacsave.%lu", file, i-1);
|
|
|
|
snprintf(newfile, PATH_MAX, "%s.pacsave.%lu", file, i);
|
|
|
|
rename(oldfile, newfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(oldfile, PATH_MAX, "%s.pacsave", file);
|
|
|
|
if(stat(oldfile, &st) == 0) {
|
|
|
|
snprintf(newfile, PATH_MAX, "%s.1", oldfile);
|
|
|
|
rename(oldfile, newfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
regfree(®);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
free(dirname);
|
|
|
|
closedir(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-21 00:30:19 -04:00
|
|
|
/**
|
|
|
|
* @brief Unlink a package file, backing it up if necessary.
|
|
|
|
*
|
|
|
|
* @param handle the context handle
|
|
|
|
* @param oldpkg the package being removed
|
|
|
|
* @param newpkg the package replacing \a oldpkg
|
|
|
|
* @param fileobj file to remove
|
|
|
|
* @param nosave whether files should be backed up
|
|
|
|
*
|
|
|
|
* @return 0 on success, -1 if there was an error unlinking the file, 1 if the
|
|
|
|
* file was skipped or did not exist
|
|
|
|
*/
|
2011-10-14 15:50:58 -04:00
|
|
|
static int unlink_file(alpm_handle_t *handle, alpm_pkg_t *oldpkg,
|
2014-11-29 18:02:57 -05:00
|
|
|
alpm_pkg_t *newpkg, const alpm_file_t *fileobj, 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
|
|
|
|
2014-06-26 11:50:34 -04:00
|
|
|
if(llstat(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);
|
2012-07-12 16:29:59 -04:00
|
|
|
} else if(newpkg && alpm_filelist_contains(alpm_pkg_get_files(newpkg),
|
2011-10-14 15:50:58 -04:00
|
|
|
fileobj->name)) {
|
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
|
|
|
"keeping directory %s (in new package)\n", file);
|
2013-01-06 19:08:00 -05:00
|
|
|
} else if(dir_is_mountpoint(handle, file, &buf)) {
|
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
|
|
|
"keeping directory %s (mountpoint)\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. */
|
2011-10-14 15:50:58 -04:00
|
|
|
if(oldpkg->name_hash == local_pkg->name_hash
|
|
|
|
&& strcmp(oldpkg->name, local_pkg->name) == 0) {
|
2011-07-16 11:07:25 -04:00
|
|
|
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);
|
2012-07-12 16:29:59 -04:00
|
|
|
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-10-14 15:50:58 -04:00
|
|
|
alpm_backup_t *backup = _alpm_needbackup(fileobj->name, oldpkg);
|
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) {
|
2014-02-12 10:32:30 -05:00
|
|
|
alpm_event_pacsave_created_t event = {
|
|
|
|
.type = ALPM_EVENT_PACSAVE_CREATED,
|
|
|
|
.oldpkg = oldpkg,
|
|
|
|
.file = file
|
|
|
|
};
|
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));
|
2012-08-01 11:34:37 -04:00
|
|
|
shift_pacsave(handle, file);
|
2011-09-28 05:45:30 -04:00
|
|
|
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));
|
2013-01-18 20:42:21 -05:00
|
|
|
alpm_logaction(handle, ALPM_CALLER_PREFIX,
|
|
|
|
"error: could not rename %s to %s (%s)\n",
|
2011-08-08 13:24:43 -04:00
|
|
|
file, newpath, strerror(errno));
|
2011-09-28 05:45:30 -04:00
|
|
|
free(newpath);
|
2011-08-08 13:24:43 -04:00
|
|
|
return -1;
|
|
|
|
}
|
2014-02-12 10:32:30 -05:00
|
|
|
EVENT(handle, &event);
|
2013-01-18 20:42:21 -05:00
|
|
|
alpm_logaction(handle, ALPM_CALLER_PREFIX,
|
|
|
|
"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));
|
2013-01-18 20:42:21 -05:00
|
|
|
alpm_logaction(handle, ALPM_CALLER_PREFIX,
|
|
|
|
"error: cannot remove %s (%s)\n", file, strerror(errno));
|
2011-08-08 13:24:43 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-11-29 18:02:57 -05:00
|
|
|
/**
|
|
|
|
* @brief Check if a package file should be removed.
|
|
|
|
*
|
|
|
|
* @param handle the context handle
|
|
|
|
* @param newpkg the package replacing the current owner of \a path
|
|
|
|
* @param path file to be removed
|
|
|
|
*
|
|
|
|
* @return 1 if the file should be skipped, 0 if it should be removed
|
|
|
|
*/
|
|
|
|
static int should_skip_file(alpm_handle_t *handle,
|
|
|
|
alpm_pkg_t *newpkg, const char *path)
|
|
|
|
{
|
|
|
|
return _alpm_fnmatch_patterns(handle->noupgrade, path) == 0
|
|
|
|
|| alpm_list_find_str(handle->trans->skip_remove, path)
|
|
|
|
|| (newpkg && _alpm_needbackup(path, newpkg)
|
|
|
|
&& alpm_filelist_contains(alpm_pkg_get_files(newpkg), path));
|
|
|
|
}
|
|
|
|
|
2012-05-21 00:30:19 -04:00
|
|
|
/**
|
|
|
|
* @brief Remove a package's files, optionally skipping its replacement's
|
|
|
|
* files.
|
|
|
|
*
|
|
|
|
* @param handle the context handle
|
|
|
|
* @param oldpkg package to remove
|
|
|
|
* @param newpkg package to replace \a oldpkg (optional)
|
|
|
|
* @param targ_count current index within the transaction (1-based)
|
|
|
|
* @param pkg_count the number of packages affected by the transaction
|
|
|
|
*
|
|
|
|
* @return 0 on success, -1 if alpm lacks permission to delete some of the
|
|
|
|
* files, >0 the number of files alpm was unable to delete
|
|
|
|
*/
|
2011-12-23 11:12:08 -05:00
|
|
|
static int remove_package_files(alpm_handle_t *handle,
|
2011-07-06 10:18:59 -04:00
|
|
|
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_filelist_t *filelist;
|
2012-01-02 13:52:00 -05:00
|
|
|
size_t i;
|
2011-12-23 11:12:08 -05:00
|
|
|
int err = 0;
|
|
|
|
int nosave = handle->trans->flags & ALPM_TRANS_FLAG_NOSAVE;
|
2010-10-11 18:42:04 -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;
|
2014-11-29 18:02:57 -05:00
|
|
|
if(!should_skip_file(handle, newpkg, file->name)
|
|
|
|
&& !can_remove_file(handle, file)) {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
2011-12-23 11:12:08 -05:00
|
|
|
"not removing package '%s', can't remove all files\n",
|
|
|
|
oldpkg->name);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-02 13:52:00 -05:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "removing %zd files\n", filelist->count);
|
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-12-23 11:12:08 -05:00
|
|
|
PROGRESS(handle, ALPM_PROGRESS_REMOVE_START, oldpkg->name, 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;
|
2014-11-29 18:02:57 -05:00
|
|
|
|
|
|
|
/* check the remove skip list before removing the file.
|
|
|
|
* see the big comment block in db_find_fileconflicts() for an
|
|
|
|
* explanation. */
|
|
|
|
if(should_skip_file(handle, newpkg, file->name)) {
|
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
|
|
|
"%s is in skip_remove, skipping removal\n", file->name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(unlink_file(handle, oldpkg, newpkg, file, nosave) < 0) {
|
2011-12-23 11:12:08 -05:00
|
|
|
err++;
|
|
|
|
}
|
2011-07-06 10:18:59 -04:00
|
|
|
|
|
|
|
if(!newpkg) {
|
|
|
|
/* update progress bar after each file */
|
2012-01-02 13:52:00 -05:00
|
|
|
int percent = ((filelist->count - i) * 100) / filelist->count;
|
2011-12-23 11:12:08 -05:00
|
|
|
PROGRESS(handle, ALPM_PROGRESS_REMOVE_START, oldpkg->name,
|
2011-07-06 10:18:59 -04:00
|
|
|
percent, pkg_count, targ_count);
|
|
|
|
}
|
2009-07-15 13:14:01 -04:00
|
|
|
}
|
|
|
|
|
2011-07-06 10:18:59 -04:00
|
|
|
if(!newpkg) {
|
|
|
|
/* set progress to 100% after we finish unlinking files */
|
2011-12-23 11:12:08 -05:00
|
|
|
PROGRESS(handle, ALPM_PROGRESS_REMOVE_START, oldpkg->name, 100,
|
2011-07-06 10:18:59 -04:00
|
|
|
pkg_count, targ_count);
|
2011-12-23 11:12:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2012-05-21 00:30:19 -04:00
|
|
|
/**
|
|
|
|
* @brief Remove a package from the filesystem.
|
|
|
|
*
|
|
|
|
* @param handle the context handle
|
|
|
|
* @param oldpkg package to remove
|
|
|
|
* @param newpkg package to replace \a oldpkg (optional)
|
|
|
|
* @param targ_count current index within the transaction (1-based)
|
|
|
|
* @param pkg_count the number of packages affected by the transaction
|
|
|
|
*
|
|
|
|
* @return 0
|
|
|
|
*/
|
2011-12-23 11:12:08 -05: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)
|
|
|
|
{
|
|
|
|
const char *pkgname = oldpkg->name;
|
|
|
|
const char *pkgver = oldpkg->version;
|
2014-01-10 10:25:14 -05:00
|
|
|
alpm_event_package_operation_t event = {
|
|
|
|
.type = ALPM_EVENT_PACKAGE_OPERATION_START,
|
|
|
|
.operation = ALPM_PACKAGE_REMOVE,
|
|
|
|
.oldpkg = oldpkg,
|
|
|
|
.newpkg = NULL
|
|
|
|
};
|
2011-12-23 11:12:08 -05:00
|
|
|
|
|
|
|
if(newpkg) {
|
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "removing old package first (%s-%s)\n",
|
|
|
|
pkgname, pkgver);
|
|
|
|
} else {
|
2014-01-10 10:25:14 -05:00
|
|
|
EVENT(handle, &event);
|
2011-12-23 11:12:08 -05:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "removing package %s-%s\n",
|
|
|
|
pkgname, pkgver);
|
2011-07-06 10:18:59 -04:00
|
|
|
|
2013-11-08 00:44:40 -05:00
|
|
|
/* run the pre-remove scriptlet if it exists */
|
2011-07-06 10:18:59 -04:00
|
|
|
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-12-23 11:12:08 -05: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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-23 11:12:08 -05:00
|
|
|
if(!(handle->trans->flags & ALPM_TRANS_FLAG_DBONLY)) {
|
|
|
|
/* TODO check returned errors if any */
|
|
|
|
remove_package_files(handle, oldpkg, newpkg, targ_count, pkg_count);
|
|
|
|
}
|
|
|
|
|
2013-11-05 11:29:55 -05:00
|
|
|
if(!newpkg) {
|
|
|
|
alpm_logaction(handle, ALPM_CALLER_PREFIX, "removed %s (%s)\n",
|
|
|
|
oldpkg->name, oldpkg->version);
|
|
|
|
}
|
|
|
|
|
2013-11-08 00:44:40 -05:00
|
|
|
/* run the post-remove script if it exists */
|
2011-12-23 11:12:08 -05:00
|
|
|
if(!newpkg && alpm_pkg_has_scriptlet(oldpkg) &&
|
|
|
|
!(handle->trans->flags & ALPM_TRANS_FLAG_NOSCRIPTLET)) {
|
|
|
|
char *scriptlet = _alpm_local_db_pkgpath(handle->db_local,
|
|
|
|
oldpkg, "install");
|
|
|
|
_alpm_runscriptlet(handle, scriptlet, "post_remove", pkgver, NULL, 0);
|
|
|
|
free(scriptlet);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!newpkg) {
|
2014-01-10 10:25:14 -05:00
|
|
|
event.type = ALPM_EVENT_PACKAGE_OPERATION_DONE;
|
|
|
|
EVENT(handle, &event);
|
2011-12-23 11:12:08 -05:00
|
|
|
}
|
|
|
|
|
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, "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);
|
|
|
|
}
|
|
|
|
|
2012-05-21 00:30:19 -04:00
|
|
|
/* TODO: useful return values */
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2009-07-15 13:14:01 -04:00
|
|
|
}
|
|
|
|
|
2012-05-21 00:30:19 -04:00
|
|
|
/**
|
|
|
|
* @brief Remove packages in the current transaction.
|
|
|
|
*
|
|
|
|
* @param handle the context handle
|
|
|
|
* @param run_ldconfig whether to run ld_config after removing the packages
|
|
|
|
*
|
|
|
|
* @return 0 on success, -1 if errors occurred while removing files
|
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
2014-01-22 18:06:11 -05:00
|
|
|
/* vim: set noet: */
|