index: more informative error message

when failed to load an existing index.
cute-signatures
Timo Teras 2009-07-23 11:35:40 +03:00
parent 90aaa28a95
commit a388f4bfa6
4 changed files with 16 additions and 10 deletions

View File

@ -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);
}

View File

@ -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)

View File

@ -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++) {

View File

@ -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)