2009-08-17 22:37:20 +05:30
|
|
|
/*-
|
2010-01-14 06:44:31 +05:30
|
|
|
* Copyright (c) 2008-2010 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 <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
|
2010-05-20 10:51:24 +05:30
|
|
|
store_dependency(prop_dictionary_t trans_dict, prop_dictionary_t repo_pkg_dict,
|
2009-10-27 06:16:00 +05:30
|
|
|
const char *repoloc)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
|
|
|
prop_dictionary_t dict;
|
|
|
|
prop_array_t array;
|
2010-05-19 02:34:14 +05:30
|
|
|
const char *pkgname, *pkgver;
|
|
|
|
int flags = xbps_get_flags(), rv = 0;
|
2009-08-17 22:37:20 +05:30
|
|
|
pkg_state_t state = 0;
|
|
|
|
|
2010-05-20 10:51:24 +05:30
|
|
|
assert(trans_dict != NULL);
|
|
|
|
assert(repo_pkg_dict != NULL);
|
2009-10-27 06:16:00 +05:30
|
|
|
assert(repoloc != NULL);
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
|
|
|
* Get some info about dependencies and current repository.
|
|
|
|
*/
|
2010-11-06 11:14:00 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(repo_pkg_dict, "pkgname", &pkgname);
|
|
|
|
prop_dictionary_get_cstring_nocopy(repo_pkg_dict, "pkgver", &pkgver);
|
2010-05-19 02:34:14 +05:30
|
|
|
|
2010-05-20 10:51:24 +05:30
|
|
|
dict = prop_dictionary_copy(repo_pkg_dict);
|
2009-08-17 22:37:20 +05:30
|
|
|
if (dict == NULL)
|
|
|
|
return errno;
|
|
|
|
|
2010-05-20 10:51:24 +05:30
|
|
|
array = prop_dictionary_get(trans_dict, "unsorted_deps");
|
2009-08-17 22:37:20 +05:30
|
|
|
if (array == NULL) {
|
|
|
|
prop_object_release(dict);
|
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Always set "not-installed" package state. Will be overwritten
|
|
|
|
* to its correct state later.
|
|
|
|
*/
|
|
|
|
rv = xbps_set_pkg_state_dictionary(dict, XBPS_PKG_STATE_NOT_INSTALLED);
|
|
|
|
if (rv != 0) {
|
|
|
|
prop_object_release(dict);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Overwrite package state in dictionary if it was unpacked
|
|
|
|
* previously.
|
|
|
|
*/
|
|
|
|
rv = xbps_get_pkg_state_installed(pkgname, &state);
|
|
|
|
if (rv == 0) {
|
|
|
|
if ((rv = xbps_set_pkg_state_dictionary(dict, state)) != 0) {
|
|
|
|
prop_object_release(dict);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Add required objects into package dep's dictionary.
|
|
|
|
*/
|
2009-11-23 15:16:51 +05:30
|
|
|
if (!prop_dictionary_set_cstring(dict, "repository", repoloc)) {
|
|
|
|
prop_object_release(dict);
|
|
|
|
return errno;
|
|
|
|
}
|
2009-12-22 17:07:36 +05:30
|
|
|
if (!prop_dictionary_set_bool(dict, "automatic-install", true)) {
|
|
|
|
prop_object_release(dict);
|
|
|
|
return errno;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
|
|
|
* Add the dictionary into the array.
|
|
|
|
*/
|
|
|
|
if (!xbps_add_obj_to_array(array, dict)) {
|
|
|
|
prop_object_release(dict);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
2010-05-19 02:34:14 +05:30
|
|
|
if (flags & XBPS_FLAG_VERBOSE)
|
2010-05-20 10:51:24 +05:30
|
|
|
printf("\n Added package '%s' into the transaction (%s).\n",
|
2010-05-19 02:34:14 +05:30
|
|
|
pkgver, repoloc);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-05-20 10:51:24 +05:30
|
|
|
add_missing_reqdep(prop_dictionary_t trans_dict, const char *reqpkg)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2009-11-21 11:42:42 +05:30
|
|
|
prop_array_t missing_rdeps;
|
2009-11-29 07:47:35 +05:30
|
|
|
prop_string_t reqpkg_str;
|
|
|
|
prop_object_iterator_t iter = NULL;
|
|
|
|
prop_object_t obj;
|
|
|
|
size_t idx = 0;
|
|
|
|
bool add_pkgdep, pkgfound, update_pkgdep;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2010-05-20 10:51:24 +05:30
|
|
|
assert(trans_dict != NULL);
|
2009-11-29 07:47:35 +05:30
|
|
|
assert(reqpkg != NULL);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2009-11-29 07:47:35 +05:30
|
|
|
add_pkgdep = update_pkgdep = pkgfound = false;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2009-11-29 07:47:35 +05:30
|
|
|
reqpkg_str = prop_string_create_cstring_nocopy(reqpkg);
|
|
|
|
if (reqpkg_str == NULL)
|
2009-11-21 11:42:42 +05:30
|
|
|
return errno;
|
|
|
|
|
2010-05-20 10:51:24 +05:30
|
|
|
missing_rdeps = prop_dictionary_get(trans_dict, "missing_deps");
|
2009-11-29 07:47:35 +05:30
|
|
|
iter = prop_array_iterator(missing_rdeps);
|
|
|
|
if (iter == NULL)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
|
|
|
const char *curdep, *curver, *pkgver;
|
|
|
|
char *curpkgnamedep = NULL, *pkgnamedep = NULL;
|
|
|
|
|
|
|
|
assert(prop_object_type(obj) == PROP_TYPE_STRING);
|
|
|
|
curdep = prop_string_cstring_nocopy(obj);
|
2010-01-21 07:40:19 +05:30
|
|
|
curver = xbps_get_pkgpattern_version(curdep);
|
|
|
|
pkgver = xbps_get_pkgpattern_version(reqpkg);
|
2009-11-29 07:47:35 +05:30
|
|
|
if (curver == NULL || pkgver == NULL)
|
|
|
|
goto out;
|
2010-01-21 07:40:19 +05:30
|
|
|
curpkgnamedep = xbps_get_pkgpattern_name(curdep);
|
2009-11-29 07:47:35 +05:30
|
|
|
if (curpkgnamedep == NULL)
|
|
|
|
goto out;
|
2010-01-21 07:40:19 +05:30
|
|
|
pkgnamedep = xbps_get_pkgpattern_name(reqpkg);
|
2009-11-29 07:47:35 +05:30
|
|
|
if (pkgnamedep == NULL) {
|
|
|
|
free(curpkgnamedep);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (strcmp(pkgnamedep, curpkgnamedep) == 0) {
|
|
|
|
pkgfound = true;
|
|
|
|
/*
|
|
|
|
* if new dependency version is greater than current
|
|
|
|
* one, store it.
|
|
|
|
*/
|
|
|
|
DPRINTF(("Missing pkgdep name matched, curver: %s "
|
|
|
|
"newver: %s\n", curver, pkgver));
|
|
|
|
if (xbps_cmpver(curver, pkgver) <= 0) {
|
|
|
|
add_pkgdep = false;
|
|
|
|
free(curpkgnamedep);
|
|
|
|
free(pkgnamedep);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
update_pkgdep = true;
|
|
|
|
}
|
|
|
|
free(curpkgnamedep);
|
|
|
|
free(pkgnamedep);
|
|
|
|
if (pkgfound)
|
|
|
|
break;
|
|
|
|
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
add_pkgdep = true;
|
|
|
|
out:
|
|
|
|
if (iter)
|
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
if (update_pkgdep)
|
|
|
|
prop_array_remove(missing_rdeps, idx);
|
|
|
|
if (add_pkgdep && !xbps_add_obj_to_array(missing_rdeps, reqpkg_str)) {
|
|
|
|
prop_object_release(reqpkg_str);
|
2009-11-23 15:16:51 +05:30
|
|
|
return errno;
|
|
|
|
}
|
2009-11-29 07:47:35 +05:30
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-05-20 10:51:24 +05:30
|
|
|
remove_missing_reqdep(prop_dictionary_t trans_dict, const char *reqpkg)
|
2009-11-29 07:47:35 +05:30
|
|
|
{
|
|
|
|
prop_array_t missing_rdeps;
|
|
|
|
prop_object_iterator_t iter = NULL;
|
|
|
|
prop_object_t obj;
|
|
|
|
size_t idx = 0;
|
|
|
|
int rv = 0;
|
|
|
|
bool found = false;
|
|
|
|
|
2010-05-20 10:51:24 +05:30
|
|
|
assert(trans_dict != NULL);
|
2009-11-29 07:47:35 +05:30
|
|
|
assert(reqpkg != NULL);
|
|
|
|
|
2010-05-20 10:51:24 +05:30
|
|
|
missing_rdeps = prop_dictionary_get(trans_dict, "missing_deps");
|
2009-11-29 07:47:35 +05:30
|
|
|
iter = prop_array_iterator(missing_rdeps);
|
|
|
|
if (iter == NULL)
|
2009-11-23 15:16:51 +05:30
|
|
|
return errno;
|
2009-11-29 07:47:35 +05:30
|
|
|
|
|
|
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
|
|
|
const char *curdep;
|
|
|
|
char *curpkgnamedep, *reqpkgname;
|
|
|
|
|
|
|
|
curdep = prop_string_cstring_nocopy(obj);
|
2010-01-21 07:40:19 +05:30
|
|
|
curpkgnamedep = xbps_get_pkgpattern_name(curdep);
|
2009-11-29 07:47:35 +05:30
|
|
|
if (curpkgnamedep == NULL) {
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
2010-01-21 07:40:19 +05:30
|
|
|
reqpkgname = xbps_get_pkgpattern_name(reqpkg);
|
2009-11-29 07:47:35 +05:30
|
|
|
if (reqpkgname == NULL) {
|
|
|
|
free(curpkgnamedep);
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (strcmp(reqpkgname, curpkgnamedep) == 0)
|
|
|
|
found = true;
|
|
|
|
|
|
|
|
free(curpkgnamedep);
|
|
|
|
free(reqpkgname);
|
|
|
|
if (found)
|
|
|
|
break;
|
|
|
|
idx++;
|
2009-11-23 15:16:51 +05:30
|
|
|
}
|
2009-11-29 07:47:35 +05:30
|
|
|
out:
|
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
if (found) {
|
|
|
|
prop_array_remove(missing_rdeps, idx);
|
|
|
|
return 0;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2009-11-29 07:47:35 +05:30
|
|
|
if (rv == 0)
|
|
|
|
rv = ENOENT;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2009-11-29 07:47:35 +05:30
|
|
|
return rv;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-05-20 10:51:24 +05:30
|
|
|
find_repo_deps(prop_dictionary_t trans_dict, prop_dictionary_t repo_dict,
|
|
|
|
const char *repoloc, const char *originpkgn,
|
|
|
|
prop_array_t pkg_rdeps_array)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2009-11-23 05:13:48 +05:30
|
|
|
prop_dictionary_t curpkgd, tmpd;
|
2009-08-17 22:37:20 +05:30
|
|
|
prop_array_t curpkg_rdeps;
|
2009-11-23 05:13:48 +05:30
|
|
|
prop_object_t obj;
|
2009-08-17 22:37:20 +05:30
|
|
|
prop_object_iterator_t iter;
|
2009-11-26 07:52:50 +05:30
|
|
|
pkg_state_t state = 0;
|
2009-11-29 10:22:32 +05:30
|
|
|
const char *reqpkg, *reqvers, *pkg_queued, *repo_pkgver;
|
2009-08-17 22:37:20 +05:30
|
|
|
char *pkgname;
|
2010-05-19 02:34:14 +05:30
|
|
|
int flags = xbps_get_flags(), rv = 0;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2010-05-20 10:51:24 +05:30
|
|
|
iter = prop_array_iterator(pkg_rdeps_array);
|
2009-08-17 22:37:20 +05:30
|
|
|
if (iter == NULL)
|
|
|
|
return ENOMEM;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterate over the list of required run dependencies for
|
|
|
|
* current package.
|
|
|
|
*/
|
2009-11-23 02:22:57 +05:30
|
|
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
2009-08-17 22:37:20 +05:30
|
|
|
reqpkg = prop_string_cstring_nocopy(obj);
|
2009-11-23 15:16:51 +05:30
|
|
|
if (reqpkg == NULL) {
|
|
|
|
rv = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2010-05-20 10:51:24 +05:30
|
|
|
if (flags & XBPS_FLAG_VERBOSE) {
|
|
|
|
if (originpkgn)
|
|
|
|
printf(" %s requires dependency '%s' "
|
|
|
|
"[direct]: ", originpkgn, reqpkg);
|
|
|
|
else
|
|
|
|
printf(" requires dependency '%s' "
|
|
|
|
"[indirect]: ", reqpkg);
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
|
|
|
* Check if required dep is satisfied and installed.
|
|
|
|
*/
|
2009-11-07 21:11:59 +05:30
|
|
|
rv = xbps_check_is_installed_pkg(reqpkg);
|
|
|
|
if (rv == -1) {
|
|
|
|
/* There was an error checking it... */
|
2009-11-23 05:13:48 +05:30
|
|
|
DPRINTF(("Error matching reqdep %s\n", reqpkg));
|
2009-11-07 21:11:59 +05:30
|
|
|
break;
|
|
|
|
} else if (rv == 1) {
|
2009-11-22 09:45:47 +05:30
|
|
|
/* Required pkg dependency is satisfied */
|
2010-05-19 02:34:14 +05:30
|
|
|
if (flags & XBPS_FLAG_VERBOSE)
|
|
|
|
printf("satisfied and installed.\n");
|
2009-11-21 11:42:42 +05:30
|
|
|
rv = 0;
|
2009-08-17 22:37:20 +05:30
|
|
|
continue;
|
2009-11-07 21:11:59 +05:30
|
|
|
}
|
2010-01-21 07:40:19 +05:30
|
|
|
pkgname = xbps_get_pkgpattern_name(reqpkg);
|
2009-11-07 21:11:59 +05:30
|
|
|
if (pkgname == NULL) {
|
|
|
|
rv = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2010-01-21 07:40:19 +05:30
|
|
|
reqvers = xbps_get_pkgpattern_version(reqpkg);
|
2009-11-07 21:11:59 +05:30
|
|
|
if (reqvers == NULL) {
|
|
|
|
free(pkgname);
|
2009-11-07 09:26:20 +05:30
|
|
|
rv = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
|
|
|
* Check if package is already added in the
|
2009-11-22 09:45:47 +05:30
|
|
|
* array of unsorted deps, and check if current required
|
|
|
|
* dependency pattern is matched.
|
2009-08-17 22:37:20 +05:30
|
|
|
*/
|
2010-05-20 10:51:24 +05:30
|
|
|
curpkgd = xbps_find_pkg_in_dict_by_name(trans_dict,
|
2010-01-14 06:44:31 +05:30
|
|
|
"unsorted_deps", pkgname);
|
2009-11-26 07:52:50 +05:30
|
|
|
if (curpkgd == NULL) {
|
|
|
|
if (errno && errno != ENOENT) {
|
|
|
|
free(pkgname);
|
|
|
|
rv = errno;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (curpkgd) {
|
2010-11-06 11:14:00 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(curpkgd,
|
|
|
|
"pkgver", &pkg_queued);
|
2010-01-21 07:40:19 +05:30
|
|
|
if (xbps_pkgpattern_match(pkg_queued,
|
|
|
|
__UNCONST(reqpkg))) {
|
2010-05-19 02:34:14 +05:30
|
|
|
if (flags & XBPS_FLAG_VERBOSE)
|
|
|
|
printf("queued in the transaction.\n");
|
2009-11-22 09:45:47 +05:30
|
|
|
free(pkgname);
|
|
|
|
continue;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2009-11-21 11:42:42 +05:30
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
|
|
|
* If required package is not in repo, add it into the
|
|
|
|
* missing deps array and pass to the next one.
|
|
|
|
*/
|
2010-05-20 10:51:24 +05:30
|
|
|
curpkgd = xbps_find_pkg_in_dict_by_name(repo_dict,
|
2010-01-14 06:44:31 +05:30
|
|
|
"packages", pkgname);
|
2009-08-17 22:37:20 +05:30
|
|
|
if (curpkgd == NULL) {
|
2009-11-26 07:52:50 +05:30
|
|
|
if (errno && errno != ENOENT) {
|
|
|
|
free(pkgname);
|
|
|
|
rv = errno;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-05-20 10:51:24 +05:30
|
|
|
rv = add_missing_reqdep(trans_dict, reqpkg);
|
2009-11-21 11:42:42 +05:30
|
|
|
if (rv != 0 && rv != EEXIST) {
|
2009-11-23 05:13:48 +05:30
|
|
|
DPRINTF(("add missing reqdep failed %s\n",
|
|
|
|
reqpkg));
|
2009-11-21 11:42:42 +05:30
|
|
|
free(pkgname);
|
2009-08-17 22:37:20 +05:30
|
|
|
break;
|
2009-11-21 11:42:42 +05:30
|
|
|
} else if (rv == EEXIST) {
|
|
|
|
DPRINTF(("Missing dep %s already added.\n",
|
|
|
|
reqpkg));
|
|
|
|
rv = 0;
|
|
|
|
free(pkgname);
|
|
|
|
continue;
|
|
|
|
} else {
|
2010-05-19 02:34:14 +05:30
|
|
|
if (flags & XBPS_FLAG_VERBOSE)
|
|
|
|
printf("missing package in repository!\n");
|
2009-11-21 11:42:42 +05:30
|
|
|
free(pkgname);
|
2009-08-17 22:37:20 +05:30
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2009-11-29 10:22:32 +05:30
|
|
|
/*
|
|
|
|
* If version in repo does not satisfy the rundep, pass
|
|
|
|
* to the next rundep.
|
|
|
|
*/
|
2010-11-06 11:14:00 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(curpkgd, "pkgver", &repo_pkgver);
|
2010-01-21 07:40:19 +05:30
|
|
|
if (xbps_pkgpattern_match(repo_pkgver, __UNCONST(reqpkg)) < 1) {
|
2009-11-29 10:22:32 +05:30
|
|
|
free(pkgname);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
|
|
|
* If package is installed but version doesn't satisfy
|
|
|
|
* the dependency mark it as an update, otherwise as
|
2009-11-26 07:52:50 +05:30
|
|
|
* an install. Packages that were unpacked previously
|
|
|
|
* will be marked as pending to be configured.
|
2009-08-17 22:37:20 +05:30
|
|
|
*/
|
2010-01-21 07:40:19 +05:30
|
|
|
tmpd = xbps_find_pkg_dict_installed(pkgname, false);
|
2009-11-26 07:52:50 +05:30
|
|
|
if (tmpd == NULL) {
|
|
|
|
if (errno && errno != ENOENT) {
|
|
|
|
free(pkgname);
|
|
|
|
rv = errno;
|
|
|
|
break;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
prop_dictionary_set_cstring_nocopy(curpkgd,
|
|
|
|
"trans-action", "install");
|
2009-11-26 07:52:50 +05:30
|
|
|
} else if (tmpd) {
|
|
|
|
rv = xbps_get_pkg_state_installed(pkgname, &state);
|
|
|
|
if (rv != 0) {
|
2009-11-29 07:47:35 +05:30
|
|
|
free(pkgname);
|
2009-11-26 07:52:50 +05:30
|
|
|
prop_object_release(tmpd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (state == XBPS_PKG_STATE_INSTALLED)
|
|
|
|
prop_dictionary_set_cstring_nocopy(curpkgd,
|
|
|
|
"trans-action", "update");
|
|
|
|
else
|
|
|
|
prop_dictionary_set_cstring_nocopy(curpkgd,
|
|
|
|
"trans-action", "configure");
|
|
|
|
|
|
|
|
prop_object_release(tmpd);
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Package is on repo, add it into the dictionary.
|
|
|
|
*/
|
2010-05-20 10:51:24 +05:30
|
|
|
if ((rv = store_dependency(trans_dict, curpkgd,
|
|
|
|
repoloc)) != 0) {
|
2009-11-23 05:13:48 +05:30
|
|
|
DPRINTF(("store_dependency failed %s\n", reqpkg));
|
2010-05-20 10:51:24 +05:30
|
|
|
free(pkgname);
|
2009-08-17 22:37:20 +05:30
|
|
|
break;
|
|
|
|
}
|
2009-11-21 11:42:42 +05:30
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
2009-11-21 11:42:42 +05:30
|
|
|
* If package was added in the missing_deps array, we
|
|
|
|
* can remove it now it has been found in current repository.
|
2009-08-17 22:37:20 +05:30
|
|
|
*/
|
2010-05-20 10:51:24 +05:30
|
|
|
rv = remove_missing_reqdep(trans_dict, reqpkg);
|
2009-11-23 05:13:48 +05:30
|
|
|
if (rv == ENOENT) {
|
|
|
|
rv = 0;
|
|
|
|
} else if (rv == 0) {
|
2009-11-29 07:47:35 +05:30
|
|
|
DPRINTF(("Removed missing dep %s.\n", reqpkg));
|
2009-11-23 05:13:48 +05:30
|
|
|
} else {
|
|
|
|
DPRINTF(("Removing missing dep %s returned %s\n",
|
2009-11-29 07:47:35 +05:30
|
|
|
reqpkg, strerror(rv)));
|
2010-05-20 10:51:24 +05:30
|
|
|
free(pkgname);
|
2009-08-17 22:37:20 +05:30
|
|
|
break;
|
|
|
|
}
|
2009-11-21 11:42:42 +05:30
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
|
|
|
* If package doesn't have rundeps, pass to the next one.
|
|
|
|
*/
|
|
|
|
curpkg_rdeps = prop_dictionary_get(curpkgd, "run_depends");
|
2010-05-20 10:51:24 +05:30
|
|
|
if (curpkg_rdeps == NULL) {
|
|
|
|
free(pkgname);
|
2009-08-17 22:37:20 +05:30
|
|
|
continue;
|
2010-05-20 10:51:24 +05:30
|
|
|
}
|
2009-11-21 11:42:42 +05:30
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
|
|
|
* Iterate on required pkg to find more deps.
|
|
|
|
*/
|
2010-05-19 02:34:14 +05:30
|
|
|
if (flags & XBPS_FLAG_VERBOSE)
|
2010-05-20 10:51:24 +05:30
|
|
|
printf(" Finding dependencies for '%s-%s' [%s]:\n",
|
|
|
|
pkgname, reqvers, originpkgn ? "direct" : "indirect");
|
2010-05-19 02:34:14 +05:30
|
|
|
|
2010-05-20 10:51:24 +05:30
|
|
|
free(pkgname);
|
|
|
|
if ((rv = find_repo_deps(trans_dict, repo_dict, repoloc,
|
|
|
|
NULL, curpkg_rdeps)) != 0) {
|
2009-11-23 05:13:48 +05:30
|
|
|
DPRINTF(("Error checking %s rundeps %s\n",
|
2009-11-26 07:52:50 +05:30
|
|
|
reqpkg, strerror(errno)));
|
2009-11-23 02:22:57 +05:30
|
|
|
break;
|
2009-11-23 05:13:48 +05:30
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2010-01-21 07:40:19 +05:30
|
|
|
|
|
|
|
int HIDDEN
|
2010-05-20 10:51:24 +05:30
|
|
|
xbps_repository_find_pkg_deps(prop_dictionary_t trans_dict,
|
|
|
|
prop_dictionary_t repo_pkg_dict)
|
2010-01-21 07:40:19 +05:30
|
|
|
{
|
|
|
|
prop_array_t pkg_rdeps, missing_rdeps;
|
|
|
|
struct repository_pool *rpool;
|
2010-05-19 02:34:14 +05:30
|
|
|
const char *pkgname, *pkgver;
|
|
|
|
int flags = xbps_get_flags(), rv = 0;
|
2010-01-21 07:40:19 +05:30
|
|
|
|
2010-05-20 10:51:24 +05:30
|
|
|
assert(trans_dict != NULL);
|
|
|
|
assert(repo_pkg_dict != NULL);
|
2010-01-21 07:40:19 +05:30
|
|
|
|
2010-05-20 10:51:24 +05:30
|
|
|
pkg_rdeps = prop_dictionary_get(repo_pkg_dict, "run_depends");
|
2010-01-21 07:40:19 +05:30
|
|
|
if (pkg_rdeps == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2010-11-06 11:14:00 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(repo_pkg_dict, "pkgname", &pkgname);
|
|
|
|
prop_dictionary_get_cstring_nocopy(repo_pkg_dict, "pkgver", &pkgver);
|
2010-05-19 02:34:14 +05:30
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
if ((rv = xbps_repository_pool_init()) != 0)
|
|
|
|
return rv;
|
|
|
|
|
2010-05-19 02:34:14 +05:30
|
|
|
if (flags & XBPS_FLAG_VERBOSE)
|
|
|
|
printf(" Finding required dependencies for '%s':\n", pkgver);
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
/*
|
|
|
|
* Iterate over the repository pool and find out if we have
|
|
|
|
* all available binary packages.
|
|
|
|
*/
|
|
|
|
SIMPLEQ_FOREACH(rpool, &rp_queue, rp_entries) {
|
|
|
|
/*
|
|
|
|
* This will find direct and indirect deps,
|
|
|
|
* if any of them is not there it will be added
|
|
|
|
* into the missing_deps array.
|
|
|
|
*/
|
2010-05-20 10:51:24 +05:30
|
|
|
if ((rv = find_repo_deps(trans_dict, rpool->rp_repod,
|
|
|
|
rpool->rp_uri, pkgname, pkg_rdeps)) != 0) {
|
2010-01-21 07:40:19 +05:30
|
|
|
DPRINTF(("Error '%s' while checking rundeps!\n",
|
|
|
|
strerror(rv)));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there are no missing deps, there's nothing to do.
|
|
|
|
*/
|
2010-05-20 10:51:24 +05:30
|
|
|
missing_rdeps = prop_dictionary_get(trans_dict, "missing_deps");
|
2010-01-21 07:40:19 +05:30
|
|
|
if (prop_array_count(missing_rdeps) == 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterate one more time, but this time with missing deps
|
|
|
|
* that were found in previous pass.
|
|
|
|
*/
|
|
|
|
DPRINTF(("Checking for missing deps in %s.\n", pkgname));
|
|
|
|
SIMPLEQ_FOREACH(rpool, &rp_queue, rp_entries) {
|
2010-05-20 10:51:24 +05:30
|
|
|
if ((rv = find_repo_deps(trans_dict, rpool->rp_repod,
|
|
|
|
rpool->rp_uri, pkgname, missing_rdeps)) != 0) {
|
2010-01-21 07:40:19 +05:30
|
|
|
DPRINTF(("Error '%s' while checking for "
|
|
|
|
"missing rundeps!\n", strerror(rv)));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
xbps_repository_pool_release();
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|