[pacman-dev] [PATCH] Add handle argument to alpm_(add|remove)_pkg()

Dan McGee dan at archlinux.org
Thu Jun 9 17:01:52 EDT 2011


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 at archlinux.org>
---
 lib/libalpm/add.c    |    8 ++++----
 lib/libalpm/alpm.h   |    6 ++++--
 lib/libalpm/remove.c |    8 ++++----
 src/pacman/remove.c  |    4 ++--
 src/pacman/sync.c    |    2 +-
 src/pacman/upgrade.c |    2 +-
 6 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index abce175..6f93c61 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -50,16 +50,16 @@
 #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;
-	pmhandle_t *handle;
 	pmtrans_t *trans;
 	pmpkg_t *local;
 
 	/* Sanity checks */
-	ASSERT(pkg != NULL, return -1);
-	handle = pkg->handle;
+	ASSERT(handle != NULL, return -1);
+	ASSERT(pkg != NULL, RET_ERR(handle, PM_ERR_WRONG_ARGS, -1));
+	ASSERT(handle == pkg->handle, RET_ERR(handle, PM_ERR_WRONG_ARGS, -1));
 	trans = handle->trans;
 	ASSERT(trans != NULL, RET_ERR(handle, PM_ERR_TRANS_NULL, -1));
 	ASSERT(trans->state == STATE_INITIALIZED,
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 37bea6d..b62c62d 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -873,16 +873,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);
 
 /** @} */
 
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index 8a1bbcb..52f60fc 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -44,15 +44,15 @@
 #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)
 {
 	const char *pkgname;
-	pmhandle_t *handle;
 	pmtrans_t *trans;
 
 	/* Sanity checks */
-	ASSERT(pkg != NULL, return -1);
-	handle = pkg->handle;
+	ASSERT(handle != NULL, return -1);
+	ASSERT(pkg != NULL, RET_ERR(handle, PM_ERR_WRONG_ARGS, -1));
+	ASSERT(handle == pkg->handle, RET_ERR(handle, PM_ERR_WRONG_ARGS, -1));
 	trans = handle->trans;
 	ASSERT(trans != NULL, RET_ERR(handle, PM_ERR_TRANS_NULL, -1));
 	ASSERT(trans->state == STATE_INITIALIZED,
diff --git a/src/pacman/remove.c b/src/pacman/remove.c
index 595263a..2c4a3fc 100644
--- a/src/pacman/remove.c
+++ b/src/pacman/remove.c
@@ -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_strerror(alpm_errno(config->handle)));
 			return -1;
@@ -54,7 +54,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_strerror(alpm_errno(config->handle)));
 			return -1;
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 36c7799..539e651 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -616,7 +616,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) {
 		enum _pmerrno_t err = alpm_errno(config->handle);
diff --git a/src/pacman/upgrade.c b/src/pacman/upgrade.c
index ef273cf..35624eb 100644
--- a/src/pacman/upgrade.c
+++ b/src/pacman/upgrade.c
@@ -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_strerror(alpm_errno(config->handle)));
 			alpm_pkg_free(pkg);
-- 
1.7.5.2



More information about the pacman-dev mailing list