libxbps: globally check for unresolved reverse dependencies.

Close #46. See NEWS for more information.
This commit is contained in:
Juan RP
2015-02-03 10:20:13 +01:00
parent 7d23a7e69c
commit d607655371
7 changed files with 121 additions and 83 deletions

View File

@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2009-2014 Juan Romero Pardines.
* Copyright (c) 2009-2015 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -304,9 +304,13 @@ xbps_transaction_prepare(struct xbps_handle *xhp)
*/
xbps_transaction_revdeps(xhp, pkgs);
array = xbps_dictionary_get(xhp->transd, "missing_deps");
if (xbps_array_count(array))
return ENODEV;
if (xbps_array_count(array)) {
if (xhp->flags & XBPS_FLAG_FORCE_REMOVE_REVDEPS) {
xbps_dbg_printf(xhp, "[trans] continuing with broken reverse dependencies!");
} else {
return ENODEV;
}
}
for (i = 0; i < xbps_array_count(pkgs); i++)
xbps_pkg_find_conflicts(xhp, pkgs, xbps_array_get(pkgs, i));
/*
@@ -319,8 +323,13 @@ xbps_transaction_prepare(struct xbps_handle *xhp)
* Check for unresolved shared libraries.
*/
if (xbps_transaction_shlibs(xhp, pkgs,
xbps_dictionary_get(xhp->transd, "missing_shlibs")))
return ENOEXEC;
xbps_dictionary_get(xhp->transd, "missing_shlibs"))) {
if (xhp->flags & XBPS_FLAG_FORCE_REMOVE_REVDEPS) {
xbps_dbg_printf(xhp, "[trans] continuing with unresolved shared libraries!");
} else {
return ENOEXEC;
}
}
/*
* Check for packages to be replaced.
*/

View File

@@ -272,7 +272,7 @@ xbps_transaction_remove_pkg(struct xbps_handle *xhp,
bool recursive)
{
xbps_dictionary_t pkgd;
xbps_array_t pkgs, orphans, orphans_pkg, reqby;
xbps_array_t pkgs, orphans, orphans_pkg;
xbps_object_t obj;
const char *pkgver;
int rv = 0;
@@ -314,16 +314,6 @@ xbps_transaction_remove_pkg(struct xbps_handle *xhp,
return EINVAL;
xbps_dbg_printf(xhp, "%s: added into transaction (remove).\n", pkgver);
}
reqby = xbps_pkgdb_get_pkg_revdeps(xhp, pkgname);
/*
* If target pkg is required by any installed pkg, the client must be aware
* of this to take appropiate action.
*/
if ((xbps_object_type(reqby) == XBPS_TYPE_ARRAY) &&
(xbps_array_count(reqby) > 0))
rv = EEXIST;
xbps_object_release(orphans);
return rv;
rmpkg:
@@ -335,15 +325,6 @@ rmpkg:
if ((rv = xbps_transaction_store(xhp, pkgs, pkgd, false)) != 0)
return EINVAL;
xbps_dbg_printf(xhp, "%s: added into transaction (remove).\n", pkgver);
reqby = xbps_pkgdb_get_pkg_revdeps(xhp, pkgver);
/*
* If target pkg is required by any installed pkg, the client must be aware
* of this to take appropiate action.
*/
if ((xbps_object_type(reqby) == XBPS_TYPE_ARRAY) &&
(xbps_array_count(reqby) > 0))
rv = EEXIST;
return rv;
}

View File

