2005-03-14 20:51:43 -05:00
|
|
|
/*
|
|
|
|
* remove.c
|
2007-11-16 21:18:45 -05:00
|
|
|
*
|
2007-12-10 23:55:22 -05:00
|
|
|
* Copyright (c) 2002-2007 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 "error.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "backup.h"
|
|
|
|
#include "package.h"
|
|
|
|
#include "db.h"
|
|
|
|
#include "cache.h"
|
|
|
|
#include "deps.h"
|
|
|
|
#include "handle.h"
|
|
|
|
#include "alpm.h"
|
|
|
|
|
2006-02-17 17:35:26 -05:00
|
|
|
int _alpm_remove_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
|
|
|
pmpkg_t *info;
|
|
|
|
|
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));
|
|
|
|
ASSERT(name != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-02-26 03:38:48 -05:00
|
|
|
if(_alpm_pkg_find(name, trans->packages)) {
|
2006-01-18 17:37:16 -05:00
|
|
|
RET_ERR(PM_ERR_TRANS_DUP_TARGET, -1);
|
|
|
|
}
|
|
|
|
|
2007-03-03 03:13:59 -05:00
|
|
|
if((info = _alpm_db_scan(db, name)) == NULL) {
|
2006-12-01 04:32:29 -05:00
|
|
|
/* Unimportant - just ignore it if we can't find it */
|
2007-08-23 22:26:55 -04:00
|
|
|
_alpm_log(PM_LOG_DEBUG, "could not find %s in database\n", name);
|
2005-03-16 17:10:05 -05:00
|
|
|
RET_ERR(PM_ERR_PKG_NOT_FOUND, -1);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2005-04-24 17:27:35 -04:00
|
|
|
|
2006-10-15 15:31:03 -04:00
|
|
|
/* ignore holdpkgs on upgrade */
|
2007-01-29 22:46:33 -05:00
|
|
|
if((trans == handle->trans)
|
|
|
|
&& alpm_list_find_str(handle->holdpkg, info->name)) {
|
2006-10-15 15:31:03 -04:00
|
|
|
int resp = 0;
|
|
|
|
QUESTION(trans, PM_TRANS_CONV_REMOVE_HOLDPKG, info, NULL, NULL, &resp);
|
|
|
|
if(!resp) {
|
|
|
|
RET_ERR(PM_ERR_PKG_HOLD, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-23 22:26:55 -04:00
|
|
|
_alpm_log(PM_LOG_DEBUG, "adding %s in the targets list\n", info->name);
|
2007-01-19 04:28:44 -05:00
|
|
|
trans->packages = alpm_list_add(trans->packages, info);
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2007-07-14 09:34:39 -04:00
|
|
|
/* skip all checks if we are doing this removal as part of an upgrade */
|
|
|
|
if(trans->type == PM_TRANS_TYPE_REMOVEUPGRADE) {
|
2007-07-12 07:49:23 -04:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
EVENT(trans, PM_TRANS_EVT_CHECKDEPS_START, NULL, NULL);
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-07-12 07:49:23 -04:00
|
|
|
if(!(trans->flags & PM_TRANS_FLAG_NODEPS)) {
|
2007-08-23 22:26:55 -04:00
|
|
|
_alpm_log(PM_LOG_DEBUG, "looking for unsatisfied dependencies\n");
|
2007-08-12 16:26:54 -04:00
|
|
|
lp = alpm_checkdeps(db, 1, trans->packages, NULL);
|
2006-01-15 10:55:16 -05:00
|
|
|
if(lp != NULL) {
|
2005-03-14 20:51:43 -05:00
|
|
|
if(trans->flags & PM_TRANS_FLAG_CASCADE) {
|
|
|
|
while(lp) {
|
2007-01-19 04:28:44 -05:00
|
|
|
alpm_list_t *i;
|
2006-01-16 17:27:09 -05:00
|
|
|
for(i = lp; i; i = i->next) {
|
|
|
|
pmdepmissing_t *miss = (pmdepmissing_t *)i->data;
|
2007-06-10 08:40:25 -04:00
|
|
|
pmpkg_t *info = _alpm_db_scan(db, miss->target);
|
2006-01-16 17:27:09 -05:00
|
|
|
if(info) {
|
2007-09-01 08:12:39 -04:00
|
|
|
if(!_alpm_pkg_find(alpm_pkg_get_name(info), trans->packages)) {
|
|
|
|
_alpm_log(PM_LOG_DEBUG, "pulling %s in the targets list\n",
|
|
|
|
alpm_pkg_get_name(info));
|
|
|
|
trans->packages = alpm_list_add(trans->packages, info);
|
|
|
|
}
|
2006-01-16 17:27:09 -05:00
|
|
|
} else {
|
2007-08-23 22:26:55 -04:00
|
|
|
_alpm_log(PM_LOG_ERROR, _("could not find %s in database -- skipping\n"),
|
2007-10-26 10:37:47 -04:00
|
|
|
miss->target);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
FREELIST(lp);
|
2007-08-12 16:26:54 -04:00
|
|
|
lp = alpm_checkdeps(db, 1, trans->packages, NULL);
|
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 {
|
|
|
|
FREELIST(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");
|
2007-07-12 07:49:23 -04:00
|
|
|
lp = _alpm_sortbydeps(trans->packages, PM_TRANS_TYPE_REMOVE);
|
|
|
|
/* free the old alltargs */
|
|
|
|
alpm_list_free(trans->packages);
|
|
|
|
trans->packages = lp;
|
2005-03-25 17:09:14 -05:00
|
|
|
|
2007-11-14 06:42:15 -05:00
|
|
|
if(trans->flags & PM_TRANS_FLAG_RECURSE) {
|
|
|
|
_alpm_log(PM_LOG_DEBUG, "finding removable dependencies\n");
|
|
|
|
_alpm_recursedeps(db, trans->packages, 0);
|
|
|
|
}
|
|
|
|
|
2007-07-12 07:49:23 -04:00
|
|
|
EVENT(trans, PM_TRANS_EVT_CHECKDEPS_DONE, NULL, NULL);
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2007-02-19 21:14:27 -05:00
|
|
|
static int can_remove_file(pmtrans_t *trans, const char *path)
|
2007-02-08 03:09:34 -05:00
|
|
|
{
|
|
|
|
char file[PATH_MAX+1];
|
|
|
|
|
|
|
|
snprintf(file, PATH_MAX, "%s%s", handle->root, path);
|
|
|
|
|
2007-02-19 21:14:27 -05:00
|
|
|
if(alpm_list_find_str(trans->skip_remove, file)) {
|
|
|
|
/* return success because we will never actually remove this file */
|
|
|
|
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));
|
2007-02-08 03:09:34 -05:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
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. */
|
|
|
|
static void unlink_file(pmpkg_t *info, alpm_list_t *lp, pmtrans_t *trans)
|
2007-01-16 23:47:19 -05:00
|
|
|
{
|
2007-01-18 11:04:05 -05:00
|
|
|
struct stat buf;
|
2007-02-17 03:55:05 -05:00
|
|
|
int needbackup = 0;
|
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;
|
|
|
|
|
2007-03-03 03:13:59 -05:00
|
|
|
char *hash = _alpm_needbackup(lp->data, alpm_pkg_get_backup(info));
|
2007-02-17 03:55:05 -05:00
|
|
|
if(hash) {
|
|
|
|
needbackup = 1;
|
|
|
|
FREE(hash);
|
2007-02-08 03:09:34 -05:00
|
|
|
}
|
2007-11-16 21:18:45 -05:00
|
|
|
|
2007-06-27 19:20:30 -04:00
|
|
|
snprintf(file, PATH_MAX, "%s%s", handle->root, (char *)lp->data);
|
|
|
|
|
2007-07-14 09:34:39 -04:00
|
|
|
if(trans->type == PM_TRANS_TYPE_REMOVEUPGRADE) {
|
2007-01-18 11:04:05 -05:00
|
|
|
/* check noupgrade */
|
2007-02-08 03:09:34 -05:00
|
|
|
if(alpm_list_find_str(handle->noupgrade, lp->data)) {
|
2007-09-23 15:43:03 -04:00
|
|
|
_alpm_log(PM_LOG_DEBUG, "Skipping removal of '%s' due to NoUpgrade\n",
|
|
|
|
file);
|
2007-02-21 01:44:14 -05:00
|
|
|
return;
|
2007-01-18 11:04:05 -05:00
|
|
|
}
|
|
|
|
}
|
2007-02-17 03:55:05 -05:00
|
|
|
|
2007-11-04 19:02:25 -05:00
|
|
|
if(_alpm_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 {
|
2007-02-19 21:14:27 -05:00
|
|
|
/* check the remove skip list before removing the file.
|
2007-11-18 04:29:55 -05:00
|
|
|
* see the big comment block in db_find_fileconflicts() for an
|
2007-01-18 11:04:05 -05:00
|
|
|
* explanation. */
|
2007-02-19 21:14:27 -05:00
|
|
|
if(alpm_list_find_str(trans->skip_remove, file)) {
|
2007-09-23 15:43:03 -04:00
|
|
|
_alpm_log(PM_LOG_DEBUG, "%s is in trans->skip_remove, skipping removal\n",
|
|
|
|
file);
|
2007-02-21 01:44:14 -05:00
|
|
|
return;
|
2007-02-17 03:55:05 -05:00
|
|
|
} else if(needbackup) {
|
2007-01-18 11:04:05 -05:00
|
|
|
/* if the file is flagged, back it up to .pacsave */
|
2007-09-23 15:43:03 -04:00
|
|
|
if(!(trans->flags & PM_TRANS_FLAG_NOSAVE)) {
|
|
|
|
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);
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
_alpm_log(PM_LOG_DEBUG, "transaction is set to NOSAVE, not backing up '%s'\n", file);
|
2007-02-17 03:55:05 -05:00
|
|
|
}
|
2007-02-21 01:44:14 -05: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"),
|
2007-10-08 22:25:52 -04:00
|
|
|
(char *)lp->data, strerror(errno));
|
2007-01-18 11:04:05 -05:00
|
|
|
}
|
|
|
|
}
|
2007-01-16 23:47:19 -05:00
|
|
|
}
|
|
|
|
|
2006-02-17 17:35:26 -05:00
|
|
|
int _alpm_remove_commit(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;
|
2007-09-23 16:44:40 -04:00
|
|
|
int 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
|
|
|
|
2007-09-23 16:44:40 -04:00
|
|
|
pkg_count = alpm_list_count(trans->packages);
|
|
|
|
|
2005-04-06 17:00:57 -04:00
|
|
|
for(targ = trans->packages; 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];
|
2007-03-03 03:13:59 -05:00
|
|
|
alpm_list_t *files;
|
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;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2006-07-14 19:15:07 -04:00
|
|
|
if(handle->trans->state == STATE_INTERRUPTED) {
|
2007-09-07 18:36:38 -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);
|
2007-04-05 12:40:18 -04:00
|
|
|
snprintf(scriptlet, PATH_MAX, "%s%s-%s/install", db->path,
|
|
|
|
pkgname, alpm_pkg_get_version(info));
|
2007-03-03 15:22:48 -05:00
|
|
|
|
2007-07-14 09:34:39 -04:00
|
|
|
if(trans->type != PM_TRANS_TYPE_REMOVEUPGRADE) {
|
2005-05-04 15:55:23 -04:00
|
|
|
EVENT(trans, PM_TRANS_EVT_REMOVE_START, info, NULL);
|
2007-08-23 22:26:55 -04:00
|
|
|
_alpm_log(PM_LOG_DEBUG, "removing package %s-%s\n",
|
2007-03-03 15:22:48 -05:00
|
|
|
pkgname, alpm_pkg_get_version(info));
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
/* run the pre-remove scriptlet if it exists */
|
2007-03-03 03:13:59 -05:00
|
|
|
if(alpm_pkg_has_scriptlet(info) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
|
2007-03-22 04:22:48 -04:00
|
|
|
_alpm_runscriptlet(handle->root, scriptlet, "pre_remove",
|
2007-11-04 10:47:21 -05:00
|
|
|
alpm_pkg_get_version(info), NULL, trans);
|
2005-03-26 08:29:47 -05:00
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2007-03-03 03:13:59 -05:00
|
|
|
files = alpm_pkg_get_files(info);
|
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
if(!(trans->flags & PM_TRANS_FLAG_DBONLY)) {
|
2007-03-03 03:13:59 -05:00
|
|
|
for(lp = files; lp; lp = lp->next) {
|
2007-02-19 21:14:27 -05:00
|
|
|
if(!can_remove_file(trans, lp->data)) {
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-03 03:13:59 -05:00
|
|
|
int filenum = alpm_list_count(files);
|
2007-09-23 16:44:40 -04:00
|
|
|
double percent = 0.0;
|
2007-11-11 13:59:45 -05:00
|
|
|
alpm_list_t *newfiles;
|
2007-08-23 22:26:55 -04:00
|
|
|
_alpm_log(PM_LOG_DEBUG, "removing %d files\n", filenum);
|
2005-03-26 13:03:36 -05:00
|
|
|
|
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)) {
|
2007-09-23 16:44:40 -04:00
|
|
|
unlink_file(info, lp, trans);
|
|
|
|
|
|
|
|
/* update progress bar after each file */
|
|
|
|
percent = (double)position / (double)filenum;
|
|
|
|
PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, info->name,
|
|
|
|
(double)(percent * 100), pkg_count,
|
|
|
|
(pkg_count - alpm_list_count(targ) + 1));
|
|
|
|
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,
|
2007-09-23 16:44:40 -04:00
|
|
|
pkg_count, (pkg_count - alpm_list_count(targ) + 1));
|
2007-04-01 21:17:30 -04:00
|
|
|
|
2007-07-14 09:34:39 -04:00
|
|
|
if(trans->type != PM_TRANS_TYPE_REMOVEUPGRADE) {
|
2005-03-14 20:51:43 -05:00
|
|
|
/* run the post-remove script if it exists */
|
2007-03-03 03:13:59 -05:00
|
|
|
if(alpm_pkg_has_scriptlet(info) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
|
2007-03-22 04:22:48 -04:00
|
|
|
_alpm_runscriptlet(handle->root, scriptlet, "post_remove",
|
2007-11-04 10:47:21 -05:00
|
|
|
alpm_pkg_get_version(info), NULL, trans);
|
2005-03-26 13:03:36 -05:00
|
|
|
}
|
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);
|
2006-02-17 17:35:26 -05:00
|
|
|
if(_alpm_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
|
|
|
|
2007-04-01 21:17:30 -04:00
|
|
|
/* call a done event if this isn't an upgrade */
|
2007-07-14 09:34:39 -04:00
|
|
|
if(trans->type != PM_TRANS_TYPE_REMOVEUPGRADE) {
|
2005-05-04 15:55:23 -04:00
|
|
|
EVENT(trans, PM_TRANS_EVT_REMOVE_DONE, info, NULL);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* run ldconfig if it exists */
|
2007-09-07 18:36:38 -04:00
|
|
|
if(trans->type != PM_TRANS_TYPE_REMOVEUPGRADE) {
|
2007-08-23 22:26:55 -04:00
|
|
|
_alpm_log(PM_LOG_DEBUG, "running \"ldconfig -r %s\"\n", handle->root);
|
2005-03-26 13:03:36 -05:00
|
|
|
_alpm_ldconfig(handle->root);
|
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim: set ts=2 sw=2 noet: */
|