xbps_find_pkg_deps: simplify, fix multi-repo bug, add debugging.
--HG-- extra : convert_revision : xtraeme%40gmail.com-20091121061242-22ow43an9ksa8y0b
This commit is contained in:
parent
cf575b88c2
commit
71ea9d2d1f
@ -69,6 +69,12 @@
|
|||||||
#define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))
|
#define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
#define DPRINTF(x) printf x
|
||||||
|
#else
|
||||||
|
#define DPRINTF(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
#if __GNUC__ >= 4
|
#if __GNUC__ >= 4
|
||||||
#define SYMEXPORT __attribute__ ((visibility("default")))
|
#define SYMEXPORT __attribute__ ((visibility("default")))
|
||||||
#else
|
#else
|
||||||
|
160
lib/depends.c
160
lib/depends.c
@ -33,8 +33,6 @@
|
|||||||
static int add_missing_reqdep(prop_dictionary_t, const char *, const char *);
|
static int add_missing_reqdep(prop_dictionary_t, const char *, const char *);
|
||||||
static int find_repo_deps(prop_dictionary_t, prop_dictionary_t,
|
static int find_repo_deps(prop_dictionary_t, prop_dictionary_t,
|
||||||
const char *, prop_array_t);
|
const char *, prop_array_t);
|
||||||
static int find_repo_missing_deps(prop_dictionary_t, prop_dictionary_t,
|
|
||||||
const char *);
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
store_dependency(prop_dictionary_t master, prop_dictionary_t depd,
|
store_dependency(prop_dictionary_t master, prop_dictionary_t depd,
|
||||||
@ -109,28 +107,25 @@ static int
|
|||||||
add_missing_reqdep(prop_dictionary_t master, const char *pkgname,
|
add_missing_reqdep(prop_dictionary_t master, const char *pkgname,
|
||||||
const char *version)
|
const char *version)
|
||||||
{
|
{
|
||||||
prop_array_t array;
|
prop_array_t missing_rdeps;
|
||||||
prop_dictionary_t depd;
|
prop_dictionary_t mdepd;
|
||||||
|
|
||||||
assert(master != NULL);
|
assert(array != NULL);
|
||||||
assert(pkgname != NULL);
|
assert(reqdep != NULL);
|
||||||
assert(version != NULL);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Adds a package into the missing deps array.
|
|
||||||
*/
|
|
||||||
if (xbps_find_pkg_in_dict(master, "missing_deps", pkgname))
|
if (xbps_find_pkg_in_dict(master, "missing_deps", pkgname))
|
||||||
return EEXIST;
|
return EEXIST;
|
||||||
|
|
||||||
array = prop_dictionary_get(master, "missing_deps");
|
mdepd = prop_dictionary_create();
|
||||||
depd = prop_dictionary_create();
|
if (mdepd == NULL)
|
||||||
if (depd == NULL)
|
return errno;
|
||||||
return ENOMEM;
|
|
||||||
|
|
||||||
prop_dictionary_set_cstring(depd, "pkgname", pkgname);
|
missing_rdeps = prop_dictionary_get(master, "missing_deps");
|
||||||
prop_dictionary_set_cstring(depd, "version", version);
|
prop_dictionary_set_cstring(mdepd, "pkgname", pkgname);
|
||||||
if (!xbps_add_obj_to_array(array, depd)) {
|
prop_dictionary_set_cstring(mdepd, "version", version);
|
||||||
prop_object_release(depd);
|
|
||||||
|
if (!xbps_add_obj_to_array(missing_rdeps, mdepd)) {
|
||||||
|
prop_object_release(mdepd);
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,8 +137,8 @@ xbps_find_deps_in_pkg(prop_dictionary_t master, prop_dictionary_t pkg)
|
|||||||
{
|
{
|
||||||
prop_array_t pkg_rdeps, missing_rdeps;
|
prop_array_t pkg_rdeps, missing_rdeps;
|
||||||
struct repository_data *rdata;
|
struct repository_data *rdata;
|
||||||
|
const char *pkgname;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
bool missingdeps = false;
|
|
||||||
|
|
||||||
assert(pkg != NULL);
|
assert(pkg != NULL);
|
||||||
assert(iter != NULL);
|
assert(iter != NULL);
|
||||||
@ -152,6 +147,8 @@ xbps_find_deps_in_pkg(prop_dictionary_t master, prop_dictionary_t pkg)
|
|||||||
if (pkg_rdeps == NULL)
|
if (pkg_rdeps == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
prop_dictionary_get_cstring_nocopy(pkg, "pkgname", &pkgname);
|
||||||
|
DPRINTF(("Checking rundeps for %s.\n", pkgname));
|
||||||
/*
|
/*
|
||||||
* Iterate over the repository pool and find out if we have
|
* Iterate over the repository pool and find out if we have
|
||||||
* all available binary packages.
|
* all available binary packages.
|
||||||
@ -164,99 +161,35 @@ xbps_find_deps_in_pkg(prop_dictionary_t master, prop_dictionary_t pkg)
|
|||||||
*/
|
*/
|
||||||
rv = find_repo_deps(master, rdata->rd_repod,
|
rv = find_repo_deps(master, rdata->rd_repod,
|
||||||
rdata->rd_uri, pkg_rdeps);
|
rdata->rd_uri, pkg_rdeps);
|
||||||
if (rv != 0) {
|
if (rv != 0)
|
||||||
if (rv == ENOENT) {
|
|
||||||
rv = 0;
|
|
||||||
missingdeps = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If there are no missing deps, there's nothing to do.
|
||||||
|
*/
|
||||||
missing_rdeps = prop_dictionary_get(master, "missing_deps");
|
missing_rdeps = prop_dictionary_get(master, "missing_deps");
|
||||||
if (prop_array_count(missing_rdeps) == 0)
|
if (prop_array_count(missing_rdeps) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If there are missing deps, iterate one more time
|
* Iterate one more time, but this time with missing deps
|
||||||
* just in case that indirect deps weren't found.
|
* that were found in previous pass.
|
||||||
*/
|
*/
|
||||||
|
DPRINTF(("Checking for missing deps in %s.\n", pkgname));
|
||||||
SIMPLEQ_FOREACH(rdata, &repodata_queue, chain) {
|
SIMPLEQ_FOREACH(rdata, &repodata_queue, chain) {
|
||||||
rv = find_repo_missing_deps(master, rdata->rd_repod,
|
rv = find_repo_deps(master, rdata->rd_repod,
|
||||||
rdata->rd_uri);
|
rdata->rd_uri, missing_rdeps);
|
||||||
if (rv != 0 && rv != ENOENT)
|
if (rv != 0)
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (missingdeps)
|
|
||||||
rv = ENOENT;
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
find_repo_missing_deps(prop_dictionary_t master, prop_dictionary_t repo,
|
|
||||||
const char *repoloc)
|
|
||||||
{
|
|
||||||
prop_array_t array;
|
|
||||||
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);
|
|
||||||
|
|
||||||
array = prop_dictionary_get(master, "missing_deps");
|
|
||||||
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(master, 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(master, curpkgd, repoloc)) != 0)
|
|
||||||
break;
|
break;
|
||||||
/*
|
|
||||||
* Remove package from missing_deps array now.
|
|
||||||
*/
|
|
||||||
rv = xbps_remove_pkg_from_dict(master,
|
|
||||||
"missing_deps", pkgname);
|
|
||||||
if (rv != 0 && rv != ENOENT)
|
|
||||||
break;
|
|
||||||
|
|
||||||
prop_object_iterator_reset(iter);
|
|
||||||
}
|
}
|
||||||
prop_object_iterator_release(iter);
|
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
find_repo_deps(prop_dictionary_t master, prop_dictionary_t repo,
|
find_repo_deps(prop_dictionary_t master, prop_dictionary_t repo,
|
||||||
const char *repoloc, prop_array_t pkg_rdeps)
|
const char *repoloc, prop_array_t array)
|
||||||
{
|
{
|
||||||
prop_dictionary_t curpkgd, tmpd = NULL;
|
prop_dictionary_t curpkgd, tmpd = NULL;
|
||||||
prop_array_t curpkg_rdeps;
|
prop_array_t curpkg_rdeps;
|
||||||
@ -266,7 +199,7 @@ find_repo_deps(prop_dictionary_t master, prop_dictionary_t repo,
|
|||||||
char *pkgname;
|
char *pkgname;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
iter = prop_array_iterator(pkg_rdeps);
|
iter = prop_array_iterator(array);
|
||||||
if (iter == NULL)
|
if (iter == NULL)
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
|
|
||||||
@ -285,9 +218,11 @@ find_repo_deps(prop_dictionary_t master, prop_dictionary_t repo,
|
|||||||
break;
|
break;
|
||||||
} else if (rv == 1) {
|
} else if (rv == 1) {
|
||||||
/* pkgdep is satisfied */
|
/* pkgdep is satisfied */
|
||||||
|
DPRINTF(("Dependency %s satisfied.\n", reqpkg));
|
||||||
|
rv = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
DPRINTF(("Dependency %s not mached.\n", reqpkg));
|
||||||
pkgname = xbps_get_pkgdep_name(reqpkg);
|
pkgname = xbps_get_pkgdep_name(reqpkg);
|
||||||
if (pkgname == NULL) {
|
if (pkgname == NULL) {
|
||||||
rv = EINVAL;
|
rv = EINVAL;
|
||||||
@ -304,9 +239,11 @@ find_repo_deps(prop_dictionary_t master, prop_dictionary_t repo,
|
|||||||
* array of unsorted deps.
|
* array of unsorted deps.
|
||||||
*/
|
*/
|
||||||
if (xbps_find_pkg_in_dict(master, "unsorted_deps", pkgname)) {
|
if (xbps_find_pkg_in_dict(master, "unsorted_deps", pkgname)) {
|
||||||
|
DPRINTF(("Dependency %s already queued.\n", pkgname));
|
||||||
free(pkgname);
|
free(pkgname);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If required package is not in repo, add it into the
|
* If required package is not in repo, add it into the
|
||||||
* missing deps array and pass to the next one.
|
* missing deps array and pass to the next one.
|
||||||
@ -314,11 +251,19 @@ find_repo_deps(prop_dictionary_t master, prop_dictionary_t repo,
|
|||||||
curpkgd = xbps_find_pkg_in_dict(repo, "packages", pkgname);
|
curpkgd = xbps_find_pkg_in_dict(repo, "packages", pkgname);
|
||||||
if (curpkgd == NULL) {
|
if (curpkgd == NULL) {
|
||||||
rv = add_missing_reqdep(master, pkgname, reqvers);
|
rv = add_missing_reqdep(master, pkgname, reqvers);
|
||||||
free(pkgname);
|
if (rv != 0 && rv != EEXIST) {
|
||||||
if (rv != 0 && rv != EEXIST)
|
free(pkgname);
|
||||||
break;
|
break;
|
||||||
else {
|
} else if (rv == EEXIST) {
|
||||||
rv = ENOENT;
|
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);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -343,25 +288,32 @@ find_repo_deps(prop_dictionary_t master, prop_dictionary_t repo,
|
|||||||
free(pkgname);
|
free(pkgname);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
DPRINTF(("Added reqdep %s (repo: %s)\n", pkgname, repoloc));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Remove package from missing_deps now it's been found.
|
* If package was added in the missing_deps array, we
|
||||||
|
* can remove it now it has been found in current repository.
|
||||||
*/
|
*/
|
||||||
rv = xbps_remove_pkg_from_dict(master,
|
rv = xbps_remove_pkg_from_dict(master, "missing_deps", pkgname);
|
||||||
"missing_deps", pkgname);
|
if (rv == 0)
|
||||||
if (rv != 0 && rv != ENOENT) {
|
DPRINTF(("Removed missing dep %s.\n", pkgname));
|
||||||
|
else if (rv != 0 && rv != ENOENT) {
|
||||||
free(pkgname);
|
free(pkgname);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
free(pkgname);
|
free(pkgname);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If package doesn't have rundeps, pass to the next one.
|
* If package doesn't have rundeps, pass to the next one.
|
||||||
*/
|
*/
|
||||||
curpkg_rdeps = prop_dictionary_get(curpkgd, "run_depends");
|
curpkg_rdeps = prop_dictionary_get(curpkgd, "run_depends");
|
||||||
if (curpkg_rdeps == NULL)
|
if (curpkg_rdeps == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Iterate on required pkg to find more deps.
|
* Iterate on required pkg to find more deps.
|
||||||
*/
|
*/
|
||||||
|
DPRINTF(("Looking for rundeps on %s.\n", reqpkg));
|
||||||
if (!find_repo_deps(master, repo, repoloc, curpkg_rdeps))
|
if (!find_repo_deps(master, repo, repoloc, curpkg_rdeps))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -232,10 +232,9 @@ xbps_find_new_packages(void)
|
|||||||
else if (rv == EEXIST) {
|
else if (rv == EEXIST) {
|
||||||
rv = 0;
|
rv = 0;
|
||||||
continue;
|
continue;
|
||||||
} else if (rv != 0) {
|
} else if (rv != 0)
|
||||||
prop_object_iterator_release(iter);
|
break;
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
newpkg_found = true;
|
newpkg_found = true;
|
||||||
}
|
}
|
||||||
prop_object_iterator_release(iter);
|
prop_object_iterator_release(iter);
|
||||||
@ -282,10 +281,16 @@ xbps_find_new_pkg(const char *pkgname, prop_dictionary_t instpkg)
|
|||||||
prop_dictionary_get_cstring_nocopy(pkgrd,
|
prop_dictionary_get_cstring_nocopy(pkgrd,
|
||||||
"version", &repover);
|
"version", &repover);
|
||||||
if (xbps_cmpver(repover, instver) > 0) {
|
if (xbps_cmpver(repover, instver) > 0) {
|
||||||
|
DPRINTF(("Found %s-%s in repo %s.\n",
|
||||||
|
pkgname, repover, rdata->rd_uri));
|
||||||
newpkg_found = true;
|
newpkg_found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
DPRINTF(("Skipping %s-%s in repo %s.\n",
|
||||||
|
pkgname, repover, rdata->rd_uri));
|
||||||
}
|
}
|
||||||
|
DPRINTF(("Package %s not found in repo %s.\n",
|
||||||
|
pkgname, rdata->rd_uri));
|
||||||
}
|
}
|
||||||
if (!newpkg_found)
|
if (!newpkg_found)
|
||||||
return EEXIST;
|
return EEXIST;
|
||||||
|
Loading…
Reference in New Issue
Block a user