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 *);
|
2009-02-14 00:37:12 +00:00
|
|
|
static int remove_missing_reqdep(const char *);
|
|
|
|
static int find_pkg_deps_from_repo(prop_dictionary_t, prop_dictionary_t,
|
|
|
|
prop_array_t);
|
|
|
|
static int find_pkg_missing_deps_from_repo(prop_dictionary_t,
|
|
|
|
prop_dictionary_t);
|
2009-02-07 12:27:24 +00:00
|
|
|
|
|
|
|
static prop_dictionary_t chaindeps;
|
2009-02-15 19:23:23 +00:00
|
|
|
static bool deps_dict;
|
2009-02-07 12:27:24 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Creates the dictionary to store the dependency chain.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
create_deps_dictionary(void)
|
2008-12-24 06:20:19 +00:00
|
|
|
{
|
2009-02-14 00:37:12 +00:00
|
|
|
prop_array_t unsorted, missing;
|
2009-02-07 12:27:24 +00:00
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
chaindeps = prop_dictionary_create();
|
|
|
|
if (chaindeps == NULL)
|
|
|
|
return ENOMEM;
|
|
|
|
|
|
|
|
missing = prop_array_create();
|
|
|
|
if (missing == NULL) {
|
|
|
|
rv = ENOMEM;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2009-02-12 16:30:38 +00:00
|
|
|
unsorted = prop_array_create();
|
|
|
|
if (unsorted == NULL) {
|
2009-02-07 12:27:24 +00:00
|
|
|
rv = ENOMEM;
|
2009-02-14 00:37:12 +00:00
|
|
|
goto fail2;
|
2009-02-07 12:27:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!xbps_add_obj_to_dict(chaindeps, missing, "missing_deps")) {
|
|
|
|
rv = EINVAL;
|
2009-02-14 00:37:12 +00:00
|
|
|
goto fail3;
|
2008-12-26 03:36:51 +00:00
|
|
|
}
|
2009-02-12 16:30:38 +00:00
|
|
|
if (!xbps_add_obj_to_dict(chaindeps, unsorted, "unsorted_deps")) {
|
2009-02-07 12:27:24 +00:00
|
|
|
rv = EINVAL;
|
2009-02-14 00:37:12 +00:00
|
|
|
goto fail3;
|
2009-02-07 12:27:24 +00:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
fail3:
|
2009-02-14 00:37:12 +00:00
|
|
|
prop_object_release(unsorted);
|
2009-02-07 12:27:24 +00:00
|
|
|
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-12 16:30:38 +00:00
|
|
|
prop_dictionary_t dict, curdict;
|
|
|
|
prop_array_t array, rundeps_array, reqby_array;
|
|
|
|
prop_string_t reqbystr;
|
2009-02-07 12:27:24 +00:00
|
|
|
uint32_t prio = 0;
|
2009-02-12 16:30:38 +00:00
|
|
|
size_t len = 0, dirdepscnt = 0, indirdepscnt = 0;
|
2009-02-15 23:39:41 +00:00
|
|
|
const char *pkgname, *version, *reqbyname, *reqbyver, *arch;
|
2009-02-14 00:37:12 +00:00
|
|
|
const char *repoloc, *binfile, *originpkg, *short_desc;
|
2009-02-12 21:51:46 +00:00
|
|
|
char *reqby, *pkgnver;
|
2009-02-07 12:27:24 +00:00
|
|
|
int rv = 0;
|
2009-02-12 16:30:38 +00:00
|
|
|
bool indirectdep = false;
|
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-15 23:39:41 +00:00
|
|
|
prop_dictionary_get_cstring_nocopy(depd, "architecture", &arch);
|
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);
|
2009-02-12 16:30:38 +00:00
|
|
|
reqbystr = prop_string_create_cstring(reqby);
|
2009-02-07 12:27:24 +00:00
|
|
|
|
2009-02-12 21:51:46 +00:00
|
|
|
len = strlen(pkgname) + strlen(version) + 2;
|
|
|
|
pkgnver = malloc(len + 1);
|
|
|
|
if (pkgnver == NULL) {
|
|
|
|
free(reqby);
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
(void)snprintf(pkgnver, len, "%s-%s", pkgname, version);
|
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
/*
|
2009-02-14 00:37:12 +00:00
|
|
|
* Required dependency is not installed. Check if it's
|
|
|
|
* already registered in the chain, and update some objects
|
|
|
|
* or add the object into array otherwise.
|
2009-02-07 12:27:24 +00:00
|
|
|
*/
|
2009-02-14 00:37:12 +00:00
|
|
|
prop_dictionary_get_cstring_nocopy(chaindeps, "origin", &originpkg);
|
|
|
|
curdict = xbps_find_pkg_in_dict(chaindeps, "unsorted_deps", pkgname);
|
|
|
|
/*
|
|
|
|
* Update priority and required_by objects.
|
|
|
|
*/
|
|
|
|
if (curdict) {
|
|
|
|
prop_dictionary_get_uint32(curdict, "priority", &prio);
|
|
|
|
prop_dictionary_set_uint32(curdict, "priority", ++prio);
|
|
|
|
reqby_array = prop_dictionary_get(curdict, "required_by");
|
|
|
|
if (!xbps_find_string_in_array(reqby_array, reqby))
|
|
|
|
prop_array_add(reqby_array, reqbystr);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (strcmp(originpkg, reqbyname)) {
|
|
|
|
indirectdep = true;
|
|
|
|
prop_dictionary_get_uint32(chaindeps, "indirectdeps_count",
|
|
|
|
&indirdepscnt);
|
|
|
|
prop_dictionary_set_uint32(chaindeps, "indirectdeps_count",
|
|
|
|
++indirdepscnt);
|
2009-02-07 12:27:24 +00:00
|
|
|
} else {
|
2009-02-14 00:37:12 +00:00
|
|
|
prop_dictionary_get_uint32(chaindeps, "directdeps_count",
|
|
|
|
&dirdepscnt);
|
|
|
|
prop_dictionary_set_uint32(chaindeps, "directdeps_count",
|
|
|
|
++dirdepscnt);
|
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-14 00:37:12 +00:00
|
|
|
array = prop_dictionary_get(chaindeps, "unsorted_deps");
|
2009-02-07 12:27:24 +00:00
|
|
|
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);
|
2009-02-10 01:52:12 +00:00
|
|
|
rundeps_array = prop_dictionary_get(depd, "run_depends");
|
|
|
|
if (rundeps_array && prop_array_count(rundeps_array) > 0)
|
|
|
|
prop_dictionary_set(dict, "run_depends", rundeps_array);
|
2009-02-07 12:27:24 +00:00
|
|
|
|
2009-02-12 16:30:38 +00:00
|
|
|
reqby_array = prop_array_create();
|
|
|
|
if (reqby_array == NULL) {
|
|
|
|
prop_object_release(dict);
|
|
|
|
rv = ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
prop_array_add(reqby_array, reqbystr);
|
|
|
|
prop_dictionary_set(dict, "required_by", reqby_array);
|
2009-02-14 00:37:12 +00:00
|
|
|
prop_dictionary_set_cstring(dict, "repository", repoloc);
|
|
|
|
prop_dictionary_set_cstring(dict, "filename", binfile);
|
|
|
|
prop_dictionary_set_uint32(dict, "priority", prio);
|
|
|
|
prop_dictionary_set_cstring(dict, "short_desc", short_desc);
|
|
|
|
prop_dictionary_set_bool(dict, "indirect_dep", indirectdep);
|
2009-02-15 23:39:41 +00:00
|
|
|
prop_dictionary_set_cstring(dict, "architecture", arch);
|
2009-02-12 16:30:38 +00:00
|
|
|
|
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;
|
2008-12-29 05:46:08 +00:00
|
|
|
}
|
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
out:
|
|
|
|
free(reqby);
|
2009-02-12 21:51:46 +00:00
|
|
|
free(pkgnver);
|
2009-02-12 16:30:38 +00:00
|
|
|
prop_object_release(reqbystr);
|
2009-02-07 12:27:24 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
assert(pkgname != NULL);
|
|
|
|
assert(version != NULL);
|
2008-12-29 05:46:08 +00:00
|
|
|
|
2009-02-12 16:30:38 +00:00
|
|
|
/*
|
|
|
|
* Adds a package into the missing deps array.
|
|
|
|
*/
|
2009-02-14 00:37:12 +00:00
|
|
|
if (xbps_find_pkg_in_dict(chaindeps, "missing_deps", pkgname))
|
2009-02-07 12:27:24 +00:00
|
|
|
return EEXIST;
|
|
|
|
|
|
|
|
array = prop_dictionary_get(chaindeps, "missing_deps");
|
|
|
|
depd = prop_dictionary_create();
|
|
|
|
if (depd == NULL)
|
|
|
|
return ENOMEM;
|
|
|
|
|
2009-02-14 00:37:12 +00:00
|
|
|
prop_dictionary_set_cstring(depd, "pkgname", pkgname);
|
|
|
|
prop_dictionary_set_cstring(depd, "version", version);
|
2009-02-07 12:27:24 +00:00
|
|
|
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
|
2009-02-14 00:37:12 +00:00
|
|
|
remove_missing_reqdep(const char *pkgname)
|
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;
|
2009-02-14 00:37:12 +00:00
|
|
|
size_t idx = 0;
|
|
|
|
const char *curname;
|
|
|
|
bool found = false;
|
2008-12-24 06:20:19 +00:00
|
|
|
|
2009-02-14 00:37:12 +00:00
|
|
|
array = prop_dictionary_get(chaindeps, "missing_deps");
|
2009-02-07 12:27:24 +00:00
|
|
|
assert(pkgname != NULL);
|
|
|
|
assert(version != NULL);
|
|
|
|
assert(array != NULL);
|
|
|
|
iter = prop_array_iterator(array);
|
|
|
|
if (iter == NULL)
|
|
|
|
return ENOMEM;
|
2009-02-12 16:30:38 +00:00
|
|
|
/*
|
|
|
|
* Finds the index of a package in the missing deps array.
|
|
|
|
*/
|
2009-02-07 12:27:24 +00:00
|
|
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
2009-02-14 00:37:12 +00:00
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &curname);
|
|
|
|
if (strcmp(pkgname, curname) == 0) {
|
|
|
|
found = true;
|
|
|
|
break;
|
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
|
|
|
}
|
2009-02-14 00:37:12 +00:00
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
if (found) {
|
|
|
|
prop_array_remove(array, idx);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
xbps_find_deps_in_pkg(prop_dictionary_t pkg)
|
|
|
|
{
|
|
|
|
prop_array_t array, pkg_rdeps, missing_rdeps;
|
|
|
|
prop_dictionary_t repolistd, repod;
|
|
|
|
prop_object_t obj;
|
|
|
|
prop_object_iterator_t iter;
|
|
|
|
char *plist;
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
assert(pkg != NULL);
|
|
|
|
|
2009-02-16 23:08:03 +00:00
|
|
|
pkg_rdeps = prop_dictionary_get(pkg, "run_depends");
|
|
|
|
if (pkg_rdeps == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2009-02-14 00:37:12 +00:00
|
|
|
/*
|
|
|
|
* Get the dictionary with the list of registered repositories.
|
|
|
|
*/
|
|
|
|
plist = xbps_append_full_path(true, NULL, XBPS_REPOLIST);
|
|
|
|
if (plist == NULL)
|
|
|
|
return EINVAL;
|
|
|
|
/*
|
|
|
|
* Get the dictionary with the list of registered repositories.
|
|
|
|
*/
|
|
|
|
repolistd = prop_dictionary_internalize_from_file(plist);
|
|
|
|
if (repolistd == NULL) {
|
|
|
|
free(plist);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
free(plist);
|
|
|
|
plist = NULL;
|
|
|
|
|
|
|
|
array = prop_dictionary_get(repolistd, "repository-list");
|
|
|
|
if (array == NULL) {
|
|
|
|
prop_object_release(repolistd);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
iter = prop_array_iterator(array);
|
|
|
|
if (iter == NULL) {
|
|
|
|
prop_object_release(repolistd);
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterate over the repository pool and find out if we have
|
|
|
|
* all available binary packages.
|
|
|
|
*/
|
|
|
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
2009-02-15 23:39:41 +00:00
|
|
|
plist =
|
|
|
|
xbps_get_pkg_index_plist(prop_string_cstring_nocopy(obj));
|
2009-02-14 00:37:12 +00:00
|
|
|
if (plist == NULL) {
|
|
|
|
rv = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
repod = prop_dictionary_internalize_from_file(plist);
|
|
|
|
if (repod == NULL) {
|
|
|
|
free(plist);
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
free(plist);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This will find direct and indirect deps,
|
|
|
|
* if any of them is not there it will be added
|
|
|
|
* into the missing_deps array.
|
|
|
|
*/
|
|
|
|
rv = find_pkg_deps_from_repo(repod, pkg, pkg_rdeps);
|
|
|
|
if (rv != 0) {
|
|
|
|
if (rv == ENOENT) {
|
|
|
|
rv = 0;
|
|
|
|
prop_object_release(repod);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
prop_object_release(repod);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
prop_object_release(repod);
|
|
|
|
}
|
|
|
|
|
|
|
|
missing_rdeps = prop_dictionary_get(chaindeps, "missing_deps");
|
|
|
|
if (prop_array_count(missing_rdeps) == 0)
|
|
|
|
goto out;
|
2009-02-15 19:23:23 +00:00
|
|
|
|
2009-02-14 00:37:12 +00:00
|
|
|
/*
|
|
|
|
* If there are missing deps, iterate one more time
|
|
|
|
* just in case that indirect deps weren't found.
|
|
|
|
*/
|
|
|
|
prop_object_iterator_reset(iter);
|
|
|
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
2009-02-15 23:39:41 +00:00
|
|
|
plist =
|
|
|
|
xbps_get_pkg_index_plist(prop_string_cstring_nocopy(obj));
|
2009-02-14 00:37:12 +00:00
|
|
|
if (plist == NULL) {
|
|
|
|
rv = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
repod = prop_dictionary_internalize_from_file(plist);
|
|
|
|
if (repod == NULL) {
|
|
|
|
free(plist);
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
free(plist);
|
|
|
|
|
|
|
|
rv = find_pkg_missing_deps_from_repo(repod, pkg);
|
|
|
|
if (rv != 0 && rv != ENOENT) {
|
|
|
|
prop_object_release(repod);
|
|
|
|
break;
|
|
|
|
}
|
2008-12-24 06:20:19 +00:00
|
|
|
|
2009-02-14 00:37:12 +00:00
|
|
|
prop_object_release(repod);
|
|
|
|
}
|
2008-12-24 06:20:19 +00:00
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
out:
|
|
|
|
prop_object_iterator_release(iter);
|
2009-02-14 00:37:12 +00:00
|
|
|
prop_object_release(repolistd);
|
|
|
|
|
|
|
|
return rv;
|
2009-02-07 12:27:24 +00:00
|
|
|
}
|
2008-12-24 06:20:19 +00:00
|
|
|
|
2009-02-15 19:23:23 +00:00
|
|
|
prop_dictionary_t
|
|
|
|
xbps_get_pkg_deps_dictionary(void)
|
|
|
|
{
|
|
|
|
if (!deps_dict)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return prop_dictionary_copy(chaindeps);
|
|
|
|
}
|
|
|
|
|
2009-02-14 00:37:12 +00:00
|
|
|
static int
|
|
|
|
find_pkg_missing_deps_from_repo(prop_dictionary_t repo, prop_dictionary_t pkg)
|
2009-02-07 12:27:24 +00:00
|
|
|
{
|
|
|
|
prop_array_t array;
|
2009-02-14 00:37:12 +00:00
|
|
|
prop_dictionary_t curpkgd;
|
|
|
|
prop_object_t obj;
|
|
|
|
prop_object_iterator_t iter;
|
|
|
|
const char *pkgname, *version;
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
assert(repo != NULL);
|
|
|
|
assert(pkg != NULL);
|
2008-12-24 06:20:19 +00:00
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
array = prop_dictionary_get(chaindeps, "missing_deps");
|
2009-02-14 00:37:12 +00:00
|
|
|
if (prop_array_count(array) == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
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", &pkgname);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
|
|
|
/*
|
|
|
|
* If required package is not in repo, add it into the
|
|
|
|
* missing deps array and pass to the next one.
|
|
|
|
*/
|
|
|
|
curpkgd = xbps_find_pkg_in_dict(repo, "packages", pkgname);
|
|
|
|
if (curpkgd == NULL) {
|
|
|
|
rv = add_missing_reqdep(pkgname, version);
|
|
|
|
if (rv != 0 && rv != EEXIST)
|
|
|
|
break;
|
|
|
|
else {
|
|
|
|
rv = ENOENT;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Package is on repo, add it into the dictionary.
|
|
|
|
*/
|
|
|
|
if ((rv = store_dependency(pkg, curpkgd, repo)) != 0)
|
|
|
|
break;
|
|
|
|
/*
|
|
|
|
* Remove package from missing now.
|
|
|
|
*/
|
|
|
|
rv = remove_missing_reqdep(pkgname);
|
|
|
|
if (rv != 0 && rv != ENOENT)
|
|
|
|
break;
|
|
|
|
|
|
|
|
prop_object_iterator_reset(iter);
|
|
|
|
}
|
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
|
|
|
|
return rv;
|
2008-12-24 06:20:19 +00:00
|
|
|
}
|
|
|
|
|
2009-02-14 00:37:12 +00:00
|
|
|
static int
|
|
|
|
find_pkg_deps_from_repo(prop_dictionary_t repo, prop_dictionary_t pkg,
|
|
|
|
prop_array_t pkg_rdeps)
|
2008-12-24 06:20:19 +00:00
|
|
|
{
|
2009-02-14 00:37:12 +00:00
|
|
|
prop_dictionary_t curpkgd;
|
|
|
|
prop_array_t curpkg_rdeps;
|
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;
|
|
|
|
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;
|
2008-12-23 11:28:21 +00:00
|
|
|
|
2009-02-14 00:37:12 +00:00
|
|
|
/*
|
|
|
|
* Package doesn't have deps, check to be sure.
|
|
|
|
*/
|
|
|
|
if (pkg_rdeps == NULL || prop_array_count(pkg_rdeps) == 0)
|
2008-12-23 11:28:21 +00:00
|
|
|
return 0;
|
|
|
|
|
2009-02-14 00:37:12 +00:00
|
|
|
iter = prop_array_iterator(pkg_rdeps);
|
2008-12-24 06:20:19 +00:00
|
|
|
if (iter == NULL)
|
2009-02-07 12:27:24 +00:00
|
|
|
return ENOMEM;
|
2009-02-14 00:37:12 +00:00
|
|
|
/*
|
|
|
|
* Save the name of the origin package once.
|
|
|
|
*/
|
2009-02-07 12:27:24 +00:00
|
|
|
if (deps_dict == false) {
|
|
|
|
deps_dict = true;
|
|
|
|
rv = create_deps_dictionary();
|
2009-02-14 00:37:12 +00:00
|
|
|
if (rv != 0) {
|
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
return rv;
|
|
|
|
}
|
2009-02-07 12:27:24 +00:00
|
|
|
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
|
2009-02-14 00:37:12 +00:00
|
|
|
* current package.
|
2008-12-26 03:36:51 +00:00
|
|
|
*/
|
2008-12-23 11:28:21 +00:00
|
|
|
while ((obj = prop_object_iterator_next(iter))) {
|
2009-02-14 00:37:12 +00:00
|
|
|
reqpkg = prop_string_cstring_nocopy(obj);
|
|
|
|
pkgname = xbps_get_pkg_name(reqpkg);
|
|
|
|
reqvers = xbps_get_pkg_version(reqpkg);
|
|
|
|
/*
|
|
|
|
* Check if required dep is satisfied and installed.
|
|
|
|
*/
|
|
|
|
if (xbps_check_is_installed_pkg(reqpkg) == 0) {
|
|
|
|
free(pkgname);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Check if package is already added in the
|
|
|
|
* array of unsorted deps.
|
|
|
|
*/
|
|
|
|
if (xbps_find_pkg_in_dict(chaindeps, "unsorted_deps",
|
|
|
|
pkgname)) {
|
|
|
|
free(pkgname);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2009-02-14 00:37:12 +00:00
|
|
|
curpkgd = xbps_find_pkg_in_dict(repo, "packages", pkgname);
|
|
|
|
if (curpkgd == 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 {
|
2009-02-14 00:37:12 +00:00
|
|
|
rv = ENOENT;
|
2009-02-07 12:27:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2008-12-26 03:36:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-02-14 00:37:12 +00:00
|
|
|
* Package is on repo, add it into the dictionary.
|
2008-12-26 03:36:51 +00:00
|
|
|
*/
|
2009-02-14 00:37:12 +00:00
|
|
|
if ((rv = store_dependency(pkg, curpkgd, repo)) != 0) {
|
|
|
|
free(pkgname);
|
2009-02-07 12:27:24 +00:00
|
|
|
break;
|
2009-02-14 00:37:12 +00:00
|
|
|
}
|
2009-02-07 12:33:20 +00:00
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
/*
|
2009-02-14 00:37:12 +00:00
|
|
|
* Remove package from missing_deps now it's been found.
|
2009-02-07 12:27:24 +00:00
|
|
|
*/
|
2009-02-14 00:37:12 +00:00
|
|
|
rv = remove_missing_reqdep(pkgname);
|
|
|
|
if (rv != 0 && rv != ENOENT) {
|
|
|
|
free(pkgname);
|
2009-02-07 12:27:24 +00:00
|
|
|
break;
|
2009-02-14 00:37:12 +00:00
|
|
|
}
|
|
|
|
free(pkgname);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If package doesn't have rundeps, pass to the next one.
|
|
|
|
*/
|
|
|
|
curpkg_rdeps = prop_dictionary_get(curpkgd, "run_depends");
|
|
|
|
if (curpkg_rdeps == NULL)
|
|
|
|
continue;
|
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
/*
|
|
|
|
* Iterate on required pkg to find more deps.
|
|
|
|
*/
|
2009-02-14 00:37:12 +00:00
|
|
|
if (!find_pkg_deps_from_repo(repo, curpkgd, curpkg_rdeps))
|
2009-02-07 12:27:24 +00:00
|
|
|
continue;
|
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-18 00:07:51 +00:00
|
|
|
xbps_install_pkg_deps(const char *pkgname, const char *destdir, int flags)
|
2008-12-24 06:20:19 +00:00
|
|
|
{
|
2009-02-14 00:37:12 +00:00
|
|
|
prop_array_t required, missing;
|
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;
|
2008-12-24 09:58:19 +00:00
|
|
|
int rv = 0;
|
2008-12-23 11:28:21 +00:00
|
|
|
|
2009-02-18 00:07:51 +00:00
|
|
|
/*
|
|
|
|
* If origin object in chaindeps is not the same, bail out.
|
|
|
|
*/
|
|
|
|
obj = prop_dictionary_get(chaindeps, "origin");
|
|
|
|
if (obj == NULL || !prop_string_equals_cstring(obj, pkgname))
|
|
|
|
return EINVAL;
|
2009-02-14 00:37:12 +00:00
|
|
|
/*
|
|
|
|
* If there are missing deps, bail out.
|
|
|
|
*/
|
|
|
|
missing = prop_dictionary_get(chaindeps, "missing_deps");
|
|
|
|
if (prop_array_count(missing) > 0)
|
|
|
|
return ENOTSUP;
|
2008-12-26 03:36:51 +00:00
|
|
|
/*
|
2009-02-12 16:30:38 +00:00
|
|
|
* Sort the dependency chain into an array.
|
2008-12-26 03:36:51 +00:00
|
|
|
*/
|
2009-02-12 16:30:38 +00:00
|
|
|
if ((rv = xbps_sort_pkg_deps(chaindeps)) != 0)
|
2009-02-14 00:37:12 +00:00
|
|
|
return rv;
|
2008-12-26 03:36:51 +00:00
|
|
|
|
2009-02-12 16:30:38 +00:00
|
|
|
required = prop_dictionary_get(chaindeps, "required_deps");
|
|
|
|
if (required == NULL)
|
2009-02-07 12:27:24 +00:00
|
|
|
return 0;
|
2008-12-23 11:28:21 +00:00
|
|
|
|
2009-02-15 19:23:23 +00:00
|
|
|
|
2009-02-12 16:30:38 +00:00
|
|
|
iter = prop_array_iterator(required);
|
2009-02-14 00:37:12 +00:00
|
|
|
if (iter == NULL)
|
|
|
|
return ENOMEM;
|
2008-12-26 03:36:51 +00:00
|
|
|
|
2009-02-12 16:30:38 +00:00
|
|
|
/*
|
|
|
|
* Install all required dependencies, previously sorted.
|
|
|
|
*/
|
2008-12-26 03:36:51 +00:00
|
|
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
2009-02-16 23:08:03 +00:00
|
|
|
rv = xbps_install_binary_pkg_fini(NULL, obj, destdir, flags);
|
2009-02-12 16:30:38 +00:00
|
|
|
if (rv != 0)
|
2009-02-12 20:17:35 +00:00
|
|
|
break;
|
2008-12-26 03:36:51 +00:00
|
|
|
}
|
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
|
|
|
|
return rv;
|
2008-12-23 11:28:21 +00:00
|
|
|
}
|