2011-02-05 16:36:03 +05:30
|
|
|
/*-
|
2020-04-24 15:14:19 +05:30
|
|
|
* Licensed under the SPDX BSD-2-Clause identifier.
|
|
|
|
* Use is subject to license terms, as specified in the LICENSE file.
|
2011-02-05 16:36:03 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "xbps_api_impl.h"
|
|
|
|
|
|
|
|
static bool
|
2013-06-20 13:56:12 +05:30
|
|
|
remove_obj_from_array(xbps_array_t array, const char *str, int mode)
|
2011-02-05 16:36:03 +05:30
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_iterator_t iter;
|
|
|
|
xbps_object_t obj;
|
2012-11-30 11:41:51 +05:30
|
|
|
const char *curname, *pkgdep;
|
2020-02-09 00:01:29 +05:30
|
|
|
char curpkgname[XBPS_NAME_SIZE];
|
2013-06-12 13:34:10 +05:30
|
|
|
unsigned int idx = 0;
|
2012-11-30 11:41:51 +05:30
|
|
|
bool found = false;
|
2011-02-05 16:36:03 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
assert(xbps_object_type(array) == XBPS_TYPE_ARRAY);
|
2011-10-19 20:23:38 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
iter = xbps_array_iterator(array);
|
2011-12-24 05:35:26 +05:30
|
|
|
if (iter == NULL)
|
|
|
|
return false;
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
while ((obj = xbps_object_iterator_next(iter))) {
|
2011-02-05 16:36:03 +05:30
|
|
|
if (mode == 0) {
|
|
|
|
/* exact match, obj is a string */
|
2013-06-20 13:56:12 +05:30
|
|
|
if (xbps_string_equals_cstring(obj, str)) {
|
2011-02-05 16:36:03 +05:30
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (mode == 1) {
|
|
|
|
/* match by pkgname, obj is a string */
|
2013-06-20 13:56:12 +05:30
|
|
|
pkgdep = xbps_string_cstring_nocopy(obj);
|
2020-02-09 00:01:29 +05:30
|
|
|
if (!xbps_pkg_name(curpkgname, sizeof(curpkgname), pkgdep))
|
2011-02-05 16:36:03 +05:30
|
|
|
break;
|
2020-02-09 00:01:29 +05:30
|
|
|
|
2011-02-05 16:36:03 +05:30
|
|
|
if (strcmp(curpkgname, str) == 0) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (mode == 2) {
|
|
|
|
/* match by pkgname, obj is a dictionary */
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(obj,
|
2011-02-05 16:36:03 +05:30
|
|
|
"pkgname", &curname);
|
|
|
|
if (strcmp(curname, str) == 0) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
2012-01-17 15:20:35 +05:30
|
|
|
} else if (mode == 3) {
|
|
|
|
/* match by pkgver, obj is a dictionary */
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(obj,
|
2012-01-17 15:20:35 +05:30
|
|
|
"pkgver", &curname);
|
|
|
|
if (strcmp(curname, str) == 0) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
2012-01-20 15:40:52 +05:30
|
|
|
} else if (mode == 4) {
|
|
|
|
/* match by pattern, obj is a dictionary */
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(obj,
|
2012-01-20 15:40:52 +05:30
|
|
|
"pkgver", &curname);
|
|
|
|
if (xbps_pkgpattern_match(curname, str)) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
2011-02-05 16:36:03 +05:30
|
|
|
}
|
|
|
|
idx++;
|
|
|
|
}
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_iterator_release(iter);
|
2011-12-24 05:35:26 +05:30
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
errno = ENOENT;
|
2011-02-05 16:36:03 +05:30
|
|
|
return false;
|
2011-12-24 05:35:26 +05:30
|
|
|
}
|
2011-02-05 16:36:03 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_array_remove(array, idx);
|
2011-02-05 16:36:03 +05:30
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-13 21:43:25 +05:30
|
|
|
bool
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_remove_string_from_array(xbps_array_t array, const char *str)
|
2011-02-05 16:36:03 +05:30
|
|
|
{
|
2012-11-30 11:41:51 +05:30
|
|
|
return remove_obj_from_array(array, str, 0);
|
2011-02-05 16:36:03 +05:30
|
|
|
}
|
|
|
|
|
2014-09-13 21:43:25 +05:30
|
|
|
bool
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_remove_pkgname_from_array(xbps_array_t array, const char *str)
|
2011-02-05 16:36:03 +05:30
|
|
|
{
|
2012-11-30 11:41:51 +05:30
|
|
|
return remove_obj_from_array(array, str, 1);
|
2011-02-05 16:36:03 +05:30
|
|
|
}
|
|
|
|
|
2012-11-30 11:41:51 +05:30
|
|
|
bool HIDDEN
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_remove_pkg_from_array_by_name(xbps_array_t array, const char *str)
|
2011-02-05 16:36:03 +05:30
|
|
|
{
|
2012-11-30 11:41:51 +05:30
|
|
|
return remove_obj_from_array(array, str, 2);
|
2011-02-05 16:36:03 +05:30
|
|
|
}
|
|
|
|
|
2012-11-30 11:41:51 +05:30
|
|
|
bool HIDDEN
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_remove_pkg_from_array_by_pkgver(xbps_array_t array, const char *str)
|
2012-01-17 15:20:35 +05:30
|
|
|
{
|
2012-11-30 11:41:51 +05:30
|
|
|
return remove_obj_from_array(array, str, 3);
|
2012-01-20 15:40:52 +05:30
|
|
|
}
|
|
|
|
|
2012-11-30 11:41:51 +05:30
|
|
|
bool HIDDEN
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_remove_pkg_from_array_by_pattern(xbps_array_t array, const char *str)
|
2012-01-20 15:40:52 +05:30
|
|
|
{
|
2012-11-30 11:41:51 +05:30
|
|
|
return remove_obj_from_array(array, str, 4);
|
2011-02-05 16:36:03 +05:30
|
|
|
}
|