tar: make checksumming of inner files conditional

and force checksumming only when unpacking archive. otherwise
it's extra computation for nothing.
cute-signatures
Timo Teras 2009-07-29 19:16:04 +03:00
parent 2887e04cd7
commit 7b05eef61f
5 changed files with 19 additions and 12 deletions

View File

@ -20,8 +20,11 @@ typedef int (*apk_archive_entry_parser)(void *ctx,
const struct apk_file_info *ae,
struct apk_istream *istream);
int apk_tar_parse(struct apk_istream *, apk_archive_entry_parser parser, void *ctx);
int apk_tar_write_entry(struct apk_ostream *, const struct apk_file_info *ae, char *data);
int apk_tar_parse(struct apk_istream *,
apk_archive_entry_parser parser, void *ctx,
int soft_checksums);
int apk_tar_write_entry(struct apk_ostream *, const struct apk_file_info *ae,
char *data);
int apk_tar_write_padding(struct apk_ostream *, const struct apk_file_info *ae);
int apk_archive_entry_extract(const struct apk_file_info *ae,

View File

@ -114,7 +114,7 @@ static void tar_entry_close(void *stream)
}
int apk_tar_parse(struct apk_istream *is, apk_archive_entry_parser parser,
void *ctx)
void *ctx, int soft_checksums)
{
struct apk_file_info entry;
struct apk_tar_entry_istream teis = {
@ -152,6 +152,7 @@ int apk_tar_parse(struct apk_istream *is, apk_archive_entry_parser parser,
.device = makedev(GET_OCTAL(buf.devmajor),
GET_OCTAL(buf.devminor)),
};
teis.csum = NULL;
switch (buf.typeflag) {
case 'L':
@ -170,8 +171,7 @@ int apk_tar_parse(struct apk_istream *is, apk_archive_entry_parser parser,
di->size <= sizeof(entry.csum.data)) {
entry.csum.type = di->size;
memcpy(entry.csum.data, di->digest, di->size);
teis.csum = NULL;
} else {
} else if (soft_checksums) {
teis.csum = &entry.csum;
}
break;
@ -202,7 +202,10 @@ int apk_tar_parse(struct apk_istream *is, apk_archive_entry_parser parser,
entry.name = strdup(buf.name);
/* callback parser function */
EVP_DigestInit_ex(&teis.mdctx, apk_default_checksum(), NULL);
if (teis.csum != NULL)
EVP_DigestInit_ex(&teis.mdctx,
apk_default_checksum(), NULL);
r = parser(ctx, &entry, &teis.is);
free(entry.name);
if (r != 0)

View File

@ -706,7 +706,8 @@ static int apk_db_read_state(struct apk_database *db, int flags)
if (!(flags & APK_OPENF_NO_SCRIPTS)) {
is = apk_istream_from_file("var/lib/apk/scripts.tar");
if (is != NULL) {
apk_tar_parse(is, apk_read_script_archive_entry, db);
apk_tar_parse(is, apk_read_script_archive_entry, db,
FALSE);
} else {
is = apk_istream_from_file("var/lib/apk/scripts");
if (is != NULL)
@ -1119,7 +1120,7 @@ int apk_cache_download(struct apk_database *db, struct apk_checksum *csum,
apk_sign_ctx_init(&sctx, APK_SIGN_VERIFY, NULL);
is = apk_bstream_gunzip_mpart(apk_bstream_from_file(tmp2),
apk_sign_ctx_mpart_cb, &sctx);
r = apk_tar_parse(is, apk_sign_ctx_verify_tar, &sctx);
r = apk_tar_parse(is, apk_sign_ctx_verify_tar, &sctx, FALSE);
is->close(is);
apk_sign_ctx_free(&sctx);
if (r != 0) {
@ -1224,7 +1225,7 @@ static int load_index(struct apk_database *db, struct apk_bstream *bs,
ctx.found = 0;
apk_sign_ctx_init(&ctx.sctx, APK_SIGN_VERIFY, NULL);
is = apk_bstream_gunzip_mpart(bs, apk_sign_ctx_mpart_cb, &ctx.sctx);
r = apk_tar_parse(is, load_apkindex, &ctx);
r = apk_tar_parse(is, load_apkindex, &ctx, FALSE);
is->close(is);
apk_sign_ctx_free(&ctx.sctx);
if (ctx.found == 0)
@ -1639,7 +1640,7 @@ static int apk_db_unpack_pkg(struct apk_database *db,
};
apk_sign_ctx_init(&ctx.sctx, APK_SIGN_VERIFY_IDENTITY, &newpkg->csum);
tar = apk_bstream_gunzip_mpart(bs, apk_sign_ctx_mpart_cb, &ctx.sctx);
r = apk_tar_parse(tar, apk_db_install_archive_entry, &ctx);
r = apk_tar_parse(tar, apk_db_install_archive_entry, &ctx, TRUE);
apk_sign_ctx_free(&ctx.sctx);
tar->close(tar);

View File

@ -713,7 +713,7 @@ int apk_pkg_read(struct apk_database *db, const char *file,
ctx.pkg->size = fi.size;
tar = apk_bstream_gunzip_mpart(bs, apk_sign_ctx_mpart_cb, sctx);
r = apk_tar_parse(tar, read_info_entry, &ctx);
r = apk_tar_parse(tar, read_info_entry, &ctx, FALSE);
tar->close(tar);
if (r < 0 && r != -ECANCELED)
goto err;

View File

@ -25,7 +25,7 @@ static int verify_main(void *ctx, int argc, char **argv)
apk_sign_ctx_init(&sctx, APK_SIGN_VERIFY, NULL);
is = apk_bstream_gunzip_mpart(apk_bstream_from_file(argv[i]),
apk_sign_ctx_mpart_cb, &sctx);
r = apk_tar_parse(is, apk_sign_ctx_verify_tar, &sctx);
r = apk_tar_parse(is, apk_sign_ctx_verify_tar, &sctx, FALSE);
is->close(is);
ok = sctx.control_verified && sctx.data_verified;
if (apk_verbosity >= 1)