summaryrefslogtreecommitdiff
path: root/src/info.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2014-12-08 08:30:58 +0200
committerTimo Teräs <timo.teras@iki.fi>2014-12-08 08:31:41 +0200
commit02cd5a9c76cd676545c232bb567d7eb01e5bd6fd (patch)
treece05b50bff40784b36c310eee0916be229e640b2 /src/info.c
parent6697ed5e86e64516ac56894d2f81c575ff72fd4f (diff)
downloadapk-tools-02cd5a9c76cd676545c232bb567d7eb01e5bd6fd.tar.gz
apk-tools-02cd5a9c76cd676545c232bb567d7eb01e5bd6fd.tar.bz2
apk-tools-02cd5a9c76cd676545c232bb567d7eb01e5bd6fd.tar.xz
apk-tools-02cd5a9c76cd676545c232bb567d7eb01e5bd6fd.zip
make del, fetch, fix and info return errors
In case all applet arguments are packages names (that is are not including wildcards), return error if they do not match to some package.
Diffstat (limited to 'src/info.c')
-rw-r--r--src/info.c37
1 files changed, 18 insertions, 19 deletions
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[] = {