2011-02-05 16:36:03 +05:30
|
|
|
/*-
|
2012-01-20 15:40:52 +05:30
|
|
|
* Copyright (c) 2008-2012 Juan Romero Pardines.
|
2011-02-05 16:36:03 +05:30
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "xbps_api_impl.h"
|
|
|
|
|
|
|
|
static bool
|
2012-11-30 11:41:51 +05:30
|
|
|
remove_obj_from_array(prop_array_t array, const char *str, int mode)
|
2011-02-05 16:36:03 +05:30
|
|
|
{
|
2011-12-24 05:35:26 +05:30
|
|
|
prop_object_iterator_t iter;
|
2011-02-05 16:36:03 +05:30
|
|
|
prop_object_t obj;
|
2012-11-30 11:41:51 +05:30
|
|
|
const char *curname, *pkgdep;
|
2011-02-05 16:36:03 +05:30
|
|
|
char *curpkgname;
|
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
|
|
|
|
2011-10-19 20:23:38 +05:30
|
|
|
assert(prop_object_type(array) == PROP_TYPE_ARRAY);
|
|
|
|
|
2011-12-24 05:35:26 +05:30
|
|
|
iter = prop_array_iterator(array);
|
|
|
|
if (iter == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
while ((obj = prop_object_iterator_next(iter))) {
|
2011-02-05 16:36:03 +05:30
|
|
|
if (mode == 0) {
|
|
|
|
/* exact match, obj is a string */
|
|
|
|
if (prop_string_equals_cstring(obj, str)) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (mode == 1) {
|
|
|
|
/* match by pkgname, obj is a string */
|
|
|
|
pkgdep = prop_string_cstring_nocopy(obj);
|
2011-06-01 13:07:32 +05:30
|
|
|
curpkgname = xbps_pkg_name(pkgdep);
|
2011-02-05 16:36:03 +05:30
|
|
|
if (curpkgname == NULL)
|
|
|
|
break;
|
|
|
|
if (strcmp(curpkgname, str) == 0) {
|
|
|
|
free(curpkgname);
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free(curpkgname);
|
|
|
|
} else if (mode == 2) {
|
|
|
|
/* match by pkgname, obj is a dictionary */
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj,
|
|
|
|
"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 */
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj,
|
|
|
|
"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 */
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj,
|
|
|
|
"pkgver", &curname);
|
|
|
|
if (xbps_pkgpattern_match(curname, str)) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
2011-02-05 16:36:03 +05:30
|
|
|
}
|
|
|
|
idx++;
|
|
|
|
}
|
2011-12-24 05:35:26 +05:30
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
prop_array_remove(array, idx);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-30 11:41:51 +05:30
|
|
|
bool HIDDEN
|
|
|
|
xbps_remove_string_from_array(prop_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
|
|
|
}
|
|
|
|
|
2012-11-30 11:41:51 +05:30
|
|
|
bool HIDDEN
|
|
|
|
xbps_remove_pkgname_from_array(prop_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
|
|
|
|
xbps_remove_pkg_from_array_by_name(prop_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
|
|
|
|
xbps_remove_pkg_from_array_by_pkgver(prop_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
|
|
|
|
xbps_remove_pkg_from_array_by_pattern(prop_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
|
|
|
}
|