2005-03-14 20:51:43 -05:00
|
|
|
/*
|
|
|
|
* remove.c
|
|
|
|
*
|
|
|
|
* Copyright (c) 2002-2005 by Judd Vinet <jvinet@zeroflux.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
|
|
|
|
* (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
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
|
|
* USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <zlib.h>
|
|
|
|
#include <libtar.h>
|
|
|
|
/* pacman */
|
|
|
|
#include "util.h"
|
|
|
|
#include "error.h"
|
|
|
|
#include "rpmvercmp.h"
|
|
|
|
#include "md5.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "backup.h"
|
|
|
|
#include "package.h"
|
|
|
|
#include "db.h"
|
|
|
|
#include "cache.h"
|
|
|
|
#include "deps.h"
|
|
|
|
#include "provide.h"
|
|
|
|
#include "remove.h"
|
|
|
|
#include "handle.h"
|
|
|
|
#include "alpm.h"
|
|
|
|
|
|
|
|
extern pmhandle_t *handle;
|
|
|
|
|
|
|
|
int remove_loadtarget(pmdb_t *db, pmtrans_t *trans, char *name)
|
|
|
|
{
|
|
|
|
pmpkg_t *info;
|
|
|
|
|
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
|
|
|
|
2005-04-06 14:25:33 -04:00
|
|
|
/* ORE
|
|
|
|
we should better find the package in the cache, and then perform a
|
|
|
|
db_read(INFRQ_FILES) to add files information to it. */
|
2005-03-14 20:51:43 -05:00
|
|
|
if((info = db_scan(db, name, INFRQ_ALL)) == NULL) {
|
|
|
|
_alpm_log(PM_LOG_ERROR, "could not find %s in database", 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-06 17:00:57 -04:00
|
|
|
trans->packages = pm_list_add(trans->packages, info);
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int remove_prepare(pmdb_t *db, pmtrans_t *trans, PMList **data)
|
|
|
|
{
|
|
|
|
pmpkg_t *info;
|
2005-03-28 02:45:24 -05:00
|
|
|
PMList *lp;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
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(data != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
if(!(trans->flags & (PM_TRANS_FLAG_NODEPS)) && (trans->type != PM_TRANS_TYPE_UPGRADE)) {
|
2005-04-02 15:37:50 -05:00
|
|
|
TRANS_CB(trans, PM_TRANS_EVT_CHECKDEPS_START, NULL, NULL);
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2005-04-06 14:25:33 -04:00
|
|
|
_alpm_log(PM_LOG_FLOW1, "looking for unsatisfied dependencies");
|
2005-04-06 17:00:57 -04:00
|
|
|
if((lp = checkdeps(db, trans->type, trans->packages)) != NULL) {
|
2005-03-14 20:51:43 -05:00
|
|
|
if(trans->flags & PM_TRANS_FLAG_CASCADE) {
|
|
|
|
while(lp) {
|
|
|
|
PMList *j;
|
|
|
|
for(j = lp; j; j = j->next) {
|
|
|
|
pmdepmissing_t* miss = (pmdepmissing_t*)j->data;
|
|
|
|
info = db_scan(db, miss->depend.name, INFRQ_ALL);
|
2005-04-06 17:00:57 -04:00
|
|
|
if(!pkg_isin(info, trans->packages)) {
|
|
|
|
trans->packages = pm_list_add(trans->packages, info);
|
2005-04-08 12:29:55 -04:00
|
|
|
} else {
|
|
|
|
FREEPKG(info);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
FREELIST(lp);
|
2005-04-06 17:00:57 -04:00
|
|
|
lp = checkdeps(db, trans->type, trans->packages);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*data = lp;
|
2005-03-16 17:10:05 -05:00
|
|
|
RET_ERR(PM_ERR_UNSATISFIED_DEPS, -1);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(trans->flags & PM_TRANS_FLAG_RECURSE) {
|
2005-03-26 13:03:36 -05:00
|
|
|
_alpm_log(PM_LOG_FLOW1, "finding removable dependencies");
|
2005-04-06 17:00:57 -04:00
|
|
|
trans->packages = removedeps(db, trans->packages);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2005-03-25 17:09:14 -05:00
|
|
|
/* re-order w.r.t. dependencies */
|
2005-03-26 13:03:36 -05:00
|
|
|
_alpm_log(PM_LOG_FLOW1, "sorting by dependencies");
|
2005-04-06 17:00:57 -04:00
|
|
|
lp = sortbydeps(trans->packages, PM_TRANS_TYPE_REMOVE);
|
2005-03-25 17:09:14 -05:00
|
|
|
/* free the old alltargs */
|
2005-04-06 17:00:57 -04:00
|
|
|
FREELISTPTR(trans->packages);
|
|
|
|
trans->packages = lp;
|
2005-03-25 17:09:14 -05:00
|
|
|
|
2005-04-02 15:37:50 -05:00
|
|
|
TRANS_CB(trans, PM_TRANS_EVT_CHECKDEPS_DONE, NULL, NULL);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int remove_commit(pmdb_t *db, pmtrans_t *trans)
|
|
|
|
{
|
|
|
|
pmpkg_t *info;
|
|
|
|
struct stat buf;
|
|
|
|
PMList *targ, *lp;
|
|
|
|
char line[PATH_MAX+1];
|
|
|
|
|
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
|
|
|
|
2005-04-06 17:00:57 -04:00
|
|
|
for(targ = trans->packages; targ; targ = targ->next) {
|
2005-03-14 20:51:43 -05:00
|
|
|
char pm_install[PATH_MAX];
|
|
|
|
info = (pmpkg_t*)targ->data;
|
|
|
|
|
|
|
|
if(trans->type != PM_TRANS_TYPE_UPGRADE) {
|
2005-03-15 13:41:02 -05:00
|
|
|
TRANS_CB(trans, PM_TRANS_EVT_REMOVE_START, info, NULL);
|
2005-03-26 13:03:36 -05:00
|
|
|
_alpm_log(PM_LOG_FLOW1, "removing package %s-%s", info->name, info->version);
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
/* run the pre-remove scriptlet if it exists */
|
2005-03-26 08:29:47 -05:00
|
|
|
if(info->scriptlet) {
|
2005-03-28 15:01:11 -05:00
|
|
|
snprintf(pm_install, PATH_MAX, "%s/%s-%s/install", db->path, info->name, info->version);
|
2005-03-26 08:29:47 -05:00
|
|
|
_alpm_runscriptlet(handle->root, pm_install, "pre_remove", info->version, NULL);
|
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!(trans->flags & PM_TRANS_FLAG_DBONLY)) {
|
2005-03-26 13:03:36 -05:00
|
|
|
_alpm_log(PM_LOG_FLOW1, "removing files");
|
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
/* iterate through the list backwards, unlinking files */
|
|
|
|
for(lp = pm_list_last(info->files); lp; lp = lp->prev) {
|
|
|
|
int nb = 0;
|
2005-03-26 13:03:36 -05:00
|
|
|
char *file = lp->data;
|
2005-03-14 20:51:43 -05:00
|
|
|
if(_alpm_needbackup(lp->data, info->backup)) {
|
|
|
|
nb = 1;
|
|
|
|
}
|
|
|
|
if(!nb && trans->type == PM_TRANS_TYPE_UPGRADE) {
|
|
|
|
/* check noupgrade */
|
|
|
|
if(pm_list_is_strin(lp->data, handle->noupgrade)) {
|
|
|
|
nb = 1;
|
|
|
|
}
|
|
|
|
}
|
2005-03-26 13:03:36 -05:00
|
|
|
snprintf(line, PATH_MAX, "%s%s", handle->root, file);
|
2005-03-14 20:51:43 -05:00
|
|
|
if(lstat(line, &buf)) {
|
2005-03-26 13:03:36 -05:00
|
|
|
_alpm_log(PM_LOG_ERROR, "file %s does not exist", file);
|
2005-03-14 20:51:43 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(S_ISDIR(buf.st_mode)) {
|
2005-03-26 13:03:36 -05:00
|
|
|
_alpm_log(PM_LOG_FLOW2, "removing directory %s", file);
|
2005-03-14 20:51:43 -05:00
|
|
|
if(rmdir(line)) {
|
|
|
|
/* this is okay, other packages are probably using it. */
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* if the file is flagged, back it up to .pacsave */
|
|
|
|
if(nb) {
|
|
|
|
if(trans->type == PM_TRANS_TYPE_UPGRADE) {
|
|
|
|
/* we're upgrading so just leave the file as is. pacman_add() will handle it */
|
|
|
|
} else {
|
|
|
|
if(!(trans->flags & PM_TRANS_FLAG_NOSAVE)) {
|
2005-03-26 16:20:03 -05:00
|
|
|
char newpath[PATH_MAX];
|
|
|
|
snprintf(newpath, PATH_MAX, "%s.pacsave", line);
|
2005-03-14 20:51:43 -05:00
|
|
|
rename(line, newpath);
|
2005-03-26 13:03:36 -05:00
|
|
|
_alpm_log(PM_LOG_WARNING, "%s saved as %s", file, newpath);
|
2005-03-14 20:51:43 -05:00
|
|
|
alpm_logaction("%s saved as %s", line, newpath);
|
|
|
|
} else {
|
2005-03-26 13:03:36 -05:00
|
|
|
_alpm_log(PM_LOG_FLOW2, "unlinking %s", file);
|
2005-03-14 20:51:43 -05:00
|
|
|
if(unlink(line)) {
|
2005-03-26 13:03:36 -05:00
|
|
|
_alpm_log(PM_LOG_ERROR, "cannot remove file %s", file);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2005-03-26 13:03:36 -05:00
|
|
|
_alpm_log(PM_LOG_FLOW2, "unlinking %s", file);
|
2005-03-14 20:51:43 -05:00
|
|
|
if(unlink(line)) {
|
2005-03-26 13:03:36 -05:00
|
|
|
_alpm_log(PM_LOG_ERROR, "cannot remove file %s", file);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(trans->type != PM_TRANS_TYPE_UPGRADE) {
|
|
|
|
/* run the post-remove script if it exists */
|
2005-03-26 13:03:36 -05:00
|
|
|
if(info->scriptlet) {
|
|
|
|
char pm_install[PATH_MAX];
|
|
|
|
snprintf(pm_install, PATH_MAX, "%s/%s-%s/install", db->path, info->name, info->version);
|
|
|
|
_alpm_runscriptlet(handle->root, pm_install, "post_remove", info->version, NULL);
|
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* remove the package from the database */
|
2005-04-03 04:10:54 -04:00
|
|
|
_alpm_log(PM_LOG_FLOW1, "updating database");
|
2005-03-14 20:51:43 -05:00
|
|
|
if(db_remove(db, info) == -1) {
|
2005-03-26 13:03:36 -05:00
|
|
|
_alpm_log(PM_LOG_ERROR, "failed to remove database entry %s/%s-%s", db->treename, info->name, info->version);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* update dependency packages' REQUIREDBY fields */
|
2005-03-26 13:03:36 -05:00
|
|
|
_alpm_log(PM_LOG_FLOW2, "updating dependency packages 'requiredby' fields");
|
2005-03-14 20:51:43 -05:00
|
|
|
for(lp = info->depends; lp; lp = lp->next) {
|
2005-03-26 08:29:47 -05:00
|
|
|
PMList *j;
|
2005-03-14 20:51:43 -05:00
|
|
|
pmpkg_t *depinfo = NULL;
|
|
|
|
pmdepend_t depend;
|
|
|
|
|
2005-03-26 16:20:03 -05:00
|
|
|
if(splitdep((char*)lp->data, &depend)) {
|
|
|
|
continue;
|
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
depinfo = db_scan(db, depend.name, INFRQ_DESC|INFRQ_DEPENDS);
|
|
|
|
if(depinfo == NULL) {
|
|
|
|
/* look for a provides package */
|
|
|
|
PMList *provides = _alpm_db_whatprovides(db, depend.name);
|
|
|
|
if(provides) {
|
|
|
|
/* TODO: should check _all_ packages listed in provides, not just
|
|
|
|
* the first one.
|
|
|
|
*/
|
|
|
|
/* use the first one */
|
2005-03-27 02:41:51 -05:00
|
|
|
depinfo = db_scan(db, ((pmpkg_t *)provides->data)->name, INFRQ_DESC|INFRQ_DEPENDS);
|
2005-03-28 02:45:24 -05:00
|
|
|
FREELISTPTR(provides);
|
2005-03-14 20:51:43 -05:00
|
|
|
if(depinfo == NULL) {
|
|
|
|
/* wtf */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* splice out this entry from requiredby */
|
|
|
|
for(j = depinfo->requiredby; j; j = j->next) {
|
|
|
|
if(!strcmp((char*)j->data, info->name)) {
|
2005-03-26 08:29:47 -05:00
|
|
|
depinfo->requiredby = _alpm_list_remove(depinfo->requiredby, j);
|
2005-03-14 20:51:43 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-03-26 13:03:36 -05:00
|
|
|
_alpm_log(PM_LOG_DEBUG, "updating 'requiredby' field for package %s", depinfo->name);
|
|
|
|
if(db_write(db, depinfo, INFRQ_DEPENDS)) {
|
|
|
|
_alpm_log(PM_LOG_ERROR, "could not update 'requiredby' database entry %s/%s-%s", db->treename, depinfo->name, depinfo->version);
|
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
FREEPKG(depinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(trans->type != PM_TRANS_TYPE_UPGRADE) {
|
2005-03-15 13:41:02 -05:00
|
|
|
TRANS_CB(trans, PM_TRANS_EVT_REMOVE_DONE, info, NULL);
|
2005-03-14 20:51:43 -05:00
|
|
|
alpm_logaction("removed %s (%s)", info->name, info->version);
|
|
|
|
}
|
2005-04-02 15:37:50 -05:00
|
|
|
|
|
|
|
/* cache needs to be rebuilt */
|
|
|
|
db_free_pkgcache(db);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* run ldconfig if it exists */
|
2005-03-26 13:03:36 -05:00
|
|
|
if(trans->type != PM_TRANS_TYPE_UPGRADE) {
|
|
|
|
_alpm_log(PM_LOG_FLOW1, "running \"ldconfig -r %s\"", handle->root);
|
|
|
|
_alpm_ldconfig(handle->root);
|
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim: set ts=2 sw=2 noet: */
|