From b7f9f9bdb21ffeb50f5814fdcce2f315215fdb1e Mon Sep 17 00:00:00 2001 From: Timo Teras Date: Tue, 13 Jan 2009 15:22:14 +0200 Subject: info: implement who owns packages query (apk_info -W) In quiet mode e.g. "apk info -q -W " a list of dependencies suitable for .PKGINFO is output in one line. --- src/info.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/info.c') diff --git a/src/info.c b/src/info.c index 2e41742..c981c18 100644 --- a/src/info.c +++ b/src/info.c @@ -54,6 +54,38 @@ static int info_exists(struct apk_database *db, int argc, char **argv) return 0; } +static int info_who_owns(struct apk_database *db, int argc, char **argv) +{ + struct apk_package *pkg; + struct apk_dependency_array *deps = NULL; + struct apk_dependency dep; + int i; + + for (i = 0; i < argc; i++) { + pkg = apk_db_get_file_owner(db, APK_BLOB_STR(argv[i])); + if (pkg == NULL) + continue; + + if (apk_quiet) { + dep = (struct apk_dependency) { + .name = pkg->name, + }; + apk_deps_add(&deps, &dep); + } else { + printf("%s is owned by %s-%s\n", argv[i], + pkg->name->name, pkg->version); + } + } + if (apk_quiet && deps != NULL) { + char buf[512]; + apk_deps_format(buf, sizeof(buf), deps); + printf("%s\n", buf); + free(deps); + } + + return 0; +} + static int info_parse(void *ctx, int optch, int optindex, const char *optarg) { struct info_ctx *ictx = (struct info_ctx *) ctx; @@ -62,6 +94,9 @@ static int info_parse(void *ctx, int optch, int optindex, const char *optarg) case 'e': ictx->action = info_exists; break; + case 'W': + ictx->action = info_who_owns; + break; default: return -1; } @@ -88,6 +123,7 @@ static int info_main(void *ctx, int argc, char **argv) static struct option info_options[] = { { "installed", no_argument, NULL, 'e' }, + { "who-owns", no_argument, NULL, 'W' }, }; static struct apk_applet apk_info = { -- cgit v1.2.3-60-g2f50