Commit fac4cdb3 authored by Timo Teräs's avatar Timo Teräs

blob: function to checksum a blob

And use it in couple of places. Some whitespace fixes too.
parent 7a29678a
......@@ -41,14 +41,6 @@ static int add_parse(void *ctx, int optch, int optindex, const char *optarg)
return 0;
}
static void md5_str(const char *str, md5sum_t csum)
{
struct md5_ctx ctx;
md5_init(&ctx);
md5_process(&ctx, str, strlen(str));
md5_finish(&ctx, csum);
}
static int cup(void)
{
/* compressed/uncompressed size is 259/1213 */
......@@ -111,7 +103,7 @@ static int add_main(void *ctx, int argc, char **argv)
goto err;
}
virtpkg->name = apk_db_get_name(&db, APK_BLOB_STR(actx->virtpkg));
md5_str(virtpkg->name->name, virtpkg->csum);
apk_blob_csum(APK_BLOB_STR(virtpkg->name->name), virtpkg->csum);
virtpkg->version = strdup("0");
virtpkg->description = strdup("virtual meta package");
virtdep = apk_dep_from_pkg(&db, virtpkg);
......
......@@ -13,6 +13,7 @@
#define APK_BLOB_H
#include <string.h>
#include "apk_defines.h"
struct apk_blob {
unsigned int len;
......@@ -43,6 +44,7 @@ int apk_blob_rsplit(apk_blob_t blob, char split, apk_blob_t *l, apk_blob_t *r);
unsigned apk_blob_uint(apk_blob_t blob, int base);
unsigned long apk_blob_hash(apk_blob_t str);
int apk_blob_compare(apk_blob_t a, apk_blob_t b);
void apk_blob_csum(apk_blob_t blob, csum_t csum);
int apk_blob_for_each_segment(apk_blob_t blob, const char *split,
apk_blob_cb cb, void *ctx);
......
......@@ -4,7 +4,7 @@
* Copyright (C) 2008 Timo Teräs <timo.teras@iki.fi>
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation. See http://www.gnu.org/ for details.
*/
......@@ -165,6 +165,15 @@ unsigned apk_blob_uint(apk_blob_t blob, int base)
return val;
}
void apk_blob_csum(apk_blob_t blob, csum_t csum)
{
csum_ctx_t ctx;
csum_init(&ctx);
csum_process(&ctx, blob.ptr, blob.len);
csum_finish(&ctx, csum);
}
int apk_hexdump_parse(apk_blob_t to, apk_blob_t from)
{
int i;
......
......@@ -4,7 +4,7 @@
* Copyright (C) 2008 Timo Teräs <timo.teras@iki.fi>
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation. See http://www.gnu.org/ for details.
*/
......@@ -903,7 +903,7 @@ static struct apk_bstream *apk_db_cache_open(struct apk_database *db,
if (db->root == NULL)
return NULL;
snprintf(tmp, sizeof(tmp), "%s/var/lib/apk/%s", db->root, file);
snprintf(tmp, sizeof(tmp), "%s/var/lib/apk/%s", db->root, file);
return apk_bstream_from_file(tmp);
}
......@@ -977,7 +977,7 @@ int apk_db_add_repository(apk_database_t _db, apk_blob_t repository)
char buf[2*sizeof(csum_t)+32], *name;
int r, n;
if (repository.ptr == NULL || *repository.ptr == '\0'
if (repository.ptr == NULL || *repository.ptr == '\0'
|| *repository.ptr == '#')
return 0;
......@@ -991,14 +991,10 @@ int apk_db_add_repository(apk_database_t _db, apk_blob_t repository)
};
if (apk_url_local_file(db->repos[r].url) == NULL) {
csum_ctx_t csum;
csum_t res;
csum_init(&csum);
csum_process(&csum, repository.ptr, repository.len);
csum_finish(&csum, res);
csum_t cs;
n = apk_hexdump_format(sizeof(buf), buf, APK_BLOB_BUF(res)) - 1;
apk_blob_csum(repository, cs);
n = apk_hexdump_format(sizeof(buf), buf, APK_BLOB_BUF(cs)) - 1;
snprintf(&buf[n], sizeof(buf) - n, ".index.gz");
db->repos[r].cache = strdup(buf);
......@@ -1156,7 +1152,7 @@ static int apk_db_install_archive_entry(void *_ctx,
apk_db_file_change_owner(db, file, diri,
&ctx->file_diri_node);
}
if (apk_verbosity > 1)
printf("%s\n", ae->name);
......@@ -1272,7 +1268,7 @@ static int apk_db_unpack_pkg(struct apk_database *db,
ctx = (struct install_ctx) {
.db = db,
.pkg = newpkg,
.script = upgrade ?
.script = upgrade ?
APK_SCRIPT_PRE_UPGRADE : APK_SCRIPT_PRE_INSTALL,
.cb = cb,
.cb_ctx = cb_ctx,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment