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 <time.h>
|
|
|
|
#include <fcntl.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"
|
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"
|
|
|
|
#include "alpm.h"
|
|
|
|
|
2010-10-17 05:14:43 -04:00
|
|
|
int SYMEXPORT alpm_remove_pkg(pmpkg_t *pkg)
|
|
|
|
{
|
|
|
|
pmtrans_t *trans;
|
|
|
|
const char *pkgname;
|
|
|
|
|
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
|
|
|
|
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
|
|
|
|
trans = handle->trans;
|
|
|
|
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
|
|
|
|
ASSERT(trans->state == STATE_INITIALIZED,
|
|
|
|
RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1));
|
|
|
|
|
|
|
|
pkgname = alpm_pkg_get_name(pkg);
|
|
|
|
|
|
|
|
if(_alpm_pkg_find(trans->remove, pkgname)) {
|
|
|
|
RET_ERR(PM_ERR_TRANS_DUP_TARGET, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
_alpm_log(PM_LOG_DEBUG, "adding %s in the target list\n", pkgname);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-04-04 23:02:23 -04:00
|
|
|
static void remove_prepare_cascade(pmtrans_t *trans, pmdb_t *db,
|
|
|
|
alpm_list_t *lp)
|
|
|
|
{
|
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
|
|
|
while(lp) {
|
|
|
|
alpm_list_t *i;
|
|
|
|
for(i = lp; i; i = i->next) {
|
|
|
|
pmdepmissing_t *miss = (pmdepmissing_t *)i->data;
|
|
|
|
pmpkg_t *info = _alpm_db_get_pkgfromcache(db, miss->target);
|
|
|
|
if(info) {
|
2009-07-15 13:14:01 -04:00
|
|
|
if(!_alpm_pkg_find(trans->remove, alpm_pkg_get_name(info))) {
|
2009-09-16 20:03:23 -04:00
|
|
|
_alpm_log(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 {
|
|
|
|
_alpm_log(PM_LOG_ERROR, _("could not find %s in database -- skipping\n"),
|
|
|
|
miss->target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
alpm_list_free_inner(lp, (alpm_list_fn_free)_alpm_depmiss_free);
|
|
|
|
alpm_list_free(lp);
|
2011-02-25 09:22:09 -05:00
|
|
|
lp = alpm_checkdeps(_alpm_db_get_pkgcache(db), 1, trans->remove, NULL);
|
2008-04-04 23:02:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void remove_prepare_keep_needed(pmtrans_t *trans, pmdb_t *db,
|
|
|
|
alpm_list_t *lp)
|
|
|
|
{
|
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
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) {
|
2009-09-16 20:03:23 -04:00
|
|
|
_alpm_log(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-02-25 09:22:09 -05:00
|
|
|
lp = alpm_checkdeps(_alpm_db_get_pkgcache(db), 1, trans->remove, NULL);
|
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.
|
|
|
|
* @param trans the transaction object
|
|
|
|
* @param db the database of local packages
|
|
|
|
* @param data a pointer to an alpm_list_t* to fill
|
|
|
|
*/
|
2007-01-19 04:28:44 -05:00
|
|
|
int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2007-01-19 04:28:44 -05:00
|
|
|
alpm_list_t *lp;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-01-30 03:14:10 -05:00
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
2005-03-16 17:10:05 -05:00
|
|
|
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
|
|
|
|
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
|
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)) {
|
|
|
|
_alpm_log(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);
|
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);
|
|
|
|
|
2007-08-23 22:26:55 -04:00
|
|
|
_alpm_log(PM_LOG_DEBUG, "looking for unsatisfied dependencies\n");
|
2011-02-25 09:22:09 -05:00
|
|
|
lp = alpm_checkdeps(_alpm_db_get_pkgcache(db), 1, trans->remove, NULL);
|
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) {
|
2008-04-04 23:02:23 -04:00
|
|
|
remove_prepare_cascade(trans, db, lp);
|
2007-11-18 12:45:46 -05: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 */
|
2008-04-04 23:02:23 -04:00
|
|
|
remove_prepare_keep_needed(trans, db, 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
|
|
|
}
|
2005-03-16 17:10:05 -05:00
|
|
|
RET_ERR(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 */
|
2007-08-23 22:26:55 -04:00
|
|
|
_alpm_log(PM_LOG_DEBUG, "sorting by dependencies\n");
|
2009-07-15 13:14:01 -04:00
|
|
|
lp = _alpm_sortbydeps(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)) {
|
2007-11-14 06:42:15 -05:00
|
|
|
_alpm_log(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
|
|
|
}
|
|
|
|
|
2009-07-15 13:14:01 -04:00
|
|
|
static int can_remove_file(const char *path, alpm_list_t *skip)
|
2007-02-08 03:09:34 -05:00
|
|
|
{
|
|
|
|
char file[PATH_MAX+1];
|
|
|
|
|
|
|
|
snprintf(file, PATH_MAX, "%s%s", handle->root, path);
|
|
|
|
|
2009-07-15 13:14:01 -04:00
|
|
|
if(alpm_list_find_str(skip, 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 */
|
2007-08-23 22:26:55 -04:00
|
|
|
_alpm_log(PM_LOG_ERROR, _("cannot remove file '%s': %s\n"),
|
2007-02-19 21:14:27 -05: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. */
|
2009-07-15 13:14:01 -04:00
|
|
|
static void unlink_file(pmpkg_t *info, char *filename, 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;
|
2007-02-08 03:09:34 -05:00
|
|
|
char file[PATH_MAX+1];
|
2007-01-18 11:04:05 -05:00
|
|
|
|
2007-01-30 03:14:10 -05:00
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
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)) {
|
|
|
|
_alpm_log(PM_LOG_DEBUG, "%s is in skip_remove, skipping removal\n",
|
|
|
|
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)) {
|
2007-08-23 22:26:55 -04:00
|
|
|
_alpm_log(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) */
|
2007-08-23 22:26:55 -04:00
|
|
|
_alpm_log(PM_LOG_DEBUG, "keeping directory %s\n", file);
|
2007-01-18 11:04:05 -05:00
|
|
|
} else {
|
2007-08-23 22:26:55 -04:00
|
|
|
_alpm_log(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 */
|
|
|
|
char *pkghash = _alpm_needbackup(filename, alpm_pkg_get_backup(info));
|
|
|
|
if(pkghash) {
|
2009-07-15 13:14:01 -04:00
|
|
|
if(nosave) {
|
2007-09-23 15:43:03 -04:00
|
|
|
_alpm_log(PM_LOG_DEBUG, "transaction is set to NOSAVE, not backing up '%s'\n", file);
|
2009-07-21 09:50:08 -04:00
|
|
|
FREE(pkghash);
|
2009-07-19 13:49:59 -04:00
|
|
|
} else {
|
|
|
|
char *filehash = alpm_compute_md5sum(file);
|
|
|
|
int cmp = strcmp(filehash,pkghash);
|
|
|
|
FREE(filehash);
|
|
|
|
FREE(pkghash);
|
|
|
|
if(cmp != 0) {
|
|
|
|
char newpath[PATH_MAX];
|
|
|
|
snprintf(newpath, PATH_MAX, "%s.pacsave", file);
|
|
|
|
rename(file, newpath);
|
|
|
|
_alpm_log(PM_LOG_WARNING, _("%s saved as %s\n"), file, newpath);
|
|
|
|
alpm_logaction("warning: %s saved as %s\n", file, newpath);
|
|
|
|
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
|
|
|
|
2007-08-23 22:26:55 -04:00
|
|
|
_alpm_log(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) {
|
2007-09-27 22:18:06 -04:00
|
|
|
_alpm_log(PM_LOG_ERROR, _("cannot remove file '%s': %s\n"),
|
2009-07-19 13:49:59 -04:00
|
|
|
filename, strerror(errno));
|
2007-01-18 11:04:05 -05:00
|
|
|
}
|
|
|
|
}
|
2007-01-16 23:47:19 -05:00
|
|
|
}
|
|
|
|
|
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
|
|
|
int _alpm_upgraderemove_package(pmpkg_t *oldpkg, pmpkg_t *newpkg,
|
|
|
|
pmtrans_t *trans)
|
2009-07-15 13:14:01 -04:00
|
|
|
{
|
|
|
|
alpm_list_t *skip_remove, *b;
|
|
|
|
alpm_list_t *newfiles, *lp;
|
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
|
|
|
size_t filenum;
|
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);
|
|
|
|
|
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
|
|
|
_alpm_log(PM_LOG_DEBUG, "removing old package first (%s-%s)\n",
|
|
|
|
oldpkg->name, oldpkg->version);
|
|
|
|
|
2010-10-11 18:42:04 -04:00
|
|
|
if(trans->flags & PM_TRANS_FLAG_DBONLY) {
|
|
|
|
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(
|
|
|
|
alpm_list_strdup(trans->skip_remove),
|
|
|
|
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) {
|
|
|
|
char *backup = _alpm_backup_file(b->data);
|
|
|
|
/* safety check (fix the upgrade026 pactest) */
|
|
|
|
if(!alpm_list_find_str(filelist, backup)) {
|
|
|
|
FREE(backup);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
_alpm_log(PM_LOG_DEBUG, "adding %s to the skip_remove array\n", backup);
|
|
|
|
skip_remove = alpm_list_add(skip_remove, backup);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(lp = files; lp; lp = lp->next) {
|
|
|
|
if(!can_remove_file(lp->data, skip_remove)) {
|
|
|
|
_alpm_log(PM_LOG_DEBUG, "not removing package '%s', can't remove all files\n",
|
|
|
|
pkgname);
|
|
|
|
RET_ERR(PM_ERR_PKG_CANT_REMOVE, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
filenum = alpm_list_count(files);
|
|
|
|
_alpm_log(PM_LOG_DEBUG, "removing %ld files\n", (unsigned long)filenum);
|
|
|
|
|
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)) {
|
|
|
|
unlink_file(oldpkg, lp->data, skip_remove, 0);
|
|
|
|
}
|
|
|
|
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 */
|
|
|
|
_alpm_log(PM_LOG_DEBUG, "updating database\n");
|
|
|
|
_alpm_log(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) {
|
2009-07-15 13:14:01 -04:00
|
|
|
_alpm_log(PM_LOG_ERROR, _("could not remove database entry %s-%s\n"),
|
|
|
|
pkgname, alpm_pkg_get_version(oldpkg));
|
|
|
|
}
|
|
|
|
/* remove the package from the cache */
|
|
|
|
if(_alpm_db_remove_pkgfromcache(handle->db_local, oldpkg) == -1) {
|
|
|
|
_alpm_log(PM_LOG_ERROR, _("could not remove entry '%s' from cache\n"),
|
|
|
|
pkgname);
|
|
|
|
}
|
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2009-07-15 13:14:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
|
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;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-01-30 03:14:10 -05:00
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
2005-03-16 17:10:05 -05:00
|
|
|
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
|
|
|
|
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
|
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];
|
2005-03-14 20:51:43 -05: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
|
|
|
|
2006-07-14 19:15:07 -04:00
|
|
|
if(handle->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",
|
|
|
|
_alpm_db_path(db), 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);
|
|
|
|
_alpm_log(PM_LOG_DEBUG, "removing package %s-%s\n",
|
|
|
|
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)) {
|
|
|
|
_alpm_runscriptlet(handle->root, scriptlet, "pre_remove",
|
|
|
|
alpm_pkg_get_version(info), NULL, trans);
|
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;
|
|
|
|
size_t filenum;
|
|
|
|
|
2007-03-03 03:13:59 -05:00
|
|
|
for(lp = files; lp; lp = lp->next) {
|
2009-07-15 13:14:01 -04:00
|
|
|
if(!can_remove_file(lp->data, NULL)) {
|
2007-08-23 22:26:55 -04:00
|
|
|
_alpm_log(PM_LOG_DEBUG, "not removing package '%s', can't remove all files\n",
|
2007-03-03 15:22:48 -05:00
|
|
|
pkgname);
|
2007-02-08 03:09:34 -05:00
|
|
|
RET_ERR(PM_ERR_PKG_CANT_REMOVE, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
filenum = alpm_list_count(files);
|
2010-12-08 00:13:36 -05:00
|
|
|
_alpm_log(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;
|
2009-07-15 13:14:01 -04:00
|
|
|
unlink_file(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)) {
|
|
|
|
_alpm_runscriptlet(handle->root, scriptlet, "post_remove",
|
|
|
|
alpm_pkg_get_version(info), NULL, trans);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* remove the package from the database */
|
2007-08-23 22:26:55 -04:00
|
|
|
_alpm_log(PM_LOG_DEBUG, "updating database\n");
|
|
|
|
_alpm_log(PM_LOG_DEBUG, "removing database entry '%s'\n", pkgname);
|
2010-10-13 04:04:07 -04:00
|
|
|
if(_alpm_local_db_remove(db, info) == -1) {
|
2007-08-23 22:26:55 -04:00
|
|
|
_alpm_log(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 */
|
2006-02-17 17:35:26 -05:00
|
|
|
if(_alpm_db_remove_pkgfromcache(db, info) == -1) {
|
2007-08-23 22:26:55 -04:00
|
|
|
_alpm_log(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 */
|
2009-07-15 13:14:01 -04:00
|
|
|
_alpm_ldconfig(handle->root);
|
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: */
|