From f3fc0105f8c621bd1a77363cbb53f843c58100f4 Mon Sep 17 00:00:00 2001 From: Paul Spooren Date: Thu, 23 Dec 2021 13:43:11 +0000 Subject: [PATCH] list --manifest print installed packages in ` ` format. The format is currently used in OpenWrt and allows downstream tools to compare what's installed in the firmware. Signed-off-by: Paul Spooren --- doc/apk-list.8.scd | 3 +++ src/app_list.c | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/doc/apk-list.8.scd b/doc/apk-list.8.scd index e09577d..d41c692 100644 --- a/doc/apk-list.8.scd +++ b/doc/apk-list.8.scd @@ -38,3 +38,6 @@ globbing. *-P, --providers* List packages by provider. + +*--manifest* + List installed packages in format ` `. \ No newline at end of file diff --git a/src/app_list.c b/src/app_list.c index 5e14fe1..9489ee6 100644 --- a/src/app_list.c +++ b/src/app_list.c @@ -26,6 +26,7 @@ struct list_ctx { unsigned int match_origin : 1; unsigned int match_depends : 1; unsigned int match_providers : 1; + unsigned int manifest : 1; struct apk_string_array *filters; }; @@ -121,6 +122,11 @@ static void print_package(const struct apk_package *pkg, const struct list_ctx * printf("\n"); } +static void print_manifest(const struct apk_package *pkg, const struct list_ctx *ctx) +{ + printf("%s " BLOB_FMT "\n", pkg->name->name, BLOB_PRINTF(*pkg->version)); +} + static void filter_package(const struct apk_package *pkg, const struct list_ctx *ctx) { if (ctx->match_origin && !origin_matches(ctx, pkg)) @@ -138,7 +144,10 @@ static void filter_package(const struct apk_package *pkg, const struct list_ctx if (ctx->upgradable && !is_upgradable(pkg->name, pkg)) return; - print_package(pkg, ctx); + if (ctx->manifest) + print_manifest(pkg, ctx); + else + print_package(pkg, ctx); } static void iterate_providers(const struct apk_name *name, const struct list_ctx *ctx) @@ -180,6 +189,7 @@ static void print_result(struct apk_database *db, const char *match, struct apk_ OPT(OPT_LIST_orphaned, APK_OPT_SH("O") "orphaned") \ OPT(OPT_LIST_providers, APK_OPT_SH("P") "providers") \ OPT(OPT_LIST_upgradable, APK_OPT_SH("u") "upgradable") \ + OPT(OPT_LIST_manifest, "manifest") \ OPT(OPT_LIST_upgradeable, "upgradeable") APK_OPT_APPLET(option_desc, LIST_OPTIONS); @@ -209,6 +219,10 @@ static int option_parse_applet(void *pctx, struct apk_ctx *ac, int opt, const ch case OPT_LIST_providers: ctx->match_providers = 1; break; + case OPT_LIST_manifest: + ctx->manifest = 1; + ctx->installed = 1; + break; case OPT_LIST_upgradable: case OPT_LIST_upgradeable: ctx->available = 1;