summaryrefslogtreecommitdiff
path: root/src/info.c
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-01-13 15:22:14 +0200
committerTimo Teras <timo.teras@iki.fi>2009-01-13 15:22:14 +0200
commitb7f9f9bdb21ffeb50f5814fdcce2f315215fdb1e (patch)
treea77d7e52c7d61b6601ea6f0021bd529da3e85dbe /src/info.c
parentc831ead63c5fdb4d1e75c264084576cfefe581e6 (diff)
downloadapk-tools-b7f9f9bdb21ffeb50f5814fdcce2f315215fdb1e.tar.gz
apk-tools-b7f9f9bdb21ffeb50f5814fdcce2f315215fdb1e.tar.bz2
apk-tools-b7f9f9bdb21ffeb50f5814fdcce2f315215fdb1e.tar.xz
apk-tools-b7f9f9bdb21ffeb50f5814fdcce2f315215fdb1e.zip
info: implement who owns packages query (apk_info -W)
In quiet mode e.g. "apk info -q -W <file list>" a list of dependencies suitable for .PKGINFO is output in one line.
Diffstat (limited to 'src/info.c')
-rw-r--r--src/info.c36
1 files changed, 36 insertions, 0 deletions
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 = {