2013-06-27 20:22:31 +05:30
|
|
|
/*-
|
2020-04-24 15:14:19 +05:30
|
|
|
* Licensed under the SPDX BSD-2-Clause identifier.
|
|
|
|
* Use is subject to license terms, as specified in the LICENSE file.
|
2013-06-27 20:22:31 +05:30
|
|
|
*/
|
2020-04-24 15:14:19 +05:30
|
|
|
|
2013-06-27 20:22:31 +05:30
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "xbps_api_impl.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify reverse dependencies for packages in transaction.
|
|
|
|
* This will catch cases where a package update would break its reverse dependencies:
|
|
|
|
*
|
|
|
|
* - foo-1.0 is being updated to 2.0.
|
|
|
|
* - baz-1.1 depends on foo<2.0.
|
|
|
|
* - foo is updated to 2.0, hence baz-1.1 is currently broken.
|
|
|
|
*
|
|
|
|
* Abort transaction if such case is found.
|
|
|
|
*/
|
|
|
|
static bool
|
2015-02-05 14:34:42 +05:30
|
|
|
check_virtual_pkgs(xbps_array_t mdeps,
|
2013-06-27 20:22:31 +05:30
|
|
|
xbps_dictionary_t trans_pkgd,
|
|
|
|
xbps_dictionary_t rev_pkgd)
|
|
|
|
{
|
2020-02-21 13:38:22 +05:30
|
|
|
xbps_array_t rundeps;
|
2014-10-18 16:05:47 +05:30
|
|
|
xbps_array_t provides;
|
2020-02-21 13:38:22 +05:30
|
|
|
const char *pkgver, *vpkgver, *revpkgver, *pkgpattern;
|
|
|
|
char pkgname[XBPS_NAME_SIZE], vpkgname[XBPS_NAME_SIZE];
|
|
|
|
char *str = NULL;
|
2013-06-27 20:22:31 +05:30
|
|
|
bool matched = false;
|
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
pkgver = vpkgver = revpkgver = pkgpattern = NULL;
|
2013-06-27 20:22:31 +05:30
|
|
|
provides = xbps_dictionary_get(trans_pkgd, "provides");
|
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
for (unsigned int i = 0; i < xbps_array_count(provides); i++) {
|
2015-02-05 14:34:42 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(trans_pkgd, "pkgver", &pkgver);
|
|
|
|
xbps_dictionary_get_cstring_nocopy(rev_pkgd, "pkgver", &revpkgver);
|
2020-02-21 13:38:22 +05:30
|
|
|
xbps_array_get_cstring_nocopy(provides, i, &vpkgver);
|
2020-02-09 00:01:29 +05:30
|
|
|
|
|
|
|
if (!xbps_pkg_name(vpkgname, sizeof(vpkgname), vpkgver)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-06-27 20:22:31 +05:30
|
|
|
rundeps = xbps_dictionary_get(rev_pkgd, "run_depends");
|
2013-09-15 13:36:49 +05:30
|
|
|
for (unsigned int x = 0; x < xbps_array_count(rundeps); x++) {
|
2013-06-27 20:22:31 +05:30
|
|
|
xbps_array_get_cstring_nocopy(rundeps, x, &pkgpattern);
|
2020-02-09 00:01:29 +05:30
|
|
|
|
|
|
|
if ((!xbps_pkgpattern_name(pkgname, sizeof(pkgname), pkgpattern)) &&
|
|
|
|
(!xbps_pkg_name(pkgname, sizeof(pkgname), pkgpattern)))
|
2013-06-27 20:22:31 +05:30
|
|
|
continue;
|
|
|
|
|
|
|
|
if (strcmp(vpkgname, pkgname)) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-02-05 14:34:42 +05:30
|
|
|
if (!strcmp(vpkgver, pkgpattern) ||
|
|
|
|
xbps_pkgpattern_match(vpkgver, pkgpattern)) {
|
2013-07-05 13:39:32 +05:30
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-02-05 14:34:42 +05:30
|
|
|
str = xbps_xasprintf("%s broken, needs '%s' virtual pkg (got `%s')",
|
|
|
|
revpkgver, pkgpattern, vpkgver);
|
2013-06-27 20:22:31 +05:30
|
|
|
xbps_array_add_cstring(mdeps, str);
|
|
|
|
free(str);
|
|
|
|
matched = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return matched;
|
|
|
|
}
|
|
|
|
|
2015-02-03 14:50:13 +05:30
|
|
|
static void
|
2020-02-21 13:38:22 +05:30
|
|
|
broken_pkg(xbps_array_t mdeps, const char *dep, const char *pkg)
|
2015-02-03 14:50:13 +05:30
|
|
|
{
|
|
|
|
char *str;
|
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
str = xbps_xasprintf("%s in transaction breaks installed pkg `%s'", pkg, dep);
|
2015-02-03 14:50:13 +05:30
|
|
|
xbps_array_add_cstring(mdeps, str);
|
|
|
|
free(str);
|
|
|
|
}
|
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
bool HIDDEN
|
|
|
|
xbps_transaction_check_revdeps(struct xbps_handle *xhp, xbps_array_t pkgs)
|
2013-06-27 20:22:31 +05:30
|
|
|
{
|
2015-02-03 14:50:13 +05:30
|
|
|
xbps_array_t mdeps;
|
2020-02-21 13:38:22 +05:30
|
|
|
bool error = false;
|
2015-02-03 14:50:13 +05:30
|
|
|
|
|
|
|
mdeps = xbps_dictionary_get(xhp->transd, "missing_deps");
|
2013-06-27 20:22:31 +05:30
|
|
|
|
2014-10-18 16:05:47 +05:30
|
|
|
for (unsigned int i = 0; i < xbps_array_count(pkgs); i++) {
|
2020-02-21 13:38:22 +05:30
|
|
|
xbps_array_t pkgrdeps, rundeps;
|
|
|
|
xbps_dictionary_t revpkgd;
|
2015-02-03 14:50:13 +05:30
|
|
|
xbps_object_t obj;
|
2020-02-21 13:38:22 +05:30
|
|
|
xbps_trans_type_t ttype;
|
|
|
|
const char *pkgver = NULL, *revpkgver = NULL;
|
|
|
|
char pkgname[XBPS_NAME_SIZE] = {0};
|
2015-02-03 14:50:13 +05:30
|
|
|
|
2014-10-18 16:05:47 +05:30
|
|
|
obj = xbps_array_get(pkgs, i);
|
2020-01-25 15:39:03 +05:30
|
|
|
/*
|
|
|
|
* If pkg is on hold, pass to the next one.
|
|
|
|
*/
|
2020-02-21 13:38:22 +05:30
|
|
|
ttype = xbps_transaction_pkg_type(obj);
|
|
|
|
if (ttype == XBPS_TRANS_HOLD) {
|
2020-01-25 15:39:03 +05:30
|
|
|
continue;
|
|
|
|
}
|
2020-02-21 13:38:22 +05:30
|
|
|
if (!xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver)) {
|
|
|
|
error = true;
|
|
|
|
goto out;
|
|
|
|
}
|
2020-02-09 00:01:29 +05:30
|
|
|
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
|
2020-02-21 13:38:22 +05:30
|
|
|
error = true;
|
|
|
|
goto out;
|
2020-02-09 00:01:29 +05:30
|
|
|
}
|
2020-02-21 13:38:22 +05:30
|
|
|
/*
|
|
|
|
* if pkg in transaction is not installed,
|
|
|
|
* pass to next one.
|
|
|
|
*/
|
2013-06-27 20:22:31 +05:30
|
|
|
if (xbps_pkg_is_installed(xhp, pkgname) == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If pkg is installed but does not have revdeps,
|
|
|
|
* pass to next one.
|
|
|
|
*/
|
|
|
|
pkgrdeps = xbps_pkgdb_get_pkg_revdeps(xhp, pkgname);
|
|
|
|
if (!xbps_array_count(pkgrdeps)) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-06-23 15:34:49 +05:30
|
|
|
/*
|
|
|
|
* If pkg is ignored, pass to the next one.
|
|
|
|
*/
|
|
|
|
if (xbps_pkg_is_ignored(xhp, pkgver)) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-11-24 16:14:21 +05:30
|
|
|
|
2013-06-27 20:22:31 +05:30
|
|
|
/*
|
|
|
|
* Time to validate revdeps for current pkg.
|
|
|
|
*/
|
2013-09-15 13:36:49 +05:30
|
|
|
for (unsigned int x = 0; x < xbps_array_count(pkgrdeps); x++) {
|
2020-02-21 13:38:22 +05:30
|
|
|
const char *curpkgver = NULL;
|
|
|
|
char curdepname[XBPS_NAME_SIZE] = {0};
|
|
|
|
char curpkgname[XBPS_NAME_SIZE] = {0};
|
2013-07-02 04:17:16 +05:30
|
|
|
bool found = false;
|
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
if (!xbps_array_get_cstring_nocopy(pkgrdeps, x, &curpkgver)) {
|
|
|
|
error = true;
|
|
|
|
goto out;
|
|
|
|
}
|
2020-02-09 00:01:29 +05:30
|
|
|
|
|
|
|
if (!xbps_pkg_name(pkgname, sizeof(pkgname), curpkgver)) {
|
2020-02-21 13:38:22 +05:30
|
|
|
error = true;
|
|
|
|
goto out;
|
2020-02-09 00:01:29 +05:30
|
|
|
}
|
2020-03-05 04:09:27 +05:30
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
if ((revpkgd = xbps_find_pkg_in_array(pkgs, pkgname, 0))) {
|
2020-03-05 05:09:21 +05:30
|
|
|
if (xbps_transaction_pkg_type(revpkgd) == XBPS_TRANS_REMOVE)
|
|
|
|
continue;
|
2015-02-10 15:25:05 +05:30
|
|
|
}
|
|
|
|
if (revpkgd == NULL)
|
|
|
|
revpkgd = xbps_pkgdb_get_pkg(xhp, curpkgver);
|
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
|
2015-02-10 15:25:05 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(revpkgd, "pkgver", &revpkgver);
|
2015-02-03 14:50:13 +05:30
|
|
|
/*
|
|
|
|
* If target pkg is being removed, all its revdeps
|
|
|
|
* will be broken unless those revdeps are also in
|
|
|
|
* the transaction.
|
|
|
|
*/
|
2020-02-21 13:38:22 +05:30
|
|
|
if (ttype == XBPS_TRANS_REMOVE) {
|
2015-10-14 15:16:56 +05:30
|
|
|
if (xbps_dictionary_get(obj, "replaced")) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-02-21 13:38:22 +05:30
|
|
|
if (xbps_find_pkg_in_array(pkgs, pkgname, XBPS_TRANS_REMOVE)) {
|
2015-02-03 14:50:13 +05:30
|
|
|
continue;
|
|
|
|
}
|
2020-02-21 13:38:22 +05:30
|
|
|
broken_pkg(mdeps, curpkgver, pkgver);
|
2015-02-03 14:50:13 +05:30
|
|
|
continue;
|
|
|
|
}
|
2013-06-27 20:22:31 +05:30
|
|
|
/*
|
|
|
|
* First try to match any supported virtual package.
|
|
|
|
*/
|
2015-02-05 14:34:42 +05:30
|
|
|
if (check_virtual_pkgs(mdeps, obj, revpkgd)) {
|
2013-06-27 20:22:31 +05:30
|
|
|
continue;
|
2015-02-03 14:50:13 +05:30
|
|
|
}
|
2013-06-27 20:22:31 +05:30
|
|
|
/*
|
|
|
|
* Try to match real dependencies.
|
|
|
|
*/
|
|
|
|
rundeps = xbps_dictionary_get(revpkgd, "run_depends");
|
2013-07-02 04:17:16 +05:30
|
|
|
/*
|
|
|
|
* Find out what dependency is it.
|
|
|
|
*/
|
2020-02-09 00:01:29 +05:30
|
|
|
if (!xbps_pkg_name(curpkgname, sizeof(curpkgname), pkgver)) {
|
2020-02-21 13:38:22 +05:30
|
|
|
return false;
|
2020-02-09 00:01:29 +05:30
|
|
|
}
|
2013-07-02 04:17:16 +05:30
|
|
|
|
2013-09-15 13:36:49 +05:30
|
|
|
for (unsigned int j = 0; j < xbps_array_count(rundeps); j++) {
|
2020-04-23 12:02:54 +05:30
|
|
|
const char *curdep = NULL;
|
2020-02-21 13:38:22 +05:30
|
|
|
|
2013-07-02 04:17:16 +05:30
|
|
|
xbps_array_get_cstring_nocopy(rundeps, j, &curdep);
|
2020-02-09 00:01:29 +05:30
|
|
|
if ((!xbps_pkgpattern_name(curdepname, sizeof(curdepname), curdep)) &&
|
|
|
|
(!xbps_pkg_name(curdepname, sizeof(curdepname), curdep))) {
|
2020-02-21 13:38:22 +05:30
|
|
|
return false;
|
2020-02-09 00:01:29 +05:30
|
|
|
}
|
2013-07-02 04:17:16 +05:30
|
|
|
if (strcmp(curdepname, curpkgname) == 0) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-03 14:50:13 +05:30
|
|
|
if (!found) {
|
2013-06-27 20:22:31 +05:30
|
|
|
continue;
|
2015-02-03 14:50:13 +05:30
|
|
|
}
|
|
|
|
if (xbps_match_pkgdep_in_array(rundeps, pkgver)) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-01-31 21:02:38 +05:30
|
|
|
/*
|
|
|
|
* Installed package conflicts with package
|
|
|
|
* in transaction being updated, check
|
|
|
|
* if a new version of this conflicting package
|
|
|
|
* is in the transaction.
|
|
|
|
*/
|
2020-02-21 13:38:22 +05:30
|
|
|
if (xbps_find_pkg_in_array(pkgs, pkgname, XBPS_TRANS_UPDATE)) {
|
2020-01-31 21:02:38 +05:30
|
|
|
continue;
|
|
|
|
}
|
2020-02-21 13:38:22 +05:30
|
|
|
broken_pkg(mdeps, curpkgver, pkgver);
|
2013-06-27 20:22:31 +05:30
|
|
|
}
|
|
|
|
}
|
2020-02-21 13:38:22 +05:30
|
|
|
out:
|
|
|
|
if (!error) {
|
|
|
|
mdeps = xbps_dictionary_get(xhp->transd, "missing_deps");
|
|
|
|
if (xbps_array_count(mdeps) == 0)
|
|
|
|
xbps_dictionary_remove(xhp->transd, "missing_deps");
|
|
|
|
}
|
|
|
|
return error ? false : true;
|
2013-06-27 20:22:31 +05:30
|
|
|
}
|