@@ -107,28 +107,37 @@ check_virtual_pkgs(struct xbps_handle *xhp,
return matched;
}
static void
broken_pkg(xbps_array_t mdeps, const char *dep, const char *pkg)
{
char *str;
str = xbps_xasprintf("%s broken, needs `%s'", dep, pkg);
xbps_array_add_cstring(mdeps, str);
free(str);
}
void HIDDEN
xbps_transaction_revdeps(struct xbps_handle *xhp, xbps_array_t pkgs)
{
xbps_array_t mdeps, pkgrdeps, rundeps;
xbps_dictionary_t revpkgd;
xbps_object_t obj;
const char *pkgver, *curdep, *revpkgver, *curpkgver, *tract;
char *pkgname, *curdepname, *curpkgname, *str;
xbps_array_t mdeps;
mdeps = xbps_dictionary_get(xhp->transd, "missing_deps");
for (unsigned int i = 0; i < xbps_array_count(pkgs); i++) {
xbps_array_t pkgrdeps;
xbps_object_t obj;
const char *pkgver, *tract;
char *pkgname;
obj = xbps_array_get(pkgs, i);
/*
* Only check packages in transaction being updated.
*/
xbps_dictionary_get_cstring_nocopy(obj, "transaction", &tract);
if (strcmp(tract, "update"))
continue;
/*
* if pkg in transaction is not installed,
* pass to next one.
*/
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
xbps_dictionary_get_cstring_nocopy(obj, "transaction", &tract);
pkgname = xbps_pkg_name(pkgver);
assert(pkgname);
if (xbps_pkg_is_installed(xhp, pkgname) == 0) {
@@ -149,15 +158,38 @@ xbps_transaction_revdeps(struct xbps_handle *xhp, xbps_array_t pkgs)
* Time to validate revdeps for current pkg.
*/
for (unsigned int x = 0; x < xbps_array_count(pkgrdeps); x++) {
xbps_array_t rundeps;
xbps_dictionary_t revpkgd;
const char *curpkgver, *revpkgver, *curdep;
char *curpkgname, *curdepname;
bool found = false;
xbps_array_get_cstring_nocopy(pkgrdeps, x, &curpkgver);
revpkgd = xbps_pkgdb_get_pkg(xhp, curpkgver);
xbps_dictionary_get_cstring_nocopy(revpkgd, "pkgver", &revpkgver);
pkgname = xbps_pkg_name(curpkgver);
assert(pkgname);
/*
* If target pkg is being removed, all its revdeps
* will be broken unless those revdeps are also in
* the transaction.
*/
if (strcmp(tract, "remove") == 0) {
if (xbps_find_pkg_in_array(pkgs, pkgname, "remove")) {
free(pkgname);
continue;
}
free(pkgname);
broken_pkg(mdeps, curpkgver, pkgver);
continue;
}
/*
* First try to match any supported virtual package.
*/
if (check_virtual_pkgs(xhp, pkgs, obj, revpkgd))
if (check_virtual_pkgs(xhp, pkgs, obj, revpkgd)) {
free(pkgname);
continue;
}
/*
* Try to match real dependencies.
*/
@@ -181,31 +213,28 @@ xbps_transaction_revdeps(struct xbps_handle *xhp, xbps_array_t pkgs)
}
free(curdepname);
}
if (!found)
continue;
free(curpkgname);
if (xbps_match_pkgdep_in_array(rundeps, pkgver))
if (!found) {
free(pkgname);
continue;
}
if (xbps_match_pkgdep_in_array(rundeps, pkgver)) {
free(pkgname);
continue;
}
/*
* Installed package conflicts with package
* in transaction being updated, check
* if a new version of this conflicting package
* is in the transaction.
*/
pkgname = xbps_pkg_name(curpkgver);
if (xbps_find_pkg_in_array(pkgs, pkgname, NULL)) {
if (xbps_find_pkg_in_array(pkgs, pkgname, "update")) {
free(pkgname);
continue;
}
free(pkgname);
mdeps = xbps_dictionary_get(xhp->transd, "missing_deps");
xbps_dictionary_get_cstring_nocopy(revpkgd,
"pkgver", &revpkgver);
str = xbps_xasprintf("CONFLICT: `%s' "
"update breaks `%s', needs `%s'",
pkgver, revpkgver, curdep);
xbps_array_add_cstring(mdeps, str);
free(str);
broken_pkg(mdeps, curpkgver, pkgver);
}
}