diff options
author | Timo Teräs <timo.teras@iki.fi> | 2021-07-26 16:25:03 +0300 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2021-07-27 14:09:38 +0300 |
commit | 9c843e4ecdfee916ec835b5d35c10b3818aba9e3 (patch) | |
tree | d2c703035bbdaa1f21ce0e8ed0cf121b7388f656 /src/app_convndx.c | |
parent | 2d4e88aeb1690220ce57420e8d1d9de327ae901d (diff) | |
download | apk-tools-9c843e4ecdfee916ec835b5d35c10b3818aba9e3.tar.gz apk-tools-9c843e4ecdfee916ec835b5d35c10b3818aba9e3.tar.bz2 apk-tools-9c843e4ecdfee916ec835b5d35c10b3818aba9e3.tar.xz apk-tools-9c843e4ecdfee916ec835b5d35c10b3818aba9e3.zip |
Refactor .apk extraction code
This moves and isolates the tar code to tar.c. And the actual
file extraction to disk is moved to extract.c.
A new API is introduced and used for v2 file extraction. This
essentially moves and isolates the apk_sign_ctx_* beast into
extract_v2.c and offers a saner interface to handling packages.
A place holder is added for v3 extraction.
Diffstat (limited to 'src/app_convndx.c')
-rw-r--r-- | src/app_convndx.c | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/src/app_convndx.c b/src/app_convndx.c index 21015cb..d405b03 100644 --- a/src/app_convndx.c +++ b/src/app_convndx.c @@ -4,12 +4,13 @@ #include "apk_adb.h" #include "apk_applet.h" +#include "apk_extract.h" struct conv_ctx { struct apk_ctx *ac; struct adb_obj pkgs; struct adb dbi; - struct apk_sign_ctx sctx; + struct apk_extract_ctx ectx; int found; }; @@ -31,38 +32,27 @@ static void convert_index(struct conv_ctx *ctx, struct apk_istream *is) } } -static int load_apkindex(void *sctx, const struct apk_file_info *fi, +static int load_apkindex(struct apk_extract_ctx *ectx, const struct apk_file_info *fi, struct apk_istream *is) { - struct conv_ctx *ctx = sctx; - int r; - - r = apk_sign_ctx_process_file(&ctx->sctx, fi, is); - if (r <= 0) return r; + struct conv_ctx *ctx = container_of(ectx, struct conv_ctx, ectx); if (strcmp(fi->name, "APKINDEX") == 0) { ctx->found = 1; convert_index(ctx, is); return apk_istream_close(is); } - return 0; } static int load_index(struct conv_ctx *ctx, struct apk_istream *is) { int r = 0; - - if (IS_ERR_OR_NULL(is)) return is ? PTR_ERR(is) : -EINVAL; - + if (IS_ERR(is)) return PTR_ERR(is); ctx->found = 0; - apk_sign_ctx_init(&ctx->sctx, APK_SIGN_VERIFY, NULL, apk_ctx_get_trust(ctx->ac)); - r = apk_tar_parse( - apk_istream_gunzip_mpart(is, apk_sign_ctx_mpart_cb, &ctx->sctx), - load_apkindex, ctx, apk_ctx_get_id_cache(ctx->ac)); - apk_sign_ctx_free(&ctx->sctx); + apk_extract_init(&ctx->ectx, ctx->ac, load_apkindex); + r = apk_extract(&ctx->ectx, is); if (r >= 0 && ctx->found == 0) r = -APKE_V2NDX_FORMAT; - return r; } |