2009-08-17 22:37:20 +05:30
|
|
|
/*-
|
|
|
|
* Copyright (c) 2008-2009 Juan Romero Pardines.
|
|
|
|
* 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>
|
|
|
|
|
|
|
|
static int add_missing_reqdep(prop_dictionary_t, const char *, const char *);
|
2009-10-27 06:16:00 +05:30
|
|
|
static int find_repo_deps(prop_dictionary_t, prop_dictionary_t,
|
|
|
|
const char *, prop_array_t);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
static int
|
|
|
|
store_dependency(prop_dictionary_t master, prop_dictionary_t depd,
|
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;
|
2009-10-27 06:16:00 +05:30
|
|
|
const char *pkgname;
|
2009-08-17 22:37:20 +05:30
|
|
|
int rv = 0;
|
|
|
|
pkg_state_t state = 0;
|
|
|
|
|
|
|
|
assert(master != NULL);
|
|
|
|
assert(depd != 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.
|
|
|
|
*/
|
|
|
|
prop_dictionary_get_cstring_nocopy(depd, "pkgname", &pkgname);
|
|
|
|
|
|
|
|
dict = prop_dictionary_copy(depd);
|
|
|
|
if (dict == NULL)
|
|
|
|
return errno;
|
|
|
|
|
|
|
|
array = prop_dictionary_get(master, "unsorted_deps");
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
prop_dictionary_set_cstring(dict, "repository", repoloc);
|
|
|
|
/*
|
|
|
|
* Remove some unneeded objects.
|
|
|
|
*/
|
|
|
|
prop_dictionary_remove(dict, "conf_files");
|
|
|
|
prop_dictionary_remove(dict, "maintainer");
|
|
|
|
prop_dictionary_remove(dict, "long_desc");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add the dictionary into the array.
|
|
|
|
*/
|
|
|
|
if (!xbps_add_obj_to_array(array, dict)) {
|
|
|
|
prop_object_release(dict);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
add_missing_reqdep(prop_dictionary_t master, const char *pkgname,
|
|
|
|
const char *version)
|
|
|
|
{
|
2009-11-21 11:42:42 +05:30
|
|
|
prop_array_t missing_rdeps;
|
|
|
|
prop_dictionary_t mdepd;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2009-11-21 11:42:42 +05:30
|
|
|
assert(array != NULL);
|
|
|
|
assert(reqdep != NULL);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
if (xbps_find_pkg_in_dict(master, "missing_deps", pkgname))
|
|
|
|
return EEXIST;
|
|
|
|
|
2009-11-21 11:42:42 +05:30
|
|
|
mdepd = prop_dictionary_create();
|
|
|
|
if (mdepd == NULL)
|
|
|
|
return errno;
|
|
|
|
|
|
|
|
missing_rdeps = prop_dictionary_get(master, "missing_deps");
|
|
|
|
prop_dictionary_set_cstring(mdepd, "pkgname", pkgname);
|
|
|
|
prop_dictionary_set_cstring(mdepd, "version", version);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2009-11-21 11:42:42 +05:30
|
|
|
if (!xbps_add_obj_to_array(missing_rdeps, mdepd)) {
|
|
|
|
prop_object_release(mdepd);
|
2009-08-17 22:37:20 +05:30
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-27 06:16:00 +05:30
|
|
|
int SYMEXPORT
|
2009-08-17 22:37:20 +05:30
|
|
|
xbps_find_deps_in_pkg(prop_dictionary_t master, prop_dictionary_t pkg)
|
|
|
|
{
|
|
|
|
prop_array_t pkg_rdeps, missing_rdeps;
|
|
|
|
struct repository_data *rdata;
|
2009-11-21 11:42:42 +05:30
|
|
|
const char *pkgname;
|
2009-08-17 22:37:20 +05:30
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
assert(pkg != NULL);
|
|
|
|
assert(iter != NULL);
|
|
|
|
|
|
|
|
pkg_rdeps = prop_dictionary_get(pkg, "run_depends");
|
|
|
|
if (pkg_rdeps == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2009-11-21 11:42:42 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(pkg, "pkgname", &pkgname);
|
|
|
|
DPRINTF(("Checking rundeps for %s.\n", pkgname));
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
|
|
|
* Iterate over the repository pool and find out if we have
|
|
|
|
* all available binary packages.
|
|
|
|
*/
|
|
|
|
SIMPLEQ_FOREACH(rdata, &repodata_queue, chain) {
|
|
|
|
/*
|
|
|
|
* This will find direct and indirect deps,
|
|
|
|
* if any of them is not there it will be added
|
|
|
|
* into the missing_deps array.
|
|
|
|
*/
|
2009-10-27 06:16:00 +05:30
|
|
|
rv = find_repo_deps(master, rdata->rd_repod,
|
|
|
|
rdata->rd_uri, pkg_rdeps);
|
2009-11-21 11:42:42 +05:30
|
|
|
if (rv != 0)
|
2009-08-17 22:37:20 +05:30
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-11-21 11:42:42 +05:30
|
|
|
/*
|
|
|
|
* If there are no missing deps, there's nothing to do.
|
|
|
|
*/
|
2009-08-17 22:37:20 +05:30
|
|
|
missing_rdeps = prop_dictionary_get(master, "missing_deps");
|
|
|
|
if (prop_array_count(missing_rdeps) == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
2009-11-21 11:42:42 +05:30
|
|
|
* Iterate one more time, but this time with missing deps
|
|
|
|
* that were found in previous pass.
|
2009-08-17 22:37:20 +05:30
|
|
|
*/
|
2009-11-21 11:42:42 +05:30
|
|
|
DPRINTF(("Checking for missing deps in %s.\n", pkgname));
|
2009-08-17 22:37:20 +05:30
|
|
|
SIMPLEQ_FOREACH(rdata, &repodata_queue, chain) {
|
2009-11-21 11:42:42 +05:30
|
|
|
rv = find_repo_deps(master, rdata->rd_repod,
|
|
|
|
rdata->rd_uri, missing_rdeps);
|
|
|
|
if (rv != 0)
|
2009-08-17 22:37:20 +05:30
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
find_repo_deps(prop_dictionary_t master, prop_dictionary_t repo,
|
2009-11-21 11:42:42 +05:30
|
|
|
const char *repoloc, prop_array_t array)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
|
|
|
prop_dictionary_t curpkgd, tmpd = NULL;
|
|
|
|
prop_array_t curpkg_rdeps;
|
|
|
|
prop_object_t obj;
|
|
|
|
prop_object_iterator_t iter;
|
2009-11-22 09:45:47 +05:30
|
|
|
const char *reqpkg, *reqvers, *pkg_queued;
|
2009-08-17 22:37:20 +05:30
|
|
|
char *pkgname;
|
|
|
|
int rv = 0;
|
|
|
|
|
2009-11-21 11:42:42 +05:30
|
|
|
iter = prop_array_iterator(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.
|
|
|
|
*/
|
|
|
|
while ((obj = prop_object_iterator_next(iter))) {
|
|
|
|
reqpkg = prop_string_cstring_nocopy(obj);
|
|
|
|
/*
|
|
|
|
* 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... */
|
|
|
|
break;
|
|
|
|
} else if (rv == 1) {
|
2009-11-22 09:45:47 +05:30
|
|
|
/* Required pkg dependency is satisfied */
|
2009-11-21 11:42:42 +05:30
|
|
|
DPRINTF(("Dependency %s satisfied.\n", reqpkg));
|
|
|
|
rv = 0;
|
2009-08-17 22:37:20 +05:30
|
|
|
continue;
|
2009-11-07 21:11:59 +05:30
|
|
|
}
|
2009-11-22 09:45:47 +05:30
|
|
|
DPRINTF(("Dependency %s not installed.\n", reqpkg));
|
2009-11-07 09:26:20 +05:30
|
|
|
pkgname = xbps_get_pkgdep_name(reqpkg);
|
2009-11-07 21:11:59 +05:30
|
|
|
if (pkgname == NULL) {
|
|
|
|
rv = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2009-11-07 09:26:20 +05:30
|
|
|
reqvers = xbps_get_pkgdep_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
|
|
|
*/
|
2009-11-22 09:45:47 +05:30
|
|
|
curpkgd = xbps_find_pkg_in_dict(master, "unsorted_deps", pkgname);
|
|
|
|
if (curpkgd) {
|
|
|
|
prop_dictionary_get_cstring_nocopy(curpkgd,
|
|
|
|
"pkgver", &pkg_queued);
|
|
|
|
if (pkg_queued == NULL) {
|
|
|
|
free(pkgname);
|
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
if (xbps_pkgdep_match(pkg_queued, __UNCONST(reqpkg))) {
|
|
|
|
DPRINTF(("Dependency %s already queued.\n",
|
|
|
|
pkgname));
|
|
|
|
free(pkgname);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
curpkgd = NULL;
|
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.
|
|
|
|
*/
|
|
|
|
curpkgd = xbps_find_pkg_in_dict(repo, "packages", pkgname);
|
|
|
|
if (curpkgd == NULL) {
|
|
|
|
rv = add_missing_reqdep(master, pkgname, reqvers);
|
2009-11-21 11:42:42 +05:30
|
|
|
if (rv != 0 && rv != EEXIST) {
|
|
|
|
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 {
|
|
|
|
DPRINTF(("Added missing dep %s (repo: %s).\n",
|
|
|
|
pkgname, repoloc));
|
|
|
|
free(pkgname);
|
2009-08-17 22:37:20 +05:30
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If package is installed but version doesn't satisfy
|
|
|
|
* the dependency mark it as an update, otherwise as
|
|
|
|
* an install.
|
|
|
|
*/
|
|
|
|
tmpd = xbps_find_pkg_installed_from_plist(pkgname);
|
|
|
|
if (tmpd != NULL) {
|
|
|
|
prop_dictionary_set_cstring_nocopy(curpkgd,
|
|
|
|
"trans-action", "update");
|
|
|
|
prop_object_release(tmpd);
|
|
|
|
} else {
|
|
|
|
prop_dictionary_set_cstring_nocopy(curpkgd,
|
|
|
|
"trans-action", "install");
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Package is on repo, add it into the dictionary.
|
|
|
|
*/
|
2009-10-27 06:16:00 +05:30
|
|
|
if ((rv = store_dependency(master, curpkgd, repoloc)) != 0) {
|
2009-08-17 22:37:20 +05:30
|
|
|
free(pkgname);
|
|
|
|
break;
|
|
|
|
}
|
2009-11-21 11:42:42 +05:30
|
|
|
DPRINTF(("Added reqdep %s (repo: %s)\n", pkgname, repoloc));
|
|
|
|
|
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
|
|
|
*/
|
2009-11-21 11:42:42 +05:30
|
|
|
rv = xbps_remove_pkg_from_dict(master, "missing_deps", pkgname);
|
|
|
|
if (rv == 0)
|
|
|
|
DPRINTF(("Removed missing dep %s.\n", pkgname));
|
|
|
|
else if (rv != 0 && rv != ENOENT) {
|
2009-08-17 22:37:20 +05:30
|
|
|
free(pkgname);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free(pkgname);
|
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");
|
|
|
|
if (curpkg_rdeps == NULL)
|
|
|
|
continue;
|
2009-11-21 11:42:42 +05:30
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
|
|
|
* Iterate on required pkg to find more deps.
|
|
|
|
*/
|
2009-11-21 11:42:42 +05:30
|
|
|
DPRINTF(("Looking for rundeps on %s.\n", reqpkg));
|
2009-10-27 06:16:00 +05:30
|
|
|
if (!find_repo_deps(master, repo, repoloc, curpkg_rdeps))
|
2009-08-17 22:37:20 +05:30
|
|
|
continue;
|
|
|
|
}
|
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|