diff options
-rw-r--r-- | src/apk.c | 2 | ||||
-rw-r--r-- | src/database.c | 14 | ||||
-rw-r--r-- | src/index.c | 8 | ||||
-rw-r--r-- | src/package.c | 2 |
4 files changed, 16 insertions, 10 deletions
@@ -67,6 +67,8 @@ const char *apk_error_str(int error) return "IO ERROR"; case EBADMSG: return "BAD archive"; + case ENOMSG: + return "archive does not contain expected data"; default: return strerror(error); } diff --git a/src/database.c b/src/database.c index 719a445..076f72f 100644 --- a/src/database.c +++ b/src/database.c @@ -1165,12 +1165,14 @@ static int load_apkindex(void *sctx, const struct apk_file_info *fi, apk_db_index_read(ctx->db, bs, ctx->repo); bs->close(bs, NULL); - return 0; + return -ECANCELED; } static int load_index(struct apk_database *db, struct apk_bstream *bs, int targz, int repo) { + int r = 0; + if (targz) { struct apk_istream *is; struct apkindex_ctx ctx; @@ -1179,17 +1181,19 @@ static int load_index(struct apk_database *db, struct apk_bstream *bs, ctx.repo = repo; apk_sign_ctx_init(&ctx.sctx, APK_SIGN_VERIFY, NULL); is = apk_bstream_gunzip_mpart(bs, apk_sign_ctx_mpart_cb, &ctx.sctx); - apk_tar_parse(is, load_apkindex, &ctx); + r = apk_tar_parse(is, load_apkindex, &ctx); is->close(is); apk_sign_ctx_free(&ctx.sctx); - if (!ctx.sctx.data_verified) - return -1; + if (r == 0) + r = -ENOMSG; + else if (r == -ECANCELED) + r = 0; } else { bs = apk_bstream_from_istream(apk_bstream_gunzip(bs)); apk_db_index_read(db, bs, repo); bs->close(bs, NULL); } - return 0; + return r; } int apk_db_index_read_file(struct apk_database *db, const char *file, int repo) diff --git a/src/index.c b/src/index.c index cd0c0b5..c27d020 100644 --- a/src/index.c +++ b/src/index.c @@ -86,7 +86,7 @@ static int index_main(void *ctx, int argc, char **argv) struct counts counts = {0}; struct apk_ostream *os; struct apk_file_info fi; - int total, i, j, found, newpkgs = 0; + int total, r, i, j, found, newpkgs = 0; struct index_ctx *ictx = (struct index_ctx *) ctx; if (isatty(STDOUT_FILENO) && ictx->output == NULL && @@ -100,10 +100,10 @@ static int index_main(void *ctx, int argc, char **argv) ictx->method = APK_SIGN_GENERATE; apk_db_open(&db, NULL, APK_OPENF_READ); - if (index_read_file(&db, ictx) < 0) { + if ((r = index_read_file(&db, ictx)) < 0) { apk_db_close(&db); - apk_error("The index is corrupt, or of unknown format."); - return -1; + apk_error("%s: %s", ictx->index, apk_error_str(r)); + return r; } for (i = 0; i < argc; i++) { diff --git a/src/package.c b/src/package.c index 1c9ff3d..1d2e50a 100644 --- a/src/package.c +++ b/src/package.c @@ -723,7 +723,7 @@ int apk_pkg_read(struct apk_database *db, const char *file, if (r < 0 && r != -ECANCELED) goto err; if (ctx.pkg->name == NULL) { - r = -EBADMSG; + r = -ENOMSG; goto err; } if (sctx->action != APK_SIGN_VERIFY) |