Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
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.c68
1 files changed, 33 insertions, 35 deletions
diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c
index 6dfddd61..8a6ed6c4 100644
--- a/lib/libalpm/be_package.c
+++ b/lib/libalpm/be_package.c
@@ -20,10 +20,8 @@
#include "config.h"
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <limits.h>
#include <errno.h>
/* libarchive */
@@ -47,7 +45,7 @@ static void *_package_changelog_open(pmpkg_t *pkg)
{
ALPM_LOG_FUNC;
- ASSERT(pkg != NULL, return(NULL));
+ ASSERT(pkg != NULL, return NULL);
struct archive *archive = NULL;
struct archive_entry *entry;
@@ -60,7 +58,7 @@ static void *_package_changelog_open(pmpkg_t *pkg)
archive_read_support_compression_all(archive);
archive_read_support_format_all(archive);
- if (archive_read_open_filename(archive, pkgfile,
+ if(archive_read_open_filename(archive, pkgfile,
ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) {
RET_ERR(PM_ERR_PKG_OPEN, NULL);
}
@@ -69,14 +67,14 @@ static void *_package_changelog_open(pmpkg_t *pkg)
const char *entry_name = archive_entry_pathname(entry);
if(strcmp(entry_name, ".CHANGELOG") == 0) {
- return(archive);
+ return archive;
}
}
/* we didn't find a changelog */
archive_read_finish(archive);
errno = ENOENT;
- return(NULL);
+ return NULL;
}
/**
@@ -91,24 +89,16 @@ static void *_package_changelog_open(pmpkg_t *pkg)
static size_t _package_changelog_read(void *ptr, size_t size,
const pmpkg_t *pkg, const void *fp)
{
- ssize_t sret = archive_read_data((struct archive*)fp, ptr, size);
+ ssize_t sret = archive_read_data((struct archive *)fp, ptr, size);
/* Report error (negative values) */
if(sret < 0) {
pm_errno = PM_ERR_LIBARCHIVE;
- return(0);
+ return 0;
} else {
- return((size_t)sret);
+ return (size_t)sret;
}
}
-/*
-static int _package_changelog_feof(const pmpkg_t *pkg, void *fp)
-{
- // note: this doesn't quite work, no feof in libarchive
- return( archive_read_data((struct archive*)fp, NULL, 0) );
-}
-*/
-
/**
* Close a package changelog for reading. Similar to fclose in functionality,
* except that the 'file stream' is from an archive.
@@ -118,7 +108,7 @@ static int _package_changelog_feof(const pmpkg_t *pkg, void *fp)
*/
static int _package_changelog_close(const pmpkg_t *pkg, void *fp)
{
- return( archive_read_finish((struct archive *)fp) );
+ return archive_read_finish((struct archive *)fp);
}
/** Package file operations struct accessor. We implement this as a method
@@ -137,7 +127,7 @@ static struct pkg_operations *get_file_pkg_ops(void)
file_pkg_ops.changelog_close = _package_changelog_close;
file_pkg_ops_initialized = 1;
}
- return(&file_pkg_ops);
+ return &file_pkg_ops;
}
/**
@@ -226,7 +216,7 @@ static int parse_descfile(struct archive *a, pmpkg_t *newpkg)
line[0] = '\0';
}
- return(0);
+ return 0;
}
/**
@@ -251,31 +241,39 @@ static pmpkg_t *pkg_load(const char *pkgfile, int full)
RET_ERR(PM_ERR_WRONG_ARGS, NULL);
}
- if(stat(pkgfile, &st) != 0) {
+ /* attempt to stat the package file, ensure it exists */
+ if(stat(pkgfile, &st) == 0) {
+ int sig_ret;
+
+ newpkg = _alpm_pkg_new();
+ if(newpkg == NULL) {
+ RET_ERR(PM_ERR_MEMORY, NULL);
+ }
+ newpkg->filename = strdup(pkgfile);
+ newpkg->size = st.st_size;
+
+ /* TODO: do something with ret value */
+ sig_ret = _alpm_load_signature(pkgfile, &(newpkg->pgpsig));
+ (void)sig_ret;
+ } else {
+ /* couldn't stat the pkgfile, return an error */
RET_ERR(PM_ERR_PKG_OPEN, NULL);
}
if((archive = archive_read_new()) == NULL) {
+ alpm_pkg_free(newpkg);
RET_ERR(PM_ERR_LIBARCHIVE, NULL);
}
archive_read_support_compression_all(archive);
archive_read_support_format_all(archive);
- if (archive_read_open_filename(archive, pkgfile,
+ 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);
}
- newpkg = _alpm_pkg_new();
- if(newpkg == NULL) {
- archive_read_finish(archive);
- RET_ERR(PM_ERR_MEMORY, NULL);
- }
-
- newpkg->filename = strdup(pkgfile);
- newpkg->size = st.st_size;
-
_alpm_log(PM_LOG_DEBUG, "starting package load for %s\n", pkgfile);
/* If full is false, only read through the archive until we find our needed
@@ -356,7 +354,7 @@ static pmpkg_t *pkg_load(const char *pkgfile, int full)
newpkg->infolevel = INFRQ_BASE | INFRQ_DESC;
}
- return(newpkg);
+ return newpkg;
pkg_invalid:
pm_errno = PM_ERR_PKG_INVALID;
@@ -364,7 +362,7 @@ error:
_alpm_pkg_free(newpkg);
archive_read_finish(archive);
- return(NULL);
+ return NULL;
}
int SYMEXPORT alpm_pkg_load(const char *filename, int full, pmpkg_t **pkg)
@@ -379,10 +377,10 @@ int SYMEXPORT alpm_pkg_load(const char *filename, int full, pmpkg_t **pkg)
*pkg = pkg_load(filename, full);
if(*pkg == NULL) {
/* pm_errno is set by pkg_load */
- return(-1);
+ return -1;
}
- return(0);
+ return 0;
}
/* vim: set ts=2 sw=2 noet: */