summaryrefslogtreecommitdiff
path: root/src/package.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2021-07-27 15:34:04 +0300
committerTimo Teräs <timo.teras@iki.fi>2021-07-27 16:28:22 +0300
commit5843daf7a1cdf15cbc76952c60a1d822414b2ef3 (patch)
tree46d5307df67341e3c8f90c3f3746f90c96da9459 /src/package.c
parent9c843e4ecdfee916ec835b5d35c10b3818aba9e3 (diff)
downloadapk-tools-5843daf7a1cdf15cbc76952c60a1d822414b2ef3.tar.gz
apk-tools-5843daf7a1cdf15cbc76952c60a1d822414b2ef3.tar.bz2
apk-tools-5843daf7a1cdf15cbc76952c60a1d822414b2ef3.tar.xz
apk-tools-5843daf7a1cdf15cbc76952c60a1d822414b2ef3.zip
Further refactor extract API to have separate ops vtable
This splits the callbacks by type, and further prepares the API to be usable for v3 files too.
Diffstat (limited to 'src/package.c')
-rw-r--r--src/package.c31
1 files changed, 10 insertions, 21 deletions
diff --git a/src/package.c b/src/package.c
index 9e272b6..3b634d6 100644
--- a/src/package.c
+++ b/src/package.c
@@ -592,29 +592,19 @@ static int read_info_line(struct read_info_ctx *ri, apk_blob_t line)
return 0;
}
-static int apk_pkg_parse_entry(struct apk_extract_ctx *ectx, const struct apk_file_info *ae,
- struct apk_istream *is)
+static int apk_pkg_v2meta(struct apk_extract_ctx *ectx, struct apk_istream *is)
{
struct read_info_ctx *ri = container_of(ectx, struct read_info_ctx, ectx);
- struct apk_package *pkg = ri->pkg;
-
- if (ectx->metadata_verified) return -ECANCELED;
- if (!ectx->metadata) return 0;
-
- if (strcmp(ae->name, ".PKGINFO") == 0) {
- /* APK 2.0 format */
- apk_blob_t l, token = APK_BLOB_STR("\n");
- while (apk_istream_get_delim(is, token, &l) == 0)
- read_info_line(ri, l);
- } else if (strcmp(ae->name, ".INSTALL") == 0) {
- apk_warn(&ri->db->ctx->out,
- "Package '%s-" BLOB_FMT "' contains deprecated .INSTALL",
- pkg->name->name, BLOB_PRINTF(*pkg->version));
- }
-
+ apk_blob_t l, token = APK_BLOB_STR("\n");
+ while (apk_istream_get_delim(is, token, &l) == 0)
+ read_info_line(ri, l);
return 0;
}
+static const struct apk_extract_ops extract_pkgmeta_ops = {
+ .v2meta = apk_pkg_v2meta,
+};
+
int apk_pkg_read(struct apk_database *db, const char *file, struct apk_package **pkg)
{
struct read_info_ctx ctx;
@@ -633,12 +623,11 @@ int apk_pkg_read(struct apk_database *db, const char *file, struct apk_package *
goto err;
ctx.pkg->size = fi.size;
- apk_extract_init(&ctx.ectx, db->ctx, apk_pkg_parse_entry);
+ apk_extract_init(&ctx.ectx, db->ctx, &extract_pkgmeta_ops);
apk_extract_generate_identity(&ctx.ectx, &ctx.pkg->csum);
r = apk_extract(&ctx.ectx, apk_istream_from_file(AT_FDCWD, file));
- if (r < 0 && r != -ECANCELED)
- goto err;
+ if (r < 0) goto err;
if (ctx.pkg->name == NULL || ctx.pkg->uninstallable) {
r = -ENOTSUP;
goto err;