Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
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.c84
1 files changed, 39 insertions, 45 deletions
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index 153c0426..823795be 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -1,7 +1,7 @@
/*
* remove.c
*
- * Copyright (c) 2006-2010 Pacman Development Team <pacman-dev@archlinux.org>
+ * Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>
* 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>
@@ -42,51 +42,33 @@
#include "backup.h"
#include "package.h"
#include "db.h"
-#include "cache.h"
#include "deps.h"
#include "handle.h"
#include "alpm.h"
-int SYMEXPORT alpm_remove_target(char *target)
+int SYMEXPORT alpm_remove_pkg(pmpkg_t *pkg)
{
- pmpkg_t *info;
pmtrans_t *trans;
- pmdb_t *db_local;
- alpm_list_t *p;
+ const char *pkgname;
ALPM_LOG_FUNC;
/* Sanity checks */
- ASSERT(target != NULL && strlen(target) != 0, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+ ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
trans = handle->trans;
- db_local = handle->db_local;
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
- ASSERT(trans->state == STATE_INITIALIZED, RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1));
- ASSERT(db_local != NULL, RET_ERR(PM_ERR_DB_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, target)) {
+ if(_alpm_pkg_find(trans->remove, pkgname)) {
RET_ERR(PM_ERR_TRANS_DUP_TARGET, -1);
}
- if((info = _alpm_db_get_pkgfromcache(db_local, target)) != NULL) {
- _alpm_log(PM_LOG_DEBUG, "adding %s in the target list\n", info->name);
- trans->remove = alpm_list_add(trans->remove, _alpm_pkg_dup(info));
- return(0);
- }
-
- _alpm_log(PM_LOG_DEBUG, "could not find %s in database\n", target);
- pmgrp_t *grp = alpm_db_readgrp(db_local, target);
- if(grp == NULL) {
- RET_ERR(PM_ERR_PKG_NOT_FOUND, -1);
- }
- for(p = alpm_grp_get_pkgs(grp); p; p = alpm_list_next(p)) {
- pmpkg_t *pkg = alpm_list_getdata(p);
- _alpm_log(PM_LOG_DEBUG, "adding %s in the target list\n", pkg->name);
- trans->remove = alpm_list_add(trans->remove, _alpm_pkg_dup(pkg));
- }
-
+ _alpm_log(PM_LOG_DEBUG, "adding %s in the target list\n", pkgname);
+ trans->remove = alpm_list_add(trans->remove, _alpm_pkg_dup(pkg));
return(0);
}
@@ -113,7 +95,7 @@ static void remove_prepare_cascade(pmtrans_t *trans, pmdb_t *db,
}
alpm_list_free_inner(lp, (alpm_list_fn_free)_alpm_depmiss_free);
alpm_list_free(lp);
- lp = alpm_checkdeps(_alpm_db_get_pkgcache(db), 1, trans->remove, NULL);
+ lp = alpm_checkdeps(_alpm_db_get_pkgcache_list(db), 1, trans->remove, NULL);
}
}
@@ -143,7 +125,7 @@ static void remove_prepare_keep_needed(pmtrans_t *trans, pmdb_t *db,
}
alpm_list_free_inner(lp, (alpm_list_fn_free)_alpm_depmiss_free);
alpm_list_free(lp);
- lp = alpm_checkdeps(_alpm_db_get_pkgcache(db), 1, trans->remove, NULL);
+ lp = alpm_checkdeps(_alpm_db_get_pkgcache_list(db), 1, trans->remove, NULL);
}
}
@@ -165,7 +147,7 @@ int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data)
EVENT(trans, PM_TRANS_EVT_CHECKDEPS_START, NULL, NULL);
_alpm_log(PM_LOG_DEBUG, "looking for unsatisfied dependencies\n");
- lp = alpm_checkdeps(_alpm_db_get_pkgcache(db), 1, trans->remove, NULL);
+ lp = alpm_checkdeps(_alpm_db_get_pkgcache_list(db), 1, trans->remove, NULL);
if(lp != NULL) {
if(trans->flags & PM_TRANS_FLAG_CASCADE) {
@@ -299,10 +281,12 @@ static void unlink_file(pmpkg_t *info, char *filename, alpm_list_t *skip_remove,
}
}
-int _alpm_upgraderemove_package(pmpkg_t *oldpkg, pmpkg_t *newpkg, pmtrans_t *trans)
+int _alpm_upgraderemove_package(pmpkg_t *oldpkg, pmpkg_t *newpkg,
+ pmtrans_t *trans)
{
alpm_list_t *skip_remove, *b;
alpm_list_t *newfiles, *lp;
+ size_t filenum;
alpm_list_t *files = alpm_pkg_get_files(oldpkg);
const char *pkgname = alpm_pkg_get_name(oldpkg);
@@ -311,9 +295,14 @@ int _alpm_upgraderemove_package(pmpkg_t *oldpkg, pmpkg_t *newpkg, pmtrans_t *tra
_alpm_log(PM_LOG_DEBUG, "removing old package first (%s-%s)\n",
oldpkg->name, oldpkg->version);
+ if(trans->flags & PM_TRANS_FLAG_DBONLY) {
+ goto db;
+ }
+
/* copy the remove skiplist over */
- skip_remove =
- alpm_list_join(alpm_list_strdup(trans->skip_remove),alpm_list_strdup(handle->noupgrade));
+ skip_remove = alpm_list_join(
+ alpm_list_strdup(trans->skip_remove),
+ alpm_list_strdup(handle->noupgrade));
/* Add files in the NEW backup array to the skip_remove array
* so this removal operation doesn't kill them */
/* old package backup list */
@@ -337,6 +326,9 @@ int _alpm_upgraderemove_package(pmpkg_t *oldpkg, pmpkg_t *newpkg, pmtrans_t *tra
}
}
+ filenum = alpm_list_count(files);
+ _alpm_log(PM_LOG_DEBUG, "removing %ld files\n", (unsigned long)filenum);
+
/* iterate through the list backwards, unlinking files */
newfiles = alpm_list_reverse(files);
for(lp = newfiles; lp; lp = alpm_list_next(lp)) {
@@ -345,10 +337,11 @@ int _alpm_upgraderemove_package(pmpkg_t *oldpkg, pmpkg_t *newpkg, pmtrans_t *tra
alpm_list_free(newfiles);
FREELIST(skip_remove);
+db:
/* 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);
- if(_alpm_db_remove(handle->db_local, oldpkg) == -1) {
+ if(_alpm_local_db_remove(handle->db_local, oldpkg) == -1) {
_alpm_log(PM_LOG_ERROR, _("could not remove database entry %s-%s\n"),
pkgname, alpm_pkg_get_version(oldpkg));
}
@@ -365,7 +358,7 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
{
pmpkg_t *info;
alpm_list_t *targ, *lp;
- int pkg_count;
+ size_t pkg_count;
ALPM_LOG_FUNC;
@@ -379,7 +372,7 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
char scriptlet[PATH_MAX];
info = (pmpkg_t*)targ->data;
const char *pkgname = NULL;
- int targcount = alpm_list_count(targ);
+ size_t targcount = alpm_list_count(targ);
if(handle->trans->state == STATE_INTERRUPTED) {
return(0);
@@ -402,6 +395,9 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
if(!(trans->flags & PM_TRANS_FLAG_DBONLY)) {
alpm_list_t *files = alpm_pkg_get_files(info);
+ alpm_list_t *newfiles;
+ size_t filenum;
+
for(lp = files; lp; lp = lp->next) {
if(!can_remove_file(lp->data, NULL)) {
_alpm_log(PM_LOG_DEBUG, "not removing package '%s', can't remove all files\n",
@@ -410,9 +406,8 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
}
}
- int filenum = alpm_list_count(files);
- alpm_list_t *newfiles;
- _alpm_log(PM_LOG_DEBUG, "removing %d files\n", filenum);
+ filenum = alpm_list_count(files);
+ _alpm_log(PM_LOG_DEBUG, "removing %ld files\n", (unsigned long)filenum);
/* init progress bar */
PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, info->name, 0,
@@ -421,14 +416,13 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
/* iterate through the list backwards, unlinking files */
newfiles = alpm_list_reverse(files);
for(lp = newfiles; lp; lp = alpm_list_next(lp)) {
- double percent;
+ int percent;
unlink_file(info, lp->data, NULL, trans->flags & PM_TRANS_FLAG_NOSAVE);
/* update progress bar after each file */
- percent = (double)position / (double)filenum;
+ percent = (position * 100) / filenum;
PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, info->name,
- (double)(percent * 100), pkg_count,
- (pkg_count - targcount + 1));
+ percent, pkg_count, (pkg_count - targcount + 1));
position++;
}
alpm_list_free(newfiles);
@@ -447,7 +441,7 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
/* 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);
- if(_alpm_db_remove(db, info) == -1) {
+ if(_alpm_local_db_remove(db, info) == -1) {
_alpm_log(PM_LOG_ERROR, _("could not remove database entry %s-%s\n"),
pkgname, alpm_pkg_get_version(info));
}