2008-12-23 11:28:21 +00:00
|
|
|
/*-
|
2009-02-05 15:53:49 +00:00
|
|
|
* Copyright (c) 2008-2009 Juan Romero Pardines.
|
2008-12-23 11:28:21 +00:00
|
|
|
* 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 <limits.h>
|
|
|
|
|
|
|
|
#include <xbps_api.h>
|
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
static int add_missing_reqdep(const char *, const char *);
|
|
|
|
static int check_missing_reqdep(const char *, const char *, size_t *);
|
|
|
|
static void remove_missing_reqdep(size_t *);
|
|
|
|
|
|
|
|
static prop_dictionary_t chaindeps;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Creates the dictionary to store the dependency chain.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
create_deps_dictionary(void)
|
2008-12-24 06:20:19 +00:00
|
|
|
{
|
2009-02-07 12:27:24 +00:00
|
|
|
prop_array_t installed, direct, indirect, missing;
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
chaindeps = prop_dictionary_create();
|
|
|
|
if (chaindeps == NULL)
|
|
|
|
return ENOMEM;
|
|
|
|
|
|
|
|
missing = prop_array_create();
|
|
|
|
if (missing == NULL) {
|
|
|
|
rv = ENOMEM;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
installed = prop_array_create();
|
|
|
|
if (installed == NULL) {
|
|
|
|
rv = ENOMEM;
|
|
|
|
goto fail2;
|
|
|
|
}
|
|
|
|
|
|
|
|
direct = prop_array_create();
|
|
|
|
if (direct == NULL) {
|
|
|
|
rv = ENOMEM;
|
|
|
|
goto fail3;
|
|
|
|
}
|
|
|
|
|
|
|
|
indirect = prop_array_create();
|
|
|
|
if (indirect == NULL) {
|
|
|
|
rv = ENOMEM;
|
|
|
|
goto fail4;
|
|
|
|
}
|
2008-12-26 03:36:51 +00:00
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
if (!xbps_add_obj_to_dict(chaindeps, missing, "missing_deps")) {
|
|
|
|
rv = EINVAL;
|
|
|
|
goto fail5;
|
|
|
|
}
|
|
|
|
if (!xbps_add_obj_to_dict(chaindeps, installed, "installed_deps")) {
|
|
|
|
rv = EINVAL;
|
|
|
|
goto fail5;
|
|
|
|
}
|
|
|
|
if (!xbps_add_obj_to_dict(chaindeps, direct, "direct_deps")) {
|
|
|
|
rv = EINVAL;
|
|
|
|
goto fail5;
|
2008-12-26 03:36:51 +00:00
|
|
|
}
|
2009-02-07 12:27:24 +00:00
|
|
|
if (!xbps_add_obj_to_dict(chaindeps, indirect, "indirect_deps")) {
|
|
|
|
rv = EINVAL;
|
|
|
|
goto fail5;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
fail5:
|
|
|
|
prop_object_release(indirect);
|
|
|
|
fail4:
|
|
|
|
prop_object_release(direct);
|
|
|
|
fail3:
|
|
|
|
prop_object_release(installed);
|
|
|
|
fail2:
|
|
|
|
prop_object_release(missing);
|
|
|
|
fail:
|
|
|
|
prop_object_release(chaindeps);
|
|
|
|
|
|
|
|
return rv;
|
2008-12-26 03:36:51 +00:00
|
|
|
}
|
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
static int
|
|
|
|
store_dependency(prop_dictionary_t origind, prop_dictionary_t depd,
|
|
|
|
prop_dictionary_t repod)
|
2008-12-29 05:46:08 +00:00
|
|
|
{
|
2009-02-07 12:27:24 +00:00
|
|
|
prop_dictionary_t dict, curpkgdir, curpkgindir;
|
|
|
|
prop_array_t array;
|
|
|
|
uint32_t prio = 0;
|
|
|
|
size_t len = 0;
|
|
|
|
const char *pkgname, *version, *reqbyname, *reqbyver;
|
2009-02-09 15:39:55 +00:00
|
|
|
const char *repoloc, *binfile, *array_key, *originpkg, *short_desc;
|
2009-02-07 12:27:24 +00:00
|
|
|
char *reqby;
|
|
|
|
int rv = 0;
|
2008-12-29 05:46:08 +00:00
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
assert(origind != NULL);
|
|
|
|
assert(depd != NULL);
|
|
|
|
assert(repod != NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get some info about dependencies and current repository.
|
|
|
|
*/
|
|
|
|
prop_dictionary_get_cstring_nocopy(depd, "pkgname", &pkgname);
|
|
|
|
prop_dictionary_get_cstring_nocopy(depd, "version", &version);
|
|
|
|
prop_dictionary_get_cstring_nocopy(depd, "filename", &binfile);
|
2009-02-09 15:39:55 +00:00
|
|
|
prop_dictionary_get_cstring_nocopy(depd, "short_desc", &short_desc);
|
2009-02-07 12:27:24 +00:00
|
|
|
prop_dictionary_get_uint32(depd, "priority", &prio);
|
|
|
|
prop_dictionary_get_cstring_nocopy(origind, "pkgname", &reqbyname);
|
|
|
|
prop_dictionary_get_cstring_nocopy(origind, "version", &reqbyver);
|
|
|
|
prop_dictionary_get_cstring_nocopy(repod, "location-local", &repoloc);
|
|
|
|
|
|
|
|
len = strlen(reqbyname) + strlen(reqbyver) + 2;
|
|
|
|
reqby = malloc(len + 1);
|
|
|
|
if (reqby == NULL)
|
|
|
|
return ENOMEM;
|
2008-12-29 05:46:08 +00:00
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
(void)snprintf(reqby, len, "%s-%s", reqbyname, reqbyver);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if dependency is already installed to select the
|
|
|
|
* correct array object.
|
|
|
|
*/
|
|
|
|
if (xbps_check_is_installed_pkgname(pkgname)) {
|
|
|
|
/*
|
|
|
|
* Dependency is already installed.
|
|
|
|
*/
|
|
|
|
array_key = "installed_deps";
|
|
|
|
dict = xbps_find_pkg_in_dict(chaindeps, array_key, pkgname);
|
|
|
|
if (dict)
|
|
|
|
goto out;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Required dependency is not installed. Check if it's
|
|
|
|
* already registered in the chain, and update priority
|
|
|
|
* or add the object into array otherwise.
|
|
|
|
*/
|
|
|
|
prop_dictionary_get_cstring_nocopy(chaindeps, "origin",
|
|
|
|
&originpkg);
|
|
|
|
curpkgdir = xbps_find_pkg_in_dict(chaindeps,
|
|
|
|
"direct_deps", pkgname);
|
|
|
|
curpkgindir = xbps_find_pkg_in_dict(chaindeps,
|
|
|
|
"indirect_deps", pkgname);
|
|
|
|
|
|
|
|
if (strcmp(originpkg, reqbyname) == 0)
|
|
|
|
array_key = "direct_deps";
|
|
|
|
else
|
|
|
|
array_key = "indirect_deps";
|
|
|
|
|
|
|
|
if (curpkgdir && curpkgindir) {
|
2008-12-29 05:46:08 +00:00
|
|
|
goto out;
|
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
} else if (curpkgdir) {
|
|
|
|
/*
|
|
|
|
* Update the priority.
|
|
|
|
*/
|
|
|
|
prop_dictionary_get_uint32(curpkgdir,
|
|
|
|
"priority", &prio);
|
|
|
|
prop_dictionary_set_uint32(curpkgdir,
|
|
|
|
"priority", ++prio);
|
|
|
|
goto out;
|
|
|
|
} else if (curpkgindir) {
|
|
|
|
prop_dictionary_get_uint32(curpkgindir,
|
|
|
|
"priority", &prio);
|
|
|
|
prop_dictionary_set_uint32(curpkgindir,
|
|
|
|
"priority", ++prio);
|
2008-12-29 05:46:08 +00:00
|
|
|
goto out;
|
2009-02-07 12:27:24 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-29 05:46:08 +00:00
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
/*
|
|
|
|
* Create package dep's dictionary and array.
|
|
|
|
*/
|
|
|
|
dict = prop_dictionary_create();
|
|
|
|
if (dict == NULL) {
|
|
|
|
rv = ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
2008-12-29 05:46:08 +00:00
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
array = prop_dictionary_get(chaindeps, array_key);
|
|
|
|
if (array == NULL) {
|
|
|
|
prop_object_release(dict);
|
|
|
|
rv = ENOENT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add required objects into package dep's dictionary.
|
|
|
|
*/
|
|
|
|
prop_dictionary_set_cstring(dict, "pkgname", pkgname);
|
|
|
|
prop_dictionary_set_cstring(dict, "version", version);
|
|
|
|
prop_dictionary_set_cstring(dict, "requiredby", reqby);
|
|
|
|
|
|
|
|
if ((strcmp(array_key, "direct_deps") == 0) ||
|
|
|
|
(strcmp(array_key, "indirect_deps") == 0)) {
|
|
|
|
prop_dictionary_set_cstring(dict, "repository", repoloc);
|
|
|
|
prop_dictionary_set_cstring(dict, "filename", binfile);
|
|
|
|
prop_dictionary_set_uint32(dict, "priority", prio);
|
2009-02-09 15:39:55 +00:00
|
|
|
prop_dictionary_set_cstring(dict, "short_desc", short_desc);
|
2009-02-07 12:27:24 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Add the dictionary into the array.
|
|
|
|
*/
|
|
|
|
if (!xbps_add_obj_to_array(array, dict)) {
|
|
|
|
prop_object_release(dict);
|
|
|
|
rv = EINVAL;
|
|
|
|
goto out;
|
2008-12-29 05:46:08 +00:00
|
|
|
}
|
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
out:
|
|
|
|
free(reqby);
|
|
|
|
|
|
|
|
return rv;
|
2008-12-29 05:46:08 +00:00
|
|
|
}
|
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
static int
|
|
|
|
add_missing_reqdep(const char *pkgname, const char *version)
|
2008-12-29 05:46:08 +00:00
|
|
|
{
|
2009-02-07 12:27:24 +00:00
|
|
|
prop_array_t array;
|
|
|
|
prop_dictionary_t depd;
|
|
|
|
size_t idx = 0;
|
|
|
|
|
|
|
|
assert(pkgname != NULL);
|
|
|
|
assert(version != NULL);
|
2008-12-29 05:46:08 +00:00
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
if (check_missing_reqdep(pkgname, version, &idx) == 0)
|
|
|
|
return EEXIST;
|
|
|
|
|
|
|
|
array = prop_dictionary_get(chaindeps, "missing_deps");
|
|
|
|
depd = prop_dictionary_create();
|
|
|
|
if (depd == NULL)
|
|
|
|
return ENOMEM;
|
|
|
|
|
|
|
|
prop_dictionary_set_cstring_nocopy(depd, "pkgname", pkgname);
|
|
|
|
prop_dictionary_set_cstring_nocopy(depd, "version", version);
|
|
|
|
if (!xbps_add_obj_to_array(array, depd)) {
|
|
|
|
prop_object_release(depd);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2008-12-29 05:46:08 +00:00
|
|
|
}
|
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
static int
|
|
|
|
check_missing_reqdep(const char *pkgname, const char *version,
|
|
|
|
size_t *idx)
|
2008-12-26 03:36:51 +00:00
|
|
|
{
|
2009-02-07 12:27:24 +00:00
|
|
|
prop_array_t array;
|
|
|
|
prop_object_t obj;
|
|
|
|
prop_object_iterator_t iter;
|
|
|
|
const char *missname, *missver;
|
|
|
|
size_t lidx = 0;
|
|
|
|
int rv = 0;
|
2008-12-24 06:20:19 +00:00
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
assert(pkgname != NULL);
|
|
|
|
assert(version != NULL);
|
|
|
|
assert(idx != NULL);
|
2008-12-24 06:20:19 +00:00
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
array = prop_dictionary_get(chaindeps, "missing_deps");
|
|
|
|
assert(array != NULL);
|
2008-12-26 09:13:03 +00:00
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
iter = prop_array_iterator(array);
|
|
|
|
if (iter == NULL)
|
|
|
|
return ENOMEM;
|
|
|
|
|
|
|
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &missname);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "version", &missver);
|
|
|
|
if ((strcmp(pkgname, missname) == 0) &&
|
|
|
|
(strcmp(version, missver) == 0)) {
|
|
|
|
*idx = lidx;
|
|
|
|
goto out;
|
2008-12-26 09:13:03 +00:00
|
|
|
}
|
2009-02-07 12:27:24 +00:00
|
|
|
idx++;
|
2008-12-26 09:13:03 +00:00
|
|
|
}
|
2008-12-24 06:20:19 +00:00
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
rv = ENOENT;
|
2008-12-24 06:20:19 +00:00
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
out:
|
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
return rv;
|
|
|
|
}
|
2008-12-24 06:20:19 +00:00
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
static void
|
|
|
|
remove_missing_reqdep(size_t *idx)
|
|
|
|
{
|
|
|
|
prop_array_t array;
|
2008-12-24 06:20:19 +00:00
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
array = prop_dictionary_get(chaindeps, "missing_deps");
|
|
|
|
assert(array != NULL);
|
|
|
|
prop_array_remove(array, *idx);
|
2008-12-24 06:20:19 +00:00
|
|
|
}
|
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
int
|
|
|
|
xbps_find_deps_in_pkg(prop_dictionary_t repo, prop_dictionary_t pkg)
|
2008-12-24 06:20:19 +00:00
|
|
|
{
|
|
|
|
prop_dictionary_t pkgdict;
|
|
|
|
prop_array_t array;
|
2008-12-23 11:28:21 +00:00
|
|
|
prop_object_t obj;
|
2009-02-07 12:27:24 +00:00
|
|
|
prop_object_iterator_t iter;
|
|
|
|
size_t idx = 0;
|
|
|
|
const char *reqpkg, *reqvers;
|
2008-12-24 06:20:19 +00:00
|
|
|
char *pkgname;
|
2009-02-07 12:27:24 +00:00
|
|
|
int rv = 0;
|
|
|
|
static bool deps_dict;
|
2008-12-23 11:28:21 +00:00
|
|
|
|
|
|
|
array = prop_dictionary_get(pkg, "run_depends");
|
2008-12-24 06:20:19 +00:00
|
|
|
if (array == NULL || prop_array_count(array) == 0)
|
2008-12-23 11:28:21 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
iter = prop_array_iterator(array);
|
2008-12-24 06:20:19 +00:00
|
|
|
if (iter == NULL)
|
2009-02-07 12:27:24 +00:00
|
|
|
return ENOMEM;
|
|
|
|
|
|
|
|
if (deps_dict == false) {
|
|
|
|
deps_dict = true;
|
|
|
|
rv = create_deps_dictionary();
|
|
|
|
if (rv != 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
prop_dictionary_get_cstring_nocopy(pkg, "pkgname", &reqpkg);
|
|
|
|
prop_dictionary_set_cstring_nocopy(chaindeps,
|
|
|
|
"origin", reqpkg);
|
|
|
|
}
|
2008-12-23 11:28:21 +00:00
|
|
|
|
2008-12-26 03:36:51 +00:00
|
|
|
/*
|
|
|
|
* Iterate over the list of required run dependencies for
|
|
|
|
* a package.
|
|
|
|
*/
|
2008-12-23 11:28:21 +00:00
|
|
|
while ((obj = prop_object_iterator_next(iter))) {
|
2008-12-26 03:36:51 +00:00
|
|
|
/*
|
2009-02-07 12:27:24 +00:00
|
|
|
* If required package is not in repo, add it into the
|
|
|
|
* missing deps array and pass to the next one.
|
2008-12-26 03:36:51 +00:00
|
|
|
*/
|
2008-12-23 11:28:21 +00:00
|
|
|
reqpkg = prop_string_cstring_nocopy(obj);
|
2008-12-24 06:20:19 +00:00
|
|
|
pkgname = xbps_get_pkg_name(reqpkg);
|
2009-02-07 12:27:24 +00:00
|
|
|
reqvers = xbps_get_pkg_version(reqpkg);
|
|
|
|
pkgdict = xbps_find_pkg_in_dict(repo, "packages", pkgname);
|
2008-12-26 03:36:51 +00:00
|
|
|
if (pkgdict == NULL) {
|
2009-02-07 12:27:24 +00:00
|
|
|
rv = add_missing_reqdep(pkgname, reqvers);
|
2008-12-26 03:36:51 +00:00
|
|
|
free(pkgname);
|
2009-02-07 12:27:24 +00:00
|
|
|
if (rv != 0 && rv != EEXIST)
|
|
|
|
break;
|
|
|
|
else if (rv == EEXIST)
|
|
|
|
continue;
|
|
|
|
else {
|
|
|
|
rv = XBPS_PKG_ENOTINREPO;
|
|
|
|
continue;
|
|
|
|
}
|
2008-12-26 03:36:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-02-07 12:27:24 +00:00
|
|
|
* Check if dependency wasn't found before.
|
2008-12-26 03:36:51 +00:00
|
|
|
*/
|
2009-02-07 12:27:24 +00:00
|
|
|
rv = check_missing_reqdep(pkgname, reqvers, &idx);
|
2008-12-24 06:20:19 +00:00
|
|
|
free(pkgname);
|
2009-02-07 12:27:24 +00:00
|
|
|
if (rv == 0) {
|
|
|
|
/*
|
2009-02-07 12:33:20 +00:00
|
|
|
* Found in current repository, remove it.
|
|
|
|
*/
|
2009-02-07 12:27:24 +00:00
|
|
|
remove_missing_reqdep(&idx);
|
2008-12-24 06:20:19 +00:00
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
} else if (rv != 0 && rv != ENOENT)
|
|
|
|
break;
|
2009-02-07 12:33:20 +00:00
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
/*
|
|
|
|
* Package is on repo, add it into the dictionary.
|
|
|
|
*/
|
|
|
|
if ((rv = store_dependency(pkg, pkgdict, repo)) != 0)
|
|
|
|
break;
|
|
|
|
/*
|
|
|
|
* Iterate on required pkg to find more deps.
|
|
|
|
*/
|
|
|
|
if (!xbps_find_deps_in_pkg(repo, pkgdict))
|
|
|
|
continue;
|
2008-12-24 06:20:19 +00:00
|
|
|
}
|
2008-12-23 11:28:21 +00:00
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
out:
|
2008-12-24 06:20:19 +00:00
|
|
|
prop_object_iterator_release(iter);
|
2008-12-23 11:28:21 +00:00
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
return rv;
|
2008-12-24 06:20:19 +00:00
|
|
|
}
|
2008-12-23 11:28:21 +00:00
|
|
|
|
2008-12-24 06:20:19 +00:00
|
|
|
int
|
2009-02-09 15:39:55 +00:00
|
|
|
xbps_install_pkg_deps(prop_dictionary_t pkg, const char *destdir)
|
2008-12-24 06:20:19 +00:00
|
|
|
{
|
2009-02-07 12:27:24 +00:00
|
|
|
prop_array_t array, installed, direct, indirect;
|
|
|
|
prop_dictionary_t dict;
|
2008-12-26 03:36:51 +00:00
|
|
|
prop_object_t obj;
|
2009-02-07 12:27:24 +00:00
|
|
|
prop_object_iterator_t iter;
|
|
|
|
uint32_t maxprio = 0, prio = 0;
|
|
|
|
size_t curidx = 0, idx = 0;
|
2009-02-09 15:39:55 +00:00
|
|
|
const char *array_key, *reqby, *curname, *curver;
|
2008-12-24 09:58:19 +00:00
|
|
|
int rv = 0;
|
2008-12-23 11:28:21 +00:00
|
|
|
|
2008-12-26 09:13:03 +00:00
|
|
|
assert(pkg != NULL);
|
|
|
|
|
2008-12-26 03:36:51 +00:00
|
|
|
/*
|
2009-02-07 12:27:24 +00:00
|
|
|
* Install required dependencies of a package.
|
|
|
|
* The order for installation will be:
|
|
|
|
*
|
|
|
|
* - Indirect deps with high->low prio.
|
|
|
|
* - Direct deps with high->low prio.
|
2008-12-26 03:36:51 +00:00
|
|
|
*/
|
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
/*
|
|
|
|
* First case: all deps are satisfied.
|
|
|
|
*/
|
|
|
|
installed = prop_dictionary_get(chaindeps, "installed_deps");
|
|
|
|
direct = prop_dictionary_get(chaindeps, "direct_deps");
|
|
|
|
indirect = prop_dictionary_get(chaindeps, "indirect_deps");
|
|
|
|
if (prop_array_count(direct) == 0 && prop_array_count(indirect) == 0 &&
|
|
|
|
prop_array_count(installed) > 0)
|
|
|
|
return 0;
|
2008-12-23 11:28:21 +00:00
|
|
|
|
2008-12-26 03:36:51 +00:00
|
|
|
/*
|
2009-02-07 12:27:24 +00:00
|
|
|
* Second case: only direct deps are required.
|
2008-12-26 03:36:51 +00:00
|
|
|
*/
|
2009-02-07 12:27:24 +00:00
|
|
|
if (prop_array_count(indirect) == 0 && prop_array_count(direct) > 0)
|
|
|
|
array_key = "direct_deps";
|
|
|
|
else
|
|
|
|
array_key = "indirect_deps";
|
|
|
|
|
|
|
|
again:
|
|
|
|
array = prop_dictionary_get(chaindeps, array_key);
|
2009-02-09 15:39:55 +00:00
|
|
|
if (array && prop_array_count(array) == 0) {
|
|
|
|
rv = 0;
|
|
|
|
goto out;
|
|
|
|
} else if (array == NULL || prop_array_count(array) == 0) {
|
2009-02-07 12:27:24 +00:00
|
|
|
rv = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2008-12-26 03:36:51 +00:00
|
|
|
iter = prop_array_iterator(array);
|
|
|
|
if (iter == NULL) {
|
|
|
|
rv = ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
2009-02-07 12:27:24 +00:00
|
|
|
prop_dictionary_get_uint32(obj, "priority", &prio);
|
|
|
|
if (maxprio < prio) {
|
|
|
|
curidx = idx;
|
|
|
|
maxprio = prio;
|
2008-12-26 03:36:51 +00:00
|
|
|
}
|
2009-02-07 12:27:24 +00:00
|
|
|
idx++;
|
2008-12-26 03:36:51 +00:00
|
|
|
}
|
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
dict = prop_array_get(array, curidx);
|
|
|
|
if (dict == NULL) {
|
|
|
|
rv = ENOENT;
|
2008-12-26 03:36:51 +00:00
|
|
|
goto out;
|
2008-12-24 06:20:19 +00:00
|
|
|
}
|
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
prop_dictionary_get_cstring_nocopy(dict, "pkgname", &curname);
|
2009-02-09 15:39:55 +00:00
|
|
|
prop_dictionary_get_cstring_nocopy(dict, "version", &curver);
|
2009-02-07 12:27:24 +00:00
|
|
|
prop_dictionary_get_cstring_nocopy(dict, "requiredby", &reqby);
|
|
|
|
|
2009-02-09 15:39:55 +00:00
|
|
|
printf("Installing %s-%s required by %s...\n", curname, curver, reqby);
|
|
|
|
rv = xbps_install_binary_pkg_fini(NULL, dict, destdir);
|
|
|
|
if (rv != 0) {
|
|
|
|
printf("Error while installing %s-%s (%s)\n", curname, curver,
|
|
|
|
strerror(rv));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
prop_array_remove(array, curidx);
|
|
|
|
if (prop_array_count(array) > 0) {
|
|
|
|
prio = maxprio = 0;
|
|
|
|
curidx = idx = 0;
|
|
|
|
goto again;
|
|
|
|
} else {
|
|
|
|
prio = maxprio = 0;
|
|
|
|
curidx = idx = 0;
|
|
|
|
array_key = "direct_deps";
|
|
|
|
goto again;
|
2008-12-24 06:20:19 +00:00
|
|
|
}
|
2008-12-23 11:28:21 +00:00
|
|
|
|
2008-12-26 03:36:51 +00:00
|
|
|
out:
|
2009-02-07 12:27:24 +00:00
|
|
|
prop_object_release(chaindeps);
|
2008-12-26 09:13:03 +00:00
|
|
|
|
2008-12-26 03:36:51 +00:00
|
|
|
return rv;
|
2008-12-23 11:28:21 +00:00
|
|
|
}
|