fetch: implement --world

fixes #10838
cute-signatures
Timo Teräs 2022-05-02 10:58:29 +03:00
parent f8cf7a0a0d
commit ff7c8f6ee9
2 changed files with 24 additions and 7 deletions

View File

@ -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.

View File

@ -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);