From 93f0b3524c1263b99a1a4bf718c27e6ad7b6aea8 Mon Sep 17 00:00:00 2001 From: Timo Teras Date: Wed, 22 Jul 2009 14:56:27 +0300 Subject: various: more informative error messages --- src/package.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'src/package.c') diff --git a/src/package.c b/src/package.c index 5bf4478d4e9..e480c6f77f3 100644 --- a/src/package.c +++ b/src/package.c @@ -693,8 +693,8 @@ static int read_info_entry(void *ctx, const struct apk_file_info *ae, return 0; } -struct apk_package *apk_pkg_read(struct apk_database *db, const char *file, - struct apk_sign_ctx *sctx) +int apk_pkg_read(struct apk_database *db, const char *file, + struct apk_sign_ctx *sctx, struct apk_package **pkg) { struct read_info_ctx ctx; struct apk_file_info fi; @@ -704,16 +704,17 @@ struct apk_package *apk_pkg_read(struct apk_database *db, const char *file, int r; if (realpath(file, realfile) < 0) - return NULL; - if (apk_file_get_info(realfile, APK_CHECKSUM_NONE, &fi) < 0) - return NULL; + return -errno; + r = apk_file_get_info(realfile, APK_CHECKSUM_NONE, &fi); + if (r != 0) + return r; memset(&ctx, 0, sizeof(ctx)); ctx.sctx = sctx; ctx.pkg = apk_pkg_new(); + r = -ENOMEM; if (ctx.pkg == NULL) - return NULL; - + goto err; bs = apk_bstream_from_file(realfile); if (bs == NULL) goto err; @@ -727,11 +728,10 @@ struct apk_package *apk_pkg_read(struct apk_database *db, const char *file, tar->close(tar); if (r < 0 && r != -ECANCELED) goto err; - if (ctx.pkg->name == NULL) - goto err; - if (sctx->action == APK_SIGN_VERIFY && !sctx->data_verified && - !(apk_flags & APK_FORCE)) + if (ctx.pkg->name == NULL) { + r = -EBADMSG; goto err; + } if (sctx->action != APK_SIGN_VERIFY) ctx.pkg->csum = sctx->identity; @@ -744,10 +744,13 @@ struct apk_package *apk_pkg_read(struct apk_database *db, const char *file, } ctx.pkg->filename = strdup(realfile); - return apk_db_pkg_add(db, ctx.pkg); + ctx.pkg = apk_db_pkg_add(db, ctx.pkg); + if (pkg != NULL) + *pkg = ctx.pkg; + r = 0; err: apk_pkg_free(ctx.pkg); - return NULL; + return r; } void apk_pkg_free(struct apk_package *pkg) -- cgit v1.2.3