diff options
author | Timo Teräs <timo.teras@iki.fi> | 2020-10-05 18:52:51 +0300 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2020-10-09 16:09:19 +0300 |
commit | 354713d2f746c197eed6a1feb4c6af3420af6c15 (patch) | |
tree | f9dd51bbdde0f25f8e122832cf006076b8452d28 /src/app_manifest.c | |
parent | 7a7eca86709fcf31dbb1acf8b82ff411828fb67b (diff) | |
download | apk-tools-354713d2f746c197eed6a1feb4c6af3420af6c15.tar.gz apk-tools-354713d2f746c197eed6a1feb4c6af3420af6c15.tar.bz2 apk-tools-354713d2f746c197eed6a1feb4c6af3420af6c15.tar.xz apk-tools-354713d2f746c197eed6a1feb4c6af3420af6c15.zip |
rename apk_db_options to apk_ctx, rework logging
makes apk_verbosity non-global
fixes #10682
Diffstat (limited to 'src/app_manifest.c')
-rw-r--r-- | src/app_manifest.c | 62 |
1 files changed, 39 insertions, 23 deletions
diff --git a/src/app_manifest.c b/src/app_manifest.c index c2e20e8..9b9a2db 100644 --- a/src/app_manifest.c +++ b/src/app_manifest.c @@ -24,43 +24,50 @@ static char *csum_types[APK_CHECKSUM_SHA1 + 1] = { [APK_CHECKSUM_SHA1] = "sha1", }; -struct manifest_file_ctx { - const char *file; - struct apk_sign_ctx *sctx; -}; - static void process_package(struct apk_database *db, struct apk_package *pkg) { + struct apk_out *out = &db->ctx->out; struct apk_installed_package *ipkg = pkg->ipkg; struct apk_db_dir_instance *diri; struct apk_db_file *file; struct hlist_node *dc, *dn, *fc, *fn; + const char *prefix1 = "", *prefix2 = ""; char csum_buf[APK_BLOB_CHECKSUM_BUF]; if (ipkg == NULL) return; + if (apk_out_verbosity(out) > 1) { + prefix1 = pkg->name->name; + prefix2 = ": "; + } + hlist_for_each_entry_safe(diri, dc, dn, &ipkg->owned_dirs, pkg_dirs_list) { hlist_for_each_entry_safe(file, fc, fn, &diri->owned_files, diri_files_list) { apk_blob_t csum_blob = APK_BLOB_BUF(csum_buf); - memset(csum_buf, '\0', sizeof(csum_buf)); apk_blob_push_hexdump(&csum_blob, APK_BLOB_CSUM(file->csum)); - if (apk_verbosity > 1) - printf("%s: ", pkg->name->name); - - printf("%s:%s " DIR_FILE_FMT "\n", csum_types[file->csum.type], csum_buf, DIR_FILE_PRINTF(diri->dir, file)); - } + apk_out(out, "%s%s%s:%s " DIR_FILE_FMT, + prefix1, prefix2, + csum_types[file->csum.type], csum_buf, + DIR_FILE_PRINTF(diri->dir, file)); + } } } -static int read_file_entry(void *ctx, const struct apk_file_info *ae, - struct apk_istream *is) +struct manifest_file_ctx { + struct apk_out *out; + struct apk_sign_ctx *sctx; + const char *prefix1, *prefix2; +}; + +static int read_file_entry(void *ctx, const struct apk_file_info *ae, struct apk_istream *is) { struct manifest_file_ctx *mctx = ctx; + struct apk_out *out = mctx->out; char csum_buf[APK_BLOB_CHECKSUM_BUF]; apk_blob_t csum_blob = APK_BLOB_BUF(csum_buf); int r; @@ -78,34 +85,43 @@ static int read_file_entry(void *ctx, const struct apk_file_info *ae, memset(csum_buf, '\0', sizeof(csum_buf)); apk_blob_push_hexdump(&csum_blob, APK_BLOB_CSUM(ae->csum)); - if (apk_verbosity > 1) - printf("%s: ", mctx->file); - - printf("%s:%s %s\n", csum_types[ae->csum.type], csum_buf, ae->name); + apk_out(out, "%s%s%s:%s %s\n", + mctx->prefix1, mctx->prefix2, + csum_types[ae->csum.type], csum_buf, ae->name); return 0; } static void process_file(struct apk_database *db, const char *match) { + struct apk_out *out = &db->ctx->out; struct apk_sign_ctx sctx; - struct manifest_file_ctx ctx = {match, &sctx}; + struct manifest_file_ctx ctx = { + .out = out, + .sctx = &sctx, + .prefix1 = "", + .prefix2 = "", + }; int r; - apk_sign_ctx_init(&sctx, APK_SIGN_VERIFY, NULL, db->keys_fd, db->flags & APK_ALLOW_UNTRUSTED); + if (apk_out_verbosity(out) > 1) { + ctx.prefix1 = match; + ctx.prefix2 = ": "; + } + + 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); apk_sign_ctx_free(&sctx); - if (r < 0) apk_error("%s: %s", match, apk_error_str(r)); + if (r < 0) apk_err(out, "%s: %s", match, apk_error_str(r)); } static void process_match(struct apk_database *db, const char *match, struct apk_name *name, void *ctx) { struct apk_provider *p; - if (name == NULL) - { + if (name == NULL) { process_file(db, match); return; } @@ -114,7 +130,7 @@ static void process_match(struct apk_database *db, const char *match, struct apk process_package(db, p->pkg); } -static int manifest_main(void *ctx, struct apk_database *db, struct apk_string_array *args) +static int manifest_main(void *applet_ctx, struct apk_database *db, struct apk_string_array *args) { apk_name_foreach_matching(db, args, apk_foreach_genid(), process_match, NULL); return 0; |