2012-06-11 19:44:03 +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.
|
2012-06-11 19:44:03 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "xbps_api_impl.h"
|
|
|
|
|
2015-10-28 09:53:42 +05:30
|
|
|
static void
|
|
|
|
pkg_conflicts_trans(struct xbps_handle *xhp, xbps_array_t array,
|
|
|
|
xbps_dictionary_t pkg_repod)
|
2012-06-11 19:44:03 +05:30
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_array_t pkg_cflicts, trans_cflicts;
|
2013-11-01 22:35:11 +05:30
|
|
|
xbps_dictionary_t pkgd, tpkgd;
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_t obj;
|
|
|
|
xbps_object_iterator_t iter;
|
2020-02-21 13:38:22 +05:30
|
|
|
xbps_trans_type_t ttype;
|
|
|
|
const char *cfpkg, *repopkgver, *repopkgname;
|
2020-02-09 00:01:29 +05:30
|
|
|
char *buf;
|
2012-06-11 19:44:03 +05:30
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
assert(xhp);
|
|
|
|
assert(array);
|
|
|
|
assert(pkg_repod);
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
pkg_cflicts = xbps_dictionary_get(pkg_repod, "conflicts");
|
2020-02-21 13:38:22 +05:30
|
|
|
if (xbps_array_count(pkg_cflicts) == 0) {
|
2012-06-11 19:44:03 +05:30
|
|
|
return;
|
2020-02-21 13:38:22 +05:30
|
|
|
}
|
2012-06-11 19:44:03 +05:30
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
ttype = xbps_transaction_pkg_type(pkg_repod);
|
|
|
|
if (ttype == XBPS_TRANS_HOLD || ttype == XBPS_TRANS_REMOVE) {
|
|
|
|
return;
|
2015-11-09 20:30:15 +05:30
|
|
|
}
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
trans_cflicts = xbps_dictionary_get(xhp->transd, "conflicts");
|
2020-02-21 13:38:22 +05:30
|
|
|
if (!xbps_dictionary_get_cstring_nocopy(pkg_repod, "pkgver", &repopkgver)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!xbps_dictionary_get_cstring_nocopy(pkg_repod, "pkgname", &repopkgname)) {
|
|
|
|
return;
|
2020-02-09 00:01:29 +05:30
|
|
|
}
|
2012-06-11 19:44:03 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
iter = xbps_array_iterator(pkg_cflicts);
|
2012-11-30 14:19:09 +05:30
|
|
|
assert(iter);
|
2013-02-01 17:11:27 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
while ((obj = xbps_object_iterator_next(iter))) {
|
2020-02-21 13:38:22 +05:30
|
|
|
const char *pkgver = NULL, *pkgname = NULL;
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
cfpkg = xbps_string_cstring_nocopy(obj);
|
2013-02-01 17:11:27 +05:30
|
|
|
|
2012-06-11 19:44:03 +05:30
|
|
|
/*
|
|
|
|
* Check if current pkg conflicts with an installed package.
|
|
|
|
*/
|
2012-11-30 11:41:51 +05:30
|
|
|
if ((pkgd = xbps_pkgdb_get_pkg(xhp, cfpkg)) ||
|
|
|
|
(pkgd = xbps_pkgdb_get_virtualpkg(xhp, cfpkg))) {
|
2015-11-12 17:53:00 +05:30
|
|
|
/* If the conflicting pkg is on hold, ignore it */
|
|
|
|
if (xbps_dictionary_get(pkgd, "hold"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Ignore itself */
|
2020-02-21 13:38:22 +05:30
|
|
|
if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgname", &pkgname)) {
|
|
|
|
break;
|
2020-02-09 00:01:29 +05:30
|
|
|
}
|
2013-03-06 17:25:00 +05:30
|
|
|
if (strcmp(pkgname, repopkgname) == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-02-21 13:38:22 +05:30
|
|
|
if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver)) {
|
|
|
|
break;
|
|
|
|
}
|
2013-11-01 22:35:11 +05:30
|
|
|
/*
|
2015-11-10 20:06:25 +05:30
|
|
|
* If there's a pkg for the conflict in transaction,
|
2013-11-01 22:35:11 +05:30
|
|
|
* ignore it.
|
|
|
|
*/
|
2020-02-21 13:38:22 +05:30
|
|
|
if ((tpkgd = xbps_find_pkg_in_array(array, pkgname, 0))) {
|
|
|
|
ttype = xbps_transaction_pkg_type(tpkgd);
|
|
|
|
if (ttype == XBPS_TRANS_INSTALL ||
|
|
|
|
ttype == XBPS_TRANS_UPDATE ||
|
|
|
|
ttype == XBPS_TRANS_REMOVE ||
|
|
|
|
ttype == XBPS_TRANS_HOLD) {
|
2013-11-01 22:35:11 +05:30
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2013-02-01 17:11:27 +05:30
|
|
|
xbps_dbg_printf(xhp, "found conflicting installed "
|
2015-11-10 20:06:25 +05:30
|
|
|
"pkg %s with pkg in transaction %s "
|
2015-11-12 17:36:09 +05:30
|
|
|
"(matched by %s [trans])\n", pkgver, repopkgver, cfpkg);
|
2013-06-27 20:22:31 +05:30
|
|
|
buf = xbps_xasprintf("CONFLICT: %s with "
|
2015-11-10 20:06:25 +05:30
|
|
|
"installed pkg %s (matched by %s)",
|
|
|
|
repopkgver, pkgver, cfpkg);
|
2014-07-13 13:04:19 +05:30
|
|
|
if (!xbps_match_string_in_array(trans_cflicts, buf))
|
|
|
|
xbps_array_add_cstring(trans_cflicts, buf);
|
|
|
|
|
2012-06-11 19:44:03 +05:30
|
|
|
free(buf);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Check if current pkg conflicts with any pkg in transaction.
|
|
|
|
*/
|
2020-02-21 13:38:22 +05:30
|
|
|
if ((pkgd = xbps_find_pkg_in_array(array, cfpkg, 0)) ||
|
|
|
|
(pkgd = xbps_find_virtualpkg_in_array(xhp, array, cfpkg, 0))) {
|
2015-11-12 17:53:00 +05:30
|
|
|
/* ignore pkgs to be removed or on hold */
|
2020-02-21 13:38:22 +05:30
|
|
|
ttype = xbps_transaction_pkg_type(pkgd);
|
|
|
|
if (ttype == XBPS_TRANS_REMOVE || ttype == XBPS_TRANS_HOLD) {
|
|
|
|
continue;
|
2015-11-12 17:53:00 +05:30
|
|
|
}
|
|
|
|
/* ignore itself */
|
2020-02-21 13:38:22 +05:30
|
|
|
if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgname", &pkgname)) {
|
|
|
|
break;
|
2020-02-09 00:01:29 +05:30
|
|
|
}
|
2013-03-06 17:25:00 +05:30
|
|
|
if (strcmp(pkgname, repopkgname) == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-02-21 13:38:22 +05:30
|
|
|
if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver)) {
|
|
|
|
break;
|
|
|
|
}
|
2013-02-01 17:11:27 +05:30
|
|
|
xbps_dbg_printf(xhp, "found conflicting pkgs in "
|
2015-11-12 17:36:09 +05:30
|
|
|
"transaction %s <-> %s (matched by %s [trans])\n",
|
2015-11-10 20:06:25 +05:30
|
|
|
pkgver, repopkgver, cfpkg);
|
2013-06-27 20:22:31 +05:30
|
|
|
buf = xbps_xasprintf("CONFLICT: %s with "
|
2015-11-12 16:54:33 +05:30
|
|
|
"%s in transaction (matched by %s)",
|
|
|
|
repopkgver, pkgver, cfpkg);
|
2014-07-13 13:04:19 +05:30
|
|
|
if (!xbps_match_string_in_array(trans_cflicts, buf))
|
|
|
|
xbps_array_add_cstring(trans_cflicts, buf);
|
|
|
|
|
2012-06-11 19:44:03 +05:30
|
|
|
free(buf);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_iterator_release(iter);
|
2012-06-11 19:44:03 +05:30
|
|
|
}
|
2015-10-28 09:53:42 +05:30
|
|
|
|
|
|
|
static int
|
|
|
|
pkgdb_conflicts_cb(struct xbps_handle *xhp, xbps_object_t obj,
|
2018-07-18 07:54:26 +05:30
|
|
|
const char *key UNUSED, void *arg, bool *done UNUSED)
|
2015-10-28 09:53:42 +05:30
|
|
|
{
|
|
|
|
xbps_array_t pkg_cflicts, trans_cflicts, pkgs = arg;
|
|
|
|
xbps_dictionary_t pkgd;
|
|
|
|
xbps_object_t obj2;
|
|
|
|
xbps_object_iterator_t iter;
|
2020-02-21 13:38:22 +05:30
|
|
|
xbps_trans_type_t ttype;
|
|
|
|
const char *cfpkg, *repopkgver, *repopkgname;
|
2020-02-09 00:01:29 +05:30
|
|
|
char *buf;
|
2020-02-21 13:38:22 +05:30
|
|
|
int rv = 0;
|
2015-10-28 09:53:42 +05:30
|
|
|
|
|
|
|
pkg_cflicts = xbps_dictionary_get(obj, "conflicts");
|
|
|
|
if (xbps_array_count(pkg_cflicts) == 0)
|
|
|
|
return 0;
|
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
if (!xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &repopkgver)) {
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
if (!xbps_dictionary_get_cstring_nocopy(obj, "pkgname", &repopkgname)) {
|
|
|
|
return EINVAL;
|
2020-02-09 00:01:29 +05:30
|
|
|
}
|
2015-10-28 09:53:42 +05:30
|
|
|
|
2015-11-10 20:06:25 +05:30
|
|
|
/* if a pkg is in the transaction, ignore the one from pkgdb */
|
2020-02-21 13:38:22 +05:30
|
|
|
if (xbps_find_pkg_in_array(pkgs, repopkgname, 0)) {
|
2015-11-10 20:06:25 +05:30
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
trans_cflicts = xbps_dictionary_get(xhp->transd, "conflicts");
|
2015-10-28 09:53:42 +05:30
|
|
|
iter = xbps_array_iterator(pkg_cflicts);
|
|
|
|
assert(iter);
|
|
|
|
|
|
|
|
while ((obj2 = xbps_object_iterator_next(iter))) {
|
2020-02-21 13:38:22 +05:30
|
|
|
const char *pkgver = NULL, *pkgname = NULL;
|
|
|
|
|
2015-10-28 09:53:42 +05:30
|
|
|
cfpkg = xbps_string_cstring_nocopy(obj2);
|
2020-02-21 13:38:22 +05:30
|
|
|
if ((pkgd = xbps_find_pkg_in_array(pkgs, cfpkg, 0)) ||
|
|
|
|
(pkgd = xbps_find_virtualpkg_in_array(xhp, pkgs, cfpkg, 0))) {
|
2015-11-12 17:53:00 +05:30
|
|
|
/* ignore pkgs to be removed or on hold */
|
2020-02-21 13:38:22 +05:30
|
|
|
ttype = xbps_transaction_pkg_type(pkgd);
|
|
|
|
if (ttype == XBPS_TRANS_REMOVE || ttype == XBPS_TRANS_HOLD) {
|
|
|
|
continue;
|
2015-11-12 17:53:00 +05:30
|
|
|
}
|
|
|
|
/* ignore itself */
|
2020-02-21 13:38:22 +05:30
|
|
|
if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgname", &pkgname)) {
|
|
|
|
rv = EINVAL;
|
|
|
|
break;
|
2020-02-09 00:01:29 +05:30
|
|
|
}
|
2015-10-28 09:53:42 +05:30
|
|
|
if (strcmp(pkgname, repopkgname) == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-02-21 13:38:22 +05:30
|
|
|
if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver)) {
|
|
|
|
rv = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2015-10-28 09:53:42 +05:30
|
|
|
xbps_dbg_printf(xhp, "found conflicting pkgs in "
|
2015-11-12 17:36:09 +05:30
|
|
|
"transaction %s <-> %s (matched by %s [pkgdb])\n",
|
2015-11-10 20:06:25 +05:30
|
|
|
pkgver, repopkgver, cfpkg);
|
2015-10-28 09:53:42 +05:30
|
|
|
buf = xbps_xasprintf("CONFLICT: %s with "
|
2015-11-10 20:06:25 +05:30
|
|
|
"%s in transaction (matched by %s)",
|
|
|
|
repopkgver, pkgver, cfpkg);
|
2015-10-28 09:53:42 +05:30
|
|
|
if (!xbps_match_string_in_array(trans_cflicts, buf))
|
|
|
|
xbps_array_add_cstring(trans_cflicts, buf);
|
|
|
|
|
|
|
|
free(buf);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xbps_object_iterator_release(iter);
|
2020-02-21 13:38:22 +05:30
|
|
|
return rv;
|
2015-10-28 09:53:42 +05:30
|
|
|
}
|
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
bool HIDDEN
|
|
|
|
xbps_transaction_check_conflicts(struct xbps_handle *xhp, xbps_array_t pkgs)
|
2015-10-28 09:53:42 +05:30
|
|
|
{
|
2020-02-21 13:38:22 +05:30
|
|
|
xbps_array_t array;
|
2015-10-28 09:53:42 +05:30
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
/* find conflicts in transaction */
|
|
|
|
for (i = 0; i < xbps_array_count(pkgs); i++) {
|
2020-02-21 13:38:22 +05:30
|
|
|
pkg_conflicts_trans(xhp, pkgs, xbps_array_get(pkgs, i));
|
2015-10-28 09:53:42 +05:30
|
|
|
}
|
|
|
|
/* find conflicts in pkgdb */
|
2020-02-21 13:38:22 +05:30
|
|
|
if (xbps_pkgdb_foreach_cb_multi(xhp, pkgdb_conflicts_cb, pkgs) != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
array = xbps_dictionary_get(xhp->transd, "conflicts");
|
|
|
|
if (xbps_array_count(array) == 0) {
|
|
|
|
xbps_dictionary_remove(xhp->transd, "conflicts");
|
|
|
|
}
|
|
|
|
return true;
|
2015-10-28 09:53:42 +05:30
|
|
|
}
|