diff --git a/include/plist.h b/include/plist.h index 0f23c73ac15..30b7491b5aa 100644 --- a/include/plist.h +++ b/include/plist.h @@ -107,4 +107,7 @@ xbps_remove_pkg_dict_from_file(const char *, const char *); bool xbps_remove_pkg_from_dict(prop_dictionary_t, const char *, const char *); +int +xbps_remove_string_from_array(prop_array_t, const char *); + #endif /* !_XBPS_PLIST_H_ */ diff --git a/lib/plist.c b/lib/plist.c index 0c3ed0d6ff3..3f91b2305bf 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -237,6 +237,39 @@ xbps_get_array_iter_from_dict(prop_dictionary_t dict, const char *key) return prop_array_iterator(array); } +int +xbps_remove_string_from_array(prop_array_t array, const char *str) +{ + prop_object_t obj; + prop_object_iterator_t iter; + size_t idx = 0; + bool found = false; + + assert(array != NULL); + assert(str != NULL); + + iter = prop_array_iterator(array); + if (iter == NULL) + return ENOMEM; + + while ((obj = prop_object_iterator_next(iter)) != NULL) { + if (prop_object_type(obj) != PROP_TYPE_STRING) + continue; + if (prop_string_equals_cstring(obj, str)) { + found = true; + break; + } + idx++; + } + prop_object_iterator_release(iter); + if (found == false) + return ENOENT; + + prop_array_remove(array, idx); + + return 0; +} + bool xbps_remove_pkg_from_dict(prop_dictionary_t dict, const char *key, const char *pkgname)