summaryrefslogtreecommitdiff
path: root/lib/libalpm/remove.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libalpm/remove.c')
-rw-r--r--lib/libalpm/remove.c211
1 files changed, 101 insertions, 110 deletions
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index 291eb7a0..349ff10c 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -1,12 +1,12 @@
/*
* remove.c
- *
+ *
* Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
* 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>
- *
+ *
* 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
@@ -19,7 +19,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*/
@@ -31,15 +31,8 @@
#include <fcntl.h>
#include <string.h>
#include <limits.h>
-#if defined(__APPLE__) || defined(__OpenBSD__)
-#include <sys/syslimits.h>
-#endif
-#if defined(__APPLE__) || defined(__OpenBSD__) || defined(__sun__)
-#include <sys/stat.h>
-#endif
#include <unistd.h>
-#include <errno.h>
-#include <libintl.h>
+#include <sys/stat.h>
/* libalpm */
#include "remove.h"
@@ -47,16 +40,12 @@
#include "trans.h"
#include "util.h"
#include "error.h"
-#include "versioncmp.h"
-#include "md5.h"
-#include "sha1.h"
#include "log.h"
#include "backup.h"
#include "package.h"
#include "db.h"
#include "cache.h"
#include "deps.h"
-#include "provide.h"
#include "handle.h"
#include "alpm.h"
@@ -76,7 +65,7 @@ int _alpm_remove_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
if((info = _alpm_db_scan(db, name)) == NULL) {
/* Unimportant - just ignore it if we can't find it */
- _alpm_log(PM_LOG_DEBUG, _("could not find %s in database"), name);
+ _alpm_log(PM_LOG_DEBUG, "could not find %s in database\n", name);
RET_ERR(PM_ERR_PKG_NOT_FOUND, -1);
}
@@ -90,7 +79,7 @@ int _alpm_remove_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
}
}
- _alpm_log(PM_LOG_DEBUG, _("adding %s in the targets list"), info->name);
+ _alpm_log(PM_LOG_DEBUG, "adding %s in the targets list\n", info->name);
trans->packages = alpm_list_add(trans->packages, info);
return(0);
@@ -105,28 +94,36 @@ int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data)
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
- if(!(trans->flags & (PM_TRANS_FLAG_NODEPS)) && (trans->type != PM_TRANS_TYPE_UPGRADE)) {
- EVENT(trans, PM_TRANS_EVT_CHECKDEPS_START, NULL, NULL);
+ /* skip all checks if we are doing this removal as part of an upgrade */
+ if(trans->type == PM_TRANS_TYPE_REMOVEUPGRADE) {
+ return(0);
+ }
+
+ EVENT(trans, PM_TRANS_EVT_CHECKDEPS_START, NULL, NULL);
- _alpm_log(PM_LOG_DEBUG, _("looking for unsatisfied dependencies"));
- lp = _alpm_checkdeps(trans, db, trans->type, trans->packages);
+ if(!(trans->flags & PM_TRANS_FLAG_NODEPS)) {
+ _alpm_log(PM_LOG_DEBUG, "looking for unsatisfied dependencies\n");
+ lp = alpm_checkdeps(db, 1, trans->packages, NULL);
if(lp != NULL) {
if(trans->flags & PM_TRANS_FLAG_CASCADE) {
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_scan(db, miss->depend.name);
+ pmpkg_t *info = _alpm_db_scan(db, miss->target);
if(info) {
- _alpm_log(PM_LOG_DEBUG, _("pulling %s in the targets list"), alpm_pkg_get_name(info));
- trans->packages = alpm_list_add(trans->packages, info);
+ 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);
+ }
} else {
- _alpm_log(PM_LOG_ERROR, _("could not find %s in database -- skipping"),
- miss->depend.name);
+ _alpm_log(PM_LOG_ERROR, _("could not find %s in database -- skipping\n"),
+ miss->target);
}
}
FREELIST(lp);
- lp = _alpm_checkdeps(trans, db, trans->type, trans->packages);
+ lp = alpm_checkdeps(db, 1, trans->packages, NULL);
}
} else {
if(data) {
@@ -137,22 +134,22 @@ int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data)
RET_ERR(PM_ERR_UNSATISFIED_DEPS, -1);
}
}
+ }
- if(trans->flags & PM_TRANS_FLAG_RECURSE) {
- _alpm_log(PM_LOG_DEBUG, _("finding removable dependencies"));
- trans->packages = _alpm_removedeps(db, trans->packages);
- }
-
- /* re-order w.r.t. dependencies */
- _alpm_log(PM_LOG_DEBUG, _("sorting by dependencies"));
- lp = _alpm_sortbydeps(trans->packages, PM_TRANS_TYPE_REMOVE);
- /* free the old alltargs */
- FREELISTPTR(trans->packages);
- trans->packages = lp;
+ /* re-order w.r.t. dependencies */
+ _alpm_log(PM_LOG_DEBUG, "sorting by dependencies\n");
+ lp = _alpm_sortbydeps(trans->packages, PM_TRANS_TYPE_REMOVE);
+ /* free the old alltargs */
+ alpm_list_free(trans->packages);
+ trans->packages = lp;
- EVENT(trans, PM_TRANS_EVT_CHECKDEPS_DONE, NULL, NULL);
+ if(trans->flags & PM_TRANS_FLAG_RECURSE) {
+ _alpm_log(PM_LOG_DEBUG, "finding removable dependencies\n");
+ _alpm_recursedeps(db, trans->packages, 0);
}
+ EVENT(trans, PM_TRANS_EVT_CHECKDEPS_DONE, NULL, NULL);
+
return(0);
}
@@ -169,10 +166,10 @@ static int can_remove_file(pmtrans_t *trans, const char *path)
/* 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) {
- if(errno != EACCES && access(file, F_OK) == 0) {
+ if(errno != EACCES && errno != ETXTBSY && access(file, F_OK) == 0) {
/* only return failure if the file ACTUALLY exists and we can't write to
* it - ignore "chmod -w" simple permission failures */
- _alpm_log(PM_LOG_ERROR, _("cannot remove file '%s': %s"),
+ _alpm_log(PM_LOG_ERROR, _("cannot remove file '%s': %s\n"),
file, strerror(errno));
return(0);
}
@@ -182,97 +179,86 @@ static int can_remove_file(pmtrans_t *trans, const char *path)
}
/* Helper function for iterating through a package's file and deleting them
- * Used by _alpm_remove_commit
- *
- * TODO the parameters are a bit out of control here. This function doesn't
- * need to report PROGRESS, do it in the parent function.
-*/
-static void unlink_file(pmpkg_t *info, alpm_list_t *lp, alpm_list_t *targ,
- pmtrans_t *trans, int filenum, int *position)
+ * Used by _alpm_remove_commit. */
+static void unlink_file(pmpkg_t *info, alpm_list_t *lp, pmtrans_t *trans)
{
struct stat buf;
int needbackup = 0;
- double percent = 0.0;
char file[PATH_MAX+1];
ALPM_LOG_FUNC;
- if(*position != 0) {
- percent = (double)*position / filenum;
- }
-
char *hash = _alpm_needbackup(lp->data, alpm_pkg_get_backup(info));
if(hash) {
needbackup = 1;
FREE(hash);
}
-
- if(trans->type == PM_TRANS_TYPE_UPGRADE) {
+
+ snprintf(file, PATH_MAX, "%s%s", handle->root, (char *)lp->data);
+
+ if(trans->type == PM_TRANS_TYPE_REMOVEUPGRADE) {
/* check noupgrade */
if(alpm_list_find_str(handle->noupgrade, lp->data)) {
- _alpm_log(PM_LOG_DEBUG, _("Skipping removal of '%s' due to NoUpgrade"), file);
+ _alpm_log(PM_LOG_DEBUG, "Skipping removal of '%s' due to NoUpgrade\n",
+ file);
return;
}
}
- snprintf(file, PATH_MAX, "%s%s", handle->root, (char *)lp->data);
- if(lstat(file, &buf)) {
- _alpm_log(PM_LOG_DEBUG, _("file %s does not exist"), file);
+ if(_alpm_lstat(file, &buf)) {
+ _alpm_log(PM_LOG_DEBUG, "file %s does not exist\n", file);
return;
}
-
+
if(S_ISDIR(buf.st_mode)) {
if(rmdir(file)) {
- /* this is okay, other pakcages are probably using it (like /usr) */
- _alpm_log(PM_LOG_DEBUG, _("keeping directory %s"), file);
+ /* this is okay, other packages are probably using it (like /usr) */
+ _alpm_log(PM_LOG_DEBUG, "keeping directory %s\n", file);
} else {
- _alpm_log(PM_LOG_DEBUG, _("removing directory %s"), file);
+ _alpm_log(PM_LOG_DEBUG, "removing directory %s\n", file);
}
} else {
/* check the remove skip list before removing the file.
- * see the big comment block in db_find_conflicts() for an
+ * see the big comment block in db_find_fileconflicts() for an
* explanation. */
if(alpm_list_find_str(trans->skip_remove, file)) {
- _alpm_log(PM_LOG_DEBUG, _("%s is in trans->skip_remove, skipping removal"), file);
+ _alpm_log(PM_LOG_DEBUG, "%s is in trans->skip_remove, skipping removal\n",
+ file);
return;
} else if(needbackup) {
/* if the file is flagged, back it up to .pacsave */
- if(!(trans->type == PM_TRANS_TYPE_UPGRADE)) {
- /* if it was an upgrade, the file would be left alone because
- * pacman_add() would handle it */
- 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"), file, newpath);
- return;
- } else {
- _alpm_log(PM_LOG_DEBUG, _("transaction is set to NOSAVE, not backing up '%s'"), file);
- }
+ 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);
}
}
- _alpm_log(PM_LOG_DEBUG, _("unlinking %s"), file);
- int list_count = alpm_list_count(trans->packages); /* this way we don't have to call alpm_list_count twice during PROGRESS */
-
- PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, info->name, (double)(percent * 100), list_count, (list_count - alpm_list_count(targ) + 1));
- ++(*position);
+ _alpm_log(PM_LOG_DEBUG, "unlinking %s\n", file);
if(unlink(file) == -1) {
- _alpm_log(PM_LOG_ERROR, _("cannot remove file %s: %s"), lp->data, strerror(errno));
+ _alpm_log(PM_LOG_ERROR, _("cannot remove file '%s': %s\n"),
+ (char *)lp->data, strerror(errno));
}
}
}
int _alpm_remove_commit(pmtrans_t *trans, pmdb_t *db)
{
- pmpkg_t *info, *infodup;
+ pmpkg_t *info;
alpm_list_t *targ, *lp;
+ int pkg_count;
ALPM_LOG_FUNC;
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
+ pkg_count = alpm_list_count(trans->packages);
+
for(targ = trans->packages; targ; targ = targ->next) {
int position = 0;
char scriptlet[PATH_MAX];
@@ -281,7 +267,7 @@ int _alpm_remove_commit(pmtrans_t *trans, pmdb_t *db)
const char *pkgname = NULL;
if(handle->trans->state == STATE_INTERRUPTED) {
- break;
+ return(0);
}
/* get the name now so we can use it after package is removed */
@@ -289,9 +275,9 @@ int _alpm_remove_commit(pmtrans_t *trans, pmdb_t *db)
snprintf(scriptlet, PATH_MAX, "%s%s-%s/install", db->path,
pkgname, alpm_pkg_get_version(info));
- if(trans->type != PM_TRANS_TYPE_UPGRADE) {
+ if(trans->type != PM_TRANS_TYPE_REMOVEUPGRADE) {
EVENT(trans, PM_TRANS_EVT_REMOVE_START, info, NULL);
- _alpm_log(PM_LOG_DEBUG, _("removing package %s-%s"),
+ _alpm_log(PM_LOG_DEBUG, "removing package %s-%s\n",
pkgname, alpm_pkg_get_version(info));
/* run the pre-remove scriptlet if it exists */
@@ -306,22 +292,37 @@ int _alpm_remove_commit(pmtrans_t *trans, pmdb_t *db)
if(!(trans->flags & PM_TRANS_FLAG_DBONLY)) {
for(lp = files; lp; lp = lp->next) {
if(!can_remove_file(trans, lp->data)) {
- _alpm_log(PM_LOG_DEBUG, _("not removing package '%s', can't remove all files"),
+ _alpm_log(PM_LOG_DEBUG, "not removing package '%s', can't remove all files\n",
pkgname);
RET_ERR(PM_ERR_PKG_CANT_REMOVE, -1);
}
}
int filenum = alpm_list_count(files);
- _alpm_log(PM_LOG_DEBUG, _("removing %d files"), filenum);
+ double percent = 0.0;
+ alpm_list_t *newfiles;
+ _alpm_log(PM_LOG_DEBUG, "removing %d files\n", filenum);
/* iterate through the list backwards, unlinking files */
- for(lp = alpm_list_last(files); lp; lp = lp->prev) {
- unlink_file(info, lp, targ, trans, filenum, &position);
+ newfiles = alpm_list_reverse(files);
+ for(lp = newfiles; lp; lp = alpm_list_next(lp)) {
+ 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++;
}
+ alpm_list_free(newfiles);
}
- if(trans->type != PM_TRANS_TYPE_UPGRADE) {
+ /* set progress to 100% after we finish unlinking files */
+ PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, pkgname, 100,
+ pkg_count, (pkg_count - alpm_list_count(targ) + 1));
+
+ if(trans->type != PM_TRANS_TYPE_REMOVEUPGRADE) {
/* 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",
@@ -329,38 +330,28 @@ int _alpm_remove_commit(pmtrans_t *trans, pmdb_t *db)
}
}
- /* duplicate the package so we can remove the requiredby fields later */
- infodup = _alpm_pkg_dup(info);
-
/* remove the package from the database */
- _alpm_log(PM_LOG_DEBUG, _("updating database"));
- _alpm_log(PM_LOG_DEBUG, _("removing database entry '%s'"), pkgname);
+ _alpm_log(PM_LOG_DEBUG, "updating database\n");
+ _alpm_log(PM_LOG_DEBUG, "removing database entry '%s'\n", pkgname);
if(_alpm_db_remove(db, info) == -1) {
- _alpm_log(PM_LOG_ERROR, _("could not remove database entry %s-%s"),
+ _alpm_log(PM_LOG_ERROR, _("could not remove database entry %s-%s\n"),
pkgname, alpm_pkg_get_version(info));
}
/* remove the package from the cache */
if(_alpm_db_remove_pkgfromcache(db, info) == -1) {
- _alpm_log(PM_LOG_ERROR, _("could not remove entry '%s' from cache"),
+ _alpm_log(PM_LOG_ERROR, _("could not remove entry '%s' from cache\n"),
pkgname);
}
-
- /* update dependency packages' REQUIREDBY fields */
- _alpm_trans_update_depends(trans, infodup);
- _alpm_pkg_free(infodup);
-
- PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, pkgname, 100,
- alpm_list_count(trans->packages),
- (alpm_list_count(trans->packages) - alpm_list_count(targ) +1));
- if(trans->type != PM_TRANS_TYPE_UPGRADE) {
+ /* call a done event if this isn't an upgrade */
+ if(trans->type != PM_TRANS_TYPE_REMOVEUPGRADE) {
EVENT(trans, PM_TRANS_EVT_REMOVE_DONE, info, NULL);
}
}
/* run ldconfig if it exists */
- if((trans->type != PM_TRANS_TYPE_UPGRADE) && (handle->trans->state != STATE_INTERRUPTED)) {
- _alpm_log(PM_LOG_DEBUG, _("running \"ldconfig -r %s\""), handle->root);
+ if(trans->type != PM_TRANS_TYPE_REMOVEUPGRADE) {
+ _alpm_log(PM_LOG_DEBUG, "running \"ldconfig -r %s\"\n", handle->root);
_alpm_ldconfig(handle->root);
}