summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2022-05-02 10:58:29 +0300
committerTimo Teräs <timo.teras@iki.fi>2022-06-03 14:41:11 +0300
commit9c97552e1dd987b3b636ced2cd0bb6ccaa74e1c6 (patch)
tree7fc3f99297671d68b63b56b00e2f426b7afbb4bc
parent892425381682008463b7528bdc994fb2bf6f5c71 (diff)
downloadapk-tools-9c97552e1dd987b3b636ced2cd0bb6ccaa74e1c6.tar.gz
apk-tools-9c97552e1dd987b3b636ced2cd0bb6ccaa74e1c6.tar.bz2
apk-tools-9c97552e1dd987b3b636ced2cd0bb6ccaa74e1c6.tar.xz
apk-tools-9c97552e1dd987b3b636ced2cd0bb6ccaa74e1c6.zip
fetch: implement --world
fixes #10838
-rw-r--r--doc/apk-fetch.8.scd3
-rw-r--r--src/app_fetch.c25
2 files changed, 23 insertions, 5 deletions
diff --git a/doc/apk-fetch.8.scd b/doc/apk-fetch.8.scd
index fa39241..dd86ce4 100644
--- a/doc/apk-fetch.8.scd
+++ b/doc/apk-fetch.8.scd
@@ -32,6 +32,9 @@ specified.
*Note*: this option is incompatible with *-o*, *-R*, and the global
*--progress* option.
+*-w, --world*
+ Download packages needed to satisfy _world_. Implies *--recursive*.
+
*--simulate*
Simulate the requested operation without making any changes.
diff --git a/src/app_fetch.c b/src/app_fetch.c
index adac2af..0cc1918 100644
--- a/src/app_fetch.c
+++ b/src/app_fetch.c
@@ -20,10 +20,11 @@
#include "apk_print.h"
#include "apk_solver.h"
-#define FETCH_RECURSIVE 1
-#define FETCH_STDOUT 2
-#define FETCH_LINK 4
-#define FETCH_URL 8
+#define FETCH_RECURSIVE 0x01
+#define FETCH_STDOUT 0x02
+#define FETCH_LINK 0x04
+#define FETCH_URL 0x08
+#define FETCH_WORLD 0x10
struct fetch_ctx {
unsigned int flags;
@@ -74,6 +75,7 @@ static int cup(void)
OPT(OPT_FETCH_simulate, "simulate") \
OPT(OPT_FETCH_stdout, APK_OPT_SH("s") "stdout") \
OPT(OPT_FETCH_url, "url") \
+ OPT(OPT_FETCH_world, APK_OPT_SH("w") "world") \
APK_OPT_APPLET(option_desc, FETCH_OPTIONS);
@@ -100,6 +102,10 @@ static int option_parse_applet(void *ctx, struct apk_db_options *dbopts, int opt
case OPT_FETCH_url:
fctx->flags |= FETCH_URL;
break;
+ case OPT_FETCH_world:
+ fctx->flags |= FETCH_WORLD | FETCH_RECURSIVE;
+ dbopts->open_flags &= ~APK_OPENF_NO_WORLD;
+ break;
default:
return -ENOTSUP;
}
@@ -223,6 +229,12 @@ static void mark_error(struct fetch_ctx *ctx, const char *match, struct apk_name
ctx->errors++;
}
+static void mark_dep_flags(struct fetch_ctx *ctx, struct apk_dependency *dep)
+{
+ dep->name->auto_select_virtual = 1;
+ apk_deps_add(&ctx->world, dep);
+}
+
static void mark_name_flags(struct apk_database *db, const char *match, struct apk_name *name, void *pctx)
{
struct fetch_ctx *ctx = (struct fetch_ctx *) pctx;
@@ -312,6 +324,7 @@ static int purge_package(void *pctx, int dirfd, const char *filename)
static int fetch_main(void *pctx, struct apk_database *db, struct apk_string_array *args)
{
struct fetch_ctx *ctx = (struct fetch_ctx *) pctx;
+ struct apk_dependency *dep;
if (ctx->flags & FETCH_STDOUT) {
apk_flags &= ~APK_PROGRESS;
@@ -331,6 +344,8 @@ static int fetch_main(void *pctx, struct apk_database *db, struct apk_string_arr
if (ctx->flags & FETCH_RECURSIVE) {
apk_dependency_array_init(&ctx->world);
+ foreach_array_item(dep, db->world)
+ mark_dep_flags(ctx, dep);
apk_name_foreach_matching(db, args, apk_foreach_genid(), mark_name_flags, ctx);
if (ctx->errors == 0)
mark_names_recursive(db, args, ctx);
@@ -351,7 +366,7 @@ static int fetch_main(void *pctx, struct apk_database *db, struct apk_string_arr
static struct apk_applet apk_fetch = {
.name = "fetch",
- .open_flags = APK_OPENF_READ | APK_OPENF_NO_STATE,
+ .open_flags = APK_OPENF_READ | APK_OPENF_NO_STATE,
.context_size = sizeof(struct fetch_ctx),
.optgroups = { &optgroup_global, &optgroup_applet },
.main = fetch_main,