From 433da92e374d8924abda3b78b6652971870b9697 Mon Sep 17 00:00:00 2001 From: Timo Teräs Date: Tue, 28 Jun 2011 15:40:52 +0300 Subject: index: handle errors instead of silently failing Make indexer keep noise about errors that prevent index generation. Detect certain errors in the APKs better. And also have the applet return error in these scenarios. --- src/database.c | 19 +++++++++++++------ src/index.c | 16 ++++++++++++++-- src/package.c | 18 ++++++++++++++---- 3 files changed, 41 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/database.c b/src/database.c index 9617b4e..9a977f4 100644 --- a/src/database.c +++ b/src/database.c @@ -1005,8 +1005,11 @@ static int apk_db_index_write_nr_cache(struct apk_database *db) int apk_db_index_write(struct apk_database *db, struct apk_ostream *os) { struct index_write_ctx ctx = { os, 0, FALSE }; + int r; - apk_hash_foreach(&db->available.packages, write_index_entry, &ctx); + r = apk_hash_foreach(&db->available.packages, write_index_entry, &ctx); + if (r < 0) + return r; return ctx.count; } @@ -1634,9 +1637,11 @@ static int load_apkindex(void *sctx, const struct apk_file_info *fi, struct apkindex_ctx *ctx = (struct apkindex_ctx *) sctx; struct apk_bstream *bs; struct apk_repository *repo; + int r; - if (apk_sign_ctx_process_file(&ctx->sctx, fi, is) == 0) - return 0; + r = apk_sign_ctx_process_file(&ctx->sctx, fi, is); + if (r <= 0) + return r; repo = &ctx->db->repos[ctx->repo]; @@ -1819,12 +1824,14 @@ static int apk_db_install_archive_entry(void *_ctx, apk_blob_t name = APK_BLOB_STR(ae->name), bdir, bfile; struct apk_db_dir_instance *diri = ctx->diri; struct apk_db_file *file; - int r = 0, type = APK_SCRIPT_INVALID; + int r, type = APK_SCRIPT_INVALID; - if (apk_sign_ctx_process_file(&ctx->sctx, ae, is) == 0) - return 0; + r = apk_sign_ctx_process_file(&ctx->sctx, ae, is); + if (r <= 0) + return r; /* Package metainfo and script processing */ + r = 0; if (ae->name[0] == '.') { /* APK 2.0 format */ if (strcmp(ae->name, ".PKGINFO") == 0) { diff --git a/src/index.c b/src/index.c index 442e98a..f3f6992 100644 --- a/src/index.c +++ b/src/index.c @@ -90,7 +90,7 @@ static int index_main(void *ctx, struct apk_database *db, int argc, char **argv) struct counts counts = {0}; struct apk_ostream *os; struct apk_file_info fi; - int total, r, i, j, found, newpkgs = 0; + int total, r, i, j, found, newpkgs = 0, errors = 0; struct index_ctx *ictx = (struct index_ctx *) ctx; struct apk_package *pkg; @@ -160,13 +160,20 @@ static int index_main(void *ctx, struct apk_database *db, int argc, char **argv) if (!found) { struct apk_sign_ctx sctx; apk_sign_ctx_init(&sctx, ictx->method, NULL, db->keys_fd); - if (apk_pkg_read(db, argv[i], &sctx, &pkg) == 0) + r = apk_pkg_read(db, argv[i], &sctx, &pkg); + if (r < 0) { + apk_error("%s: %s", argv[i], apk_error_str(r)); + errors++; + } else { newpkgs++; + } if (ictx->rewrite_arch != NULL) pkg->arch = ictx->rewrite_arch; apk_sign_ctx_free(&sctx); } } + if (errors) + return -1; if (ictx->output != NULL) os = apk_ostream_to_file(AT_FDCWD, ictx->output, NULL, 0644); @@ -202,6 +209,11 @@ static int index_main(void *ctx, struct apk_database *db, int argc, char **argv) } os->close(os); + if (total < 0) { + apk_error("Index generation failed: %s", apk_error_str(r)); + return total; + } + apk_hash_foreach(&db->available.names, warn_if_no_providers, &counts); if (counts.unsatisfied != 0) diff --git a/src/package.c b/src/package.c index 2699420..28e091b 100644 --- a/src/package.c +++ b/src/package.c @@ -424,6 +424,12 @@ int apk_sign_ctx_process_file(struct apk_sign_ctx *ctx, return 1; if (fi->name[0] != '.' || strchr(fi->name, '/') != NULL) { + /* APKv1.0 compatibility - first non-hidden file is + * considered to start the data section of the file. + * This does not make any sense if the file has v2.0 + * style .PKGINFO */ + if (ctx->has_data_checksum) + return -ENOMSG; ctx->data_started = 1; ctx->control_started = 1; return 1; @@ -502,9 +508,11 @@ int apk_sign_ctx_verify_tar(void *sctx, const struct apk_file_info *fi, struct apk_istream *is) { struct apk_sign_ctx *ctx = (struct apk_sign_ctx *) sctx; + int r; - if (apk_sign_ctx_process_file(ctx, fi, is) == 0) - return 0; + r = apk_sign_ctx_process_file(ctx, fi, is); + if (r <= 0) + return r; if (strcmp(fi->name, ".PKGINFO") == 0) { apk_blob_t blob = apk_blob_from_istream(is, fi->size); @@ -734,10 +742,12 @@ static int read_info_entry(void *ctx, const struct apk_file_info *ae, { struct read_info_ctx *ri = (struct read_info_ctx *) ctx; struct apk_package *pkg = ri->pkg; + int r; /* Meta info and scripts */ - if (apk_sign_ctx_process_file(ri->sctx, ae, is) == 0) - return 0; + r = apk_sign_ctx_process_file(ri->sctx, ae, is); + if (r <= 0) + return r; if (ae->name[0] == '.') { /* APK 2.0 format */ -- cgit v1.2.3-70-g09d2