[pacman-dev] [PATCH 09/10] Remove global handle from remove.c
Dan McGee
dan at archlinux.org
Fri Jun 3 14:21:47 EDT 2011
Signed-off-by: Dan McGee <dan at archlinux.org>
---
lib/libalpm/add.c | 2 +-
lib/libalpm/remove.c | 51 +++++++++++++++++++++----------------------------
lib/libalpm/remove.h | 7 +++--
lib/libalpm/sync.c | 2 +-
lib/libalpm/trans.c | 4 +-
5 files changed, 30 insertions(+), 36 deletions(-)
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index a95f4bc..500fbde 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -527,7 +527,7 @@ static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
if(oldpkg) {
/* set up fake remove transaction */
- if(_alpm_upgraderemove_package(oldpkg, newpkg, trans) == -1) {
+ if(_alpm_upgraderemove_package(handle, oldpkg, newpkg) == -1) {
pm_errno = PM_ERR_TRANS_ABORT;
ret = -1;
goto cleanup;
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index 2adcd26..27305ae 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -44,9 +44,6 @@
#include "deps.h"
#include "handle.h"
-/* global handle variable */
-extern pmhandle_t *handle;
-
int SYMEXPORT alpm_remove_pkg(pmpkg_t *pkg)
{
pmtrans_t *trans;
@@ -54,8 +51,7 @@ int SYMEXPORT alpm_remove_pkg(pmpkg_t *pkg)
/* 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;
+ trans = pkg->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));
@@ -129,16 +125,14 @@ static void remove_prepare_keep_needed(pmtrans_t *trans, pmdb_t *db,
* 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 handle the context handle
* @param data a pointer to an alpm_list_t* to fill
*/
-int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data)
+int _alpm_remove_prepare(pmhandle_t *handle, alpm_list_t **data)
{
alpm_list_t *lp;
-
- ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
- ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
+ pmtrans_t *trans = handle->trans;
+ pmdb_t *db = handle->db_local;
if((trans->flags & PM_TRANS_FLAG_RECURSE) && !(trans->flags & PM_TRANS_FLAG_CASCADE)) {
_alpm_log(PM_LOG_DEBUG, "finding removable dependencies\n");
@@ -190,7 +184,7 @@ int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data)
return 0;
}
-static int can_remove_file(const char *path, alpm_list_t *skip)
+static int can_remove_file(pmhandle_t *handle, const char *path, alpm_list_t *skip)
{
char file[PATH_MAX+1];
@@ -217,7 +211,8 @@ static int can_remove_file(const char *path, alpm_list_t *skip)
/* Helper function for iterating through a package's file and deleting them
* Used by _alpm_remove_commit. */
-static void unlink_file(pmpkg_t *info, char *filename, alpm_list_t *skip_remove, int nosave)
+static void unlink_file(pmhandle_t *handle, pmpkg_t *info, char *filename,
+ alpm_list_t *skip_remove, int nosave)
{
struct stat buf;
char file[PATH_MAX+1];
@@ -281,8 +276,8 @@ 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(pmhandle_t *handle,
+ pmpkg_t *oldpkg, pmpkg_t *newpkg)
{
alpm_list_t *skip_remove, *b;
alpm_list_t *newfiles, *lp;
@@ -293,13 +288,13 @@ int _alpm_upgraderemove_package(pmpkg_t *oldpkg, pmpkg_t *newpkg,
_alpm_log(PM_LOG_DEBUG, "removing old package first (%s-%s)\n",
oldpkg->name, oldpkg->version);
- if(trans->flags & PM_TRANS_FLAG_DBONLY) {
+ if(handle->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->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 */
@@ -317,7 +312,7 @@ int _alpm_upgraderemove_package(pmpkg_t *oldpkg, pmpkg_t *newpkg,
}
for(lp = files; lp; lp = lp->next) {
- if(!can_remove_file(lp->data, skip_remove)) {
+ if(!can_remove_file(handle, 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);
@@ -330,7 +325,7 @@ int _alpm_upgraderemove_package(pmpkg_t *oldpkg, pmpkg_t *newpkg,
/* 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);
+ unlink_file(handle, oldpkg, lp->data, skip_remove, 0);
}
alpm_list_free(newfiles);
FREELIST(skip_remove);
@@ -352,14 +347,12 @@ db:
return 0;
}
-int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
+int _alpm_remove_packages(pmhandle_t *handle)
{
pmpkg_t *info;
alpm_list_t *targ, *lp;
size_t pkg_count;
-
- ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
- ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
+ pmtrans_t *trans = handle->trans;
pkg_count = alpm_list_count(trans->remove);
@@ -370,14 +363,14 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
const char *pkgname = NULL;
size_t targcount = alpm_list_count(targ);
- if(handle->trans->state == STATE_INTERRUPTED) {
+ if(trans->state == STATE_INTERRUPTED) {
return 0;
}
/* get the name now so we can use it after package is removed */
pkgname = alpm_pkg_get_name(info);
snprintf(scriptlet, PATH_MAX, "%s%s-%s/install",
- _alpm_db_path(db), pkgname, alpm_pkg_get_version(info));
+ _alpm_db_path(handle->db_local), pkgname, alpm_pkg_get_version(info));
EVENT(trans, PM_TRANS_EVT_REMOVE_START, info, NULL);
_alpm_log(PM_LOG_DEBUG, "removing package %s-%s\n",
@@ -395,7 +388,7 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
size_t filenum;
for(lp = files; lp; lp = lp->next) {
- if(!can_remove_file(lp->data, NULL)) {
+ if(!can_remove_file(handle, lp->data, NULL)) {
_alpm_log(PM_LOG_DEBUG, "not removing package '%s', can't remove all files\n",
pkgname);
RET_ERR(PM_ERR_PKG_CANT_REMOVE, -1);
@@ -413,7 +406,7 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
newfiles = alpm_list_reverse(files);
for(lp = newfiles; lp; lp = alpm_list_next(lp)) {
int percent;
- unlink_file(info, lp->data, NULL, trans->flags & PM_TRANS_FLAG_NOSAVE);
+ unlink_file(handle, info, lp->data, NULL, trans->flags & PM_TRANS_FLAG_NOSAVE);
/* update progress bar after each file */
percent = (position * 100) / filenum;
@@ -437,12 +430,12 @@ 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_local_db_remove(db, info) == -1) {
+ if(_alpm_local_db_remove(handle->db_local, info) == -1) {
_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) {
+ if(_alpm_db_remove_pkgfromcache(handle->db_local, info) == -1) {
_alpm_log(PM_LOG_ERROR, _("could not remove entry '%s' from cache\n"),
pkgname);
}
diff --git a/lib/libalpm/remove.h b/lib/libalpm/remove.h
index a67e37a..5cab526 100644
--- a/lib/libalpm/remove.h
+++ b/lib/libalpm/remove.h
@@ -24,10 +24,11 @@
#include "alpm_list.h"
#include "trans.h"
-int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data);
-int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db);
+int _alpm_remove_prepare(pmhandle_t *handle, alpm_list_t **data);
+int _alpm_remove_packages(pmhandle_t *handle);
-int _alpm_upgraderemove_package(pmpkg_t *oldpkg, pmpkg_t *newpkg, pmtrans_t *trans);
+int _alpm_upgraderemove_package(pmhandle_t *handle,
+ pmpkg_t *oldpkg, pmpkg_t *newpkg);
#endif /* _ALPM_REMOVE_H */
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 32060d0..f0d9b91 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -947,7 +947,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
if(replaces) {
_alpm_log(PM_LOG_DEBUG, "removing conflicting and to-be-replaced packages\n");
/* we want the frontend to be aware of commit details */
- if(_alpm_remove_packages(trans, handle->db_local) == -1) {
+ if(_alpm_remove_packages(handle) == -1) {
_alpm_log(PM_LOG_ERROR, _("could not commit removal transaction\n"));
return -1;
}
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index 19614f6..8e019cc 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -197,7 +197,7 @@ int SYMEXPORT alpm_trans_prepare(alpm_list_t **data)
}
if(trans->add == NULL) {
- if(_alpm_remove_prepare(trans, handle->db_local, data) == -1) {
+ if(_alpm_remove_prepare(handle, data) == -1) {
/* pm_errno is set by _alpm_remove_prepare() */
return -1;
}
@@ -236,7 +236,7 @@ int SYMEXPORT alpm_trans_commit(alpm_list_t **data)
trans->state = STATE_COMMITING;
if(trans->add == NULL) {
- if(_alpm_remove_packages(trans, handle->db_local) == -1) {
+ if(_alpm_remove_packages(handle) == -1) {
/* pm_errno is set by _alpm_remove_commit() */
return -1;
}
--
1.7.5.2
More information about the pacman-dev
mailing list