Signed-off-by: Dan McGee <d...@archlinux.org>
---
 lib/libalpm/alpm.h       |    5 +++--
 lib/libalpm/be_package.c |   16 ++++++++--------
 lib/libalpm/package.h    |    6 ++++--
 lib/libalpm/sync.c       |    2 +-
 src/pacman/query.c       |    2 +-
 src/pacman/sync.c        |    2 +-
 src/pacman/upgrade.c     |    2 +-
 src/util/testpkg.c       |    2 +-
 8 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 2144401..44f2ba1 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -368,6 +368,7 @@ int alpm_db_set_pkgreason(pmdb_t *db, const char *name, 
pmpkgreason_t reason);
  * metadata is found. If it is true, the entire archive is read, which
  * serves as a verification of integrity and the filelist can be created.
  * The allocated structure should be freed using alpm_pkg_free().
+ * @param handle the context handle
  * @param filename location of the package tarball
  * @param full whether to stop the load after metadata is read or continue
  * through the full archive
@@ -376,8 +377,8 @@ int alpm_db_set_pkgreason(pmdb_t *db, const char *name, 
pmpkgreason_t reason);
  * @param pkg address of the package pointer
  * @return 0 on success, -1 on error (pm_errno is set accordingly)
  */
-int alpm_pkg_load(const char *filename, int full, pgp_verify_t check_sig,
-               pmpkg_t **pkg);
+int alpm_pkg_load(pmhandle_t *handle, const char *filename, int full,
+               pgp_verify_t check_sig, pmpkg_t **pkg);
 
 /** Free a package.
  * @param pkg package pointer to free
diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c
index 0545167..5b8cd81 100644
--- a/lib/libalpm/be_package.c
+++ b/lib/libalpm/be_package.c
@@ -30,15 +30,13 @@
 
 /* libalpm */
 #include "alpm_list.h"
+#include "alpm.h"
 #include "util.h"
 #include "log.h"
 #include "handle.h"
 #include "package.h"
 #include "deps.h" /* _alpm_splitdep */
 
-/* global handle variable */
-extern pmhandle_t *handle;
-
 /**
  * Open a package changelog for reading. Similar to fopen in functionality,
  * except that the returned 'file stream' is from an archive.
@@ -225,13 +223,15 @@ static int parse_descfile(struct archive *a, pmpkg_t 
*newpkg)
 
 /**
  * Load a package and create the corresponding pmpkg_t struct.
+ * @param handle the context handle
  * @param pkgfile path to the package file
  * @param full whether to stop the load after metadata is read or continue
  *             through the full archive
  * @return An information filled pmpkg_t struct
  */
-pmpkg_t *_alpm_pkg_load_internal(const char *pkgfile, int full,
-               const char *md5sum, const char *base64_sig, pgp_verify_t 
check_sig)
+pmpkg_t *_alpm_pkg_load_internal(pmhandle_t *handle, const char *pkgfile,
+               int full, const char *md5sum, const char *base64_sig,
+               pgp_verify_t check_sig)
 {
        int ret;
        int config = 0;
@@ -383,13 +383,13 @@ error:
        return NULL;
 }
 
-int SYMEXPORT alpm_pkg_load(const char *filename, int full,
+int SYMEXPORT alpm_pkg_load(pmhandle_t *handle, const char *filename, int full,
                pgp_verify_t check_sig, pmpkg_t **pkg)
 {
-       /* Sanity checks */
+       ASSERT(handle != NULL, return -1);
        ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
 
-       *pkg = _alpm_pkg_load_internal(filename, full, NULL, NULL, check_sig);
+       *pkg = _alpm_pkg_load_internal(handle, filename, full, NULL, NULL, 
check_sig);
        if(*pkg == NULL) {
                /* pm_errno is set by pkg_load */
                return -1;
diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h
index 4e2dcf3..b5d8f73 100644
--- a/lib/libalpm/package.h
+++ b/lib/libalpm/package.h
@@ -141,8 +141,10 @@ pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg);
 void _alpm_pkg_free(pmpkg_t *pkg);
 void _alpm_pkg_free_trans(pmpkg_t *pkg);
 
-pmpkg_t *_alpm_pkg_load_internal(const char *filename, int full,
-               const char *md5sum, const char *base64_sig, pgp_verify_t 
check_sig);
+
+pmpkg_t *_alpm_pkg_load_internal(pmhandle_t *handle, const char *pkgfile,
+               int full, const char *md5sum, const char *base64_sig,
+               pgp_verify_t check_sig);
 
 int _alpm_pkg_cmp(const void *p1, const void *p2);
 int _alpm_pkg_compare_versions(pmpkg_t *local_pkg, pmpkg_t *pkg);
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 16be6d9..1882888 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -876,7 +876,7 @@ int _alpm_sync_commit(pmhandle_t *handle, alpm_list_t 
**data)
                /* load the package file and replace pkgcache entry with it in 
the target list */
                /* TODO: alpm_pkg_get_db() will not work on this target anymore 
*/
                _alpm_log(PM_LOG_DEBUG, "replacing pkgcache entry with package 
file for target %s\n", spkg->name);
-               pmpkg_t *pkgfile =_alpm_pkg_load_internal(filepath, 1, 
spkg->md5sum,
+               pmpkg_t *pkgfile =_alpm_pkg_load_internal(handle, filepath, 1, 
spkg->md5sum,
                                spkg->base64_sig, check_sig);
                if(!pkgfile) {
                        errors++;
diff --git a/src/pacman/query.c b/src/pacman/query.c
index d446534..76d9d73 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -552,7 +552,7 @@ int pacman_query(alpm_list_t *targets)
                char *strname = alpm_list_getdata(i);
 
                if(config->op_q_isfile) {
-                       alpm_pkg_load(strname, 1, PM_PGP_VERIFY_OPTIONAL, &pkg);
+                       alpm_pkg_load(config->handle, strname, 1, 
PM_PGP_VERIFY_OPTIONAL, &pkg);
                } else {
                        pkg = alpm_db_get_pkg(db_local, strname);
                }
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 4cd8d21..8405002 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -220,7 +220,7 @@ static int sync_cleancache(int level)
                        /* attempt to load the package, prompt removal on 
failures as we may have
                         * files here that aren't valid packages. we also don't 
need a full
                         * load of the package, just the metadata. */
-                       if(alpm_pkg_load(path, 0, PM_PGP_VERIFY_NEVER, 
&localpkg) != 0
+                       if(alpm_pkg_load(config->handle, path, 0, 
PM_PGP_VERIFY_NEVER, &localpkg) != 0
                                        || localpkg == NULL) {
                                if(yesno(_("File %s does not seem to be a valid 
package, remove it?"),
                                                        path)) {
diff --git a/src/pacman/upgrade.c b/src/pacman/upgrade.c
index ddb8a2e..deea1ee 100644
--- a/src/pacman/upgrade.c
+++ b/src/pacman/upgrade.c
@@ -76,7 +76,7 @@ int pacman_upgrade(alpm_list_t *targets)
                char *targ = alpm_list_getdata(i);
                pmpkg_t *pkg;
 
-               if(alpm_pkg_load(targ, 1, check_sig, &pkg) != 0) {
+               if(alpm_pkg_load(config->handle, targ, 1, check_sig, &pkg) != 
0) {
                        pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n",
                                        targ, alpm_strerrorlast());
                        trans_release();
diff --git a/src/util/testpkg.c b/src/util/testpkg.c
index 32011d4..5b8831d 100644
--- a/src/util/testpkg.c
+++ b/src/util/testpkg.c
@@ -58,7 +58,7 @@ int main(int argc, char *argv[])
        /* let us get log messages from libalpm */
        alpm_option_set_logcb(handle, output_cb);
 
-       if(alpm_pkg_load(argv[1], 1, PM_PGP_VERIFY_OPTIONAL, &pkg) == -1
+       if(alpm_pkg_load(handle, argv[1], 1, PM_PGP_VERIFY_OPTIONAL, &pkg) == -1
                        || pkg == NULL) {
                switch(pm_errno) {
                        case PM_ERR_PKG_OPEN:
-- 
1.7.5.2


Reply via email to