summaryrefslogtreecommitdiff
path: root/src/app_extract.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2021-07-26 16:25:03 +0300
committerTimo Teräs <timo.teras@iki.fi>2021-07-27 14:09:38 +0300
commit9c843e4ecdfee916ec835b5d35c10b3818aba9e3 (patch)
treed2c703035bbdaa1f21ce0e8ed0cf121b7388f656 /src/app_extract.c
parent2d4e88aeb1690220ce57420e8d1d9de327ae901d (diff)
downloadapk-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_extract.c')
-rw-r--r--src/app_extract.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/app_extract.c b/src/app_extract.c
index 89f3f5c..dd410e5 100644
--- a/src/app_extract.c
+++ b/src/app_extract.c
@@ -18,6 +18,7 @@
#include "apk_print.h"
#include "apk_adb.h"
#include "apk_pathbuilder.h"
+#include "apk_extract.h"
struct extract_ctx {
const char *destination;
@@ -151,7 +152,7 @@ static int apk_extract_volume(struct apk_ctx *ac, struct apk_file_info *fi, stru
return uvol_extract(ac, fi->uvol_name, size, fi->size, is, dctx);
}
-static int apk_extract_file(struct extract_ctx *ctx, off_t sz, struct apk_istream *is)
+static int apk_extract_adb_file(struct extract_ctx *ctx, off_t sz, struct apk_istream *is)
{
struct apk_ctx *ac = ctx->ac;
struct apk_out *out = &ac->out;
@@ -199,7 +200,7 @@ static int apk_extract_file(struct extract_ctx *ctx, off_t sz, struct apk_istrea
return -APKE_ADB_SCHEMA;
}
fi.mode |= mode;
- return apk_archive_entry_extract(
+ return apk_extract_file(
ctx->root_fd, &fi, 0, 0, is, 0, 0, 0,
ctx->extract_flags, out);
}
@@ -212,7 +213,7 @@ static int apk_extract_file(struct extract_ctx *ctx, off_t sz, struct apk_istrea
if (fi.uvol_name) {
r = apk_extract_volume(ac, &fi, is, &dctx);
} else {
- r = apk_archive_entry_extract(
+ r = apk_extract_file(
ctx->root_fd, &fi, 0, 0, is, 0, 0, &dctx,
ctx->extract_flags, out);
if (r < 0) return r;
@@ -245,7 +246,7 @@ static int apk_extract_directory(struct extract_ctx *ctx)
apk_extract_acl(&fi, adb_ro_obj(&ctx->path, ADBI_DI_ACL, &acl), apk_ctx_get_id_cache(ctx->ac));
fi.mode |= S_IFDIR;
- return apk_archive_entry_extract(
+ return apk_extract_file(
ctx->root_fd, &fi, 0, 0, 0, 0, 0, 0,
ctx->extract_flags, out);
}
@@ -285,7 +286,7 @@ static int apk_extract_next_file(struct extract_ctx *ctx)
APK_BLOB_IS_NULL(target)) {
return 0;
}
- r = apk_extract_file(ctx, 0, 0);
+ r = apk_extract_adb_file(ctx, 0, 0);
if (r != 0) return r;
} while (1);
}
@@ -316,7 +317,7 @@ static int apk_extract_data_block(struct adb *db, struct adb_block *b, struct ap
return -APKE_ADB_BLOCK;
}
- return apk_extract_file(ctx, sz, is);
+ return apk_extract_adb_file(ctx, sz, is);
}
static int apk_extract_pkg(struct extract_ctx *ctx, const char *fn)
@@ -367,12 +368,12 @@ static int extract_main(void *pctx, struct apk_ctx *ac, struct apk_string_array
return r;
}
-static struct apk_applet apk_extract = {
+static struct apk_applet app_extract = {
.name = "extract",
.context_size = sizeof(struct extract_ctx),
.optgroups = { &optgroup_global, &optgroup_applet },
.main = extract_main,
};
-APK_DEFINE_APPLET(apk_extract);
+APK_DEFINE_APPLET(app_extract);