blob: function to checksum a blob
And use it in couple of places. Some whitespace fixes too.cute-signatures
parent
7a29678aac
commit
fac4cdb3fa
10
src/add.c
10
src/add.c
|
@ -41,14 +41,6 @@ static int add_parse(void *ctx, int optch, int optindex, const char *optarg)
|
||||||
return 0;
|
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)
|
static int cup(void)
|
||||||
{
|
{
|
||||||
/* compressed/uncompressed size is 259/1213 */
|
/* compressed/uncompressed size is 259/1213 */
|
||||||
|
@ -111,7 +103,7 @@ static int add_main(void *ctx, int argc, char **argv)
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
virtpkg->name = apk_db_get_name(&db, APK_BLOB_STR(actx->virtpkg));
|
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->version = strdup("0");
|
||||||
virtpkg->description = strdup("virtual meta package");
|
virtpkg->description = strdup("virtual meta package");
|
||||||
virtdep = apk_dep_from_pkg(&db, virtpkg);
|
virtdep = apk_dep_from_pkg(&db, virtpkg);
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#define APK_BLOB_H
|
#define APK_BLOB_H
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "apk_defines.h"
|
||||||
|
|
||||||
struct apk_blob {
|
struct apk_blob {
|
||||||
unsigned int len;
|
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 apk_blob_uint(apk_blob_t blob, int base);
|
||||||
unsigned long apk_blob_hash(apk_blob_t str);
|
unsigned long apk_blob_hash(apk_blob_t str);
|
||||||
int apk_blob_compare(apk_blob_t a, apk_blob_t b);
|
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,
|
int apk_blob_for_each_segment(apk_blob_t blob, const char *split,
|
||||||
apk_blob_cb cb, void *ctx);
|
apk_blob_cb cb, void *ctx);
|
||||||
|
|
11
src/blob.c
11
src/blob.c
|
@ -4,7 +4,7 @@
|
||||||
* Copyright (C) 2008 Timo Teräs <timo.teras@iki.fi>
|
* Copyright (C) 2008 Timo Teräs <timo.teras@iki.fi>
|
||||||
* All rights reserved.
|
* 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
|
* 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.
|
* 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;
|
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 apk_hexdump_parse(apk_blob_t to, apk_blob_t from)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* Copyright (C) 2008 Timo Teräs <timo.teras@iki.fi>
|
* Copyright (C) 2008 Timo Teräs <timo.teras@iki.fi>
|
||||||
* All rights reserved.
|
* 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
|
* 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.
|
* 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)
|
if (db->root == NULL)
|
||||||
return 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);
|
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;
|
char buf[2*sizeof(csum_t)+32], *name;
|
||||||
int r, n;
|
int r, n;
|
||||||
|
|
||||||
if (repository.ptr == NULL || *repository.ptr == '\0'
|
if (repository.ptr == NULL || *repository.ptr == '\0'
|
||||||
|| *repository.ptr == '#')
|
|| *repository.ptr == '#')
|
||||||
return 0;
|
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) {
|
if (apk_url_local_file(db->repos[r].url) == NULL) {
|
||||||
csum_ctx_t csum;
|
csum_t cs;
|
||||||
csum_t res;
|
|
||||||
|
|
||||||
csum_init(&csum);
|
apk_blob_csum(repository, cs);
|
||||||
csum_process(&csum, repository.ptr, repository.len);
|
n = apk_hexdump_format(sizeof(buf), buf, APK_BLOB_BUF(cs)) - 1;
|
||||||
csum_finish(&csum, res);
|
|
||||||
|
|
||||||
n = apk_hexdump_format(sizeof(buf), buf, APK_BLOB_BUF(res)) - 1;
|
|
||||||
snprintf(&buf[n], sizeof(buf) - n, ".index.gz");
|
snprintf(&buf[n], sizeof(buf) - n, ".index.gz");
|
||||||
|
|
||||||
db->repos[r].cache = strdup(buf);
|
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,
|
apk_db_file_change_owner(db, file, diri,
|
||||||
&ctx->file_diri_node);
|
&ctx->file_diri_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (apk_verbosity > 1)
|
if (apk_verbosity > 1)
|
||||||
printf("%s\n", ae->name);
|
printf("%s\n", ae->name);
|
||||||
|
|
||||||
|
@ -1272,7 +1268,7 @@ static int apk_db_unpack_pkg(struct apk_database *db,
|
||||||
ctx = (struct install_ctx) {
|
ctx = (struct install_ctx) {
|
||||||
.db = db,
|
.db = db,
|
||||||
.pkg = newpkg,
|
.pkg = newpkg,
|
||||||
.script = upgrade ?
|
.script = upgrade ?
|
||||||
APK_SCRIPT_PRE_UPGRADE : APK_SCRIPT_PRE_INSTALL,
|
APK_SCRIPT_PRE_UPGRADE : APK_SCRIPT_PRE_INSTALL,
|
||||||
.cb = cb,
|
.cb = cb,
|
||||||
.cb_ctx = cb_ctx,
|
.cb_ctx = cb_ctx,
|
||||||
|
|
Loading…
Reference in New Issue