1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-08-13 17:03:46 -04:00

Require handle for alpm_pkg_load()

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-06-07 13:46:11 -05:00
parent fb3ad7f882
commit d76341297a
8 changed files with 20 additions and 17 deletions

View File

@ -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

View File

@ -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;
@ -384,13 +384,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;

View File

@ -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);

View File

@ -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++;

View File

@ -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);
}

View File

@ -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)) {

View File

@ -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();

View File

@ -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: