extract: pass root object instead of database
parent
bd15683670
commit
fd42c073bf
|
@ -14,7 +14,7 @@
|
||||||
#include "apk_print.h"
|
#include "apk_print.h"
|
||||||
#include "apk_io.h"
|
#include "apk_io.h"
|
||||||
|
|
||||||
struct adb;
|
struct adb_obj;
|
||||||
struct apk_ctx;
|
struct apk_ctx;
|
||||||
struct apk_extract_ctx;
|
struct apk_extract_ctx;
|
||||||
|
|
||||||
|
@ -30,8 +30,8 @@ int apk_extract_file(int atfd, const struct apk_file_info *ae,
|
||||||
struct apk_extract_ops {
|
struct apk_extract_ops {
|
||||||
int (*v2index)(struct apk_extract_ctx *, apk_blob_t *desc, struct apk_istream *is);
|
int (*v2index)(struct apk_extract_ctx *, apk_blob_t *desc, struct apk_istream *is);
|
||||||
int (*v2meta)(struct apk_extract_ctx *, struct apk_istream *is);
|
int (*v2meta)(struct apk_extract_ctx *, struct apk_istream *is);
|
||||||
int (*v3index)(struct apk_extract_ctx *, struct adb *);
|
int (*v3index)(struct apk_extract_ctx *, struct adb_obj *);
|
||||||
int (*v3meta)(struct apk_extract_ctx *, struct adb *);
|
int (*v3meta)(struct apk_extract_ctx *, struct adb_obj *);
|
||||||
int (*script)(struct apk_extract_ctx *, unsigned int script, size_t size, struct apk_istream *is);
|
int (*script)(struct apk_extract_ctx *, unsigned int script, size_t size, struct apk_istream *is);
|
||||||
int (*file)(struct apk_extract_ctx *, const struct apk_file_info *fi, struct apk_istream *is);
|
int (*file)(struct apk_extract_ctx *, const struct apk_file_info *fi, struct apk_istream *is);
|
||||||
};
|
};
|
||||||
|
|
|
@ -133,7 +133,7 @@ static int apk_extract_volume(struct apk_ctx *ac, const struct apk_file_info *fi
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int extract_v3_meta(struct apk_extract_ctx *ectx, struct adb *db)
|
static int extract_v3_meta(struct apk_extract_ctx *ectx, struct adb_obj *pkg)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,19 +87,18 @@ static int process_pkg_file(struct apk_extract_ctx *ectx, const struct apk_file_
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int process_v3_meta(struct apk_extract_ctx *ectx, struct adb *db)
|
static int process_v3_meta(struct apk_extract_ctx *ectx, struct adb_obj *pkg)
|
||||||
{
|
{
|
||||||
struct manifest_file_ctx *mctx = container_of(ectx, struct manifest_file_ctx, ectx);
|
struct manifest_file_ctx *mctx = container_of(ectx, struct manifest_file_ctx, ectx);
|
||||||
struct apk_out *out = mctx->out;
|
struct apk_out *out = mctx->out;
|
||||||
struct adb_obj pkg, paths, path, files, file;
|
struct adb_obj paths, path, files, file;
|
||||||
struct apk_digest digest;
|
struct apk_digest digest;
|
||||||
struct apk_pathbuilder pb;
|
struct apk_pathbuilder pb;
|
||||||
char buf[APK_DIGEST_MAX_LENGTH*2+1];
|
char buf[APK_DIGEST_MAX_LENGTH*2+1];
|
||||||
apk_blob_t hex;
|
apk_blob_t hex;
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
adb_r_rootobj(db, &pkg, &schema_package);
|
adb_ro_obj(pkg, ADBI_PKG_PATHS, &paths);
|
||||||
adb_ro_obj(&pkg, ADBI_PKG_PATHS, &paths);
|
|
||||||
|
|
||||||
for (i = ADBI_FIRST; i <= adb_ra_num(&paths); i++) {
|
for (i = ADBI_FIRST; i <= adb_ra_num(&paths); i++) {
|
||||||
adb_ro_obj(&paths, i, &path);
|
adb_ro_obj(&paths, i, &path);
|
||||||
|
|
|
@ -176,15 +176,13 @@ static int mkndx_parse_v2meta(struct apk_extract_ctx *ectx, struct apk_istream *
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mkndx_parse_v3meta(struct apk_extract_ctx *ectx, struct adb *db)
|
static int mkndx_parse_v3meta(struct apk_extract_ctx *ectx, struct adb_obj *pkg)
|
||||||
{
|
{
|
||||||
struct mkndx_ctx *ctx = container_of(ectx, struct mkndx_ctx, ectx);
|
struct mkndx_ctx *ctx = container_of(ectx, struct mkndx_ctx, ectx);
|
||||||
struct adb_obj obj;
|
struct adb *db = pkg->db;
|
||||||
|
|
||||||
adb_r_rootobj(db, &obj, &schema_package);
|
|
||||||
|
|
||||||
adb_val_t o = adb_wa_append(&ctx->pkgs,
|
adb_val_t o = adb_wa_append(&ctx->pkgs,
|
||||||
adb_w_copy(&ctx->db, db, adb_ro_val(&obj, ADBI_PKG_PKGINFO)));
|
adb_w_copy(&ctx->db, db, adb_ro_val(pkg, ADBI_PKG_PKGINFO)));
|
||||||
if (ADB_IS_ERROR(o)) return -ADB_VAL_VALUE(o);
|
if (ADB_IS_ERROR(o)) return -ADB_VAL_VALUE(o);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,13 +120,14 @@ static int apk_extract_v3_next_file(struct apk_extract_ctx *ectx)
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (!ctx->cur_path) {
|
if (!ctx->cur_path) {
|
||||||
r = ectx->ops->v3meta(ectx, &ctx->db);
|
|
||||||
if (r < 0) return r;
|
|
||||||
|
|
||||||
// one time init
|
// one time init
|
||||||
ctx->cur_path = ADBI_FIRST;
|
ctx->cur_path = ADBI_FIRST;
|
||||||
ctx->cur_file = 0;
|
ctx->cur_file = 0;
|
||||||
adb_r_rootobj(&ctx->db, &ctx->pkg, &schema_package);
|
adb_r_rootobj(&ctx->db, &ctx->pkg, &schema_package);
|
||||||
|
|
||||||
|
r = ectx->ops->v3meta(ectx, &ctx->pkg);
|
||||||
|
if (r < 0) return r;
|
||||||
|
|
||||||
adb_ro_obj(&ctx->pkg, ADBI_PKG_PATHS, &ctx->paths);
|
adb_ro_obj(&ctx->pkg, ADBI_PKG_PATHS, &ctx->paths);
|
||||||
adb_ro_obj(&ctx->paths, ctx->cur_path, &ctx->path);
|
adb_ro_obj(&ctx->paths, ctx->cur_path, &ctx->path);
|
||||||
adb_ro_obj(&ctx->path, ADBI_DI_FILES, &ctx->files);
|
adb_ro_obj(&ctx->path, ADBI_DI_FILES, &ctx->files);
|
||||||
|
@ -190,12 +191,12 @@ static int apk_extract_v3_data_block(struct adb *db, struct adb_block *b, struct
|
||||||
return apk_extract_v3_file(ectx, sz, is);
|
return apk_extract_v3_file(ectx, sz, is);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int apk_extract_v3_verify_index(struct apk_extract_ctx *ectx, struct adb *db)
|
static int apk_extract_v3_verify_index(struct apk_extract_ctx *ectx, struct adb_obj *obj)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int apk_extract_v3_verify_meta(struct apk_extract_ctx *ectx, struct adb *db)
|
static int apk_extract_v3_verify_meta(struct apk_extract_ctx *ectx, struct adb_obj *obj)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -222,6 +223,7 @@ int apk_extract_v3(struct apk_extract_ctx *ectx, struct apk_istream *is)
|
||||||
struct apk_extract_v3_ctx ctx = {
|
struct apk_extract_v3_ctx ctx = {
|
||||||
.ectx = ectx,
|
.ectx = ectx,
|
||||||
};
|
};
|
||||||
|
struct adb_obj obj;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (IS_ERR(is)) return PTR_ERR(is);
|
if (IS_ERR(is)) return PTR_ERR(is);
|
||||||
|
@ -244,7 +246,8 @@ int apk_extract_v3(struct apk_extract_ctx *ectx, struct apk_istream *is)
|
||||||
r = -APKE_FORMAT_NOT_SUPPORTED;
|
r = -APKE_FORMAT_NOT_SUPPORTED;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
r = ectx->ops->v3index(ectx, &ctx.db);
|
adb_r_rootobj(&ctx.db, &obj, &schema_index);
|
||||||
|
r = ectx->ops->v3index(ectx, &obj);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
r = -APKE_ADB_SCHEMA;
|
r = -APKE_ADB_SCHEMA;
|
||||||
|
|
Loading…
Reference in New Issue