Commit a627ab8e authored by Timo Teräs's avatar Timo Teräs

make apk_database optional for applets that don't need it

The new v3 applets don't use it, and eventually all applets will
use the new formats only.

This prepares the code for this, and moves trust, id_cache, and
root_fd to apk_ctx which is enough for v3 applets at this time.

The generic code is made to not initialize apk_database if it's
not needed.
parent 354713d2
......@@ -480,10 +480,16 @@ int main(int argc, char **argv)
ctx.flags |= APK_SIMULATE;
ctx.flags &= ~APK_INTERACTIVE;
#endif
r = apk_db_open(&db, &ctx);
if (r != 0) {
apk_err(out, "Failed to open apk database: %s", apk_error_str(r));
goto err;
r = apk_ctx_prepare(&ctx);
if (r != 0) goto err;
if (ctx.open_flags) {
r = apk_db_open(&db, &ctx);
if (r != 0) {
apk_err(out, "Failed to open apk database: %s", apk_error_str(r));
goto err;
}
}
#ifdef TEST_MODE
......@@ -527,7 +533,7 @@ int main(int argc, char **argv)
apk_string_array_resize(&args, argc);
memcpy(args->item, argv, argc * sizeof(*argv));
r = applet->main(applet_ctx, &db, args);
r = applet->main(applet_ctx, &ctx, args);
apk_db_close(&db);
#ifdef TEST_MODE
......
......@@ -50,7 +50,7 @@ struct apk_applet {
unsigned int open_flags, forced_force;
int context_size;
int (*main)(void *ctx, struct apk_database *db, struct apk_string_array *args);
int (*main)(void *ctx, struct apk_ctx *ac, struct apk_string_array *args);
};
extern const struct apk_option_group optgroup_global, optgroup_commit, optgroup_signing;
......
......@@ -10,6 +10,8 @@
#define APK_CONTEXT_H
#include "apk_print.h"
#include "apk_io.h"
#include "adb.h"
#define APK_SIMULATE BIT(0)
#define APK_CLEAN_PROTECTED BIT(1)
......@@ -30,6 +32,25 @@
#define APK_FORCE_NON_REPOSITORY BIT(4)
#define APK_FORCE_BINARY_STDOUT BIT(5)
struct apk_database;
#define APK_OPENF_READ 0x0001
#define APK_OPENF_WRITE 0x0002
#define APK_OPENF_CREATE 0x0004
#define APK_OPENF_NO_INSTALLED 0x0010
#define APK_OPENF_NO_SCRIPTS 0x0020
#define APK_OPENF_NO_WORLD 0x0040
#define APK_OPENF_NO_SYS_REPOS 0x0100
#define APK_OPENF_NO_INSTALLED_REPO 0x0200
#define APK_OPENF_CACHE_WRITE 0x0400
#define APK_OPENF_NO_AUTOUPDATE 0x0800
#define APK_OPENF_NO_REPOS (APK_OPENF_NO_SYS_REPOS | \
APK_OPENF_NO_INSTALLED_REPO)
#define APK_OPENF_NO_STATE (APK_OPENF_NO_INSTALLED | \
APK_OPENF_NO_SCRIPTS | \
APK_OPENF_NO_WORLD)
struct apk_ctx {
unsigned int flags, force, lock_wait;
struct apk_out out;
......@@ -43,9 +64,24 @@ struct apk_ctx {
const char *repositories_file;
struct apk_string_array *repository_list;
struct apk_string_array *private_keys;
struct adb_trust trust;
struct apk_id_cache id_cache;
struct apk_database *db;
int root_fd, keys_fd;
};
void apk_ctx_init(struct apk_ctx *ac);
void apk_ctx_free(struct apk_ctx *ac);
int apk_ctx_prepare(struct apk_ctx *ac);
int apk_ctx_fd_keys(struct apk_ctx *ac);
struct adb_trust *apk_ctx_get_trust(struct apk_ctx *ac);
struct apk_id_cache *apk_ctx_get_id_cache(struct apk_ctx *ac);
static inline int apk_ctx_fd_root(struct apk_ctx *ac) { return ac->root_fd; }
static inline time_t apk_ctx_since(struct apk_ctx *ac, time_t since) {
return (ac->force & APK_FORCE_REFRESH) ? APK_ISTREAM_FORCE_REFRESH : since;
}
#endif
......@@ -21,8 +21,6 @@
#include "apk_provider_data.h"
#include "apk_solver_data.h"
#include "adb.h"
struct apk_name;
APK_ARRAY(apk_name_array, struct apk_name *);
......@@ -148,13 +146,11 @@ struct apk_database {
int compat_newfeatures : 1;
int compat_notinstallable : 1;
struct adb_trust trust;
struct apk_dependency_array *world;
struct apk_id_cache *id_cache;
struct apk_protected_path_array *protected_paths;
struct apk_repository repos[APK_MAX_REPOS];
struct apk_repository_tag repo_tags[APK_MAX_TAGS];
struct apk_id_cache id_cache;
struct apk_atom_pool atoms;
struct {
......@@ -192,23 +188,6 @@ struct apk_db_dir *apk_db_dir_query(struct apk_database *db, apk_blob_t name);
struct apk_db_file *apk_db_file_query(struct apk_database *db,
apk_blob_t dir, apk_blob_t name);
#define APK_OPENF_READ 0x0001
#define APK_OPENF_WRITE 0x0002
#define APK_OPENF_CREATE 0x0004
#define APK_OPENF_NO_INSTALLED 0x0010
#define APK_OPENF_NO_SCRIPTS 0x0020
#define APK_OPENF_NO_WORLD 0x0040
#define APK_OPENF_NO_SYS_REPOS 0x0100
#define APK_OPENF_NO_INSTALLED_REPO 0x0200
#define APK_OPENF_CACHE_WRITE 0x0400
#define APK_OPENF_NO_AUTOUPDATE 0x0800
#define APK_OPENF_NO_REPOS (APK_OPENF_NO_SYS_REPOS | \
APK_OPENF_NO_INSTALLED_REPO)
#define APK_OPENF_NO_STATE (APK_OPENF_NO_INSTALLED | \
APK_OPENF_NO_SCRIPTS | \
APK_OPENF_NO_WORLD)
void apk_db_init(struct apk_database *db);
int apk_db_open(struct apk_database *db, struct apk_ctx *ctx);
void apk_db_close(struct apk_database *db);
......@@ -219,7 +198,7 @@ int apk_db_fire_triggers(struct apk_database *db);
int apk_db_run_script(struct apk_database *db, char *fn, char **argv);
void apk_db_update_directory_permissions(struct apk_database *db);
static inline time_t apk_db_url_since(struct apk_database *db, time_t since) {
return (db->ctx->force & APK_FORCE_REFRESH) ? APK_ISTREAM_FORCE_REFRESH : since;
return apk_ctx_since(db->ctx, since);
}
struct apk_package *apk_db_pkg_add(struct apk_database *db, struct apk_package *pkg);
......
......@@ -221,14 +221,14 @@ static int mmap_and_dump_adb(struct adb_trust *trust, int fd)
return 0;
}
static int adbdump_main(void *pctx, struct apk_database *db, struct apk_string_array *args)
static int adbdump_main(void *pctx, struct apk_ctx *ac, struct apk_string_array *args)
{
struct apk_out *out = &db->ctx->out;
struct apk_out *out = &ac->out;
char **arg;
int r;
foreach_array_item(arg, args) {
r = mmap_and_dump_adb(&db->trust, open(*arg, O_RDONLY));
r = mmap_and_dump_adb(apk_ctx_get_trust(ac), open(*arg, O_RDONLY));
if (r) {
apk_err(out, "%s: %s", *arg, apk_error_str(r));
return r;
......@@ -240,7 +240,6 @@ static int adbdump_main(void *pctx, struct apk_database *db, struct apk_string_a
static struct apk_applet apk_adbdump = {
.name = "adbdump",
.open_flags = APK_OPENF_READ | APK_OPENF_NO_STATE | APK_OPENF_NO_REPOS,
.main = adbdump_main,
};
APK_DEFINE_APPLET(apk_adbdump);
......
......@@ -8,8 +8,8 @@
#include "apk_print.h"
struct sign_ctx {
struct apk_ctx *ac;
struct adb_xfrm xfrm;
struct apk_database *db;
int reset_signatures : 1;
int signatures_written : 1;
};
......@@ -41,6 +41,7 @@ static const struct apk_option_group optgroup_applet = {
static int update_signatures(struct adb_xfrm *xfrm, struct adb_block *blk, struct apk_istream *is)
{
struct sign_ctx *ctx = container_of(xfrm, struct sign_ctx, xfrm);
struct adb_trust *trust = apk_ctx_get_trust(ctx->ac);
int r;
switch (blk ? ADB_BLOCK_TYPE(blk) : -1) {
......@@ -53,7 +54,7 @@ static int update_signatures(struct adb_xfrm *xfrm, struct adb_block *blk, struc
default:
if (!ctx->signatures_written) {
ctx->signatures_written = 1;
r = adb_trust_write_signatures(&ctx->db->trust, &xfrm->db, &xfrm->vfy, xfrm->os);
r = adb_trust_write_signatures(trust, &xfrm->db, &xfrm->vfy, xfrm->os);
if (r) return r;
}
if (!blk) break;
......@@ -62,14 +63,14 @@ static int update_signatures(struct adb_xfrm *xfrm, struct adb_block *blk, struc
return 0;
}
static int adbsign_main(void *pctx, struct apk_database *db, struct apk_string_array *args)
static int adbsign_main(void *pctx, struct apk_ctx *ac, struct apk_string_array *args)
{
struct apk_out *out = &db->ctx->out;
struct apk_out *out = &ac->out;
struct sign_ctx *ctx = pctx;
char **arg;
int r;
ctx->db = db;
ctx->ac = ac;
foreach_array_item(arg, args) {
ctx->xfrm.is = apk_istream_from_file(AT_FDCWD, *arg);
ctx->xfrm.os = apk_ostream_to_file(AT_FDCWD, *arg, 0644);
......@@ -84,7 +85,6 @@ static int adbsign_main(void *pctx, struct apk_database *db, struct apk_string_a
static struct apk_applet apk_adbsign = {
.name = "adbsign",
.open_flags = APK_OPENF_READ | APK_OPENF_NO_STATE | APK_OPENF_NO_REPOS,
.context_size = sizeof(struct sign_ctx),
.optgroups = { &optgroup_global, &optgroup_signing, &optgroup_applet },
.main = adbsign_main,
......
......@@ -110,9 +110,10 @@ static struct apk_package *create_virtual_package(struct apk_database *db, struc
return virtpkg;
}
static int add_main(void *ctx, struct apk_database *db, struct apk_string_array *args)
static int add_main(void *ctx, struct apk_ctx *ac, struct apk_string_array *args)
{
struct apk_out *out = &db->ctx->out;
struct apk_out *out = &ac->out;
struct apk_database *db = ac->db;
struct add_ctx *actx = (struct add_ctx *) ctx;
struct apk_package *virtpkg = NULL;
struct apk_dependency virtdep;
......
......@@ -307,9 +307,10 @@ static int audit_missing_files(apk_hash_item item, void *pctx)
return 0;
}
static int audit_main(void *ctx, struct apk_database *db, struct apk_string_array *args)
static int audit_main(void *ctx, struct apk_ctx *ac, struct apk_string_array *args)
{
struct apk_out *out = &db->ctx->out;
struct apk_out *out = &ac->out;
struct apk_database *db = ac->db;
struct audit_tree_ctx atctx;
struct audit_ctx *actx = (struct audit_ctx *) ctx;
char **parg, *arg;
......
......@@ -146,9 +146,10 @@ static int cache_clean(struct apk_database *db)
return apk_db_cache_foreach_item(db, cache_clean_item);
}
static int cache_main(void *ctx, struct apk_database *db, struct apk_string_array *args)
static int cache_main(void *ctx, struct apk_ctx *ac, struct apk_string_array *args)
{
struct apk_out *out = &db->ctx->out;
struct apk_out *out = &ac->out;
struct apk_database *db = ac->db;
struct cache_ctx *cctx = (struct cache_ctx *) ctx;
char *arg;
int r = 0, actions = 0;
......
......@@ -18,7 +18,7 @@ struct conv_script {
};
struct conv_ctx {
struct apk_database *db;
struct apk_atom_pool atoms;
struct adb_obj pkgs;
struct list_head script_head;
......@@ -91,7 +91,7 @@ static int read_triggers(struct conv_ctx *ctx, struct apk_istream *is)
s = find_pkg(ctx, l, ADBI_SCRPT_TRIGGER);
if (!s) continue;
s->triggers = apk_atomize_dup(&ctx->db->atoms, r);
s->triggers = apk_atomize_dup(&ctx->atoms, r);
}
apk_istream_close(is);
......@@ -189,14 +189,15 @@ static void convert_idb(struct conv_ctx *ctx, struct apk_istream *is)
}
}
static int conv_main(void *pctx, struct apk_database *db, struct apk_string_array *args)
static int conv_main(void *pctx, struct apk_ctx *ac, struct apk_string_array *args)
{
struct conv_ctx *ctx = pctx;
struct adb_obj idb;
int r;
int root_fd = apk_ctx_fd_root(ac);
ctx->db = db;
list_init(&ctx->script_head);
apk_atom_init(&ctx->atoms);
adb_w_init_alloca(&ctx->dbi, ADB_SCHEMA_INSTALLED_DB, 10);
adb_w_init_alloca(&ctx->dbp, ADB_SCHEMA_PACKAGE, 1000);
......@@ -204,12 +205,12 @@ static int conv_main(void *pctx, struct apk_database *db, struct apk_string_arra
adb_wo_alloca(&ctx->pkgs, &schema_package_adb_array, &ctx->dbi);
apk_tar_parse(
apk_istream_from_file(db->root_fd, "lib/apk/db/scripts.tar"),
read_script, ctx, &db->id_cache);
apk_istream_from_file(root_fd, "lib/apk/db/scripts.tar"),
read_script, ctx, apk_ctx_get_id_cache(ac));
read_triggers(ctx, apk_istream_from_file(db->root_fd, "lib/apk/db/triggers"));
read_triggers(ctx, apk_istream_from_file(root_fd, "lib/apk/db/triggers"));
convert_idb(ctx, apk_istream_from_file(db->root_fd, "lib/apk/db/installed"));
convert_idb(ctx, apk_istream_from_file(root_fd, "lib/apk/db/installed"));
adb_wo_obj(&idb, ADBI_IDB_PACKAGES, &ctx->pkgs);
adb_w_rootobj(&idb);
......@@ -217,20 +218,20 @@ static int conv_main(void *pctx, struct apk_database *db, struct apk_string_arra
r = adb_c_create(
//apk_ostream_to_file(db->root_fd, "lib/apk/db/installed.adb", 0644),
apk_ostream_to_file(AT_FDCWD, "installed.adb", 0644),
&ctx->dbi, &db->trust);
&ctx->dbi, apk_ctx_get_trust(ac));
if (r == 0) {
// unlink old files
}
adb_free(&ctx->dbi);
adb_free(&ctx->dbp);
apk_atom_free(&ctx->atoms);
return r;
}
static struct apk_applet apk_convdb = {
.name = "convdb",
.open_flags = APK_OPENF_READ | APK_OPENF_NO_STATE | APK_OPENF_NO_REPOS,
.context_size = sizeof(struct conv_ctx),
.optgroups = { &optgroup_global, &optgroup_signing },
.main = conv_main,
......
......@@ -7,7 +7,7 @@
#include "apk_applet.h"
struct conv_ctx {
struct apk_database *db;
struct apk_ctx *ac;
struct adb_obj pkgs;
struct adb dbi;
struct apk_sign_ctx sctx;
......@@ -52,35 +52,37 @@ static int load_apkindex(void *sctx, const struct apk_file_info *fi,
static int load_index(struct conv_ctx *ctx, struct apk_istream *is)
{
struct apk_id_cache *idc = apk_ctx_get_id_cache(ctx->ac);
int r = 0;
if (IS_ERR_OR_NULL(is)) return is ? PTR_ERR(is) : -EINVAL;
ctx->found = 0;
apk_sign_ctx_init(&ctx->sctx, APK_SIGN_VERIFY, NULL, ctx->db->keys_fd, ctx->db->ctx->flags & APK_ALLOW_UNTRUSTED);
apk_sign_ctx_init(&ctx->sctx, APK_SIGN_VERIFY, NULL, apk_ctx_fd_keys(ctx->ac), ctx->ac->flags & APK_ALLOW_UNTRUSTED);
r = apk_tar_parse(
apk_istream_gunzip_mpart(is, apk_sign_ctx_mpart_cb, &ctx->sctx),
load_apkindex, ctx, &ctx->db->id_cache);
load_apkindex, ctx, idc);
apk_sign_ctx_free(&ctx->sctx);
if (r >= 0 && ctx->found == 0) r = -ENOMSG;
return r;
}
static int conv_main(void *pctx, struct apk_database *db, struct apk_string_array *args)
static int conv_main(void *pctx, struct apk_ctx *ac, struct apk_string_array *args)
{
char **arg;
struct conv_ctx *ctx = pctx;
struct adb_trust *trust = apk_ctx_get_trust(ac);
struct adb_obj ndx;
int r;
ctx->db = db;
ctx->ac = ac;
adb_w_init_alloca(&ctx->dbi, ADB_SCHEMA_INDEX, 1000);
adb_wo_alloca(&ndx, &schema_index, &ctx->dbi);
adb_wo_alloca(&ctx->pkgs, &schema_pkginfo_array, &ctx->dbi);
foreach_array_item(arg, args) {
r = load_index(ctx, apk_istream_from_url(*arg, apk_db_url_since(db, 0)));
r = load_index(ctx, apk_istream_from_url(*arg, apk_ctx_since(ac, 0)));
if (r) goto err;
fprintf(stderr, "%s: %u packages\n", *arg, adb_ra_num(&ctx->pkgs));
}
......@@ -88,7 +90,7 @@ static int conv_main(void *pctx, struct apk_database *db, struct apk_string_arra
adb_wo_obj(&ndx, ADBI_NDX_PACKAGES, &ctx->pkgs);
adb_w_rootobj(&ndx);
r = adb_c_create(apk_ostream_to_fd(STDOUT_FILENO), &ctx->dbi, &db->trust);
r = adb_c_create(apk_ostream_to_fd(STDOUT_FILENO), &ctx->dbi, trust);
err:
adb_free(&ctx->dbi);
......@@ -97,7 +99,6 @@ err:
static struct apk_applet apk_convndx = {
.name = "convndx",
.open_flags = APK_OPENF_READ | APK_OPENF_NO_STATE | APK_OPENF_NO_REPOS,
.context_size = sizeof(struct conv_ctx),
.optgroups = { &optgroup_global, &optgroup_signing },
.main = conv_main,
......
......@@ -131,8 +131,9 @@ static void delete_name(struct apk_database *db, const char *match,
apk_deps_del(&ctx->world, name);
}
static int del_main(void *pctx, struct apk_database *db, struct apk_string_array *args)
static int del_main(void *pctx, struct apk_ctx *ac, struct apk_string_array *args)
{
struct apk_database *db = ac->db;
struct del_ctx *ctx = (struct del_ctx *) pctx;
struct not_deleted_ctx ndctx = { .out = &db->ctx->out };
struct apk_changeset changeset = {};
......
......@@ -138,8 +138,9 @@ static int foreach_pkg(apk_hash_item item, void *ctx)
return 0;
}
static int dot_main(void *pctx, struct apk_database *db, struct apk_string_array *args)
static int dot_main(void *pctx, struct apk_ctx *ac, struct apk_string_array *args)
{
struct apk_database *db = ac->db;
struct dot_ctx *ctx = (struct dot_ctx *) pctx;
struct apk_provider *p;
char **parg;
......
......@@ -306,9 +306,10 @@ static int purge_package(void *pctx, int dirfd, const char *filename)
return 0;
}
static int fetch_main(void *pctx, struct apk_database *db, struct apk_string_array *args)
static int fetch_main(void *pctx, struct apk_ctx *ac, struct apk_string_array *args)
{
struct apk_out *out = &db->ctx->out;
struct apk_out *out = &ac->out;
struct apk_database *db = ac->db;
struct fetch_ctx *ctx = (struct fetch_ctx *) pctx;
ctx->db = db;
......
......@@ -86,8 +86,9 @@ static void set_solver_flags(struct apk_database *db, const char *match, struct
mark_fix(ctx, name);
}
static int fix_main(void *pctx, struct apk_database *db, struct apk_string_array *args)
static int fix_main(void *pctx, struct apk_ctx *ac, struct apk_string_array *args)
{
struct apk_database *db = ac->db;
struct fix_ctx *ctx = (struct fix_ctx *) pctx;
struct apk_installed_package *ipkg;
......
......@@ -105,9 +105,10 @@ static int warn_if_no_providers(apk_hash_item item, void *ctx)
return 0;
}
static int index_main(void *ctx, struct apk_database *db, struct apk_string_array *args)
static int index_main(void *ctx, struct apk_ctx *ac, struct apk_string_array *args)
{
struct apk_out *out = &db->ctx->out;
struct apk_out *out = &ac->out;
struct apk_database *db = ac->db;
struct counts counts = { .out = out };
struct apk_ostream *os;
struct apk_file_info fi;
......
......@@ -438,12 +438,14 @@ static int option_parse_applet(void *pctx, struct apk_ctx *ac, int opt, const ch
return 0;
}
static int info_main(void *ctx, struct apk_database *db, struct apk_string_array *args)
static int info_main(void *ctx, struct apk_ctx *ac, struct apk_string_array *args)
{
struct apk_out *out = &ac->out;
struct apk_database *db = ac->db;
struct info_ctx *ictx = (struct info_ctx *) ctx;
struct apk_installed_package *ipkg;
verbosity = apk_out_verbosity(&db->ctx->out);
verbosity = apk_out_verbosity(out);
ictx->db = db;
if (ictx->subaction_mask == 0)
ictx->subaction_mask = APK_INFO_DESC | APK_INFO_URL | APK_INFO_SIZE;
......
......@@ -226,11 +226,13 @@ static const struct apk_option_group optgroup_applet = {
.parse = option_parse_applet,
};
static int list_main(void *pctx, struct apk_database *db, struct apk_string_array *args)
static int list_main(void *pctx, struct apk_ctx *ac, struct apk_string_array *args)
{
struct apk_out *out = &ac->out;
struct apk_database *db = ac->db;
struct list_ctx *ctx = pctx;
ctx->verbosity = apk_out_verbosity(&db->ctx->out);
ctx->verbosity = apk_out_verbosity(out);
ctx->filters = args;
if (ctx->match_origin)
......
......@@ -94,6 +94,7 @@ static int read_file_entry(void *ctx, const struct apk_file_info *ae, struct apk
static void process_file(struct apk_database *db, const char *match)
{
struct apk_id_cache *idc = apk_ctx_get_id_cache(db->ctx);
struct apk_out *out = &db->ctx->out;
struct apk_sign_ctx sctx;
struct manifest_file_ctx ctx = {
......@@ -112,7 +113,7 @@ static void process_file(struct apk_database *db, const char *match)
apk_sign_ctx_init(&sctx, APK_SIGN_VERIFY, NULL, db->keys_fd, db->ctx->flags & APK_ALLOW_UNTRUSTED);
r = apk_tar_parse(
apk_istream_gunzip_mpart(apk_istream_from_file(AT_FDCWD, match), apk_sign_ctx_mpart_cb, &sctx),
read_file_entry, &ctx, &db->id_cache);
read_file_entry, &ctx, idc);
apk_sign_ctx_free(&sctx);
if (r < 0) apk_err(out, "%s: %s", match, apk_error_str(r));
}
......@@ -130,9 +131,9 @@ static void process_match(struct apk_database *db, const char *match, struct apk
process_package(db, p->pkg);
}
static int manifest_main(void *applet_ctx, struct apk_database *db, struct apk_string_array *args)
static int manifest_main(void *applet_ctx, struct apk_ctx *ac, struct apk_string_array *args)
{
apk_name_foreach_matching(db, args, apk_foreach_genid(), process_match, NULL);
apk_name_foreach_matching(ac->db, args, apk_foreach_genid(), process_match, NULL);
return 0;
}
......
......@@ -186,9 +186,11 @@ static int mkndx_parse_v2_tar(void *pctx, const struct apk_file_info *ae, struct
return 0;
}
static int mkndx_main(void *pctx, struct apk_database *db, struct apk_string_array *args)
static int mkndx_main(void *pctx, struct apk_ctx *ac, struct apk_string_array *args)
{
struct apk_out *out = &db->ctx->out;
struct apk_out *out = &ac->out;
struct apk_id_cache *idc = apk_ctx_get_id_cache(ac);
struct adb_trust *trust = apk_ctx_get_trust(ac);
struct adb odb, tmpdb;
struct adb_obj oroot, opkgs, ndx, tmpl;
struct apk_file_info fi;
......@@ -214,7 +216,7 @@ static int mkndx_main(void *pctx, struct apk_database *db, struct apk_string_arr
apk_fileinfo_get(AT_FDCWD, ctx->index, APK_CHECKSUM_NONE, &fi, 0);
index_mtime = fi.mtime;
r = adb_m_map(&odb, open(ctx->index, O_RDONLY), ADB_SCHEMA_INDEX, &db->trust);
r = adb_m_map(&odb, open(ctx->index, O_RDONLY), ADB_SCHEMA_INDEX, trust);
if (r) {
apk_err(out, "%s: %s", ctx->index, apk_error_str(r));
return r;
......@@ -274,10 +276,10 @@ static int mkndx_main(void *pctx, struct apk_database *db, struct apk_string_arr
}
if (!found) {
do_file:
apk_sign_ctx_init(&ctx->sctx, APK_SIGN_VERIFY, NULL, db->keys_fd, db->ctx->flags & APK_ALLOW_UNTRUSTED);
apk_sign_ctx_init(&ctx->sctx, APK_SIGN_VERIFY, NULL, apk_ctx_fd_keys(ac), ac->flags & APK_ALLOW_UNTRUSTED);
r = apk_tar_parse(
apk_istream_gunzip_mpart(apk_istream_from_file(AT_FDCWD, *parg), apk_sign_ctx_mpart_cb, &ctx->sctx),
mkndx_parse_v2_tar, ctx, &db->id_cache);
mkndx_parse_v2_tar, ctx, idc);
apk_sign_ctx_free(&ctx->sctx);
if (r < 0 && r != -ECANCELED) goto err_pkg;
newpkgs++;
......@@ -295,7 +297,7 @@ static int mkndx_main(void *pctx, struct apk_database *db, struct apk_string_arr
r = adb_c_create(
apk_ostream_to_file(AT_FDCWD, ctx->output, 0644),
&ctx->db, &db->trust);
&ctx->db, trust);
adb_free(&ctx->db);
adb_free(&odb);
......@@ -320,7 +322,6 @@ static int mkndx_main(void *pctx, struct apk_database *db, struct apk_string_arr
static struct apk_applet apk_mkndx = {
.name = "mkndx",
.open_flags = APK_OPENF_READ | APK_OPENF_NO_STATE | APK_OPENF_NO_REPOS,
.context_size = sizeof(struct mkndx_ctx),
.optgroups = { &optgroup_global, &optgroup_signing, &optgroup_applet },
.main = mkndx_main,
......
......@@ -61,9 +61,9 @@ zlib1g policy:
}
}
static int policy_main(void *ctx, struct apk_database *db, struct apk_string_array *args)