Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm/package.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libalpm/package.c')
-rw-r--r--lib/libalpm/package.c129
1 files changed, 62 insertions, 67 deletions
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index f2f15af4..969458ac 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -23,13 +23,9 @@
#include "config.h"
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <ctype.h>
-#include <errno.h>
#include <sys/types.h>
-#include <sys/stat.h>
/* libalpm */
#include "package.h"
@@ -49,16 +45,14 @@
/** Free a package. */
int SYMEXPORT alpm_pkg_free(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
- ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+ ASSERT(pkg != NULL, return -1);
/* Only free packages loaded in user space */
if(pkg->origin == PKG_FROM_FILE) {
_alpm_pkg_free(pkg);
}
- return(0);
+ return 0;
}
/** Check the integrity (with md5) of a package from the sync cache. */
@@ -67,24 +61,22 @@ int SYMEXPORT alpm_pkg_checkmd5sum(pmpkg_t *pkg)
char *fpath;
int retval;
- ALPM_LOG_FUNC;
-
- ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+ ASSERT(pkg != NULL, return -1);
/* We only inspect packages from sync repositories */
- ASSERT(pkg->origin == PKG_FROM_SYNCDB, RET_ERR(PM_ERR_PKG_INVALID, -1));
+ ASSERT(pkg->origin == PKG_FROM_SYNCDB, return -1);
- fpath = _alpm_filecache_find(alpm_pkg_get_filename(pkg));
+ fpath = _alpm_filecache_find(pkg->handle, alpm_pkg_get_filename(pkg));
retval = _alpm_test_md5sum(fpath, alpm_pkg_get_md5sum(pkg));
if(retval == 0) {
- return(0);
- } else if (retval == 1) {
- pm_errno = PM_ERR_PKG_INVALID;
+ return 0;
+ } else if(retval == 1) {
+ pkg->handle->pm_errno = PM_ERR_PKG_INVALID;
retval = -1;
}
- return(retval);
+ return retval;
}
/* Default package accessor functions. These will get overridden by any
@@ -92,8 +84,6 @@ int SYMEXPORT alpm_pkg_checkmd5sum(pmpkg_t *pkg)
* a lazy-load cache. However, the defaults will work just fine for fully-
* populated package structures. */
static const char *_pkg_get_filename(pmpkg_t *pkg) { return pkg->filename; }
-static const char *_pkg_get_name(pmpkg_t *pkg) { return pkg->name; }
-static const char *_pkg_get_version(pmpkg_t *pkg) { return pkg->version; }
static const char *_pkg_get_desc(pmpkg_t *pkg) { return pkg->desc; }
static const char *_pkg_get_url(pmpkg_t *pkg) { return pkg->url; }
static time_t _pkg_get_builddate(pmpkg_t *pkg) { return pkg->builddate; }
@@ -117,17 +107,28 @@ static alpm_list_t *_pkg_get_deltas(pmpkg_t *pkg) { return pkg->deltas; }
static alpm_list_t *_pkg_get_files(pmpkg_t *pkg) { return pkg->files; }
static alpm_list_t *_pkg_get_backup(pmpkg_t *pkg) { return pkg->backup; }
-static void *_pkg_changelog_open(pmpkg_t *pkg) { return NULL; }
-static size_t _pkg_changelog_read(void *ptr, size_t size, const pmpkg_t *pkg, const void *fp) { return 0; }
-static int _pkg_changelog_close(const pmpkg_t *pkg, void *fp) { return EOF; }
+static void *_pkg_changelog_open(pmpkg_t UNUSED *pkg)
+{
+ return NULL;
+}
+
+static size_t _pkg_changelog_read(void UNUSED *ptr, size_t UNUSED size,
+ const pmpkg_t UNUSED *pkg, const UNUSED void *fp)
+{
+ return 0;
+}
+
+static int _pkg_changelog_close(const pmpkg_t UNUSED *pkg,
+ void UNUSED *fp)
+{
+ return EOF;
+}
/** The standard package operations struct. Get fields directly from the
* struct itself with no abstraction layer or any type of lazy loading.
*/
struct pkg_operations default_pkg_ops = {
.get_filename = _pkg_get_filename,
- .get_name = _pkg_get_name,
- .get_version = _pkg_get_version,
.get_desc = _pkg_get_desc,
.get_url = _pkg_get_url,
.get_builddate = _pkg_get_builddate,
@@ -166,12 +167,12 @@ const char SYMEXPORT *alpm_pkg_get_filename(pmpkg_t *pkg)
const char SYMEXPORT *alpm_pkg_get_name(pmpkg_t *pkg)
{
- return pkg->ops->get_name(pkg);
+ return pkg->name;
}
const char SYMEXPORT *alpm_pkg_get_version(pmpkg_t *pkg)
{
- return pkg->ops->get_version(pkg);
+ return pkg->version;
}
const char SYMEXPORT *alpm_pkg_get_desc(pmpkg_t *pkg)
@@ -277,10 +278,10 @@ alpm_list_t SYMEXPORT *alpm_pkg_get_backup(pmpkg_t *pkg)
pmdb_t SYMEXPORT *alpm_pkg_get_db(pmpkg_t *pkg)
{
/* Sanity checks */
- ASSERT(pkg != NULL, return(NULL));
- ASSERT(pkg->origin != PKG_FROM_FILE, return(NULL));
+ ASSERT(pkg != NULL, return NULL);
+ ASSERT(pkg->origin != PKG_FROM_FILE, return NULL);
- return(pkg->origin_data.db);
+ return pkg->origin_data.db;
}
/** Open a package changelog for reading. */
@@ -340,7 +341,7 @@ alpm_list_t SYMEXPORT *alpm_pkg_compute_requiredby(pmpkg_t *pkg)
if(pkg->origin == PKG_FROM_FILE) {
/* The sane option; search locally for things that require this. */
- db = alpm_option_get_localdb();
+ db = alpm_option_get_localdb(pkg->handle);
find_requiredby(pkg, db, &reqs);
} else {
/* We have a DB package. if it is a local package, then we should
@@ -349,14 +350,14 @@ alpm_list_t SYMEXPORT *alpm_pkg_compute_requiredby(pmpkg_t *pkg)
if(db->is_local) {
find_requiredby(pkg, db, &reqs);
} else {
- for(i = handle->dbs_sync; i; i = i->next) {
+ for(i = pkg->handle->dbs_sync; i; i = i->next) {
db = i->data;
find_requiredby(pkg, db, &reqs);
}
reqs = alpm_list_msort(reqs, alpm_list_count(reqs), _alpm_str_cmp);
}
}
- return(reqs);
+ return reqs;
}
/** @} */
@@ -365,11 +366,9 @@ pmpkg_t *_alpm_pkg_new(void)
{
pmpkg_t* pkg;
- ALPM_LOG_FUNC;
-
- CALLOC(pkg, 1, sizeof(pmpkg_t), RET_ERR(PM_ERR_MEMORY, NULL));
+ CALLOC(pkg, 1, sizeof(pmpkg_t), return NULL);
- return(pkg);
+ return pkg;
}
pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg)
@@ -377,21 +376,19 @@ pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg)
pmpkg_t *newpkg;
alpm_list_t *i;
- ALPM_LOG_FUNC;
-
- CALLOC(newpkg, 1, sizeof(pmpkg_t), RET_ERR(PM_ERR_MEMORY, NULL));
+ CALLOC(newpkg, 1, sizeof(pmpkg_t), goto cleanup);
newpkg->name_hash = pkg->name_hash;
- STRDUP(newpkg->filename, pkg->filename, RET_ERR(PM_ERR_MEMORY, newpkg));
- STRDUP(newpkg->name, pkg->name, RET_ERR(PM_ERR_MEMORY, newpkg));
- STRDUP(newpkg->version, pkg->version, RET_ERR(PM_ERR_MEMORY, newpkg));
- STRDUP(newpkg->desc, pkg->desc, RET_ERR(PM_ERR_MEMORY, newpkg));
- STRDUP(newpkg->url, pkg->url, RET_ERR(PM_ERR_MEMORY, newpkg));
+ STRDUP(newpkg->filename, pkg->filename, goto cleanup);
+ STRDUP(newpkg->name, pkg->name, goto cleanup);
+ STRDUP(newpkg->version, pkg->version, goto cleanup);
+ STRDUP(newpkg->desc, pkg->desc, goto cleanup);
+ STRDUP(newpkg->url, pkg->url, goto cleanup);
newpkg->builddate = pkg->builddate;
newpkg->installdate = pkg->installdate;
- STRDUP(newpkg->packager, pkg->packager, RET_ERR(PM_ERR_MEMORY, newpkg));
- STRDUP(newpkg->md5sum, pkg->md5sum, RET_ERR(PM_ERR_MEMORY, newpkg));
- STRDUP(newpkg->arch, pkg->arch, RET_ERR(PM_ERR_MEMORY, newpkg));
+ STRDUP(newpkg->packager, pkg->packager, goto cleanup);
+ STRDUP(newpkg->md5sum, pkg->md5sum, goto cleanup);
+ STRDUP(newpkg->arch, pkg->arch, goto cleanup);
newpkg->size = pkg->size;
newpkg->isize = pkg->isize;
newpkg->scriptlet = pkg->scriptlet;
@@ -411,22 +408,25 @@ pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg)
newpkg->deltas = alpm_list_copy_data(pkg->deltas, sizeof(pmdelta_t));
/* internal */
+ newpkg->infolevel = pkg->infolevel;
newpkg->origin = pkg->origin;
- newpkg->ops = pkg->ops;
if(newpkg->origin == PKG_FROM_FILE) {
newpkg->origin_data.file = strdup(pkg->origin_data.file);
} else {
newpkg->origin_data.db = pkg->origin_data.db;
}
- newpkg->infolevel = pkg->infolevel;
+ newpkg->ops = pkg->ops;
+ newpkg->handle = pkg->handle;
- return(newpkg);
+ return newpkg;
+
+cleanup:
+ _alpm_pkg_free(newpkg);
+ return NULL;
}
void _alpm_pkg_free(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
if(pkg == NULL) {
return;
}
@@ -438,6 +438,7 @@ void _alpm_pkg_free(pmpkg_t *pkg)
FREE(pkg->url);
FREE(pkg->packager);
FREE(pkg->md5sum);
+ FREE(pkg->base64_sig);
FREE(pkg->arch);
FREELIST(pkg->licenses);
FREELIST(pkg->replaces);
@@ -467,8 +468,6 @@ void _alpm_pkg_free(pmpkg_t *pkg)
*/
void _alpm_pkg_free_trans(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
if(pkg == NULL) {
return;
}
@@ -485,8 +484,6 @@ void _alpm_pkg_free_trans(pmpkg_t *pkg)
/* Is spkg an upgrade for localpkg? */
int _alpm_pkg_compare_versions(pmpkg_t *spkg, pmpkg_t *localpkg)
{
- ALPM_LOG_FUNC;
-
return alpm_pkg_vercmp(alpm_pkg_get_version(spkg),
alpm_pkg_get_version(localpkg));
}
@@ -497,7 +494,7 @@ int _alpm_pkg_cmp(const void *p1, const void *p2)
{
pmpkg_t *pkg1 = (pmpkg_t *)p1;
pmpkg_t *pkg2 = (pmpkg_t *)p2;
- return(strcoll(pkg1->name, pkg2->name));
+ return strcoll(pkg1->name, pkg2->name);
}
/* Test for existence of a package in a alpm_list_t*
@@ -508,10 +505,8 @@ pmpkg_t *_alpm_pkg_find(alpm_list_t *haystack, const char *needle)
alpm_list_t *lp;
unsigned long needle_hash;
- ALPM_LOG_FUNC;
-
if(needle == NULL || haystack == NULL) {
- return(NULL);
+ return NULL;
}
needle_hash = _alpm_hash_sdbm(needle);
@@ -527,11 +522,11 @@ pmpkg_t *_alpm_pkg_find(alpm_list_t *haystack, const char *needle)
/* finally: we had hash match, verify string match */
if(strcmp(info->name, needle) == 0) {
- return(info);
+ return info;
}
}
}
- return(NULL);
+ return NULL;
}
/** Test if a package should be ignored.
@@ -548,19 +543,19 @@ int _alpm_pkg_should_ignore(pmpkg_t *pkg)
alpm_list_t *groups = NULL;
/* first see if the package is ignored */
- if(alpm_list_find_str(handle->ignorepkg, alpm_pkg_get_name(pkg))) {
- return(1);
+ if(alpm_list_find_str(pkg->handle->ignorepkg, alpm_pkg_get_name(pkg))) {
+ return 1;
}
/* next see if the package is in a group that is ignored */
- for(groups = handle->ignoregrp; groups; groups = alpm_list_next(groups)) {
+ for(groups = pkg->handle->ignoregrp; groups; groups = alpm_list_next(groups)) {
char *grp = (char *)alpm_list_getdata(groups);
if(alpm_list_find_str(alpm_pkg_get_groups(pkg), grp)) {
- return(1);
+ return 1;
}
}
- return(0);
+ return 0;
}
/* vim: set ts=2 sw=2 noet: */