2014-09-09 14:38:54 +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.
|
2014-09-09 14:38:54 +05:30
|
|
|
*/
|
2020-04-24 15:14:19 +05:30
|
|
|
|
2014-09-09 14:38:54 +05:30
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "xbps_api_impl.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify shlib-{provides,requires} for packages in transaction.
|
|
|
|
* This will catch cases where a package update would break its reverse
|
|
|
|
* dependencies due to an incompatible SONAME bump:
|
|
|
|
*
|
|
|
|
* - foo-1.0 is installed and provides the 'libfoo.so.0' soname.
|
|
|
|
* - foo-2.0 provides the 'libfoo.so.1' soname.
|
|
|
|
* - baz-1.0 requires 'libfoo.so.0'.
|
|
|
|
* - foo is updated to 2.0, hence baz-1.0 is now broken.
|
|
|
|
*
|
|
|
|
* Abort transaction if such case is found.
|
|
|
|
*/
|
|
|
|
|
2015-01-18 14:53:52 +05:30
|
|
|
static void
|
|
|
|
shlib_register(xbps_dictionary_t d, const char *shlib, const char *pkgver)
|
|
|
|
{
|
|
|
|
xbps_array_t array;
|
|
|
|
bool alloc = false;
|
2014-09-09 14:38:54 +05:30
|
|
|
|
2015-01-18 14:53:52 +05:30
|
|
|
if ((array = xbps_dictionary_get(d, shlib)) == NULL) {
|
|
|
|
alloc = true;
|
|
|
|
array = xbps_array_create();
|
|
|
|
xbps_dictionary_set(d, shlib, array);
|
2014-09-12 15:19:34 +05:30
|
|
|
}
|
2015-01-18 14:53:52 +05:30
|
|
|
if (!xbps_match_string_in_array(array, pkgver))
|
|
|
|
xbps_array_add_cstring_nocopy(array, pkgver);
|
|
|
|
if (alloc)
|
|
|
|
xbps_object_release(array);
|
2014-09-09 14:38:54 +05:30
|
|
|
}
|
|
|
|
|
2015-01-18 14:53:52 +05:30
|
|
|
static xbps_dictionary_t
|
|
|
|
collect_shlibs(struct xbps_handle *xhp, xbps_array_t pkgs, bool req)
|
2014-09-09 14:38:54 +05:30
|
|
|
{
|
2015-01-18 14:53:52 +05:30
|
|
|
xbps_object_t obj;
|
|
|
|
xbps_object_iterator_t iter;
|
2015-01-18 17:14:26 +05:30
|
|
|
xbps_dictionary_t d, pd;
|
2020-02-21 13:38:22 +05:30
|
|
|
const char *pkgname, *pkgver;
|
2015-01-18 14:53:52 +05:30
|
|
|
|
|
|
|
d = xbps_dictionary_create();
|
|
|
|
assert(d);
|
2015-01-18 17:14:26 +05:30
|
|
|
|
|
|
|
/* copy pkgdb to out temporary dictionary */
|
|
|
|
pd = xbps_dictionary_copy(xhp->pkgdb);
|
|
|
|
assert(pd);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* copy pkgs from transaction to our dictionary, overriding them
|
|
|
|
* if they were there from pkgdb.
|
|
|
|
*/
|
|
|
|
iter = xbps_array_iterator(pkgs);
|
|
|
|
assert(iter);
|
|
|
|
while ((obj = xbps_object_iterator_next(iter))) {
|
2020-02-21 13:38:22 +05:30
|
|
|
if (!xbps_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname))
|
2015-10-30 16:54:46 +05:30
|
|
|
continue;
|
|
|
|
|
2020-01-25 14:47:37 +05:30
|
|
|
/* ignore shlibs if pkg is on hold mode */
|
2020-02-21 13:38:22 +05:30
|
|
|
if (xbps_transaction_pkg_type(obj) == XBPS_TRANS_HOLD) {
|
|
|
|
continue;
|
2020-01-25 14:47:37 +05:30
|
|
|
}
|
|
|
|
|
2015-01-18 17:14:26 +05:30
|
|
|
xbps_dictionary_set(pd, pkgname, obj);
|
|
|
|
}
|
|
|
|
xbps_object_iterator_release(iter);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* iterate over our dictionary to collect shlib-{requires,provides}.
|
|
|
|
*/
|
|
|
|
iter = xbps_dictionary_iterator(pd);
|
2015-01-18 14:53:52 +05:30
|
|
|
assert(iter);
|
|
|
|
|
|
|
|
while ((obj = xbps_object_iterator_next(iter))) {
|
|
|
|
xbps_array_t shobjs;
|
2014-09-12 15:19:34 +05:30
|
|
|
xbps_dictionary_t pkgd;
|
2015-01-18 14:53:52 +05:30
|
|
|
|
2015-01-18 17:14:26 +05:30
|
|
|
pkgd = xbps_dictionary_get_keysym(pd, obj);
|
2020-02-21 13:38:22 +05:30
|
|
|
if (xbps_transaction_pkg_type(pkgd) == XBPS_TRANS_REMOVE) {
|
|
|
|
continue;
|
2015-01-18 17:14:26 +05:30
|
|
|
}
|
2015-01-18 14:53:52 +05:30
|
|
|
/*
|
|
|
|
* If pkg does not have the required obj, pass to next one.
|
|
|
|
*/
|
2015-01-18 17:14:26 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
2015-01-18 14:53:52 +05:30
|
|
|
shobjs = xbps_dictionary_get(pkgd,
|
|
|
|
req ? "shlib-requires" : "shlib-provides");
|
|
|
|
if (shobjs == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < xbps_array_count(shobjs); i++) {
|
2019-06-27 20:39:43 +05:30
|
|
|
const char *shlib = NULL;
|
2015-01-18 14:53:52 +05:30
|
|
|
|
|
|
|
xbps_array_get_cstring_nocopy(shobjs, i, &shlib);
|
2015-03-07 12:32:39 +05:30
|
|
|
xbps_dbg_printf(xhp, "%s: registering %s for %s\n",
|
|
|
|
pkgver, shlib, req ? "shlib-requires" : "shlib-provides");
|
2015-01-18 14:53:52 +05:30
|
|
|
if (req)
|
|
|
|
shlib_register(d, shlib, pkgver);
|
|
|
|
else
|
|
|
|
xbps_dictionary_set_cstring_nocopy(d, shlib, pkgver);
|
2014-09-09 14:38:54 +05:30
|
|
|
}
|
|
|
|
}
|
2015-01-18 14:53:52 +05:30
|
|
|
xbps_object_iterator_release(iter);
|
2016-09-26 01:17:40 +05:30
|
|
|
xbps_object_release(pd);
|
2015-01-18 14:53:52 +05:30
|
|
|
return d;
|
2014-09-09 14:38:54 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
bool HIDDEN
|
2020-02-21 13:38:22 +05:30
|
|
|
xbps_transaction_check_shlibs(struct xbps_handle *xhp, xbps_array_t pkgs)
|
2014-09-09 14:38:54 +05:30
|
|
|
{
|
2020-02-21 13:38:22 +05:30
|
|
|
xbps_array_t array, mshlibs;
|
2016-04-17 21:24:49 +05:30
|
|
|
xbps_object_t obj, obj2;
|
2015-01-18 14:53:52 +05:30
|
|
|
xbps_object_iterator_t iter;
|
|
|
|
xbps_dictionary_t shrequires, shprovides;
|
2020-02-21 13:38:22 +05:30
|
|
|
const char *pkgver = NULL, *shlib = NULL;
|
|
|
|
char *buf;
|
|
|
|
bool broken = false;
|
2014-09-09 14:38:54 +05:30
|
|
|
|
2015-01-18 14:53:52 +05:30
|
|
|
shrequires = collect_shlibs(xhp, pkgs, true);
|
|
|
|
shprovides = collect_shlibs(xhp, pkgs, false);
|
2014-09-09 14:38:54 +05:30
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
mshlibs = xbps_dictionary_get(xhp->transd, "missing_shlibs");
|
2015-01-18 14:53:52 +05:30
|
|
|
/* iterate over shlib-requires to find unmatched shlibs */
|
|
|
|
iter = xbps_dictionary_iterator(shrequires);
|
|
|
|
assert(iter);
|
2014-09-12 15:19:34 +05:30
|
|
|
|
2015-01-18 14:53:52 +05:30
|
|
|
while ((obj = xbps_object_iterator_next(iter))) {
|
|
|
|
shlib = xbps_dictionary_keysym_cstring_nocopy(obj);
|
2015-01-18 17:14:26 +05:30
|
|
|
xbps_dbg_printf(xhp, "%s: checking for `%s': ", __func__, shlib);
|
2016-04-17 21:24:49 +05:30
|
|
|
if ((obj2 = xbps_dictionary_get(shprovides, shlib))) {
|
|
|
|
xbps_dbg_printf_append(xhp, "provided by `%s'\n",
|
|
|
|
xbps_string_cstring_nocopy(obj2));
|
2015-01-18 14:53:52 +05:30
|
|
|
continue;
|
2015-01-18 17:14:26 +05:30
|
|
|
}
|
|
|
|
xbps_dbg_printf_append(xhp, "not found\n");
|
2014-09-11 03:42:12 +05:30
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
broken = true;
|
2015-01-18 14:53:52 +05:30
|
|
|
array = xbps_dictionary_get_keysym(shrequires, obj);
|
|
|
|
for (unsigned int i = 0; i < xbps_array_count(array); i++) {
|
|
|
|
xbps_array_get_cstring_nocopy(array, i, &pkgver);
|
|
|
|
buf = xbps_xasprintf("%s: broken, unresolvable "
|
|
|
|
"shlib `%s'", pkgver, shlib);
|
|
|
|
xbps_array_add_cstring(mshlibs, buf);
|
|
|
|
free(buf);
|
2014-09-09 14:38:54 +05:30
|
|
|
}
|
|
|
|
}
|
2015-01-18 14:53:52 +05:30
|
|
|
xbps_object_iterator_release(iter);
|
2020-02-21 13:38:22 +05:30
|
|
|
if (!broken) {
|
|
|
|
xbps_dictionary_remove(xhp->transd, "missing_shlibs");
|
|
|
|
}
|
2015-01-18 14:53:52 +05:30
|
|
|
xbps_object_release(shprovides);
|
2020-02-21 13:38:22 +05:30
|
|
|
xbps_object_release(shrequires);
|
2015-01-18 14:53:52 +05:30
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
return true;
|
2014-09-09 14:38:54 +05:30
|
|
|
}
|