summaryrefslogtreecommitdiff
path: root/src
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-05-04 19:56:04 +0300
commitff7c8f6ee9dfa2add57b88dc271f6711030e72a0 (patch)
treeb2f6adf4fa33a27ddf60db411662efd2e8cdea89 /src
parentf8cf7a0a0dfd6e84741d1bf28e575690cd376356 (diff)
downloadapk-tools-ff7c8f6ee9dfa2add57b88dc271f6711030e72a0.tar.gz
apk-tools-ff7c8f6ee9dfa2add57b88dc271f6711030e72a0.tar.bz2
apk-tools-ff7c8f6ee9dfa2add57b88dc271f6711030e72a0.tar.xz
apk-tools-ff7c8f6ee9dfa2add57b88dc271f6711030e72a0.zip
fetch: implement --world
fixes #10838
Diffstat (limited to 'src')
-rw-r--r--src/app_fetch.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/app_fetch.c b/src/app_fetch.c
index 76d7a12..7c57d89 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;
@@ -75,6 +76,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);
@@ -101,6 +103,10 @@ static int option_parse_applet(void *ctx, struct apk_ctx *ac, int opt, const cha
case OPT_FETCH_url:
fctx->flags |= FETCH_URL;
break;
+ case OPT_FETCH_world:
+ fctx->flags |= FETCH_WORLD | FETCH_RECURSIVE;
+ ac->open_flags &= ~APK_OPENF_NO_WORLD;
+ break;
default:
return -ENOTSUP;
}
@@ -218,6 +224,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;
@@ -228,8 +240,7 @@ static void mark_name_flags(struct apk_database *db, const char *match, struct a
};
if (name) {
- name->auto_select_virtual = 1;
- apk_deps_add(&ctx->world, &dep);
+ mark_dep_flags(ctx, &dep);
} else {
ctx->errors++;
mark_error(ctx, match, name);
@@ -310,6 +321,7 @@ static int fetch_main(void *pctx, struct apk_ctx *ac, struct apk_string_array *a
struct apk_out *out = &ac->out;
struct apk_database *db = ac->db;
struct fetch_ctx *ctx = (struct fetch_ctx *) pctx;
+ struct apk_dependency *dep;
ctx->db = db;
ctx->prog = db->ctx->progress;
@@ -329,6 +341,8 @@ static int fetch_main(void *pctx, struct apk_ctx *ac, struct apk_string_array *a
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);
@@ -349,7 +363,7 @@ static int fetch_main(void *pctx, struct apk_ctx *ac, struct apk_string_array *a
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,