libxbps: new func xbps_array_replace_dict_by_name(array, dict, pkgname)

This function replaces a dictionary in an array matched by pkgname,
with the dictionary passed in as 2nd argument.
This commit is contained in:
Juan RP 2011-10-19 00:37:36 +02:00
parent 8fa21753b1
commit 0a041cdd2e
2 changed files with 50 additions and 7 deletions

View File

@ -55,7 +55,7 @@
*/
#define XBPS_PKGINDEX_VERSION "1.2"
#define XBPS_API_VERSION "20111017-2"
#define XBPS_API_VERSION "20111019"
#define XBPS_VERSION "0.10.0"
/**
@ -1014,6 +1014,21 @@ bool xbps_remove_string_from_array(prop_array_t array, const char *str);
*/
bool xbps_remove_pkgname_from_array(prop_array_t array, const char *name);
/**
* Replaces a dictionary with another dictionary in \a dict, in the
* array \array by matching its "pkgname" object with \a pkgname.
*
* @param[in] array Proplib array where to look for.
* @param[in] dict Proplib dictionary to be added in \a array.
* @param[in] pkgname Package name to be matched.
*
* @return 0 on success, EINVAL if dictionary couldn't be set in
* array or ENOENT if no match.
*/
int xbps_array_replace_dict_by_name(prop_array_t array,
prop_dictionary_t dict,
const char *pkgname);
/*@}*/
/** @addtogroup purge */

View File

@ -43,7 +43,7 @@ bool
xbps_add_obj_to_dict(prop_dictionary_t dict, prop_object_t obj,
const char *key)
{
assert(dict != NULL);
assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
assert(obj != NULL);
assert(key != NULL);
@ -60,7 +60,7 @@ xbps_add_obj_to_dict(prop_dictionary_t dict, prop_object_t obj,
bool
xbps_add_obj_to_array(prop_array_t array, prop_object_t obj)
{
assert(array != NULL);
assert(prop_object_type(array) == PROP_TYPE_ARRAY);
assert(obj != NULL);
if (!prop_array_add(array, obj)) {
@ -83,7 +83,7 @@ xbps_callback_array_iter(prop_array_t array,
int rv = 0;
bool loop_done = false;
assert(array != NULL);
assert(prop_object_type(array) == PROP_TYPE_ARRAY);
assert(fn != NULL);
iter = prop_array_iterator(array);
@ -111,7 +111,7 @@ xbps_callback_array_iter_in_dict(prop_dictionary_t dict,
int rv = 0;
bool cbloop_done = false;
assert(dict != NULL);
assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
assert(key != NULL);
assert(fn != NULL);
@ -142,7 +142,7 @@ xbps_callback_array_iter_reverse_in_dict(prop_dictionary_t dict,
bool cbloop_done = false;
unsigned int cnt = 0;
assert(dict != NULL);
assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
assert(key != NULL);
assert(fn != NULL);
@ -170,7 +170,7 @@ xbps_array_iter_from_dict(prop_dictionary_t dict, const char *key)
{
prop_array_t array;
assert(dict != NULL);
assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
assert(key != NULL);
array = prop_dictionary_get(dict, key);
@ -182,6 +182,34 @@ xbps_array_iter_from_dict(prop_dictionary_t dict, const char *key)
return prop_array_iterator(array);
}
int
xbps_array_replace_dict_by_name(prop_array_t array,
prop_dictionary_t dict,
const char *pkgname)
{
prop_object_t obj;
size_t i;
const char *curpkgname;
assert(prop_object_type(array) == PROP_TYPE_ARRAY);
assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
assert(pkgname != NULL);
for (i = 0; i < prop_array_count(array); i++) {
obj = prop_array_get(array, i);
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &curpkgname);
if (strcmp(curpkgname, pkgname) == 0) {
/* pkgname match, we know the index */
if (!prop_array_set(array, i, dict))
return EINVAL;
return 0;
}
}
/* no match */
return ENOENT;
}
prop_dictionary_t
xbps_dictionary_from_metadata_plist(const char *pkgname,
const char *plist)