2009-08-17 22:37:20 +05:30
|
|
|
/*-
|
2011-01-29 16:59:30 +05:30
|
|
|
* Copyright (c) 2009-2011 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>
|
|
|
|
|
|
|
|
#include <xbps_api.h>
|
2010-11-13 07:48:58 +05:30
|
|
|
#include "xbps_api_impl.h"
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
static int
|
2011-01-29 16:59:30 +05:30
|
|
|
add_pkg_into_reqby(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;
|
|
|
|
bool alloc = false;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-01-29 16:59:30 +05:30
|
|
|
if (xbps_find_string_in_array(reqby, pkgver)) {
|
|
|
|
if (alloc)
|
|
|
|
prop_object_release(reqby);
|
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
return EEXIST;
|
2011-01-29 16:59:30 +05:30
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
remove_pkg_from_reqby(prop_object_t obj, void *arg, bool *loop_done)
|
|
|
|
{
|
2011-01-29 16:59:30 +05:30
|
|
|
prop_array_t reqby;
|
2009-08-17 22:37:20 +05:30
|
|
|
const char *pkgname = arg;
|
|
|
|
|
|
|
|
(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-01-29 16:59:30 +05:30
|
|
|
if (xbps_find_pkgname_in_array(reqby, pkgname))
|
|
|
|
if (!xbps_remove_pkgname_from_array(reqby, pkgname))
|
2009-11-23 15:16:51 +05:30
|
|
|
return EINVAL;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
int HIDDEN
|
2009-08-17 22:37:20 +05:30
|
|
|
xbps_requiredby_pkg_remove(const char *pkgname)
|
|
|
|
{
|
2011-02-21 22:12:47 +05:30
|
|
|
const struct xbps_handle *xhp;
|
2009-08-17 22:37:20 +05:30
|
|
|
prop_dictionary_t dict;
|
|
|
|
char *plist;
|
|
|
|
int rv = 0;
|
|
|
|
|
2011-01-25 08:44:33 +05:30
|
|
|
assert(pkgname != NULL);
|
|
|
|
|
2011-02-21 22:12:47 +05:30
|
|
|
xhp = xbps_handle_get();
|
|
|
|
plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
|
2009-08-17 22:37:20 +05:30
|
|
|
XBPS_META_PATH, XBPS_REGPKGDB);
|
|
|
|
if (plist == NULL)
|
2010-11-19 18:10:13 +05:30
|
|
|
return ENOMEM;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2010-04-20 17:52:38 +05:30
|
|
|
if ((dict = prop_dictionary_internalize_from_zfile(plist)) == NULL) {
|
2009-08-17 22:37:20 +05:30
|
|
|
free(plist);
|
2010-11-19 18:10:13 +05:30
|
|
|
xbps_dbg_printf("[reqby-rm] cannot internalize "
|
|
|
|
"regpkgdb plist for '%s': %s\n", pkgname, strerror(errno));
|
2009-08-17 22:37:20 +05:30
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = xbps_callback_array_iter_in_dict(dict, "packages",
|
|
|
|
remove_pkg_from_reqby, __UNCONST(pkgname));
|
2010-11-19 18:10:13 +05:30
|
|
|
if (rv != 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (!prop_dictionary_externalize_to_zfile(dict, plist)) {
|
|
|
|
xbps_dbg_printf("[reqby-rm] cannot externalize plist for "
|
|
|
|
"'%s': %s\n", pkgname, strerror(errno));
|
|
|
|
rv = errno;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
out:
|
2009-08-17 22:37:20 +05:30
|
|
|
prop_object_release(dict);
|
|
|
|
free(plist);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
int HIDDEN
|
2011-01-29 16:59:30 +05:30
|
|
|
xbps_requiredby_pkg_add(prop_array_t pkgs_array, 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;
|
|
|
|
prop_object_t obj, pkgd_regpkgdb;
|
|
|
|
prop_object_iterator_t iter;
|
|
|
|
const char *pkgver, *str;
|
2009-08-17 22:37:20 +05:30
|
|
|
int rv = 0;
|
|
|
|
|
2011-01-29 16:59:30 +05:30
|
|
|
assert(pkgs_array != NULL);
|
|
|
|
assert(pkgd != NULL);
|
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
|
|
|
}
|
2011-01-29 16:59:30 +05:30
|
|
|
pkgd_regpkgdb =
|
|
|
|
xbps_find_pkg_in_array_by_pattern(pkgs_array, str);
|
|
|
|
if (pkgd_regpkgdb == NULL)
|
|
|
|
return EINVAL;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2011-01-29 16:59:30 +05:30
|
|
|
rv = add_pkg_into_reqby(pkgd_regpkgdb, pkgver);
|
|
|
|
if (rv != 0 && rv != EEXIST)
|
|
|
|
break;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|