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-09 17:00:55 -04:00
|
|
|
int SYMEXPORT alpm_remove_pkg(pmhandle_t *handle, pmpkg_t *pkg)
|
2010-10-17 05:14:43 -04:00
|
|
|
{
|
|
|
|
const char *pkgname;
|
2011-06-07 17:13:58 -04:00
|
|
|
pmtrans_t *trans;
|
2010-10-17 05:14:43 -04:00
|
|
|
|
|
|
|
/* Sanity checks */
|
2011-06-14 11:01:08 -04:00
|
|
|
CHECK_HANDLE(handle, return -1);
|
2011-06-07 17:06:16 -04:00
|
|
|
ASSERT(pkg != NULL, RET_ERR(handle, PM_ERR_WRONG_ARGS, -1));
|
|
|
|
ASSERT(handle == pkg->handle, RET_ERR(handle, PM_ERR_WRONG_ARGS, -1));
|
2011-06-09 17:00:55 -04:00
|
|
|
trans = handle->trans;
|
2011-06-07 17:06:16 -04:00
|
|
|
ASSERT(trans != NULL, RET_ERR(handle, PM_ERR_TRANS_NULL, -1));
|
2010-10-17 05:14:43 -04:00
|
|
|
ASSERT(trans->state == STATE_INITIALIZED,
|
2011-06-07 17:06:16 -04:00
|
|
|
RET_ERR(handle, PM_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-06-07 17:06:16 -04:00
|
|
|
RET_ERR(handle, PM_ERR_TRANS_DUP_TARGET, -1);
|
2010-10-17 05:14:43 -04:00
|
|
|
}
|
|
|
|
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_DEBUG, "adding package %s to the transaction remove list\n",
|
2011-04-21 23:09:57 -04:00
|
|
|
pkgname);
|
2010-10-17 05:14:43 -04:00
|
|
|
trans->remove = alpm_list_add(trans->remove, _alpm_pkg_dup(pkg));
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2010-10-17 05:14:43 -04:00
|
|
|
}
|
|
|
|
|
2011-06-07 15:05:42 -04:00
|
|
|
static void remove_prepare_cascade(pmhandle_t *handle, alpm_list_t *lp)
|
2008-04-04 23:02:23 -04:00
|
|
|
{
|
2011-06-07 15:05:42 -04:00
|
|
|
pmtrans_t *trans = handle->trans;
|
|
|
|
|
2008-04-04 23:02:23 -04:00
|
|
|
while(lp) {
|
|
|
|
alpm_list_t *i;
|
|
|
|
for(i = lp; i; i = i->next) {
|
|
|
|
pmdepmissing_t *miss = (pmdepmissing_t *)i->data;
|
2011-06-07 15:05:42 -04:00
|
|
|
pmpkg_t *info = _alpm_db_get_pkgfromcache(handle->db_local, miss->target);
|
2008-04-04 23:02:23 -04:00
|
|
|
if(info) {
|
2009-07-15 13:14:01 -04:00
|
|
|
if(!_alpm_pkg_find(trans->remove, alpm_pkg_get_name(info))) {
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_DEBUG, "pulling %s in target list\n",
|
2008-04-04 23:02:23 -04:00
|
|
|
alpm_pkg_get_name(info));
|
2009-07-15 13:14:01 -04:00
|
|
|
trans->remove = alpm_list_add(trans->remove, _alpm_pkg_dup(info));
|
2008-04-04 23:02:23 -04:00
|
|
|
}
|
|
|
|
} else {
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_ERROR, _("could not find %s in database -- skipping\n"),
|
2008-04-04 23:02:23 -04:00
|
|
|
miss->target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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-06-07 15:05:42 -04:00
|
|
|
static void remove_prepare_keep_needed(pmhandle_t *handle, alpm_list_t *lp)
|
2008-04-04 23:02:23 -04:00
|
|
|
{
|
2011-06-07 15:05:42 -04:00
|
|
|
pmtrans_t *trans = handle->trans;
|
|
|
|
|
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) {
|
|
|
|
pmdepmissing_t *miss = (pmdepmissing_t *)i->data;
|
|
|
|
void *vpkg;
|
2009-07-15 13:14:01 -04:00
|
|
|
pmpkg_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-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_WARNING, _("removing %s from target list\n"),
|
2008-04-04 23:02:23 -04:00
|
|
|
alpm_pkg_get_name(pkg));
|
|
|
|
_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
|
|
|
|
* filled with a list of pmdepmissing_t* objects representing
|
|
|
|
* 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-06-03 13:53:53 -04:00
|
|
|
int _alpm_remove_prepare(pmhandle_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-03 13:53:53 -04:00
|
|
|
pmtrans_t *trans = handle->trans;
|
|
|
|
pmdb_t *db = handle->db_local;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2008-04-19 16:31:22 -04:00
|
|
|
if((trans->flags & PM_TRANS_FLAG_RECURSE) && !(trans->flags & PM_TRANS_FLAG_CASCADE)) {
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_DEBUG, "finding removable dependencies\n");
|
2011-06-07 15:05:42 -04:00
|
|
|
_alpm_recursedeps(db, trans->remove,
|
|
|
|
trans->flags & PM_TRANS_FLAG_RECURSEALL);
|
2008-04-19 16:31:22 -04:00
|
|
|
}
|
|
|
|
|
2007-07-12 07:49:23 -04:00
|
|
|
if(!(trans->flags & PM_TRANS_FLAG_NODEPS)) {
|
2008-01-11 20:03:50 -05:00
|
|
|
EVENT(trans, PM_TRANS_EVT_CHECKDEPS_START, NULL, NULL);
|
|
|
|
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_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
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
if(trans->flags & PM_TRANS_FLAG_CASCADE) {
|
2011-06-07 15:05:42 -04:00
|
|
|
remove_prepare_cascade(handle, lp);
|
2011-04-20 20:45:16 -04:00
|
|
|
} else if(trans->flags & PM_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-06-07 17:06:16 -04:00
|
|
|
RET_ERR(handle, PM_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-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_DEBUG, "sorting by dependencies\n");
|
|
|
|
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 */
|
|
|
|
if((trans->flags & PM_TRANS_FLAG_CASCADE) && (trans->flags & PM_TRANS_FLAG_RECURSE)) {
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_DEBUG, "finding removable dependencies\n");
|
2009-07-15 13:14:01 -04:00
|
|
|
_alpm_recursedeps(db, trans->remove, trans->flags & PM_TRANS_FLAG_RECURSEALL);
|
2007-11-14 06:42:15 -05:00
|
|
|
}
|
|
|
|
|
2008-01-12 08:51:01 -05:00
|
|
|
if(!(trans->flags & PM_TRANS_FLAG_NODEPS)) {
|
|
|
|
EVENT(trans, PM_TRANS_EVT_CHECKDEPS_DONE, NULL, NULL);
|
|
|
|
}
|
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-07 17:13:58 -04:00
|
|
|
static int can_remove_file(pmhandle_t *handle, const char *path,
|
2011-06-14 10:30:46 -04:00
|
|
|
alpm_list_t *skip_remove)
|
2007-02-08 03:09:34 -05:00
|
|
|
{
|
2011-06-09 14:41:08 -04:00
|
|
|
char file[PATH_MAX];
|
2007-02-08 03:09:34 -05:00
|
|
|
|
2011-06-07 17:13:58 -04:00
|
|
|
snprintf(file, PATH_MAX, "%s%s", handle->root, path);
|
2007-02-08 03:09:34 -05:00
|
|
|
|
2011-06-14 10:30:46 -04:00
|
|
|
if(alpm_list_find_str(skip_remove, file)) {
|
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
|
|
|
}
|
|
|
|
/* If we fail write permissions due to a read-only filesystem, abort.
|
|
|
|
* Assume all other possible failures are covered somewhere else */
|
|
|
|
if(access(file, W_OK) == -1) {
|
2007-08-23 20:47:40 -04:00
|
|
|
if(errno != EACCES && errno != ETXTBSY && access(file, 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-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_ERROR, _("cannot remove file '%s': %s\n"),
|
2011-06-14 10:30:46 -04:00
|
|
|
file, 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-06-14 10:30:46 -04:00
|
|
|
static void unlink_file(pmhandle_t *handle, pmpkg_t *info, const char *filename,
|
2011-06-03 13:53:53 -04:00
|
|
|
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
|
|
|
|
2009-07-19 13:49:59 -04:00
|
|
|
snprintf(file, PATH_MAX, "%s%s", handle->root, filename);
|
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. */
|
|
|
|
if(alpm_list_find_str(skip_remove, filename)) {
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_DEBUG, "%s is in skip_remove, skipping removal\n",
|
2009-07-15 13:14:01 -04:00
|
|
|
file);
|
|
|
|
return;
|
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-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_DEBUG, "file %s does not exist\n", file);
|
2007-01-18 11:04:05 -05:00
|
|
|
return;
|
|
|
|
}
|
2007-11-16 21:18:45 -05:00
|
|
|
|
2007-02-08 03:09:34 -05:00
|
|
|
if(S_ISDIR(buf.st_mode)) {
|
|
|
|
if(rmdir(file)) {
|
2007-09-23 15:43:03 -04:00
|
|
|
/* this is okay, other packages are probably using it (like /usr) */
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_DEBUG, "keeping directory %s\n", file);
|
2007-01-18 11:04:05 -05:00
|
|
|
} else {
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_DEBUG, "removing directory %s\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-06-16 14:15:11 -04:00
|
|
|
pmbackup_t *backup = _alpm_needbackup(filename, alpm_pkg_get_backup(info));
|
|
|
|
if(backup) {
|
2009-07-15 13:14:01 -04:00
|
|
|
if(nosave) {
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_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) {
|
|
|
|
char newpath[PATH_MAX];
|
|
|
|
snprintf(newpath, PATH_MAX, "%s.pacsave", file);
|
|
|
|
rename(file, newpath);
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_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);
|
2009-07-19 13:49:59 -04:00
|
|
|
return;
|
|
|
|
}
|
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-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_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-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_ERROR, _("cannot remove file '%s': %s\n"),
|
2011-06-14 10:30:46 -04:00
|
|
|
filename, strerror(errno));
|
2007-01-18 11:04:05 -05:00
|
|
|
}
|
|
|
|
}
|
2007-01-16 23:47:19 -05:00
|
|
|
}
|
|
|
|
|
2011-06-03 13:53:53 -04:00
|
|
|
int _alpm_upgraderemove_package(pmhandle_t *handle,
|
|
|
|
pmpkg_t *oldpkg, pmpkg_t *newpkg)
|
2009-07-15 13:14:01 -04:00
|
|
|
{
|
|
|
|
alpm_list_t *skip_remove, *b;
|
|
|
|
alpm_list_t *newfiles, *lp;
|
2011-06-24 18:28:28 -04:00
|
|
|
size_t filenum = 0;
|
2009-07-15 13:14:01 -04:00
|
|
|
alpm_list_t *files = alpm_pkg_get_files(oldpkg);
|
|
|
|
const char *pkgname = alpm_pkg_get_name(oldpkg);
|
|
|
|
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_DEBUG, "removing old package first (%s-%s)\n",
|
2009-07-15 13:14:01 -04:00
|
|
|
oldpkg->name, oldpkg->version);
|
|
|
|
|
2011-06-03 13:53:53 -04:00
|
|
|
if(handle->trans->flags & PM_TRANS_FLAG_DBONLY) {
|
2010-10-11 18:42:04 -04:00
|
|
|
goto db;
|
|
|
|
}
|
|
|
|
|
2009-07-15 13:14:01 -04:00
|
|
|
/* copy the remove skiplist over */
|
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
|
|
|
skip_remove = alpm_list_join(
|
2011-06-03 13:53:53 -04:00
|
|
|
alpm_list_strdup(handle->trans->skip_remove),
|
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
|
|
|
alpm_list_strdup(handle->noupgrade));
|
2009-07-15 13:14:01 -04:00
|
|
|
/* Add files in the NEW backup array to the skip_remove array
|
|
|
|
* so this removal operation doesn't kill them */
|
|
|
|
/* old package backup list */
|
|
|
|
alpm_list_t *filelist = alpm_pkg_get_files(newpkg);
|
|
|
|
for(b = alpm_pkg_get_backup(newpkg); b; b = b->next) {
|
2011-06-16 14:15:11 -04:00
|
|
|
const pmbackup_t *backup = b->data;
|
2009-07-15 13:14:01 -04:00
|
|
|
/* safety check (fix the upgrade026 pactest) */
|
2011-06-16 14:15:11 -04:00
|
|
|
if(!alpm_list_find_str(filelist, backup->name)) {
|
2009-07-15 13:14:01 -04:00
|
|
|
continue;
|
|
|
|
}
|
2011-06-16 14:15:11 -04:00
|
|
|
_alpm_log(handle, PM_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
|
|
|
}
|
|
|
|
|
|
|
|
for(lp = files; lp; lp = lp->next) {
|
2011-06-07 17:13:58 -04:00
|
|
|
if(!can_remove_file(handle, lp->data, skip_remove)) {
|
2011-06-16 14:15:11 -04:00
|
|
|
_alpm_log(handle, PM_LOG_DEBUG,
|
|
|
|
"not removing package '%s', can't remove all files\n", pkgname);
|
2011-06-07 17:06:16 -04:00
|
|
|
RET_ERR(handle, PM_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-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_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
|
|
|
|
2009-07-15 13:14:01 -04:00
|
|
|
/* iterate through the list backwards, unlinking files */
|
|
|
|
newfiles = alpm_list_reverse(files);
|
|
|
|
for(lp = newfiles; lp; lp = alpm_list_next(lp)) {
|
2011-06-03 13:53:53 -04:00
|
|
|
unlink_file(handle, oldpkg, lp->data, skip_remove, 0);
|
2009-07-15 13:14:01 -04:00
|
|
|
}
|
|
|
|
alpm_list_free(newfiles);
|
|
|
|
FREELIST(skip_remove);
|
|
|
|
|
2010-10-11 18:42:04 -04:00
|
|
|
db:
|
2009-07-15 13:14:01 -04:00
|
|
|
/* remove the package from the database */
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_DEBUG, "updating database\n");
|
|
|
|
_alpm_log(handle, PM_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-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_ERROR, _("could not remove database entry %s-%s\n"),
|
2009-07-15 13:14:01 -04:00
|
|
|
pkgname, alpm_pkg_get_version(oldpkg));
|
|
|
|
}
|
|
|
|
/* remove the package from the cache */
|
|
|
|
if(_alpm_db_remove_pkgfromcache(handle->db_local, oldpkg) == -1) {
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_ERROR, _("could not remove entry '%s' from cache\n"),
|
2009-07-15 13:14:01 -04:00
|
|
|
pkgname);
|
|
|
|
}
|
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2009-07-15 13:14:01 -04:00
|
|
|
}
|
|
|
|
|
2011-06-03 13:53:53 -04:00
|
|
|
int _alpm_remove_packages(pmhandle_t *handle)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2007-11-12 20:40:08 -05:00
|
|
|
pmpkg_t *info;
|
2007-01-19 04:28:44 -05:00
|
|
|
alpm_list_t *targ, *lp;
|
2010-12-08 00:13:36 -05:00
|
|
|
size_t pkg_count;
|
2011-06-03 13:53:53 -04:00
|
|
|
pmtrans_t *trans = handle->trans;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2009-07-15 13:14:01 -04:00
|
|
|
pkg_count = alpm_list_count(trans->remove);
|
2007-09-23 16:44:40 -04:00
|
|
|
|
2009-07-15 13:14:01 -04:00
|
|
|
for(targ = trans->remove; targ; targ = targ->next) {
|
2006-10-15 15:31:03 -04:00
|
|
|
int position = 0;
|
2007-03-22 04:22:48 -04:00
|
|
|
char scriptlet[PATH_MAX];
|
2011-03-25 11:57:20 -04:00
|
|
|
info = (pmpkg_t *)targ->data;
|
2007-03-03 15:22:48 -05:00
|
|
|
const char *pkgname = NULL;
|
2010-12-08 00:13:36 -05:00
|
|
|
size_t targcount = alpm_list_count(targ);
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2011-06-03 13:53:53 -04:00
|
|
|
if(trans->state == STATE_INTERRUPTED) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2006-07-14 19:15:07 -04:00
|
|
|
}
|
|
|
|
|
2007-03-03 15:22:48 -05:00
|
|
|
/* get the name now so we can use it after package is removed */
|
|
|
|
pkgname = alpm_pkg_get_name(info);
|
2009-09-14 23:44:51 -04:00
|
|
|
snprintf(scriptlet, PATH_MAX, "%s%s-%s/install",
|
2011-06-03 13:53:53 -04:00
|
|
|
_alpm_db_path(handle->db_local), pkgname, alpm_pkg_get_version(info));
|
2007-03-03 15:22:48 -05:00
|
|
|
|
2009-07-15 13:14:01 -04:00
|
|
|
EVENT(trans, PM_TRANS_EVT_REMOVE_START, info, NULL);
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_DEBUG, "removing package %s-%s\n",
|
2009-07-15 13:14:01 -04:00
|
|
|
pkgname, alpm_pkg_get_version(info));
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2009-07-15 13:14:01 -04:00
|
|
|
/* run the pre-remove scriptlet if it exists */
|
|
|
|
if(alpm_pkg_has_scriptlet(info) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
|
2011-06-03 13:33:18 -04:00
|
|
|
_alpm_runscriptlet(handle, scriptlet, "pre_remove",
|
|
|
|
alpm_pkg_get_version(info), NULL);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!(trans->flags & PM_TRANS_FLAG_DBONLY)) {
|
2009-07-15 13:14:01 -04:00
|
|
|
alpm_list_t *files = alpm_pkg_get_files(info);
|
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
|
|
|
alpm_list_t *newfiles;
|
2011-06-24 18:28:28 -04:00
|
|
|
size_t filenum = 0;
|
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
|
|
|
|
2007-03-03 03:13:59 -05:00
|
|
|
for(lp = files; lp; lp = lp->next) {
|
2011-06-07 17:13:58 -04:00
|
|
|
if(!can_remove_file(handle, lp->data, NULL)) {
|
|
|
|
_alpm_log(handle, PM_LOG_DEBUG, "not removing package '%s', can't remove all files\n",
|
2007-03-03 15:22:48 -05:00
|
|
|
pkgname);
|
2011-06-07 17:06:16 -04:00
|
|
|
RET_ERR(handle, PM_ERR_PKG_CANT_REMOVE, -1);
|
2007-02-08 03:09:34 -05:00
|
|
|
}
|
2011-06-24 18:28:28 -04:00
|
|
|
filenum++;
|
2007-02-08 03:09:34 -05:00
|
|
|
}
|
|
|
|
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_DEBUG, "removing %ld files\n", (unsigned long)filenum);
|
2005-03-26 13:03:36 -05:00
|
|
|
|
2010-10-17 13:27:38 -04:00
|
|
|
/* init progress bar */
|
|
|
|
PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, info->name, 0,
|
|
|
|
pkg_count, (pkg_count - targcount + 1));
|
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
/* iterate through the list backwards, unlinking files */
|
2007-11-11 13:59:45 -05:00
|
|
|
newfiles = alpm_list_reverse(files);
|
|
|
|
for(lp = newfiles; lp; lp = alpm_list_next(lp)) {
|
2011-01-09 21:36:42 -05:00
|
|
|
int percent;
|
2011-06-03 13:53:53 -04:00
|
|
|
unlink_file(handle, info, lp->data, NULL, trans->flags & PM_TRANS_FLAG_NOSAVE);
|
2007-09-23 16:44:40 -04:00
|
|
|
|
|
|
|
/* update progress bar after each file */
|
2011-01-09 21:36:42 -05:00
|
|
|
percent = (position * 100) / filenum;
|
2007-09-23 16:44:40 -04:00
|
|
|
PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, info->name,
|
2011-01-09 21:36:42 -05:00
|
|
|
percent, pkg_count, (pkg_count - targcount + 1));
|
2007-09-23 16:44:40 -04:00
|
|
|
position++;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
Fix several memleaks, mostly related to errors handling.
* The frontend calls alpm_trans_prepare(&data), and in case of errors,
receive the missing dependencies / conflicts / etc in the data pointer.
It apparently needs to free this structure totally with :
alpm_list_free_inner(data, free)
alpm_list_free(data)
So I added alpm_list_free_inner(data, free) in
pacman/{sync.c,remove.c,add,c}
* in _alpm_sync_prepare, the deps and asked lists were not freed in case
of errors (unresolvable conflicts).
Besides the code for handling this case was duplicated.
* in _alpm_remove_commit, free was used instead of alpm_list_free for
newfiles.
* newline fix in pacman/sync.c
Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
2007-11-21 13:51:46 -05:00
|
|
|
alpm_list_free(newfiles);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2007-04-01 21:17:30 -04:00
|
|
|
/* set progress to 100% after we finish unlinking files */
|
|
|
|
PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, pkgname, 100,
|
2009-10-11 15:09:39 -04:00
|
|
|
pkg_count, (pkg_count - targcount + 1));
|
2007-04-01 21:17:30 -04:00
|
|
|
|
2009-07-15 13:14:01 -04:00
|
|
|
/* run the post-remove script if it exists */
|
|
|
|
if(alpm_pkg_has_scriptlet(info) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
|
2011-06-03 13:33:18 -04:00
|
|
|
_alpm_runscriptlet(handle, scriptlet, "post_remove",
|
|
|
|
alpm_pkg_get_version(info), NULL);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* remove the package from the database */
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_DEBUG, "updating database\n");
|
|
|
|
_alpm_log(handle, PM_LOG_DEBUG, "removing database entry '%s'\n", pkgname);
|
2011-06-03 13:53:53 -04:00
|
|
|
if(_alpm_local_db_remove(handle->db_local, info) == -1) {
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_ERROR, _("could not remove database entry %s-%s\n"),
|
2007-03-03 15:22:48 -05:00
|
|
|
pkgname, alpm_pkg_get_version(info));
|
2005-04-23 13:18:31 -04:00
|
|
|
}
|
2007-03-03 15:22:48 -05:00
|
|
|
/* remove the package from the cache */
|
2011-06-03 13:53:53 -04:00
|
|
|
if(_alpm_db_remove_pkgfromcache(handle->db_local, info) == -1) {
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_ERROR, _("could not remove entry '%s' from cache\n"),
|
2007-03-03 15:22:48 -05:00
|
|
|
pkgname);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2007-11-16 21:18:45 -05:00
|
|
|
|
2009-07-15 13:14:01 -04:00
|
|
|
EVENT(trans, PM_TRANS_EVT_REMOVE_DONE, info, NULL);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* run ldconfig if it exists */
|
2011-06-03 13:33:18 -04:00
|
|
|
_alpm_ldconfig(handle);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/* vim: set ts=2 sw=2 noet: */
|