2009-08-17 22:37:20 +05:30
|
|
|
/*-
|
2012-01-04 22:26:52 +05:30
|
|
|
* Copyright (c) 2009-2012 Juan Romero Pardines.
|
2009-08-17 22:37:20 +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>
|
|
|
|
|
2010-11-13 07:48:58 +05:30
|
|
|
#include "xbps_api_impl.h"
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
static int
|
2012-06-14 11:52:11 +05:30
|
|
|
add_pkg_into_reqby(struct xbps_handle *xhp,
|
|
|
|
prop_dictionary_t pkgd,
|
|
|
|
const char *pkgver)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2011-01-29 16:59:30 +05:30
|
|
|
prop_array_t reqby;
|
2009-08-17 22:37:20 +05:30
|
|
|
prop_string_t reqstr;
|
2012-10-26 13:14:07 +05:30
|
|
|
const char *curpkgver;
|
2012-04-04 13:50:29 +05:30
|
|
|
char *pkgname;
|
2009-08-17 22:37:20 +05:30
|
|
|
bool alloc = false;
|
|
|
|
|
2011-10-19 20:23:38 +05:30
|
|
|
assert(prop_object_type(pkgd) == PROP_TYPE_DICTIONARY);
|
|
|
|
|
2011-01-29 16:59:30 +05:30
|
|
|
if ((reqby = prop_dictionary_get(pkgd, "requiredby")) == NULL) {
|
2009-08-17 22:37:20 +05:30
|
|
|
alloc = true;
|
2011-01-29 16:59:30 +05:30
|
|
|
if ((reqby = prop_array_create()) == NULL)
|
2009-08-17 22:37:20 +05:30
|
|
|
return ENOMEM;
|
|
|
|
}
|
2012-10-26 13:14:07 +05:30
|
|
|
/*
|
|
|
|
* If the same entry already exist we are done.
|
|
|
|
*/
|
|
|
|
if (xbps_match_string_in_array(reqby, pkgver))
|
|
|
|
return 0;
|
2012-04-04 13:50:29 +05:30
|
|
|
/*
|
|
|
|
* If an existing entry matching pkgname exists remove it
|
|
|
|
* and add new pkgver object.
|
|
|
|
*/
|
|
|
|
pkgname = xbps_pkg_name(pkgver);
|
|
|
|
if (pkgname == NULL)
|
|
|
|
return ENOMEM;
|
|
|
|
|
|
|
|
if (xbps_match_pkgname_in_array(reqby, pkgname)) {
|
2012-06-15 19:03:11 +05:30
|
|
|
if (!xbps_remove_pkgname_from_array(xhp, reqby, pkgname)) {
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_dbg_printf(xhp, "%s: failed to remove %s reqby entry: "
|
2012-04-04 13:50:29 +05:30
|
|
|
"%s\n", __func__, pkgname, strerror(errno));
|
|
|
|
free(pkgname);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(pkgname);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2011-01-29 16:59:30 +05:30
|
|
|
reqstr = prop_string_create_cstring(pkgver);
|
2009-08-17 22:37:20 +05:30
|
|
|
if (reqstr == NULL) {
|
|
|
|
if (alloc)
|
2011-01-29 16:59:30 +05:30
|
|
|
prop_object_release(reqby);
|
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
return ENOMEM;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
|
2012-10-26 13:14:07 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &curpkgver);
|
|
|
|
xbps_dbg_printf(xhp, "%s: added reqby entry `%s'\n", curpkgver, pkgver);
|
|
|
|
|
2011-01-29 16:59:30 +05:30
|
|
|
if (!xbps_add_obj_to_array(reqby, reqstr)) {
|
2009-08-17 22:37:20 +05:30
|
|
|
if (alloc)
|
2011-01-29 16:59:30 +05:30
|
|
|
prop_object_release(reqby);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
prop_object_release(reqstr);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!alloc)
|
|
|
|
return 0;
|
|
|
|
|
2011-01-29 16:59:30 +05:30
|
|
|
if (!xbps_add_obj_to_dict(pkgd, reqby, "requiredby")) {
|
2009-08-17 22:37:20 +05:30
|
|
|
if (alloc)
|
2011-01-29 16:59:30 +05:30
|
|
|
prop_object_release(reqby);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-06-14 11:52:11 +05:30
|
|
|
remove_pkg_from_reqby(struct xbps_handle *xhp,
|
|
|
|
prop_object_t obj,
|
|
|
|
void *arg,
|
|
|
|
bool *loop_done)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2011-01-29 16:59:30 +05:30
|
|
|
prop_array_t reqby;
|
2009-08-17 22:37:20 +05:30
|
|
|
const char *pkgname = arg;
|
|
|
|
|
2012-06-14 11:52:11 +05:30
|
|
|
(void)xhp;
|
2009-08-17 22:37:20 +05:30
|
|
|
(void)loop_done;
|
|
|
|
|
2011-01-29 16:59:30 +05:30
|
|
|
reqby = prop_dictionary_get(obj, "requiredby");
|
|
|
|
if (reqby == NULL || prop_array_count(reqby) == 0)
|
2009-08-17 22:37:20 +05:30
|
|
|
return 0;
|
|
|
|
|
2011-12-24 05:35:26 +05:30
|
|
|
if (xbps_match_pkgname_in_array(reqby, pkgname)) {
|
2012-06-15 19:03:11 +05:30
|
|
|
if (!xbps_remove_pkgname_from_array(xhp, reqby, pkgname))
|
2009-11-23 15:16:51 +05:30
|
|
|
return EINVAL;
|
2011-12-24 05:35:26 +05:30
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
int HIDDEN
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_requiredby_pkg_remove(struct xbps_handle *xhp, const char *pkgname)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2011-01-25 08:44:33 +05:30
|
|
|
assert(pkgname != NULL);
|
2012-06-14 11:52:11 +05:30
|
|
|
return xbps_pkgdb_foreach_cb(xhp, remove_pkg_from_reqby, __UNCONST(pkgname));
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
int HIDDEN
|
2011-12-24 05:35:26 +05:30
|
|
|
xbps_requiredby_pkg_add(struct xbps_handle *xhp, prop_dictionary_t pkgd)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2011-01-29 16:59:30 +05:30
|
|
|
prop_array_t pkg_rdeps;
|
2012-01-20 15:40:52 +05:30
|
|
|
prop_object_t obj, pkgd_pkgdb;
|
2011-01-29 16:59:30 +05:30
|
|
|
prop_object_iterator_t iter;
|
|
|
|
const char *pkgver, *str;
|
2009-08-17 22:37:20 +05:30
|
|
|
int rv = 0;
|
|
|
|
|
2011-10-19 20:23:38 +05:30
|
|
|
assert(prop_object_type(pkgd) == PROP_TYPE_DICTIONARY);
|
2011-01-25 08:44:33 +05:30
|
|
|
|
2011-01-29 16:59:30 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
|
|
|
pkg_rdeps = prop_dictionary_get(pkgd, "run_depends");
|
|
|
|
if (pkg_rdeps == NULL || prop_array_count(pkg_rdeps) == 0)
|
2009-08-17 22:37:20 +05:30
|
|
|
return EINVAL;
|
|
|
|
|
2011-01-29 16:59:30 +05:30
|
|
|
iter = prop_array_iterator(pkg_rdeps);
|
2009-11-22 09:45:47 +05:30
|
|
|
if (iter == NULL)
|
2009-08-17 22:37:20 +05:30
|
|
|
return ENOMEM;
|
|
|
|
|
|
|
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
2009-11-07 09:26:20 +05:30
|
|
|
str = prop_string_cstring_nocopy(obj);
|
2009-11-23 15:16:51 +05:30
|
|
|
if (str == NULL) {
|
2010-11-19 18:10:13 +05:30
|
|
|
rv = EINVAL;
|
2011-01-29 16:59:30 +05:30
|
|
|
break;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2012-01-20 15:40:52 +05:30
|
|
|
pkgd_pkgdb = xbps_find_virtualpkg_conf_in_array_by_pattern(
|
2012-06-14 11:52:11 +05:30
|
|
|
xhp, xhp->pkgdb, str);
|
2012-01-20 15:40:52 +05:30
|
|
|
if (pkgd_pkgdb == NULL) {
|
|
|
|
pkgd_pkgdb =
|
|
|
|
xbps_find_virtualpkg_in_array_by_pattern(
|
2012-06-15 19:03:11 +05:30
|
|
|
xhp, xhp->pkgdb, str);
|
2012-01-20 15:40:52 +05:30
|
|
|
if (pkgd_pkgdb == NULL) {
|
2012-04-12 15:27:21 +05:30
|
|
|
pkgd_pkgdb = xbps_find_pkg_in_array_by_pattern(
|
2012-06-15 19:03:11 +05:30
|
|
|
xhp, xhp->pkgdb, str, NULL);
|
2012-04-12 15:27:21 +05:30
|
|
|
if (pkgd_pkgdb == NULL) {
|
|
|
|
rv = ENOENT;
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_dbg_printf(xhp,
|
|
|
|
"%s: couldnt find `%s' "
|
2012-04-12 15:27:21 +05:30
|
|
|
"entry in pkgdb\n", __func__, str);
|
|
|
|
break;
|
|
|
|
}
|
2012-01-04 22:11:22 +05:30
|
|
|
}
|
|
|
|
}
|
2012-06-14 11:52:11 +05:30
|
|
|
rv = add_pkg_into_reqby(xhp, pkgd_pkgdb, pkgver);
|
2011-11-17 17:27:43 +05:30
|
|
|
if (rv != 0)
|
2011-01-29 16:59:30 +05:30
|
|
|
break;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|