apk: use string array in applet mains, separate apk_name_foreach_matching
parent
c51d82f8f6
commit
fe41ae07b9
17
src/add.c
17
src/add.c
|
@ -58,13 +58,14 @@ static int non_repository_check(struct apk_database *db)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int add_main(void *ctx, struct apk_database *db, int argc, char **argv)
|
static int add_main(void *ctx, struct apk_database *db, struct apk_string_array *args)
|
||||||
{
|
{
|
||||||
struct add_ctx *actx = (struct add_ctx *) ctx;
|
struct add_ctx *actx = (struct add_ctx *) ctx;
|
||||||
struct apk_package *virtpkg = NULL;
|
struct apk_package *virtpkg = NULL;
|
||||||
struct apk_dependency virtdep;
|
struct apk_dependency virtdep;
|
||||||
struct apk_dependency_array *world = NULL;
|
struct apk_dependency_array *world = NULL;
|
||||||
int i, r = 0;
|
char **parg;
|
||||||
|
int r = 0;
|
||||||
|
|
||||||
apk_dependency_array_copy(&world, db->world);
|
apk_dependency_array_copy(&world, db->world);
|
||||||
|
|
||||||
|
@ -96,10 +97,10 @@ static int add_main(void *ctx, struct apk_database *db, int argc, char **argv)
|
||||||
virtpkg = apk_db_pkg_add(db, virtpkg);
|
virtpkg = apk_db_pkg_add(db, virtpkg);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < argc; i++) {
|
foreach_array_item(parg, args) {
|
||||||
struct apk_dependency dep;
|
struct apk_dependency dep;
|
||||||
|
|
||||||
if (strstr(argv[i], ".apk") != NULL) {
|
if (strstr(*parg, ".apk") != NULL) {
|
||||||
struct apk_package *pkg = NULL;
|
struct apk_package *pkg = NULL;
|
||||||
struct apk_sign_ctx sctx;
|
struct apk_sign_ctx sctx;
|
||||||
|
|
||||||
|
@ -108,20 +109,20 @@ static int add_main(void *ctx, struct apk_database *db, int argc, char **argv)
|
||||||
|
|
||||||
apk_sign_ctx_init(&sctx, APK_SIGN_VERIFY_AND_GENERATE,
|
apk_sign_ctx_init(&sctx, APK_SIGN_VERIFY_AND_GENERATE,
|
||||||
NULL, db->keys_fd);
|
NULL, db->keys_fd);
|
||||||
r = apk_pkg_read(db, argv[i], &sctx, &pkg);
|
r = apk_pkg_read(db, *parg, &sctx, &pkg);
|
||||||
apk_sign_ctx_free(&sctx);
|
apk_sign_ctx_free(&sctx);
|
||||||
if (r != 0) {
|
if (r != 0) {
|
||||||
apk_error("%s: %s", argv[i], apk_error_str(r));
|
apk_error("%s: %s", *parg, apk_error_str(r));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
apk_dep_from_pkg(&dep, db, pkg);
|
apk_dep_from_pkg(&dep, db, pkg);
|
||||||
} else {
|
} else {
|
||||||
apk_blob_t b = APK_BLOB_STR(argv[i]);
|
apk_blob_t b = APK_BLOB_STR(*parg);
|
||||||
|
|
||||||
apk_blob_pull_dep(&b, db, &dep);
|
apk_blob_pull_dep(&b, db, &dep);
|
||||||
if (APK_BLOB_IS_NULL(b) || b.len > 0) {
|
if (APK_BLOB_IS_NULL(b) || b.len > 0) {
|
||||||
apk_error("'%s' is not a valid dependency, format is name(@tag)([<>=]version)",
|
apk_error("'%s' is not a valid dependency, format is name(@tag)([<>=]version)",
|
||||||
argv[i]);
|
*parg);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -291,6 +291,7 @@ int main(int argc, char **argv)
|
||||||
struct apk_repository_list *repo = NULL;
|
struct apk_repository_list *repo = NULL;
|
||||||
struct apk_database db;
|
struct apk_database db;
|
||||||
struct apk_db_options dbopts;
|
struct apk_db_options dbopts;
|
||||||
|
struct apk_string_array *args;
|
||||||
#ifdef TEST_MODE
|
#ifdef TEST_MODE
|
||||||
const char *test_installed_db = NULL;
|
const char *test_installed_db = NULL;
|
||||||
const char *test_world = NULL;
|
const char *test_world = NULL;
|
||||||
|
@ -495,7 +496,11 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
r = applet->main(ctx, &db, argc, argv);
|
apk_string_array_init(&args);
|
||||||
|
apk_string_array_resize(&args, argc);
|
||||||
|
memcpy(args->item, argv, argc * sizeof(*argv));
|
||||||
|
|
||||||
|
r = applet->main(ctx, &db, args);
|
||||||
apk_db_close(&db);
|
apk_db_close(&db);
|
||||||
|
|
||||||
if (r == -EINVAL)
|
if (r == -EINVAL)
|
||||||
|
|
|
@ -36,7 +36,7 @@ struct apk_applet {
|
||||||
|
|
||||||
int (*parse)(void *ctx, struct apk_db_options *dbopts,
|
int (*parse)(void *ctx, struct apk_db_options *dbopts,
|
||||||
int optch, int optindex, const char *optarg);
|
int optch, int optindex, const char *optarg);
|
||||||
int (*main)(void *ctx, struct apk_database *db, int argc, char **argv);
|
int (*main)(void *ctx, struct apk_database *db, struct apk_string_array *args);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct apk_applet *__start_apkapplets, *__stop_apkapplets;
|
extern struct apk_applet *__start_apkapplets, *__stop_apkapplets;
|
||||||
|
|
|
@ -90,10 +90,15 @@ struct apk_name {
|
||||||
|
|
||||||
union {
|
union {
|
||||||
struct apk_solver_name_state ss;
|
struct apk_solver_name_state ss;
|
||||||
|
struct {
|
||||||
|
unsigned int foreach_genid;
|
||||||
|
union {
|
||||||
void *state_ptr;
|
void *state_ptr;
|
||||||
int state_int;
|
int state_int;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
struct apk_repository {
|
struct apk_repository {
|
||||||
char *url;
|
char *url;
|
||||||
|
@ -239,4 +244,8 @@ int apk_db_install_pkg(struct apk_database *db,
|
||||||
struct apk_package *newpkg,
|
struct apk_package *newpkg,
|
||||||
apk_progress_cb cb, void *cb_ctx);
|
apk_progress_cb cb, void *cb_ctx);
|
||||||
|
|
||||||
|
void apk_name_foreach_matching(struct apk_database *db, struct apk_string_array *filter, unsigned int match,
|
||||||
|
void (*cb)(struct apk_database *db, const char *match, struct apk_name *name, void *ctx),
|
||||||
|
void *ctx);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
29
src/audit.c
29
src/audit.c
|
@ -236,40 +236,41 @@ done:
|
||||||
return reason < 0 ? reason : 0;
|
return reason < 0 ? reason : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int audit_main(void *ctx, struct apk_database *db, int argc, char **argv)
|
static int audit_main(void *ctx, struct apk_database *db, struct apk_string_array *args)
|
||||||
{
|
{
|
||||||
struct audit_tree_ctx atctx;
|
struct audit_tree_ctx atctx;
|
||||||
int i, r = 0;
|
char **parg, *arg;
|
||||||
|
int r = 0;
|
||||||
|
|
||||||
atctx.db = db;
|
atctx.db = db;
|
||||||
atctx.actx = (struct audit_ctx *) ctx;
|
atctx.actx = (struct audit_ctx *) ctx;
|
||||||
atctx.pathlen = 0;
|
atctx.pathlen = 0;
|
||||||
atctx.path[0] = 0;
|
atctx.path[0] = 0;
|
||||||
|
|
||||||
if (argc == 0) {
|
if (args->num == 0) {
|
||||||
atctx.dir = apk_db_dir_get(db, APK_BLOB_PTR_LEN(atctx.path, atctx.pathlen));
|
atctx.dir = apk_db_dir_get(db, APK_BLOB_PTR_LEN(atctx.path, atctx.pathlen));
|
||||||
r = apk_dir_foreach_file(dup(db->root_fd), audit_directory_tree_item, &atctx);
|
r = apk_dir_foreach_file(dup(db->root_fd), audit_directory_tree_item, &atctx);
|
||||||
apk_db_dir_unref(db, atctx.dir, FALSE);
|
apk_db_dir_unref(db, atctx.dir, FALSE);
|
||||||
} else {
|
return r;
|
||||||
for (i = 0; i < argc; i++) {
|
}
|
||||||
if (argv[i][0] != '/') {
|
|
||||||
apk_warning("%s: relative path skipped.\n",
|
foreach_array_item(parg, args) {
|
||||||
argv[i]);
|
arg = *parg;
|
||||||
|
if (arg[0] != '/') {
|
||||||
|
apk_warning("%s: relative path skipped.\n", arg);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
argv[i]++;
|
arg++;
|
||||||
atctx.pathlen = strlen(argv[i]);
|
atctx.pathlen = strlen(arg);
|
||||||
memcpy(atctx.path, argv[i], atctx.pathlen);
|
memcpy(atctx.path, arg, atctx.pathlen);
|
||||||
if (atctx.path[atctx.pathlen-1] != '/')
|
if (atctx.path[atctx.pathlen-1] != '/')
|
||||||
atctx.path[atctx.pathlen++] = '/';
|
atctx.path[atctx.pathlen++] = '/';
|
||||||
|
|
||||||
atctx.dir = apk_db_dir_get(db, APK_BLOB_PTR_LEN(atctx.path, atctx.pathlen));
|
atctx.dir = apk_db_dir_get(db, APK_BLOB_PTR_LEN(atctx.path, atctx.pathlen));
|
||||||
r |= apk_dir_foreach_file(
|
r |= apk_dir_foreach_file(openat(db->root_fd, arg, O_RDONLY|O_CLOEXEC),
|
||||||
openat(db->root_fd, argv[i], O_RDONLY|O_CLOEXEC),
|
|
||||||
audit_directory_tree_item, &atctx);
|
audit_directory_tree_item, &atctx);
|
||||||
apk_db_dir_unref(db, atctx.dir, FALSE);
|
apk_db_dir_unref(db, atctx.dir, FALSE);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
13
src/cache.c
13
src/cache.c
|
@ -111,18 +111,20 @@ static int cache_clean(struct apk_database *db)
|
||||||
return apk_db_cache_foreach_item(db, cache_clean_item);
|
return apk_db_cache_foreach_item(db, cache_clean_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cache_main(void *ctx, struct apk_database *db, int argc, char **argv)
|
static int cache_main(void *ctx, struct apk_database *db, struct apk_string_array *args)
|
||||||
{
|
{
|
||||||
|
char *arg;
|
||||||
int r = 0, actions = 0;
|
int r = 0, actions = 0;
|
||||||
|
|
||||||
if (argc != 1)
|
if (args->num != 1)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (strcmp(argv[0], "sync") == 0)
|
arg = args->item[0];
|
||||||
|
if (strcmp(arg, "sync") == 0)
|
||||||
actions = CACHE_CLEAN | CACHE_DOWNLOAD;
|
actions = CACHE_CLEAN | CACHE_DOWNLOAD;
|
||||||
else if (strcmp(argv[0], "clean") == 0)
|
else if (strcmp(arg, "clean") == 0)
|
||||||
actions = CACHE_CLEAN;
|
actions = CACHE_CLEAN;
|
||||||
else if (strcmp(argv[0], "download") == 0)
|
else if (strcmp(arg, "download") == 0)
|
||||||
actions = CACHE_DOWNLOAD;
|
actions = CACHE_DOWNLOAD;
|
||||||
else
|
else
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -137,7 +139,6 @@ static int cache_main(void *ctx, struct apk_database *db, int argc, char **argv)
|
||||||
r = cache_clean(db);
|
r = cache_clean(db);
|
||||||
if (r == 0 && (actions & CACHE_DOWNLOAD))
|
if (r == 0 && (actions & CACHE_DOWNLOAD))
|
||||||
r = cache_download(db);
|
r = cache_download(db);
|
||||||
|
|
||||||
err:
|
err:
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2673,3 +2673,80 @@ ret_r:
|
||||||
free(script_args[2]);
|
free(script_args[2]);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct match_ctx {
|
||||||
|
struct apk_database *db;
|
||||||
|
struct apk_string_array *filter;
|
||||||
|
unsigned int match;
|
||||||
|
void (*cb)(struct apk_database *db, const char *match, struct apk_name *name, void *ctx);
|
||||||
|
void *cb_ctx;
|
||||||
|
};
|
||||||
|
|
||||||
|
static int match_names(apk_hash_item item, void *pctx)
|
||||||
|
{
|
||||||
|
struct match_ctx *ctx = (struct match_ctx *) pctx;
|
||||||
|
struct apk_name *name = (struct apk_name *) item;
|
||||||
|
unsigned int genid = ctx->match & APK_FOREACH_GENID_MASK;
|
||||||
|
char **pmatch;
|
||||||
|
|
||||||
|
if (genid) {
|
||||||
|
if (name->foreach_genid >= genid)
|
||||||
|
return 0;
|
||||||
|
name->foreach_genid = genid;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctx->filter->num == 0) {
|
||||||
|
ctx->cb(ctx->db, NULL, name, ctx->cb_ctx);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach_array_item(pmatch, ctx->filter) {
|
||||||
|
if (fnmatch(*pmatch, name->name, FNM_CASEFOLD) == 0) {
|
||||||
|
ctx->cb(ctx->db, *pmatch, name, ctx->cb_ctx);
|
||||||
|
if (genid)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void apk_name_foreach_matching(struct apk_database *db, struct apk_string_array *filter, unsigned int match,
|
||||||
|
void (*cb)(struct apk_database *db, const char *match, struct apk_name *name, void *ctx),
|
||||||
|
void *ctx)
|
||||||
|
{
|
||||||
|
char **pmatch;
|
||||||
|
unsigned int genid = match & APK_FOREACH_GENID_MASK;
|
||||||
|
struct apk_name *name;
|
||||||
|
struct match_ctx mctx = {
|
||||||
|
.db = db,
|
||||||
|
.filter = filter,
|
||||||
|
.match = match,
|
||||||
|
.cb = cb,
|
||||||
|
.cb_ctx = ctx,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (filter == NULL || filter->num == 0) {
|
||||||
|
apk_string_array_init(&mctx.filter);
|
||||||
|
goto all;
|
||||||
|
}
|
||||||
|
foreach_array_item(pmatch, filter)
|
||||||
|
if (strchr(*pmatch, '*') != NULL)
|
||||||
|
goto all;
|
||||||
|
|
||||||
|
foreach_array_item(pmatch, filter) {
|
||||||
|
name = (struct apk_name *) apk_hash_get(&db->available.names, APK_BLOB_STR(*pmatch));
|
||||||
|
if (name == NULL)
|
||||||
|
continue;
|
||||||
|
if (genid) {
|
||||||
|
if (name->foreach_genid >= genid)
|
||||||
|
continue;
|
||||||
|
name->foreach_genid = genid;
|
||||||
|
}
|
||||||
|
cb(db, *pmatch, name, ctx);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
|
||||||
|
all:
|
||||||
|
apk_hash_foreach(&db->available.names, match_names, &mctx);
|
||||||
|
}
|
||||||
|
|
24
src/del.c
24
src/del.c
|
@ -75,22 +75,24 @@ static void delete_from_world(
|
||||||
delete_from_world, pctx);
|
delete_from_world, pctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int del_main(void *pctx, struct apk_database *db, int argc, char **argv)
|
static int del_main(void *pctx, struct apk_database *db, struct apk_string_array *args)
|
||||||
{
|
{
|
||||||
struct del_ctx *ctx = (struct del_ctx *) pctx;
|
struct del_ctx *ctx = (struct del_ctx *) pctx;
|
||||||
struct not_deleted_ctx ndctx = {};
|
struct not_deleted_ctx ndctx = {};
|
||||||
struct apk_name **name;
|
struct apk_name_array *names;
|
||||||
|
struct apk_name **pname;
|
||||||
struct apk_changeset changeset = {};
|
struct apk_changeset changeset = {};
|
||||||
struct apk_change *change;
|
struct apk_change *change;
|
||||||
struct apk_provider *p;
|
struct apk_provider *p;
|
||||||
int i, r = 0;
|
int r = 0, i;
|
||||||
|
|
||||||
|
apk_name_array_init(&names);
|
||||||
|
apk_name_array_resize(&names, args->num);
|
||||||
apk_dependency_array_copy(&ctx->world, db->world);
|
apk_dependency_array_copy(&ctx->world, db->world);
|
||||||
|
|
||||||
name = alloca(argc * sizeof(struct apk_name*));
|
for (i = 0; i < args->num; i++) {
|
||||||
for (i = 0; i < argc; i++) {
|
names->item[i] = apk_db_get_name(db, APK_BLOB_STR(args->item[i]));
|
||||||
name[i] = apk_db_get_name(db, APK_BLOB_STR(argv[i]));
|
delete_from_world(apk_pkg_get_installed(names->item[i]), NULL, NULL, ctx);
|
||||||
delete_from_world(apk_pkg_get_installed(name[i]), NULL, NULL, ctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
r = apk_solver_solve(db, 0, ctx->world, &changeset);
|
r = apk_solver_solve(db, 0, ctx->world, &changeset);
|
||||||
|
@ -102,11 +104,11 @@ static int del_main(void *pctx, struct apk_database *db, int argc, char **argv)
|
||||||
continue;
|
continue;
|
||||||
pkg->marked = 1;
|
pkg->marked = 1;
|
||||||
}
|
}
|
||||||
for (i = 0; i < argc; i++) {
|
foreach_array_item(pname, names) {
|
||||||
ndctx.indent.indent = 0;
|
ndctx.indent.indent = 0;
|
||||||
ndctx.name = name[i];
|
ndctx.name = *pname;
|
||||||
ndctx.matches = apk_foreach_genid() | APK_FOREACH_MARKED | APK_DEP_SATISFIES;
|
ndctx.matches = apk_foreach_genid() | APK_FOREACH_MARKED | APK_DEP_SATISFIES;
|
||||||
foreach_array_item(p, name[i]->providers) {
|
foreach_array_item(p, (*pname)->providers) {
|
||||||
if (!p->pkg->marked)
|
if (!p->pkg->marked)
|
||||||
continue;
|
continue;
|
||||||
print_not_deleted_message(p->pkg, NULL, NULL, &ndctx);
|
print_not_deleted_message(p->pkg, NULL, NULL, &ndctx);
|
||||||
|
@ -122,6 +124,7 @@ static int del_main(void *pctx, struct apk_database *db, int argc, char **argv)
|
||||||
apk_solver_print_errors(db, &changeset, ctx->world);
|
apk_solver_print_errors(db, &changeset, ctx->world);
|
||||||
}
|
}
|
||||||
apk_dependency_array_free(&ctx->world);
|
apk_dependency_array_free(&ctx->world);
|
||||||
|
apk_name_array_free(&names);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
@ -144,4 +147,3 @@ static struct apk_applet apk_del = {
|
||||||
};
|
};
|
||||||
|
|
||||||
APK_DEFINE_APPLET(apk_del);
|
APK_DEFINE_APPLET(apk_del);
|
||||||
|
|
||||||
|
|
10
src/dot.c
10
src/dot.c
|
@ -120,15 +120,15 @@ static int foreach_pkg(apk_hash_item item, void *ctx)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dot_main(void *pctx, struct apk_database *db, int argc, char **argv)
|
static int dot_main(void *pctx, struct apk_database *db, struct apk_string_array *args)
|
||||||
{
|
{
|
||||||
struct dot_ctx *ctx = (struct dot_ctx *) pctx;
|
struct dot_ctx *ctx = (struct dot_ctx *) pctx;
|
||||||
struct apk_provider *p;
|
struct apk_provider *p;
|
||||||
int i;
|
char **parg;
|
||||||
|
|
||||||
if (argc) {
|
if (args->num) {
|
||||||
for (i = 0; i < argc; i++) {
|
foreach_array_item(parg, args) {
|
||||||
struct apk_name *name = apk_db_get_name(db, APK_BLOB_STR(argv[i]));
|
struct apk_name *name = apk_db_get_name(db, APK_BLOB_STR(*parg));
|
||||||
if (!name)
|
if (!name)
|
||||||
continue;
|
continue;
|
||||||
foreach_array_item(p, name->providers)
|
foreach_array_item(p, name->providers)
|
||||||
|
|
13
src/fetch.c
13
src/fetch.c
|
@ -190,26 +190,27 @@ static void mark_package(struct fetch_ctx *ctx, struct apk_package *pkg)
|
||||||
pkg->marked = 1;
|
pkg->marked = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fetch_main(void *pctx, struct apk_database *db, int argc, char **argv)
|
static int fetch_main(void *pctx, struct apk_database *db, struct apk_string_array *args)
|
||||||
{
|
{
|
||||||
struct fetch_ctx *ctx = (struct fetch_ctx *) pctx;
|
struct fetch_ctx *ctx = (struct fetch_ctx *) pctx;
|
||||||
struct apk_dependency_array *world;
|
struct apk_dependency_array *world;
|
||||||
struct apk_change *change;
|
struct apk_change *change;
|
||||||
int r = 0, i;
|
char **parg;
|
||||||
|
int r = 0;
|
||||||
|
|
||||||
if (ctx->outdir_fd == 0)
|
if (ctx->outdir_fd == 0)
|
||||||
ctx->outdir_fd = AT_FDCWD;
|
ctx->outdir_fd = AT_FDCWD;
|
||||||
|
|
||||||
if ((argc > 0) && (strcmp(argv[0], "coffee") == 0)) {
|
if ((args->num == 1) && (strcmp(args->item[0], "coffee") == 0)) {
|
||||||
if (apk_flags & APK_FORCE)
|
if (apk_flags & APK_FORCE)
|
||||||
return cup();
|
return cup();
|
||||||
apk_message("Go and fetch your own coffee.");
|
apk_message("Go and fetch your own coffee.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < argc; i++) {
|
foreach_array_item(parg, args) {
|
||||||
struct apk_dependency dep = (struct apk_dependency) {
|
struct apk_dependency dep = (struct apk_dependency) {
|
||||||
.name = apk_db_get_name(db, APK_BLOB_STR(argv[i])),
|
.name = apk_db_get_name(db, APK_BLOB_STR(*parg)),
|
||||||
.version = apk_blob_atomize(APK_BLOB_NULL),
|
.version = apk_blob_atomize(APK_BLOB_NULL),
|
||||||
.result_mask = APK_DEPMASK_ANY,
|
.result_mask = APK_DEPMASK_ANY,
|
||||||
};
|
};
|
||||||
|
@ -222,7 +223,7 @@ static int fetch_main(void *pctx, struct apk_database *db, int argc, char **argv
|
||||||
r = apk_solver_solve(db, 0, world, &changeset);
|
r = apk_solver_solve(db, 0, world, &changeset);
|
||||||
apk_dependency_array_free(&world);
|
apk_dependency_array_free(&world);
|
||||||
if (r != 0) {
|
if (r != 0) {
|
||||||
apk_error("%s: unable to get dependencies", argv[i]);
|
apk_error("%s: unable to get dependencies", dep.name->name);
|
||||||
ctx->errors++;
|
ctx->errors++;
|
||||||
} else {
|
} else {
|
||||||
foreach_array_item(change, changeset.changes)
|
foreach_array_item(change, changeset.changes)
|
||||||
|
|
15
src/fix.c
15
src/fix.c
|
@ -52,12 +52,13 @@ static int mark_recalculate(apk_hash_item item, void *ctx)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fix_main(void *pctx, struct apk_database *db, int argc, char **argv)
|
static int fix_main(void *pctx, struct apk_database *db, struct apk_string_array *args)
|
||||||
{
|
{
|
||||||
struct fix_ctx *ctx = (struct fix_ctx *) pctx;
|
struct fix_ctx *ctx = (struct fix_ctx *) pctx;
|
||||||
struct apk_name *name;
|
struct apk_name *name;
|
||||||
struct apk_package *pkg;
|
struct apk_package *pkg;
|
||||||
int r = 0, i;
|
char **parg;
|
||||||
|
int r = 0;
|
||||||
|
|
||||||
if (!ctx->solver_flags)
|
if (!ctx->solver_flags)
|
||||||
ctx->solver_flags = APK_SOLVERF_REINSTALL;
|
ctx->solver_flags = APK_SOLVERF_REINSTALL;
|
||||||
|
@ -65,22 +66,22 @@ static int fix_main(void *pctx, struct apk_database *db, int argc, char **argv)
|
||||||
if (ctx->fix_directory_permissions)
|
if (ctx->fix_directory_permissions)
|
||||||
apk_hash_foreach(&db->installed.dirs, mark_recalculate, db);
|
apk_hash_foreach(&db->installed.dirs, mark_recalculate, db);
|
||||||
|
|
||||||
for (i = 0; i < argc; i++) {
|
foreach_array_item(parg, args) {
|
||||||
pkg = NULL;
|
pkg = NULL;
|
||||||
if (strstr(argv[i], ".apk") != NULL) {
|
if (strstr(*parg, ".apk") != NULL) {
|
||||||
struct apk_sign_ctx sctx;
|
struct apk_sign_ctx sctx;
|
||||||
|
|
||||||
apk_sign_ctx_init(&sctx, APK_SIGN_VERIFY_AND_GENERATE,
|
apk_sign_ctx_init(&sctx, APK_SIGN_VERIFY_AND_GENERATE,
|
||||||
NULL, db->keys_fd);
|
NULL, db->keys_fd);
|
||||||
r = apk_pkg_read(db, argv[i], &sctx, &pkg);
|
r = apk_pkg_read(db, *parg, &sctx, &pkg);
|
||||||
apk_sign_ctx_free(&sctx);
|
apk_sign_ctx_free(&sctx);
|
||||||
if (r != 0) {
|
if (r != 0) {
|
||||||
apk_error("%s: %s", argv[i], apk_error_str(r));
|
apk_error("%s: %s", *parg, apk_error_str(r));
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
name = pkg->name;
|
name = pkg->name;
|
||||||
} else {
|
} else {
|
||||||
name = apk_db_get_name(db, APK_BLOB_STR(argv[i]));
|
name = apk_db_get_name(db, APK_BLOB_STR(*parg));
|
||||||
pkg = apk_pkg_get_installed(name);
|
pkg = apk_pkg_get_installed(name);
|
||||||
}
|
}
|
||||||
if (pkg == NULL || pkg->ipkg == NULL) {
|
if (pkg == NULL || pkg->ipkg == NULL) {
|
||||||
|
|
21
src/index.c
21
src/index.c
|
@ -87,14 +87,15 @@ static int warn_if_no_providers(apk_hash_item item, void *ctx)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int index_main(void *ctx, struct apk_database *db, int argc, char **argv)
|
static int index_main(void *ctx, struct apk_database *db, struct apk_string_array *args)
|
||||||
{
|
{
|
||||||
struct counts counts = {0};
|
struct counts counts = {0};
|
||||||
struct apk_ostream *os;
|
struct apk_ostream *os;
|
||||||
struct apk_file_info fi;
|
struct apk_file_info fi;
|
||||||
int total, r, i, found, newpkgs = 0, errors = 0;
|
int total, r, found, newpkgs = 0, errors = 0;
|
||||||
struct index_ctx *ictx = (struct index_ctx *) ctx;
|
struct index_ctx *ictx = (struct index_ctx *) ctx;
|
||||||
struct apk_package *pkg;
|
struct apk_package *pkg;
|
||||||
|
char **parg;
|
||||||
|
|
||||||
if (isatty(STDOUT_FILENO) && ictx->output == NULL &&
|
if (isatty(STDOUT_FILENO) && ictx->output == NULL &&
|
||||||
!(apk_flags & APK_FORCE)) {
|
!(apk_flags & APK_FORCE)) {
|
||||||
|
@ -111,9 +112,9 @@ static int index_main(void *ctx, struct apk_database *db, int argc, char **argv)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < argc; i++) {
|
foreach_array_item(parg, args) {
|
||||||
if (apk_file_get_info(AT_FDCWD, argv[i], APK_CHECKSUM_NONE, &fi) < 0) {
|
if (apk_file_get_info(AT_FDCWD, *parg, APK_CHECKSUM_NONE, &fi) < 0) {
|
||||||
apk_warning("File '%s' is unaccessible", argv[i]);
|
apk_warning("File '%s' is unaccessible", *parg);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,9 +130,9 @@ static int index_main(void *ctx, struct apk_database *db, int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Check that it looks like a package name */
|
/* Check that it looks like a package name */
|
||||||
fname = strrchr(argv[i], '/');
|
fname = strrchr(*parg, '/');
|
||||||
if (fname == NULL)
|
if (fname == NULL)
|
||||||
fname = argv[i];
|
fname = *parg;
|
||||||
else
|
else
|
||||||
fname++;
|
fname++;
|
||||||
fend = strstr(fname, ".apk");
|
fend = strstr(fname, ".apk");
|
||||||
|
@ -154,7 +155,7 @@ static int index_main(void *ctx, struct apk_database *db, int argc, char **argv)
|
||||||
continue;
|
continue;
|
||||||
if (pkg->size != fi.size)
|
if (pkg->size != fi.size)
|
||||||
continue;
|
continue;
|
||||||
pkg->filename = strdup(argv[i]);
|
pkg->filename = strdup(*parg);
|
||||||
if (ictx->rewrite_arch != NULL)
|
if (ictx->rewrite_arch != NULL)
|
||||||
pkg->arch = ictx->rewrite_arch;
|
pkg->arch = ictx->rewrite_arch;
|
||||||
found = TRUE;
|
found = TRUE;
|
||||||
|
@ -165,9 +166,9 @@ static int index_main(void *ctx, struct apk_database *db, int argc, char **argv)
|
||||||
if (!found) {
|
if (!found) {
|
||||||
struct apk_sign_ctx sctx;
|
struct apk_sign_ctx sctx;
|
||||||
apk_sign_ctx_init(&sctx, ictx->method, NULL, db->keys_fd);
|
apk_sign_ctx_init(&sctx, ictx->method, NULL, db->keys_fd);
|
||||||
r = apk_pkg_read(db, argv[i], &sctx, &pkg);
|
r = apk_pkg_read(db, *parg, &sctx, &pkg);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
apk_error("%s: %s", argv[i], apk_error_str(r));
|
apk_error("%s: %s", *parg, apk_error_str(r));
|
||||||
errors++;
|
errors++;
|
||||||
} else {
|
} else {
|
||||||
newpkgs++;
|
newpkgs++;
|
||||||
|
|
82
src/info.c
82
src/info.c
|
@ -19,8 +19,7 @@
|
||||||
|
|
||||||
struct info_ctx {
|
struct info_ctx {
|
||||||
struct apk_database *db;
|
struct apk_database *db;
|
||||||
int (*action)(struct info_ctx *ctx, struct apk_database *db,
|
int (*action)(struct info_ctx *ctx, struct apk_database *db, struct apk_string_array *args);
|
||||||
int argc, char **argv);
|
|
||||||
int subaction_mask;
|
int subaction_mask;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -55,27 +54,17 @@ static void verbose_print_pkg(struct apk_package *pkg, int minimal_verbosity)
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int info_list(struct info_ctx *ctx, struct apk_database *db,
|
|
||||||
int argc, char **argv)
|
|
||||||
{
|
|
||||||
struct apk_installed_package *ipkg;
|
|
||||||
|
|
||||||
list_for_each_entry(ipkg, &db->installed.packages, installed_pkgs_list)
|
|
||||||
verbose_print_pkg(ipkg->pkg, 1);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int info_exists(struct info_ctx *ctx, struct apk_database *db,
|
static int info_exists(struct info_ctx *ctx, struct apk_database *db,
|
||||||
int argc, char **argv)
|
struct apk_string_array *args)
|
||||||
{
|
{
|
||||||
struct apk_name *name;
|
struct apk_name *name;
|
||||||
struct apk_dependency dep;
|
struct apk_dependency dep;
|
||||||
struct apk_provider *p;
|
struct apk_provider *p;
|
||||||
int i, ok, rc = 0;
|
char **parg;
|
||||||
|
int ok, errors = 0;
|
||||||
|
|
||||||
for (i = 0; i < argc; i++) {
|
foreach_array_item(parg, args) {
|
||||||
apk_blob_t b = APK_BLOB_STR(argv[i]);
|
apk_blob_t b = APK_BLOB_STR(*parg);
|
||||||
|
|
||||||
apk_blob_pull_dep(&b, db, &dep);
|
apk_blob_pull_dep(&b, db, &dep);
|
||||||
if (APK_BLOB_IS_NULL(b) || b.len > 0)
|
if (APK_BLOB_IS_NULL(b) || b.len > 0)
|
||||||
|
@ -93,26 +82,28 @@ static int info_exists(struct info_ctx *ctx, struct apk_database *db,
|
||||||
ok = 1;
|
ok = 1;
|
||||||
}
|
}
|
||||||
if (!ok)
|
if (!ok)
|
||||||
rc++;
|
errors++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int info_who_owns(struct info_ctx *ctx, struct apk_database *db,
|
static int info_who_owns(struct info_ctx *ctx, struct apk_database *db,
|
||||||
int argc, char **argv)
|
struct apk_string_array *args)
|
||||||
{
|
{
|
||||||
struct apk_package *pkg;
|
struct apk_package *pkg;
|
||||||
struct apk_dependency_array *deps;
|
struct apk_dependency_array *deps;
|
||||||
struct apk_dependency dep;
|
struct apk_dependency dep;
|
||||||
int i, r=0;
|
struct apk_ostream *os;
|
||||||
|
char **parg;
|
||||||
|
int errors = 0;
|
||||||
|
|
||||||
apk_dependency_array_init(&deps);
|
apk_dependency_array_init(&deps);
|
||||||
for (i = 0; i < argc; i++) {
|
foreach_array_item(parg, args) {
|
||||||
pkg = apk_db_get_file_owner(db, APK_BLOB_STR(argv[i]));
|
pkg = apk_db_get_file_owner(db, APK_BLOB_STR(*parg));
|
||||||
if (pkg == NULL) {
|
if (pkg == NULL) {
|
||||||
apk_error("%s: Could not find owner package", argv[i]);
|
apk_error("%s: Could not find owner package", *parg);
|
||||||
r++;
|
errors++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,12 +116,10 @@ static int info_who_owns(struct info_ctx *ctx, struct apk_database *db,
|
||||||
apk_deps_add(&deps, &dep);
|
apk_deps_add(&deps, &dep);
|
||||||
} else {
|
} else {
|
||||||
printf("%s is owned by " PKG_VER_FMT "\n",
|
printf("%s is owned by " PKG_VER_FMT "\n",
|
||||||
argv[i], PKG_VER_PRINTF(pkg));
|
*parg, PKG_VER_PRINTF(pkg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (apk_verbosity < 1 && deps->num != 0) {
|
if (apk_verbosity < 1 && deps->num != 0) {
|
||||||
struct apk_ostream *os;
|
|
||||||
|
|
||||||
os = apk_ostream_to_fd(STDOUT_FILENO);
|
os = apk_ostream_to_fd(STDOUT_FILENO);
|
||||||
apk_deps_write(db, deps, os, APK_BLOB_PTR_LEN(" ", 1));
|
apk_deps_write(db, deps, os, APK_BLOB_PTR_LEN(" ", 1));
|
||||||
os->write(os, "\n", 1);
|
os->write(os, "\n", 1);
|
||||||
|
@ -138,7 +127,7 @@ static int info_who_owns(struct info_ctx *ctx, struct apk_database *db,
|
||||||
}
|
}
|
||||||
apk_dependency_array_free(&deps);
|
apk_dependency_array_free(&deps);
|
||||||
|
|
||||||
return r;
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void info_print_description(struct apk_database *db, struct apk_package *pkg)
|
static void info_print_description(struct apk_database *db, struct apk_package *pkg)
|
||||||
|
@ -332,16 +321,16 @@ static void info_subaction(struct info_ctx *ctx, struct apk_package *pkg)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int info_package(struct info_ctx *ctx, struct apk_database *db,
|
static int info_package(struct info_ctx *ctx, struct apk_database *db,
|
||||||
int argc, char **argv)
|
struct apk_string_array *args)
|
||||||
{
|
{
|
||||||
struct apk_name *name;
|
struct apk_name *name;
|
||||||
struct apk_provider *p;
|
struct apk_provider *p;
|
||||||
int i;
|
char **parg;
|
||||||
|
|
||||||
for (i = 0; i < argc; i++) {
|
foreach_array_item(parg, args) {
|
||||||
name = apk_db_query_name(db, APK_BLOB_STR(argv[i]));
|
name = apk_db_query_name(db, APK_BLOB_STR(*parg));
|
||||||
if (name == NULL || name->providers->num == 0) {
|
if (name == NULL || name->providers->num == 0) {
|
||||||
apk_error("Not found: %s", argv[i]);
|
apk_error("Not found: %s", *parg);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
foreach_array_item(p, name->providers)
|
foreach_array_item(p, name->providers)
|
||||||
|
@ -407,25 +396,26 @@ static int info_parse(void *ctx, struct apk_db_options *dbopts,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int info_package_short(struct info_ctx *ictx, struct apk_database *db,
|
static int info_main(void *ctx, struct apk_database *db, struct apk_string_array *args)
|
||||||
int argc, char **argv)
|
|
||||||
{
|
|
||||||
ictx->subaction_mask |= APK_INFO_DESC | APK_INFO_URL | APK_INFO_SIZE;
|
|
||||||
return info_package(ictx, db, argc, argv);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int info_main(void *ctx, struct apk_database *db, int argc, char **argv)
|
|
||||||
{
|
{
|
||||||
struct info_ctx *ictx = (struct info_ctx *) ctx;
|
struct info_ctx *ictx = (struct info_ctx *) ctx;
|
||||||
|
struct apk_installed_package *ipkg;
|
||||||
|
|
||||||
ictx->db = db;
|
ictx->db = db;
|
||||||
if (ictx->action != NULL)
|
if (ictx->action != NULL)
|
||||||
return ictx->action(ictx, db, argc, argv);
|
return ictx->action(ictx, db, args);
|
||||||
|
|
||||||
if (argc > 0)
|
if (args->num > 0) {
|
||||||
return info_package_short(ictx, db, argc, argv);
|
/* Print info on given names */
|
||||||
|
ictx->subaction_mask |= APK_INFO_DESC | APK_INFO_URL | APK_INFO_SIZE;
|
||||||
|
return info_package(ictx, db, args);
|
||||||
|
} else {
|
||||||
|
/* Print all installed packages */
|
||||||
|
list_for_each_entry(ipkg, &db->installed.packages, installed_pkgs_list)
|
||||||
|
verbose_print_pkg(ipkg->pkg, 1);
|
||||||
|
}
|
||||||
|
|
||||||
return info_list(ictx, db, argc, argv);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct apk_option info_options[] = {
|
static struct apk_option info_options[] = {
|
||||||
|
|
|
@ -1174,10 +1174,11 @@ void apk_pkg_foreach_matching_dependency(
|
||||||
unsigned int genid = match & APK_FOREACH_GENID_MASK;
|
unsigned int genid = match & APK_FOREACH_GENID_MASK;
|
||||||
struct apk_dependency *d;
|
struct apk_dependency *d;
|
||||||
|
|
||||||
if (genid && pkg->foreach_genid >= genid)
|
if (pkg && genid) {
|
||||||
|
if (pkg->foreach_genid >= genid)
|
||||||
return;
|
return;
|
||||||
if (pkg)
|
|
||||||
pkg->foreach_genid = genid;
|
pkg->foreach_genid = genid;
|
||||||
|
}
|
||||||
|
|
||||||
foreach_array_item(d, deps) {
|
foreach_array_item(d, deps) {
|
||||||
if (apk_dep_analyze(d, mpkg) & match) {
|
if (apk_dep_analyze(d, mpkg) & match) {
|
||||||
|
@ -1211,9 +1212,11 @@ static void foreach_reverse_dependency(
|
||||||
continue;
|
continue;
|
||||||
if (marked && !pkg0->marked)
|
if (marked && !pkg0->marked)
|
||||||
continue;
|
continue;
|
||||||
if (genid && pkg0->foreach_genid >= genid)
|
if (genid) {
|
||||||
|
if (pkg0->foreach_genid >= genid)
|
||||||
continue;
|
continue;
|
||||||
pkg0->foreach_genid = genid;
|
pkg0->foreach_genid = genid;
|
||||||
|
}
|
||||||
foreach_array_item(d0, pkg0->depends) {
|
foreach_array_item(d0, pkg0->depends) {
|
||||||
if (apk_dep_analyze(d0, pkg) & match)
|
if (apk_dep_analyze(d0, pkg) & match)
|
||||||
cb(pkg0, d0, pkg, ctx);
|
cb(pkg0, d0, pkg, ctx);
|
||||||
|
|
76
src/search.c
76
src/search.c
|
@ -25,8 +25,7 @@ struct search_ctx {
|
||||||
int search_description : 1;
|
int search_description : 1;
|
||||||
|
|
||||||
unsigned int matches;
|
unsigned int matches;
|
||||||
int argc;
|
struct apk_string_array *filter;
|
||||||
char **argv;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void print_package_name(struct search_ctx *ctx, struct apk_package *pkg)
|
static void print_package_name(struct search_ctx *ctx, struct apk_package *pkg)
|
||||||
|
@ -96,96 +95,71 @@ static int search_parse(void *ctx, struct apk_db_options *dbopts,
|
||||||
|
|
||||||
static void print_result_pkg(struct search_ctx *ctx, struct apk_package *pkg)
|
static void print_result_pkg(struct search_ctx *ctx, struct apk_package *pkg)
|
||||||
{
|
{
|
||||||
int i;
|
char **pmatch;
|
||||||
|
|
||||||
if (pkg == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (ctx->search_description) {
|
if (ctx->search_description) {
|
||||||
for (i = 0; i < ctx->argc; i++) {
|
foreach_array_item(pmatch, ctx->filter) {
|
||||||
if (strstr(pkg->description, ctx->argv[i]) != NULL ||
|
if (strstr(*pmatch, pkg->description) != NULL ||
|
||||||
strstr(pkg->name->name, ctx->argv[i]) != NULL)
|
strstr(*pmatch, pkg->name->name) != NULL)
|
||||||
break;
|
goto match;
|
||||||
}
|
}
|
||||||
if (i >= ctx->argc)
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
match:
|
||||||
ctx->print_result(ctx, pkg);
|
ctx->print_result(ctx, pkg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_result(struct search_ctx *ctx, struct apk_name *name)
|
static void print_result(struct apk_database *db, const char *match, struct apk_name *name, void *pctx)
|
||||||
{
|
{
|
||||||
|
struct search_ctx *ctx = pctx;
|
||||||
struct apk_provider *p;
|
struct apk_provider *p;
|
||||||
struct apk_package *pkg = NULL;
|
struct apk_package *pkg = NULL;
|
||||||
apk_blob_t *version = NULL;
|
|
||||||
|
|
||||||
if (ctx->show_all) {
|
if (ctx->show_all) {
|
||||||
foreach_array_item(p, name->providers)
|
foreach_array_item(p, name->providers)
|
||||||
print_result_pkg(ctx, p->pkg);
|
print_result_pkg(ctx, p->pkg);
|
||||||
} else {
|
} else {
|
||||||
foreach_array_item(p, name->providers) {
|
foreach_array_item(p, name->providers) {
|
||||||
if (version == NULL ||
|
if (pkg == NULL ||
|
||||||
apk_version_compare_blob(*p->version, *version) == APK_VERSION_GREATER)
|
apk_version_compare_blob(*p->version, *pkg->version) == APK_VERSION_GREATER)
|
||||||
pkg = p->pkg;
|
pkg = p->pkg;
|
||||||
}
|
}
|
||||||
|
if (pkg)
|
||||||
print_result_pkg(ctx, pkg);
|
print_result_pkg(ctx, pkg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int match_names(apk_hash_item item, void *pctx)
|
static int print_pkg(apk_hash_item item, void *pctx)
|
||||||
{
|
{
|
||||||
struct search_ctx *ctx = (struct search_ctx *) pctx;
|
print_result_pkg((struct search_ctx *) pctx, (struct apk_package *) item);
|
||||||
struct apk_name *name = (struct apk_name *) item;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (!ctx->search_description) {
|
|
||||||
for (i = 0; i < ctx->argc; i++)
|
|
||||||
if (fnmatch(ctx->argv[i], name->name, FNM_CASEFOLD) == 0)
|
|
||||||
break;
|
|
||||||
if (ctx->argc > 0 && i >= ctx->argc)
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
print_result(ctx, name);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int search_main(void *pctx, struct apk_database *db, int argc, char **argv)
|
static int search_main(void *pctx, struct apk_database *db, struct apk_string_array *args)
|
||||||
{
|
{
|
||||||
struct search_ctx *ctx = (struct search_ctx *) pctx;
|
struct search_ctx *ctx = (struct search_ctx *) pctx;
|
||||||
char s[256];
|
char *tmp, **pmatch;
|
||||||
int i, l;
|
|
||||||
|
|
||||||
|
ctx->filter = args;
|
||||||
ctx->matches = apk_foreach_genid() | APK_DEP_SATISFIES;
|
ctx->matches = apk_foreach_genid() | APK_DEP_SATISFIES;
|
||||||
if (ctx->print_package == NULL)
|
if (ctx->print_package == NULL)
|
||||||
ctx->print_package = print_package_name;
|
ctx->print_package = print_package_name;
|
||||||
if (ctx->print_result == NULL)
|
if (ctx->print_result == NULL)
|
||||||
ctx->print_result = ctx->print_package;
|
ctx->print_result = ctx->print_package;
|
||||||
|
|
||||||
if (argc == 0 && ctx->search_description)
|
if (ctx->search_description)
|
||||||
return -1;
|
return apk_hash_foreach(&db->available.packages, print_pkg, ctx);
|
||||||
|
|
||||||
ctx->argc = argc;
|
|
||||||
if (!ctx->search_exact) {
|
if (!ctx->search_exact) {
|
||||||
ctx->argv = alloca(argc * sizeof(char*));
|
foreach_array_item(pmatch, ctx->filter) {
|
||||||
for (i = 0; i < argc; i++) {
|
tmp = alloca(strlen(*pmatch) + 3);
|
||||||
l = snprintf(s, sizeof(s), "*%s*", argv[i]);
|
sprintf(tmp, "*%s*", *pmatch);
|
||||||
ctx->argv[i] = alloca(l+1);
|
*pmatch = tmp;
|
||||||
memcpy(ctx->argv[i], s, l);
|
|
||||||
ctx->argv[i][l] = 0;
|
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
ctx->argv = argv;
|
apk_name_foreach_matching(db, args, apk_foreach_genid(), print_result, ctx);
|
||||||
if (!ctx->search_description) {
|
|
||||||
for (i = 0; i < argc; i++)
|
|
||||||
print_result(ctx, apk_db_get_name(db, APK_BLOB_STR(argv[i])));
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return apk_hash_foreach(&db->available.names, match_names, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct apk_option search_options[] = {
|
static struct apk_option search_options[] = {
|
||||||
{ 'a', "all", "Show all package versions (instead of latest only)" },
|
{ 'a', "all", "Show all package versions (instead of latest only)" },
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#include "apk_version.h"
|
#include "apk_version.h"
|
||||||
#include "apk_print.h"
|
#include "apk_print.h"
|
||||||
|
|
||||||
static int update_main(void *ctx, struct apk_database *db, int argc, char **argv)
|
static int update_main(void *ctx, struct apk_database *db, struct apk_string_array *args)
|
||||||
{
|
{
|
||||||
struct apk_repository *repo;
|
struct apk_repository *repo;
|
||||||
int i;
|
int i;
|
||||||
|
|
|
@ -85,7 +85,7 @@ ret:
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int upgrade_main(void *ctx, struct apk_database *db, int argc, char **argv)
|
static int upgrade_main(void *ctx, struct apk_database *db, struct apk_string_array *args)
|
||||||
{
|
{
|
||||||
struct upgrade_ctx *uctx = (struct upgrade_ctx *) ctx;
|
struct upgrade_ctx *uctx = (struct upgrade_ctx *) ctx;
|
||||||
unsigned short solver_flags;
|
unsigned short solver_flags;
|
||||||
|
|
43
src/ver.c
43
src/ver.c
|
@ -17,12 +17,12 @@
|
||||||
#include "apk_print.h"
|
#include "apk_print.h"
|
||||||
|
|
||||||
struct ver_ctx {
|
struct ver_ctx {
|
||||||
int (*action)(struct apk_database *db, int argc, char **argv);
|
int (*action)(struct apk_database *db, struct apk_string_array *args);
|
||||||
const char *limchars;
|
const char *limchars;
|
||||||
int all_tags : 1;
|
int all_tags : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int ver_indexes(struct apk_database *db, int argc, char **argv)
|
static int ver_indexes(struct apk_database *db, struct apk_string_array *args)
|
||||||
{
|
{
|
||||||
struct apk_repository *repo;
|
struct apk_repository *repo;
|
||||||
int i;
|
int i;
|
||||||
|
@ -41,29 +41,31 @@ static int ver_indexes(struct apk_database *db, int argc, char **argv)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ver_test(struct apk_database *db, int argc, char **argv)
|
static int ver_test(struct apk_database *db, struct apk_string_array *args)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (argc != 2)
|
if (args->num != 2)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
r = apk_version_compare(argv[0], argv[1]);
|
r = apk_version_compare(args->item[0], args->item[1]);
|
||||||
printf("%s\n", apk_version_op_string(r));
|
printf("%s\n", apk_version_op_string(r));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ver_validate(struct apk_database *db, int argc, char **argv)
|
static int ver_validate(struct apk_database *db, struct apk_string_array *args)
|
||||||
{
|
{
|
||||||
int i, r = 0;
|
char **parg;
|
||||||
for (i = 0; i < argc; i++) {
|
int errors = 0;
|
||||||
if (!apk_version_validate(APK_BLOB_STR(argv[i]))) {
|
|
||||||
|
foreach_array_item(parg, args) {
|
||||||
|
if (!apk_version_validate(APK_BLOB_STR(*parg))) {
|
||||||
if (apk_verbosity > 0)
|
if (apk_verbosity > 0)
|
||||||
printf("%s\n", argv[i]);
|
printf("%s\n", *parg);
|
||||||
r++;
|
errors++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return r;
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ver_parse(void *ctx, struct apk_db_options *dbopts,
|
static int ver_parse(void *ctx, struct apk_db_options *dbopts,
|
||||||
|
@ -150,28 +152,29 @@ static void ver_print_package_status(struct ver_ctx *ictx, struct apk_database *
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ver_main(void *ctx, struct apk_database *db, int argc, char **argv)
|
static int ver_main(void *ctx, struct apk_database *db, struct apk_string_array *args)
|
||||||
{
|
{
|
||||||
struct ver_ctx *ictx = (struct ver_ctx *) ctx;
|
struct ver_ctx *ictx = (struct ver_ctx *) ctx;
|
||||||
struct apk_installed_package *ipkg;
|
struct apk_installed_package *ipkg;
|
||||||
struct apk_name *name;
|
struct apk_name *name;
|
||||||
struct apk_package *pkg;
|
struct apk_package *pkg;
|
||||||
int i, ret = 0;
|
char **parg;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
if (ictx->limchars) {
|
if (ictx->limchars) {
|
||||||
if (strlen(ictx->limchars) == 0)
|
if (strlen(ictx->limchars) == 0)
|
||||||
ictx->limchars = NULL;
|
ictx->limchars = NULL;
|
||||||
} else if (argc == 0 && apk_verbosity == 1) {
|
} else if (args->num == 0 && apk_verbosity == 1) {
|
||||||
ictx->limchars = "<";
|
ictx->limchars = "<";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ictx->action != NULL)
|
if (ictx->action != NULL)
|
||||||
return ictx->action(db, argc, argv);
|
return ictx->action(db, args);
|
||||||
|
|
||||||
if (apk_verbosity > 0)
|
if (apk_verbosity > 0)
|
||||||
printf("%-42sAvailable:\n", "Installed:");
|
printf("%-42sAvailable:\n", "Installed:");
|
||||||
|
|
||||||
if (argc == 0) {
|
if (args->num == 0) {
|
||||||
list_for_each_entry(ipkg, &db->installed.packages,
|
list_for_each_entry(ipkg, &db->installed.packages,
|
||||||
installed_pkgs_list) {
|
installed_pkgs_list) {
|
||||||
ver_print_package_status(ictx, db, ipkg->pkg);
|
ver_print_package_status(ictx, db, ipkg->pkg);
|
||||||
|
@ -179,10 +182,10 @@ static int ver_main(void *ctx, struct apk_database *db, int argc, char **argv)
|
||||||
goto ver_exit;
|
goto ver_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < argc; i++) {
|
foreach_array_item(parg, args) {
|
||||||
name = apk_db_query_name(db, APK_BLOB_STR(argv[i]));
|
name = apk_db_query_name(db, APK_BLOB_STR(*parg));
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
apk_error("Not found: %s", name);
|
apk_error("Not found: %s", *parg);
|
||||||
ret = 1;
|
ret = 1;
|
||||||
goto ver_exit;
|
goto ver_exit;
|
||||||
}
|
}
|
||||||
|
|
17
src/verify.c
17
src/verify.c
|
@ -17,21 +17,22 @@
|
||||||
#include "apk_database.h"
|
#include "apk_database.h"
|
||||||
#include "apk_print.h"
|
#include "apk_print.h"
|
||||||
|
|
||||||
static int verify_main(void *ctx, struct apk_database *db, int argc, char **argv)
|
static int verify_main(void *ctx, struct apk_database *db, struct apk_string_array *args)
|
||||||
{
|
{
|
||||||
struct apk_sign_ctx sctx;
|
struct apk_sign_ctx sctx;
|
||||||
struct apk_istream *is;
|
struct apk_istream *is;
|
||||||
int i, r, ok, rc = 0;
|
char **parg;
|
||||||
|
int r, ok, rc = 0;
|
||||||
|
|
||||||
for (i = 0; i < argc; i++) {
|
foreach_array_item(parg, args) {
|
||||||
apk_sign_ctx_init(&sctx, APK_SIGN_VERIFY, NULL, db->keys_fd);
|
apk_sign_ctx_init(&sctx, APK_SIGN_VERIFY, NULL, db->keys_fd);
|
||||||
is = apk_bstream_gunzip_mpart(apk_bstream_from_file(AT_FDCWD, argv[i]),
|
is = apk_bstream_gunzip_mpart(apk_bstream_from_file(AT_FDCWD, *parg),
|
||||||
apk_sign_ctx_mpart_cb, &sctx);
|
apk_sign_ctx_mpart_cb, &sctx);
|
||||||
if (is == NULL) {
|
if (is == NULL) {
|
||||||
if (apk_verbosity >= 1)
|
if (apk_verbosity >= 1)
|
||||||
apk_error("%s: %s", argv[i], strerror(errno));
|
apk_error("%s: %s", *parg, strerror(errno));
|
||||||
else
|
else
|
||||||
printf("%s\n", argv[i]);
|
printf("%s\n", *parg);
|
||||||
apk_sign_ctx_free(&sctx);
|
apk_sign_ctx_free(&sctx);
|
||||||
rc++;
|
rc++;
|
||||||
continue;
|
continue;
|
||||||
|
@ -40,11 +41,11 @@ static int verify_main(void *ctx, struct apk_database *db, int argc, char **argv
|
||||||
is->close(is);
|
is->close(is);
|
||||||
ok = sctx.control_verified && sctx.data_verified;
|
ok = sctx.control_verified && sctx.data_verified;
|
||||||
if (apk_verbosity >= 1)
|
if (apk_verbosity >= 1)
|
||||||
apk_message("%s: %d - %s", argv[i], r,
|
apk_message("%s: %d - %s", *parg, r,
|
||||||
ok ? "OK" :
|
ok ? "OK" :
|
||||||
!sctx.control_verified ? "UNTRUSTED" : "FAILED");
|
!sctx.control_verified ? "UNTRUSTED" : "FAILED");
|
||||||
else if (!ok)
|
else if (!ok)
|
||||||
printf("%s\n", argv[i]);
|
printf("%s\n", *parg);
|
||||||
if (!ok)
|
if (!ok)
|
||||||
rc++;
|
rc++;
|
||||||
apk_sign_ctx_free(&sctx);
|
apk_sign_ctx_free(&sctx);
|
||||||
|
|
Loading…
Reference in New Issue