From e69b81f5259f532d5f5ae9c0a0f9bbd81240fbaf Mon Sep 17 00:00:00 2001 From: Timo Teras Date: Mon, 13 Jul 2009 20:37:03 +0300 Subject: io: move csumming away from bstream to gunzip in future we want to checksum on gzip boundary basis, not the full file. --- src/package.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'src/package.c') diff --git a/src/package.c b/src/package.c index 6c51924..30b09b1 100644 --- a/src/package.c +++ b/src/package.c @@ -4,7 +4,7 @@ * Copyright (C) 2008 Timo Teräs * 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. */ @@ -415,10 +415,26 @@ static int read_info_entry(void *ctx, const struct apk_file_info *ae, return 0; } +static int apk_pkg_gzip_part(void *ctx, EVP_MD_CTX *mdctx, int part) +{ + struct read_info_ctx *ri = (struct read_info_ctx *) ctx; + + switch (part) { + case APK_MPART_BEGIN: + EVP_DigestInit_ex(mdctx, EVP_md5(), NULL); + break; + case APK_MPART_END: + EVP_DigestFinal_ex(mdctx, ri->pkg->csum, NULL); + break; + } + return 0; +} + struct apk_package *apk_pkg_read(struct apk_database *db, const char *file) { struct read_info_ctx ctx; struct apk_bstream *bs; + struct apk_istream *tar; char realfile[PATH_MAX]; if (realpath(file, realfile) < 0) @@ -434,12 +450,14 @@ struct apk_package *apk_pkg_read(struct apk_database *db, const char *file) ctx.db = db; ctx.has_install = 0; - if (apk_parse_tar_gz(bs, read_info_entry, &ctx) < 0) { + + tar = apk_bstream_gunzip_mpart(bs, FALSE, apk_pkg_gzip_part, &ctx); + if (apk_parse_tar(tar, read_info_entry, &ctx) < 0) { apk_error("File %s is not an APK archive", file); - bs->close(bs, NULL, NULL); + bs->close(bs, NULL); goto err; } - bs->close(bs, ctx.pkg->csum, &ctx.pkg->size); + bs->close(bs, &ctx.pkg->size); if (ctx.pkg->name == NULL) { apk_error("File %s is corrupted", file); @@ -682,7 +700,7 @@ struct apk_dependency apk_dep_from_str(struct apk_database *db, mask = apk_version_result_mask(v++); if (*v == '=') v++; - } + } return (struct apk_dependency) { .name = apk_db_get_name(db, name), .version = v, -- cgit v1.2.3-60-g2f50