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;
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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_t cs;
|
||||
|
||||
csum_init(&csum);
|
||||
csum_process(&csum, repository.ptr, repository.len);
|
||||
csum_finish(&csum, res);
|
||||
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue