summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/be_package.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libalpm/be_package.c')
-rw-r--r--lib/libalpm/be_package.c108
1 files changed, 55 insertions, 53 deletions
diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c
index 9e59d69a..e65db498 100644
--- a/lib/libalpm/be_package.c
+++ b/lib/libalpm/be_package.c
@@ -30,8 +30,10 @@
/* 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 */
@@ -43,8 +45,6 @@
*/
static void *_package_changelog_open(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
ASSERT(pkg != NULL, return NULL);
struct archive *archive = NULL;
@@ -52,7 +52,7 @@ static void *_package_changelog_open(pmpkg_t *pkg)
const char *pkgfile = pkg->origin_data.file;
if((archive = archive_read_new()) == NULL) {
- RET_ERR(PM_ERR_LIBARCHIVE, NULL);
+ RET_ERR(pkg->handle, PM_ERR_LIBARCHIVE, NULL);
}
archive_read_support_compression_all(archive);
@@ -60,7 +60,7 @@ static void *_package_changelog_open(pmpkg_t *pkg)
if(archive_read_open_filename(archive, pkgfile,
ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) {
- RET_ERR(PM_ERR_PKG_OPEN, NULL);
+ RET_ERR(pkg->handle, PM_ERR_PKG_OPEN, NULL);
}
while(archive_read_next_header(archive, &entry) == ARCHIVE_OK) {
@@ -92,7 +92,7 @@ static size_t _package_changelog_read(void *ptr, size_t size,
ssize_t sret = archive_read_data((struct archive *)fp, ptr, size);
/* Report error (negative values) */
if(sret < 0) {
- pm_errno = PM_ERR_LIBARCHIVE;
+ pkg->handle->pm_errno = PM_ERR_LIBARCHIVE;
return 0;
} else {
return (size_t)sret;
@@ -135,23 +135,21 @@ static struct pkg_operations *get_file_pkg_ops(void)
* @param archive the archive to read from, pointed at the .PKGINFO entry
* @param newpkg an empty pmpkg_t struct to fill with package info
*
- * @return 0 on success, 1 on error
+ * @return 0 on success, -1 on error
*/
-static int parse_descfile(struct archive *a, pmpkg_t *newpkg)
+static int parse_descfile(pmhandle_t *handle, struct archive *a, pmpkg_t *newpkg)
{
char *ptr = NULL;
char *key = NULL;
- int linenum = 0;
+ int ret, linenum = 0;
struct archive_read_buffer buf;
- ALPM_LOG_FUNC;
-
memset(&buf, 0, sizeof(buf));
/* 512K for a line length seems reasonable */
buf.max_line_size = 512 * 1024;
/* loop until we reach EOF or other error */
- while(_alpm_archive_fgets(a, &buf) == ARCHIVE_OK) {
+ while((ret = _alpm_archive_fgets(a, &buf)) == ARCHIVE_OK) {
char *line = _alpm_strtrim(buf.line);
linenum++;
@@ -161,33 +159,33 @@ static int parse_descfile(struct archive *a, pmpkg_t *newpkg)
ptr = line;
key = strsep(&ptr, "=");
if(key == NULL || ptr == NULL) {
- _alpm_log(PM_LOG_DEBUG, "%s: syntax error in description file line %d\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "%s: syntax error in description file line %d\n",
newpkg->name ? newpkg->name : "error", linenum);
} else {
key = _alpm_strtrim(key);
while(*ptr == ' ') ptr++;
ptr = _alpm_strtrim(ptr);
if(strcmp(key, "pkgname") == 0) {
- STRDUP(newpkg->name, ptr, RET_ERR(PM_ERR_MEMORY, -1));
+ STRDUP(newpkg->name, ptr, return -1);
newpkg->name_hash = _alpm_hash_sdbm(newpkg->name);
} else if(strcmp(key, "pkgbase") == 0) {
/* not used atm */
} else if(strcmp(key, "pkgver") == 0) {
- STRDUP(newpkg->version, ptr, RET_ERR(PM_ERR_MEMORY, -1));
+ STRDUP(newpkg->version, ptr, return -1);
} else if(strcmp(key, "pkgdesc") == 0) {
- STRDUP(newpkg->desc, ptr, RET_ERR(PM_ERR_MEMORY, -1));
+ STRDUP(newpkg->desc, ptr, return -1);
} else if(strcmp(key, "group") == 0) {
newpkg->groups = alpm_list_add(newpkg->groups, strdup(ptr));
} else if(strcmp(key, "url") == 0) {
- STRDUP(newpkg->url, ptr, RET_ERR(PM_ERR_MEMORY, -1));
+ STRDUP(newpkg->url, ptr, return -1);
} else if(strcmp(key, "license") == 0) {
newpkg->licenses = alpm_list_add(newpkg->licenses, strdup(ptr));
} else if(strcmp(key, "builddate") == 0) {
newpkg->builddate = _alpm_parsedate(ptr);
} else if(strcmp(key, "packager") == 0) {
- STRDUP(newpkg->packager, ptr, RET_ERR(PM_ERR_MEMORY, -1));
+ STRDUP(newpkg->packager, ptr, return -1);
} else if(strcmp(key, "arch") == 0) {
- STRDUP(newpkg->arch, ptr, RET_ERR(PM_ERR_MEMORY, -1));
+ STRDUP(newpkg->arch, ptr, return -1);
} else if(strcmp(key, "size") == 0) {
/* size in the raw package is uncompressed (installed) size */
newpkg->isize = atol(ptr);
@@ -209,25 +207,31 @@ static int parse_descfile(struct archive *a, pmpkg_t *newpkg)
} else if(strcmp(key, "makepkgopt") == 0) {
/* not used atm */
} else {
- _alpm_log(PM_LOG_DEBUG, "%s: unknown key '%s' in description file line %d\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "%s: unknown key '%s' in description file line %d\n",
newpkg->name ? newpkg->name : "error", key, linenum);
}
}
line[0] = '\0';
}
+ if(ret != ARCHIVE_EOF) {
+ _alpm_log(handle, PM_LOG_DEBUG, "error parsing package descfile\n");
+ return -1;
+ }
return 0;
}
/**
* 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;
@@ -236,49 +240,48 @@ pmpkg_t *_alpm_pkg_load_internal(const char *pkgfile, int full,
pmpkg_t *newpkg = NULL;
struct stat st;
- ALPM_LOG_FUNC;
-
if(pkgfile == NULL || strlen(pkgfile) == 0) {
- RET_ERR(PM_ERR_WRONG_ARGS, NULL);
+ RET_ERR(handle, PM_ERR_WRONG_ARGS, NULL);
}
/* attempt to stat the package file, ensure it exists */
if(stat(pkgfile, &st) == 0) {
newpkg = _alpm_pkg_new();
if(newpkg == NULL) {
- RET_ERR(PM_ERR_MEMORY, NULL);
+ RET_ERR(handle, PM_ERR_MEMORY, NULL);
}
newpkg->filename = strdup(pkgfile);
newpkg->size = st.st_size;
} else {
/* couldn't stat the pkgfile, return an error */
- RET_ERR(PM_ERR_PKG_OPEN, NULL);
+ RET_ERR(handle, PM_ERR_PKG_OPEN, NULL);
}
/* first steps- validate the package file */
- _alpm_log(PM_LOG_DEBUG, "md5sum: %s\n", md5sum);
+ _alpm_log(handle, PM_LOG_DEBUG, "md5sum: %s\n", md5sum);
if(md5sum) {
- _alpm_log(PM_LOG_DEBUG, "checking md5sum for %s\n", pkgfile);
+ _alpm_log(handle, PM_LOG_DEBUG, "checking md5sum for %s\n", pkgfile);
if(_alpm_test_md5sum(pkgfile, md5sum) != 0) {
alpm_pkg_free(newpkg);
- RET_ERR(PM_ERR_PKG_INVALID, NULL);
+ RET_ERR(handle, PM_ERR_PKG_INVALID, NULL);
}
}
- _alpm_log(PM_LOG_DEBUG, "base64_sig: %s\n", base64_sig);
+ _alpm_log(handle, PM_LOG_DEBUG, "base64_sig: %s\n", base64_sig);
if(check_sig != PM_PGP_VERIFY_NEVER) {
- _alpm_log(PM_LOG_DEBUG, "checking signature for %s\n", pkgfile);
- ret = _alpm_gpgme_checksig(pkgfile, base64_sig);
+ _alpm_log(handle, PM_LOG_DEBUG, "checking signature for %s\n", pkgfile);
+ ret = _alpm_gpgme_checksig(handle, pkgfile, base64_sig);
if((check_sig == PM_PGP_VERIFY_ALWAYS && ret != 0) ||
(check_sig == PM_PGP_VERIFY_OPTIONAL && ret == 1)) {
- RET_ERR(PM_ERR_SIG_INVALID, NULL);
+ alpm_pkg_free(newpkg);
+ RET_ERR(handle, PM_ERR_SIG_INVALID, NULL);
}
}
/* next- try to create an archive object to read in the package */
if((archive = archive_read_new()) == NULL) {
alpm_pkg_free(newpkg);
- RET_ERR(PM_ERR_LIBARCHIVE, NULL);
+ RET_ERR(handle, PM_ERR_LIBARCHIVE, NULL);
}
archive_read_support_compression_all(archive);
@@ -287,10 +290,10 @@ pmpkg_t *_alpm_pkg_load_internal(const char *pkgfile, int full,
if(archive_read_open_filename(archive, pkgfile,
ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) {
alpm_pkg_free(newpkg);
- RET_ERR(PM_ERR_PKG_OPEN, NULL);
+ RET_ERR(handle, PM_ERR_PKG_OPEN, NULL);
}
- _alpm_log(PM_LOG_DEBUG, "starting package load for %s\n", pkgfile);
+ _alpm_log(handle, PM_LOG_DEBUG, "starting package load for %s\n", pkgfile);
/* If full is false, only read through the archive until we find our needed
* metadata. If it is true, read through the entire archive, which serves
@@ -300,17 +303,17 @@ pmpkg_t *_alpm_pkg_load_internal(const char *pkgfile, int full,
if(strcmp(entry_name, ".PKGINFO") == 0) {
/* parse the info file */
- if(parse_descfile(archive, newpkg) != 0) {
- _alpm_log(PM_LOG_ERROR, _("could not parse package description file in %s\n"),
+ if(parse_descfile(handle, archive, newpkg) != 0) {
+ _alpm_log(handle, PM_LOG_ERROR, _("could not parse package description file in %s\n"),
pkgfile);
goto pkg_invalid;
}
if(newpkg->name == NULL || strlen(newpkg->name) == 0) {
- _alpm_log(PM_LOG_ERROR, _("missing package name in %s\n"), pkgfile);
+ _alpm_log(handle, PM_LOG_ERROR, _("missing package name in %s\n"), pkgfile);
goto pkg_invalid;
}
if(newpkg->version == NULL || strlen(newpkg->version) == 0) {
- _alpm_log(PM_LOG_ERROR, _("missing package version in %s\n"), pkgfile);
+ _alpm_log(handle, PM_LOG_ERROR, _("missing package version in %s\n"), pkgfile);
goto pkg_invalid;
}
config = 1;
@@ -326,9 +329,9 @@ pmpkg_t *_alpm_pkg_load_internal(const char *pkgfile, int full,
}
if(archive_read_data_skip(archive)) {
- _alpm_log(PM_LOG_ERROR, _("error while reading package %s: %s\n"),
+ _alpm_log(handle, PM_LOG_ERROR, _("error while reading package %s: %s\n"),
pkgfile, archive_error_string(archive));
- pm_errno = PM_ERR_LIBARCHIVE;
+ handle->pm_errno = PM_ERR_LIBARCHIVE;
goto error;
}
@@ -339,14 +342,14 @@ pmpkg_t *_alpm_pkg_load_internal(const char *pkgfile, int full,
}
if(ret != ARCHIVE_EOF && ret != ARCHIVE_OK) { /* An error occured */
- _alpm_log(PM_LOG_ERROR, _("error while reading package %s: %s\n"),
+ _alpm_log(handle, PM_LOG_ERROR, _("error while reading package %s: %s\n"),
pkgfile, archive_error_string(archive));
- pm_errno = PM_ERR_LIBARCHIVE;
+ handle->pm_errno = PM_ERR_LIBARCHIVE;
goto error;
}
if(!config) {
- _alpm_log(PM_LOG_ERROR, _("missing package metadata in %s\n"), pkgfile);
+ _alpm_log(handle, PM_LOG_ERROR, _("missing package metadata in %s\n"), pkgfile);
goto pkg_invalid;
}
@@ -356,10 +359,11 @@ pmpkg_t *_alpm_pkg_load_internal(const char *pkgfile, int full,
newpkg->origin = PKG_FROM_FILE;
newpkg->origin_data.file = strdup(pkgfile);
newpkg->ops = get_file_pkg_ops();
+ newpkg->handle = handle;
if(full) {
/* "checking for conflicts" requires a sorted list, ensure that here */
- _alpm_log(PM_LOG_DEBUG, "sorting package filelist for %s\n", pkgfile);
+ _alpm_log(handle, PM_LOG_DEBUG, "sorting package filelist for %s\n", pkgfile);
newpkg->files = alpm_list_msort(newpkg->files, alpm_list_count(newpkg->files),
_alpm_str_cmp);
newpkg->infolevel = INFRQ_ALL;
@@ -372,7 +376,7 @@ pmpkg_t *_alpm_pkg_load_internal(const char *pkgfile, int full,
return newpkg;
pkg_invalid:
- pm_errno = PM_ERR_PKG_INVALID;
+ handle->pm_errno = PM_ERR_PKG_INVALID;
error:
_alpm_pkg_free(newpkg);
archive_read_finish(archive);
@@ -380,15 +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)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+ ASSERT(handle != NULL, return -1);
+ ASSERT(pkg != NULL, RET_ERR(handle, 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;