Add handle argument to alpm_(add|remove)_pkg()

This makes these functions consistent with the rest of the transaction
related API calls. We do an additional assert to ensure the handle
attached to the package is the same as the handle passed in.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-06-09 16:00:55 -05:00
parent 01ad3faee9
commit fb3ad7f882
6 changed files with 19 additions and 14 deletions

View file

@ -48,19 +48,20 @@
#include "handle.h"
/** Add a package to the transaction. */
int SYMEXPORT alpm_add_pkg(pmpkg_t *pkg)
int SYMEXPORT alpm_add_pkg(pmhandle_t *handle, pmpkg_t *pkg)
{
const char *pkgname, *pkgver;
pmtrans_t *trans;
pmdb_t *db_local;
pmpkg_t *local;
/* Sanity checks */
ASSERT(handle != NULL, return -1);
ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
trans = pkg->handle->trans;
ASSERT(handle == pkg->handle, RET_ERR(PM_ERR_WRONG_ARGS, -1));
trans = 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));
db_local = pkg->handle->db_local;
ASSERT(trans->state == STATE_INITIALIZED,
RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1));
pkgname = pkg->name;
pkgver = pkg->version;
@ -71,7 +72,7 @@ int SYMEXPORT alpm_add_pkg(pmpkg_t *pkg)
RET_ERR(PM_ERR_TRANS_DUP_TARGET, -1);
}
local = _alpm_db_get_pkgfromcache(db_local, pkgname);
local = _alpm_db_get_pkgfromcache(handle->db_local, pkgname);
if(local) {
const char *localpkgname = alpm_pkg_get_name(local);
const char *localpkgver = alpm_pkg_get_version(local);

View file

@ -867,16 +867,18 @@ int alpm_sync_sysupgrade(pmhandle_t *handle, int enable_downgrade);
/** Add a package to the transaction.
* If the package was loaded by alpm_pkg_load(), it will be freed upon
* alpm_trans_release() invocation.
* @param handle the context handle
* @param pkg the package to add
* @return 0 on success, -1 on error (pm_errno is set accordingly)
*/
int alpm_add_pkg(pmpkg_t *pkg);
int alpm_add_pkg(pmhandle_t *handle, pmpkg_t *pkg);
/** Add a package removal action to the transaction.
* @param handle the context handle
* @param pkg the package to uninstall
* @return 0 on success, -1 on error (pm_errno is set accordingly)
*/
int alpm_remove_pkg(pmpkg_t *pkg);
int alpm_remove_pkg(pmhandle_t *handle, pmpkg_t *pkg);
/** @} */

View file

@ -44,14 +44,16 @@
#include "deps.h"
#include "handle.h"
int SYMEXPORT alpm_remove_pkg(pmpkg_t *pkg)
int SYMEXPORT alpm_remove_pkg(pmhandle_t *handle, pmpkg_t *pkg)
{
pmtrans_t *trans;
const char *pkgname;
/* Sanity checks */
ASSERT(handle != NULL, return -1);
ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
trans = pkg->handle->trans;
ASSERT(handle == pkg->handle, RET_ERR(PM_ERR_WRONG_ARGS, -1));
trans = 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));

View file

@ -38,7 +38,7 @@ static int remove_target(const char *target)
alpm_list_t *p;
if((info = alpm_db_get_pkg(db_local, target)) != NULL) {
if(alpm_remove_pkg(info) == -1) {
if(alpm_remove_pkg(config->handle, info) == -1) {
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", target, alpm_strerrorlast());
return -1;
}
@ -53,7 +53,7 @@ static int remove_target(const char *target)
}
for(p = alpm_grp_get_pkgs(grp); p; p = alpm_list_next(p)) {
pmpkg_t *pkg = alpm_list_getdata(p);
if(alpm_remove_pkg(pkg) == -1) {
if(alpm_remove_pkg(config->handle, pkg) == -1) {
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", target, alpm_strerrorlast());
return -1;
}

View file

@ -620,7 +620,7 @@ static pmdb_t *get_db(const char *dbname)
static int process_pkg(pmpkg_t *pkg)
{
int ret = alpm_add_pkg(pkg);
int ret = alpm_add_pkg(config->handle, pkg);
if(ret == -1) {
if(pm_errno == PM_ERR_TRANS_DUP_TARGET

View file

@ -82,7 +82,7 @@ int pacman_upgrade(alpm_list_t *targets)
trans_release();
return 1;
}
if(alpm_add_pkg(pkg) == -1) {
if(alpm_add_pkg(config->handle, pkg) == -1) {
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n",
targ, alpm_strerrorlast());
alpm_pkg_free(pkg);