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-08-08 20:29:48 +00:00
|
|
|
static int add_missing_reqdep(prop_dictionary_t, const char *, const char *);
|
|
|
|
static int find_repo_deps(prop_dictionary_t, prop_dictionary_t, prop_array_t);
|
|
|
|
static int find_repo_missing_deps(prop_dictionary_t, prop_dictionary_t);
|
2008-12-26 03:36:51 +00:00
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
static int
|
2009-08-08 20:29:48 +00:00
|
|
|
store_dependency(prop_dictionary_t master, prop_dictionary_t depd,
|
|
|
|
prop_dictionary_t repod)
|
2008-12-29 05:46:08 +00:00
|
|
|
{
|
2009-03-26 08:54:20 +00:00
|
|
|
prop_dictionary_t dict;
|
2009-04-09 00:29:15 +00:00
|
|
|
prop_array_t array;
|
2009-08-08 20:29:48 +00:00
|
|
|
const char *repoloc, *pkgname;
|
|
|
|
int rv = 0;
|
|
|
|
pkg_state_t state = 0;
|
2008-12-29 05:46:08 +00:00
|
|
|
|
2009-08-08 20:29:48 +00:00
|
|
|
assert(master != NULL);
|
2009-02-07 12:27:24 +00:00
|
|
|
assert(depd != NULL);
|
|
|
|
assert(repod != NULL);
|
|
|
|
/*
|
|
|
|
* Get some info about dependencies and current repository.
|
|
|
|
*/
|
2009-08-08 20:29:48 +00:00
|
|
|
prop_dictionary_get_cstring_nocopy(depd, "pkgname", &pkgname);
|
2009-02-07 12:27:24 +00:00
|
|
|
prop_dictionary_get_cstring_nocopy(repod, "location-local", &repoloc);
|
|
|
|
|
2009-04-09 00:29:15 +00:00
|
|
|
dict = prop_dictionary_copy(depd);
|
2009-04-06 09:40:55 +00:00
|
|
|
if (dict == NULL)
|
|
|
|
return errno;
|
|
|
|
|
2009-04-09 00:29:15 +00:00
|
|
|
array = prop_dictionary_get(master, "unsorted_deps");
|
2009-02-07 12:27:24 +00:00
|
|
|
if (array == NULL) {
|
|
|
|
prop_object_release(dict);
|
2009-04-06 09:40:55 +00:00
|
|
|
return errno;
|
2009-02-07 12:27:24 +00:00
|
|
|
}
|
2009-08-08 20:29:48 +00:00
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
}
|
2009-02-07 12:27:24 +00:00
|
|
|
/*
|
|
|
|
* Add required objects into package dep's dictionary.
|
|
|
|
*/
|
2009-02-14 00:37:12 +00:00
|
|
|
prop_dictionary_set_cstring(dict, "repository", repoloc);
|
2009-04-09 00:29:15 +00:00
|
|
|
/*
|
|
|
|
* Remove some unneeded objects.
|
|
|
|
*/
|
|
|
|
prop_dictionary_remove(dict, "conf_files");
|
|
|
|
prop_dictionary_remove(dict, "keep_dirs");
|
|
|
|
prop_dictionary_remove(dict, "maintainer");
|
|
|
|
prop_dictionary_remove(dict, "long_desc");
|
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);
|
2009-04-06 09:40:55 +00:00
|
|
|
return EINVAL;
|
2008-12-29 05:46:08 +00:00
|
|
|
}
|
|
|
|
|
2009-04-06 09:40:55 +00:00
|
|
|
return 0;
|
2008-12-29 05:46:08 +00:00
|
|
|
}
|
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
static int
|
2009-04-09 00:29:15 +00:00
|
|
|
add_missing_reqdep(prop_dictionary_t master, 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;
|
|
|
|
|
2009-04-09 00:29:15 +00:00
|
|
|
assert(master != NULL);
|
2009-02-07 12:27:24 +00:00
|
|
|
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-04-09 00:29:15 +00:00
|
|
|
if (xbps_find_pkg_in_dict(master, "missing_deps", pkgname))
|
2009-02-07 12:27:24 +00:00
|
|
|
return EEXIST;
|
|
|
|
|
2009-04-09 00:29:15 +00:00
|
|
|
array = prop_dictionary_get(master, "missing_deps");
|
2009-02-07 12:27:24 +00:00
|
|
|
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-14 00:37:12 +00:00
|
|
|
int
|
2009-05-17 02:09:26 +00:00
|
|
|
xbps_find_deps_in_pkg(prop_dictionary_t master, prop_dictionary_t pkg)
|
2009-02-14 00:37:12 +00:00
|
|
|
{
|
2009-04-04 03:24:58 +00:00
|
|
|
prop_array_t pkg_rdeps, missing_rdeps;
|
2009-05-17 02:09:26 +00:00
|
|
|
struct repository_data *rdata;
|
2009-02-14 00:37:12 +00:00
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
assert(pkg != NULL);
|
2009-04-04 03:24:58 +00:00
|
|
|
assert(iter != NULL);
|
2009-02-14 00:37:12 +00:00
|
|
|
|
2009-02-16 23:08:03 +00:00
|
|
|
pkg_rdeps = prop_dictionary_get(pkg, "run_depends");
|
2009-08-08 20:29:48 +00:00
|
|
|
assert(pkg_rdeps != NULL);
|
2009-02-16 23:08:03 +00:00
|
|
|
|
2009-02-14 00:37:12 +00:00
|
|
|
/*
|
|
|
|
* Iterate over the repository pool and find out if we have
|
|
|
|
* all available binary packages.
|
|
|
|
*/
|
2009-05-17 02:09:26 +00:00
|
|
|
SIMPLEQ_FOREACH(rdata, &repodata_queue, chain) {
|
2009-02-14 00:37:12 +00:00
|
|
|
/*
|
|
|
|
* This will find direct and indirect deps,
|
|
|
|
* if any of them is not there it will be added
|
|
|
|
* into the missing_deps array.
|
|
|
|
*/
|
2009-08-08 20:29:48 +00:00
|
|
|
rv = find_repo_deps(master, rdata->rd_repod, pkg_rdeps);
|
2009-02-14 00:37:12 +00:00
|
|
|
if (rv != 0) {
|
|
|
|
if (rv == ENOENT) {
|
|
|
|
rv = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-09 00:29:15 +00:00
|
|
|
missing_rdeps = prop_dictionary_get(master, "missing_deps");
|
2009-02-14 00:37:12 +00:00
|
|
|
if (prop_array_count(missing_rdeps) == 0)
|
2009-04-04 03:24:58 +00:00
|
|
|
return 0;
|
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.
|
|
|
|
*/
|
2009-05-17 02:09:26 +00:00
|
|
|
SIMPLEQ_FOREACH(rdata, &repodata_queue, chain) {
|
2009-08-08 20:29:48 +00:00
|
|
|
rv = find_repo_missing_deps(master, rdata->rd_repod);
|
2009-05-17 02:09:26 +00:00
|
|
|
if (rv != 0 && rv != ENOENT)
|
2009-04-04 03:24:58 +00:00
|
|
|
return rv;
|
2009-02-14 00:37:12 +00:00
|
|
|
}
|
2008-12-24 06:20:19 +00:00
|
|
|
|
2009-04-04 03:24:58 +00:00
|
|
|
return 0;
|
2009-02-07 12:27:24 +00:00
|
|
|
}
|
2008-12-24 06:20:19 +00:00
|
|
|
|
2009-02-14 00:37:12 +00:00
|
|
|
static int
|
2009-08-08 20:29:48 +00:00
|
|
|
find_repo_missing_deps(prop_dictionary_t master, prop_dictionary_t repo)
|
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-04-09 00:29:15 +00:00
|
|
|
array = prop_dictionary_get(master, "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) {
|
2009-04-09 00:29:15 +00:00
|
|
|
rv = add_missing_reqdep(master, pkgname, version);
|
2009-02-14 00:37:12 +00:00
|
|
|
if (rv != 0 && rv != EEXIST)
|
|
|
|
break;
|
|
|
|
else {
|
|
|
|
rv = ENOENT;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Package is on repo, add it into the dictionary.
|
|
|
|
*/
|
2009-08-08 20:29:48 +00:00
|
|
|
if ((rv = store_dependency(master, curpkgd, repo)) != 0)
|
2009-02-14 00:37:12 +00:00
|
|
|
break;
|
|
|
|
/*
|
2009-04-06 14:39:14 +00:00
|
|
|
* Remove package from missing_deps array now.
|
2009-02-14 00:37:12 +00:00
|
|
|
*/
|
2009-04-09 00:29:15 +00:00
|
|
|
rv = xbps_remove_pkg_from_dict(master,
|
2009-04-06 14:39:14 +00:00
|
|
|
"missing_deps", pkgname);
|
|
|
|
if (rv != 0 && rv != ENOENT)
|
|
|
|
break;
|
2009-02-14 00:37:12 +00:00
|
|
|
|
|
|
|
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
|
2009-04-09 00:29:15 +00:00
|
|
|
find_repo_deps(prop_dictionary_t master, prop_dictionary_t repo,
|
2009-08-08 20:29:48 +00:00
|
|
|
prop_array_t pkg_rdeps)
|
2008-12-24 06:20:19 +00:00
|
|
|
{
|
2009-08-08 20:29:48 +00:00
|
|
|
prop_dictionary_t curpkgd, tmpd = NULL;
|
2009-02-14 00:37:12 +00:00
|
|
|
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
|
|
|
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;
|
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.
|
|
|
|
*/
|
2009-03-17 03:32:03 +00:00
|
|
|
if (xbps_check_is_installed_pkg(reqpkg) >= 0) {
|
2009-02-14 00:37:12 +00:00
|
|
|
free(pkgname);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Check if package is already added in the
|
|
|
|
* array of unsorted deps.
|
|
|
|
*/
|
2009-04-09 00:29:15 +00:00
|
|
|
if (xbps_find_pkg_in_dict(master, "unsorted_deps", pkgname)) {
|
2009-02-14 00:37:12 +00:00
|
|
|
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-04-09 00:29:15 +00:00
|
|
|
rv = add_missing_reqdep(master, 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-08-08 20:29:48 +00:00
|
|
|
/*
|
|
|
|
* 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");
|
|
|
|
}
|
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-08-08 20:29:48 +00:00
|
|
|
if ((rv = store_dependency(master, curpkgd, repo)) != 0) {
|
2009-02-14 00:37:12 +00:00
|
|
|
free(pkgname);
|
2009-02-07 12:27:24 +00:00
|
|
|
break;
|
2009-02-14 00:37:12 +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-04-09 00:29:15 +00:00
|
|
|
rv = xbps_remove_pkg_from_dict(master,
|
2009-04-06 14:39:14 +00:00
|
|
|
"missing_deps", pkgname);
|
|
|
|
if (rv != 0 && rv != ENOENT) {
|
|
|
|
free(pkgname);
|
|
|
|
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-08-08 20:29:48 +00:00
|
|
|
if (!find_repo_deps(master, repo, 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
|
|
|
}
|