Added xbps_callback_array_iter() and use it in xbps-bin to list missing pkgdeps.
This commit is contained in:
parent
61fbf17bb9
commit
082efc3535
@ -50,26 +50,21 @@ struct transaction {
|
|||||||
static int
|
static int
|
||||||
show_missing_dep_cb(prop_object_t obj, void *arg, bool *loop_done)
|
show_missing_dep_cb(prop_object_t obj, void *arg, bool *loop_done)
|
||||||
{
|
{
|
||||||
const char *reqpkg;
|
|
||||||
|
|
||||||
(void)arg;
|
(void)arg;
|
||||||
(void)loop_done;
|
(void)loop_done;
|
||||||
|
|
||||||
reqpkg = prop_string_cstring_nocopy(obj);
|
fprintf(stderr, " * Missing binary package for: %s\n",
|
||||||
if (reqpkg == NULL)
|
prop_string_cstring_nocopy(obj));
|
||||||
return EINVAL;
|
|
||||||
|
|
||||||
fprintf(stderr, " * Missing binary package for: %s\n", reqpkg);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
show_missing_deps(prop_dictionary_t d)
|
show_missing_deps(prop_array_t a)
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"xbps-bin: unable to locate some required packages:\n");
|
"xbps-bin: unable to locate some required packages:\n");
|
||||||
(void)xbps_callback_array_iter_in_dict(d, "missing_deps",
|
(void)xbps_callback_array_iter(a, show_missing_dep_cb, NULL);
|
||||||
show_missing_dep_cb, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -644,7 +639,7 @@ xbps_exec_transaction(bool yes)
|
|||||||
if (errno == ENODEV) {
|
if (errno == ENODEV) {
|
||||||
/* missing packages */
|
/* missing packages */
|
||||||
array = xbps_transaction_missingdeps_get();
|
array = xbps_transaction_missingdeps_get();
|
||||||
show_missing_deps(trans->dict);
|
show_missing_deps(array);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
xbps_dbg_printf("Empty transaction dictionary: %s\n",
|
xbps_dbg_printf("Empty transaction dictionary: %s\n",
|
||||||
|
@ -53,7 +53,7 @@
|
|||||||
* @def XBPS_RELVER
|
* @def XBPS_RELVER
|
||||||
* Current library release date.
|
* Current library release date.
|
||||||
*/
|
*/
|
||||||
#define XBPS_RELVER "20110124"
|
#define XBPS_RELVER "20110125"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def XBPS_META_PATH
|
* @def XBPS_META_PATH
|
||||||
@ -343,6 +343,22 @@ bool xbps_add_obj_to_dict(prop_dictionary_t dict,
|
|||||||
*/
|
*/
|
||||||
bool xbps_add_obj_to_array(prop_array_t array, prop_object_t obj);
|
bool xbps_add_obj_to_array(prop_array_t array, prop_object_t obj);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes a function callback specified in \a fn with \a arg paassed
|
||||||
|
* as its argument into they array \a array.
|
||||||
|
*
|
||||||
|
* @param[in] array Proplib array to iterate.
|
||||||
|
* @param[in] fn Function callback to run on every object in the array.
|
||||||
|
* While running the function callback, the hird parameter (a pointer to
|
||||||
|
* a boolean) can be set to true to stop immediately the loop.
|
||||||
|
* @param[in] arg Argument to be passed to the function callback.
|
||||||
|
*
|
||||||
|
* @return 0 on success, otherwise an errno value is set appropiately.
|
||||||
|
*/
|
||||||
|
int xbps_callback_array_iter(prop_array_t array,
|
||||||
|
int (*fn)(prop_object_t, void *, bool *),
|
||||||
|
void *arg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes a function callback into the array associated with key \a key,
|
* Executes a function callback into the array associated with key \a key,
|
||||||
* contained in a proplib dictionary.
|
* contained in a proplib dictionary.
|
||||||
|
36
lib/plist.c
36
lib/plist.c
@ -1,5 +1,5 @@
|
|||||||
/*-
|
/*-
|
||||||
* Copyright (c) 2008-2010 Juan Romero Pardines.
|
* Copyright (c) 2008-2011 Juan Romero Pardines.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -76,7 +76,35 @@ xbps_add_obj_to_array(prop_array_t array, prop_object_t obj)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
xbps_callback_array_iter_in_dict(prop_dictionary_t dict, const char *key,
|
xbps_callback_array_iter(prop_array_t array,
|
||||||
|
int (*fn)(prop_object_t, void *, bool *),
|
||||||
|
void *arg)
|
||||||
|
{
|
||||||
|
prop_object_t obj;
|
||||||
|
prop_object_iterator_t iter;
|
||||||
|
int rv = 0;
|
||||||
|
bool loop_done = false;
|
||||||
|
|
||||||
|
assert(array != NULL);
|
||||||
|
assert(fn != NULL);
|
||||||
|
|
||||||
|
iter = prop_array_iterator(array);
|
||||||
|
if (iter == NULL)
|
||||||
|
return ENOMEM;
|
||||||
|
|
||||||
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||||
|
rv = (*fn)(obj, arg, &loop_done);
|
||||||
|
if (rv != 0 || loop_done)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
prop_object_iterator_release(iter);
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
xbps_callback_array_iter_in_dict(prop_dictionary_t dict,
|
||||||
|
const char *key,
|
||||||
int (*fn)(prop_object_t, void *, bool *),
|
int (*fn)(prop_object_t, void *, bool *),
|
||||||
void *arg)
|
void *arg)
|
||||||
{
|
{
|
||||||
@ -106,7 +134,9 @@ xbps_callback_array_iter_in_dict(prop_dictionary_t dict, const char *key,
|
|||||||
|
|
||||||
int
|
int
|
||||||
xbps_callback_array_iter_reverse_in_dict(prop_dictionary_t dict,
|
xbps_callback_array_iter_reverse_in_dict(prop_dictionary_t dict,
|
||||||
const char *key, int (*fn)(prop_object_t, void *, bool *), void *arg)
|
const char *key,
|
||||||
|
int (*fn)(prop_object_t, void *, bool *),
|
||||||
|
void *arg)
|
||||||
{
|
{
|
||||||
prop_array_t array;
|
prop_array_t array;
|
||||||
prop_object_t obj;
|
prop_object_t obj;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user