2013-06-27 20:22:31 +05:30
|
|
|
/*-
|
2015-01-15 01:30:37 +05:30
|
|
|
* Copyright (c) 2013-2015 Juan Romero Pardines.
|
2013-06-27 20:22:31 +05:30
|
|
|
* 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 <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)
|
|
|
|
{
|
2014-10-18 16:05:47 +05:30
|
|
|
xbps_array_t provides;
|
2013-06-27 20:22:31 +05:30
|
|
|
bool matched = false;
|
|
|
|
|
|
|
|
provides = xbps_dictionary_get(trans_pkgd, "provides");
|
2013-09-15 13:36:49 +05:30
|
|
|
for (unsigned int i = 0; i < xbps_array_count(provides); i++) {
|
2015-02-05 14:34:42 +05:30
|
|
|
xbps_array_t rundeps;
|
2014-10-05 12:48:59 +05:30
|
|
|
const char *pkgver, *revpkgver, *pkgpattern;
|
2015-10-25 23:33:02 +05:30
|
|
|
char *pkgname, *vpkgname, *vpkgver, *str;
|
2014-10-05 12:48:59 +05:30
|
|
|
|
|
|
|
pkgver = revpkgver = pkgpattern = NULL;
|
2015-10-25 23:33:02 +05:30
|
|
|
pkgname = vpkgname = vpkgver = str = NULL;
|
2013-06-27 20:22:31 +05:30
|
|
|
|
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);
|
2013-06-27 20:22:31 +05:30
|
|
|
xbps_array_get_cstring(provides, i, &vpkgver);
|
|
|
|
vpkgname = xbps_pkg_name(vpkgver);
|
|
|
|
assert(vpkgname);
|
|
|
|
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);
|
|
|
|
if (((pkgname = xbps_pkgpattern_name(pkgpattern)) == NULL) &&
|
|
|
|
((pkgname = xbps_pkg_name(pkgpattern)) == NULL))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (strcmp(vpkgname, pkgname)) {
|
|
|
|
free(pkgname);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
free(pkgname);
|
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;
|
|
|
|
}
|
2013-07-05 13:39:32 +05:30
|
|
|
free(vpkgname);
|
2013-06-27 20:22:31 +05:30
|
|
|
free(vpkgver);
|
|
|
|
}
|
|
|
|
return matched;
|
|
|
|
}
|
|
|
|
|
2015-02-03 14:50:13 +05:30
|
|
|
static void
|
2015-09-02 14:50:18 +05:30
|
|
|
broken_pkg(xbps_array_t mdeps, const char *dep, const char *pkg, const char *trans)
|
2015-02-03 14:50:13 +05:30
|
|
|
{
|
|
|
|
char *str;
|
|
|
|
|
2015-09-02 14:50:18 +05:30
|
|
|
str = xbps_xasprintf("%s (%s) breaks installed pkg `%s'", pkg, trans, dep);
|
2015-02-03 14:50:13 +05:30
|
|
|
xbps_array_add_cstring(mdeps, str);
|
|
|
|
free(str);
|
|
|
|
}
|
|
|
|
|
2019-08-05 15:18:15 +05:30
|
|
|
void HIDDEN
|
2014-10-18 16:05:47 +05:30
|
|
|
xbps_transaction_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;
|
|
|
|
|
|
|
|
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++) {
|
2015-02-03 14:50:13 +05:30
|
|
|
xbps_array_t pkgrdeps;
|
|
|
|
xbps_object_t obj;
|
|
|
|
const char *pkgver, *tract;
|
|
|
|
char *pkgname;
|
|
|
|
|
2014-10-18 16:05:47 +05:30
|
|
|
obj = xbps_array_get(pkgs, i);
|
2013-06-27 20:22:31 +05:30
|
|
|
/*
|
|
|
|
* if pkg in transaction is not installed,
|
|
|
|
* pass to next one.
|
|
|
|
*/
|
|
|
|
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
2015-02-03 14:50:13 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(obj, "transaction", &tract);
|
|
|
|
|
2013-06-27 20:22:31 +05:30
|
|
|
pkgname = xbps_pkg_name(pkgver);
|
|
|
|
assert(pkgname);
|
|
|
|
if (xbps_pkg_is_installed(xhp, pkgname) == 0) {
|
|
|
|
free(pkgname);
|
|
|
|
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)) {
|
|
|
|
free(pkgname);
|
|
|
|
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)) {
|
|
|
|
free(pkgname);
|
|
|
|
continue;
|
|
|
|
}
|
2013-06-27 20:22:31 +05:30
|
|
|
free(pkgname);
|
2019-11-24 16:14:21 +05:30
|
|
|
/*
|
|
|
|
* If pkg is on hold, pass to the next one.
|
|
|
|
*/
|
|
|
|
if (strcmp(tract, "hold") == 0)
|
|
|
|
continue;
|
|
|
|
|
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++) {
|
2015-02-03 14:50:13 +05:30
|
|
|
xbps_array_t rundeps;
|
|
|
|
xbps_dictionary_t revpkgd;
|
2019-06-27 20:39:43 +05:30
|
|
|
const char *curpkgver = NULL, *revpkgver, *curdep = NULL, *curtract;
|
2015-02-03 14:50:13 +05:30
|
|
|
char *curpkgname, *curdepname;
|
2013-07-02 04:17:16 +05:30
|
|
|
bool found = false;
|
|
|
|
|
2013-06-27 20:22:31 +05:30
|
|
|
xbps_array_get_cstring_nocopy(pkgrdeps, x, &curpkgver);
|
2015-02-03 14:50:13 +05:30
|
|
|
pkgname = xbps_pkg_name(curpkgver);
|
|
|
|
assert(pkgname);
|
2015-02-10 15:25:05 +05:30
|
|
|
if ((revpkgd = xbps_find_pkg_in_array(pkgs, pkgname, NULL))) {
|
|
|
|
xbps_dictionary_get_cstring_nocopy(revpkgd, "transaction", &curtract);
|
|
|
|
if (strcmp(curtract, "remove") == 0)
|
|
|
|
revpkgd = NULL;
|
|
|
|
}
|
|
|
|
if (revpkgd == NULL)
|
|
|
|
revpkgd = xbps_pkgdb_get_pkg(xhp, curpkgver);
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
if (strcmp(tract, "remove") == 0) {
|
2015-10-14 15:16:56 +05:30
|
|
|
if (xbps_dictionary_get(obj, "replaced")) {
|
|
|
|
free(pkgname);
|
|
|
|
continue;
|
|
|
|
}
|
2015-02-03 14:50:13 +05:30
|
|
|
if (xbps_find_pkg_in_array(pkgs, pkgname, "remove")) {
|
|
|
|
free(pkgname);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
free(pkgname);
|
2015-09-02 14:50:18 +05:30
|
|
|
broken_pkg(mdeps, curpkgver, pkgver, tract);
|
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)) {
|
2015-02-03 14:50:13 +05:30
|
|
|
free(pkgname);
|
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.
|
|
|
|
*/
|
|
|
|
curpkgname = xbps_pkg_name(pkgver);
|
|
|
|
assert(curpkgname);
|
|
|
|
|
2013-09-15 13:36:49 +05:30
|
|
|
for (unsigned int j = 0; j < xbps_array_count(rundeps); j++) {
|
2013-07-02 04:17:16 +05:30
|
|
|
xbps_array_get_cstring_nocopy(rundeps, j, &curdep);
|
|
|
|
if (((curdepname = xbps_pkg_name(curdep)) == NULL) &&
|
|
|
|
((curdepname = xbps_pkgpattern_name(curdep)) == NULL))
|
|
|
|
abort();
|
|
|
|
|
|
|
|
if (strcmp(curdepname, curpkgname) == 0) {
|
|
|
|
free(curdepname);
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free(curdepname);
|
|
|
|
}
|
2015-02-03 14:50:13 +05:30
|
|
|
free(curpkgname);
|
2013-07-02 04:17:16 +05:30
|
|
|
|
2015-02-03 14:50:13 +05:30
|
|
|
if (!found) {
|
|
|
|
free(pkgname);
|
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)) {
|
|
|
|
free(pkgname);
|
|
|
|
continue;
|
|
|
|
}
|
2013-06-27 20:22:31 +05:30
|
|
|
free(pkgname);
|
2015-09-02 14:50:18 +05:30
|
|
|
broken_pkg(mdeps, curpkgver, pkgver, tract);
|
2013-06-27 20:22:31 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|