summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/database.c4
-rw-r--r--src/del.c8
-rw-r--r--src/fetch.c23
-rw-r--r--src/fix.c13
-rw-r--r--src/info.c37
-rw-r--r--src/policy.c3
-rw-r--r--src/search.c2
-rw-r--r--src/ver.c5
8 files changed, 63 insertions, 32 deletions
diff --git a/src/database.c b/src/database.c
index e35c127..f94826b 100644
--- a/src/database.c
+++ b/src/database.c
@@ -2774,9 +2774,7 @@ void apk_name_foreach_matching(struct apk_database *db, struct apk_string_array
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 (genid && name) {
if (name->foreach_genid >= genid)
continue;
name->foreach_genid = genid;
diff --git a/src/del.c b/src/del.c
index fb9b1c2..1c43883 100644
--- a/src/del.c
+++ b/src/del.c
@@ -18,6 +18,7 @@
struct del_ctx {
int recursive_delete : 1;
struct apk_dependency_array *world;
+ int errors;
};
static int option_parse_applet(void *pctx, struct apk_db_options *dbopts, int optch, const char *optarg)
@@ -109,6 +110,11 @@ static void delete_name(struct apk_database *db, const char *match,
struct del_ctx *ctx = (struct del_ctx *) pctx;
struct apk_package *pkg;
+ if (!name) {
+ ctx->errors++;
+ return;
+ }
+
pkg = apk_pkg_get_installed(name);
if (pkg != NULL)
delete_pkg(pkg, NULL, NULL, pctx);
@@ -126,6 +132,8 @@ static int del_main(void *pctx, struct apk_database *db, struct apk_string_array
apk_dependency_array_copy(&ctx->world, db->world);
apk_name_foreach_matching(db, args, apk_foreach_genid(), delete_name, ctx);
+ if (ctx->errors) return ctx->errors;
+
r = apk_solver_solve(db, 0, ctx->world, &changeset);
if (r == 0) {
/* check for non-deleted package names */
diff --git a/src/fetch.c b/src/fetch.c
index 3c40963..7caf9d4 100644
--- a/src/fetch.c
+++ b/src/fetch.c
@@ -207,7 +207,7 @@ static void mark_error(struct fetch_ctx *ctx, const char *match, struct apk_name
if (strchr(match, '*') != NULL)
return;
- apk_message("%s: unable to select package (or it's dependencies)", name->name);
+ apk_message("%s: unable to select package (or it's dependencies)", name ? name->name : match);
ctx->errors++;
}
@@ -223,6 +223,11 @@ static void mark_name_recursive(struct apk_database *db, const char *match, stru
struct apk_change *change;
int r;
+ if (!name) {
+ mark_error(ctx, match, name);
+ return;
+ }
+
apk_dependency_array_init(&world);
*apk_dependency_array_add(&world) = dep;
r = apk_solver_solve(db, 0, world, &changeset);
@@ -241,14 +246,18 @@ static void mark_name(struct apk_database *db, const char *match, struct apk_nam
struct apk_package *pkg = NULL;
struct apk_provider *p;
+ if (!name) goto err;
+
foreach_array_item(p, name->providers)
if (pkg == NULL || apk_pkg_version_compare(p->pkg, pkg) == APK_VERSION_GREATER)
pkg = p->pkg;
- if (pkg != NULL)
- mark_package(ctx, pkg);
- else
- mark_error(ctx, match, name);
+ if (!pkg) goto err;
+ mark_package(ctx, pkg);
+ return;
+
+err:
+ mark_error(ctx, match, name);
}
static int fetch_main(void *pctx, struct apk_database *db, struct apk_string_array *args)
@@ -272,8 +281,10 @@ static int fetch_main(void *pctx, struct apk_database *db, struct apk_string_arr
}
ctx->db = db;
+
apk_name_foreach_matching(db, args, apk_foreach_genid(), mark, ctx);
- apk_hash_foreach(&db->available.packages, fetch_package, ctx);
+ if (!ctx->errors)
+ apk_hash_foreach(&db->available.packages, fetch_package, ctx);
return ctx->errors;
}
diff --git a/src/fix.c b/src/fix.c
index f6fd579..8951d64 100644
--- a/src/fix.c
+++ b/src/fix.c
@@ -20,6 +20,7 @@ struct fix_ctx {
unsigned short solver_flags;
int fix_depends : 1;
int fix_directory_permissions : 1;
+ int errors;
};
static int option_parse_applet(void *pctx, struct apk_db_options *dbopts, int optch, const char *optarg)
@@ -70,9 +71,15 @@ static void mark_fix(struct fix_ctx *ctx, struct apk_name *name)
apk_solver_set_name_flags(name, ctx->solver_flags, ctx->fix_depends ? ctx->solver_flags : 0);
}
-static void set_solver_flags(struct apk_database *db, const char *match, struct apk_name *name, void *ctx)
+static void set_solver_flags(struct apk_database *db, const char *match, struct apk_name *name, void *pctx)
{
- mark_fix(ctx, name);
+ struct fix_ctx *ctx = pctx;
+
+ if (!name) {
+ apk_error("Package '%s' not found", match);
+ ctx->errors++;
+ } else
+ mark_fix(ctx, name);
}
static int fix_main(void *pctx, struct apk_database *db, struct apk_string_array *args)
@@ -94,6 +101,8 @@ static int fix_main(void *pctx, struct apk_database *db, struct apk_string_array
} else
apk_name_foreach_matching(db, args, apk_foreach_genid(), set_solver_flags, ctx);
+ if (ctx->errors) return ctx->errors;
+
return apk_solver_commit(db, 0, db->world);
}
diff --git a/src/info.c b/src/info.c
index 4e2c430..43ced63 100644
--- a/src/info.c
+++ b/src/info.c
@@ -20,8 +20,9 @@
struct info_ctx {
struct apk_database *db;
- int (*action)(struct info_ctx *ctx, struct apk_database *db, struct apk_string_array *args);
+ void (*action)(struct info_ctx *ctx, struct apk_database *db, struct apk_string_array *args);
int subaction_mask;
+ int errors;
};
/* These need to stay in sync with the function pointer array in
@@ -55,14 +56,14 @@ static void verbose_print_pkg(struct apk_package *pkg, int minimal_verbosity)
printf("\n");
}
-static int info_exists(struct info_ctx *ctx, struct apk_database *db,
- struct apk_string_array *args)
+static void info_exists(struct info_ctx *ctx, struct apk_database *db,
+ struct apk_string_array *args)
{
struct apk_name *name;
struct apk_dependency dep;
struct apk_provider *p;
char **parg;
- int ok, errors = 0;
+ int ok;
foreach_array_item(parg, args) {
apk_blob_t b = APK_BLOB_STR(*parg);
@@ -82,15 +83,12 @@ static int info_exists(struct info_ctx *ctx, struct apk_database *db,
verbose_print_pkg(p->pkg, 0);
ok = 1;
}
- if (!ok)
- errors++;
+ if (!ok) ctx->errors++;
}
-
- return errors;
}
-static int info_who_owns(struct info_ctx *ctx, struct apk_database *db,
- struct apk_string_array *args)
+static void info_who_owns(struct info_ctx *ctx, struct apk_database *db,
+ struct apk_string_array *args)
{
struct apk_package *pkg;
struct apk_dependency_array *deps;
@@ -98,7 +96,6 @@ static int info_who_owns(struct info_ctx *ctx, struct apk_database *db,
struct apk_ostream *os;
const char *via;
char **parg, buf[PATH_MAX];
- int errors = 0;
ssize_t r;
apk_dependency_array_init(&deps);
@@ -115,7 +112,7 @@ static int info_who_owns(struct info_ctx *ctx, struct apk_database *db,
if (pkg == NULL) {
apk_error("%s: Could not find owner package", *parg);
- errors++;
+ ctx->errors++;
continue;
}
@@ -138,8 +135,6 @@ static int info_who_owns(struct info_ctx *ctx, struct apk_database *db,
os->close(os);
}
apk_dependency_array_free(&deps);
-
- return errors;
}
static void info_print_description(struct apk_database *db, struct apk_package *pkg)
@@ -337,6 +332,11 @@ static void print_name_info(struct apk_database *db, const char *match, struct a
struct info_ctx *ctx = (struct info_ctx *) pctx;
struct apk_provider *p;
+ if (name == NULL) {
+ ctx->errors++;
+ return;
+ }
+
foreach_array_item(p, name->providers)
info_subaction(ctx, p->pkg);
}
@@ -405,10 +405,9 @@ static int info_main(void *ctx, struct apk_database *db, struct apk_string_array
ictx->db = db;
if (ictx->subaction_mask == 0)
ictx->subaction_mask = APK_INFO_DESC | APK_INFO_URL | APK_INFO_SIZE;
- if (ictx->action != NULL)
- return ictx->action(ictx, db, args);
-
- if (args->num > 0) {
+ if (ictx->action != NULL) {
+ ictx->action(ictx, db, args);
+ } else if (args->num > 0) {
/* Print info on given names */
apk_name_foreach_matching(
db, args, APK_FOREACH_NULL_MATCHES_ALL | apk_foreach_genid(),
@@ -419,7 +418,7 @@ static int info_main(void *ctx, struct apk_database *db, struct apk_string_array
verbose_print_pkg(ipkg->pkg, 1);
}
- return 0;
+ return ictx->errors;
}
static const struct apk_option options_applet[] = {
diff --git a/src/policy.c b/src/policy.c
index 773cf69..25d39b3 100644
--- a/src/policy.c
+++ b/src/policy.c
@@ -22,6 +22,9 @@ static void print_policy(struct apk_database *db, const char *match, struct apk_
struct apk_provider *p;
struct apk_repository *repo;
int i, j, num = 0;
+
+ if (!name) return;
+
/*
zlib1g policy:
2.0:
diff --git a/src/search.c b/src/search.c
index 4e7c730..47339fd 100644
--- a/src/search.c
+++ b/src/search.c
@@ -145,6 +145,8 @@ static void print_result(struct apk_database *db, const char *match, struct apk_
struct apk_provider *p;
struct apk_package *pkg = NULL;
+ if (!name) return;
+
if (ctx->show_all) {
foreach_array_item(p, name->providers)
print_result_pkg(ctx, p->pkg);
diff --git a/src/ver.c b/src/ver.c
index 53ef062..0792937 100644
--- a/src/ver.c
+++ b/src/ver.c
@@ -123,9 +123,10 @@ static void ver_print_package_status(struct apk_database *db, const char *match,
int i, r = -1;
unsigned short tag, allowed_repos;
+ if (!name) return;
+
pkg = apk_pkg_get_installed(name);
- if (pkg == NULL)
- return;
+ if (!pkg) return;
tag = pkg->ipkg->repository_tag;
allowed_repos = db->repo_tags[tag].allowed_repos;