2014-09-09 14:38:54 +05:30
|
|
|
/*-
|
2015-01-18 14:53:52 +05:30
|
|
|
* Copyright (c) 2014-2015 Juan Romero Pardines.
|
2014-09-09 14:38:54 +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 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;
|
|
|
|
xbps_dictionary_t d;
|
|
|
|
|
|
|
|
d = xbps_dictionary_create();
|
|
|
|
assert(d);
|
|
|
|
iter = xbps_dictionary_iterator(xhp->pkgdb);
|
|
|
|
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
|
|
|
const char *pkgname, *pkgver;
|
2014-09-12 15:19:34 +05:30
|
|
|
|
2015-01-18 14:53:52 +05:30
|
|
|
pkgname = xbps_dictionary_keysym_cstring_nocopy(obj);
|
2014-09-29 18:55:09 +05:30
|
|
|
/*
|
2015-01-18 14:53:52 +05:30
|
|
|
* If there's an update for this pkg in transaction, use it.
|
2014-09-29 18:55:09 +05:30
|
|
|
*/
|
2015-01-18 14:53:52 +05:30
|
|
|
pkgd = xbps_find_pkg_in_array(pkgs, pkgname, "update");
|
|
|
|
if (pkgd == NULL)
|
|
|
|
pkgd = xbps_dictionary_get_keysym(xhp->pkgdb, obj);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If pkg does not have the required obj, pass to next one.
|
|
|
|
*/
|
|
|
|
shobjs = xbps_dictionary_get(pkgd,
|
|
|
|
req ? "shlib-requires" : "shlib-provides");
|
|
|
|
if (shobjs == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
|
|
|
for (unsigned int i = 0; i < xbps_array_count(shobjs); i++) {
|
|
|
|
const char *shlib;
|
|
|
|
|
|
|
|
xbps_array_get_cstring_nocopy(shobjs, i, &shlib);
|
|
|
|
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);
|
|
|
|
return d;
|
2014-09-09 14:38:54 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
bool HIDDEN
|
2014-10-18 16:05:47 +05:30
|
|
|
xbps_transaction_shlibs(struct xbps_handle *xhp, xbps_array_t pkgs, xbps_array_t mshlibs)
|
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;
|
|
|
|
xbps_dictionary_t shrequires, shprovides;
|
2014-09-09 14:38:54 +05:30
|
|
|
bool unmatched = false;
|
|
|
|
|
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
|
|
|
|
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))) {
|
|
|
|
xbps_array_t array;
|
|
|
|
const char *pkgver, *shlib;
|
|
|
|
char *buf;
|
2014-09-09 14:38:54 +05:30
|
|
|
|
2015-01-18 14:53:52 +05:30
|
|
|
shlib = xbps_dictionary_keysym_cstring_nocopy(obj);
|
|
|
|
if (xbps_dictionary_get(shprovides, shlib))
|
|
|
|
continue;
|
2014-09-11 03:42:12 +05:30
|
|
|
|
2015-01-18 14:53:52 +05:30
|
|
|
unmatched = true;
|
|
|
|
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_release(array);
|
2014-09-09 14:38:54 +05:30
|
|
|
}
|
2015-01-18 14:53:52 +05:30
|
|
|
xbps_object_iterator_release(iter);
|
|
|
|
xbps_object_release(shprovides);
|
|
|
|
|
2014-09-09 14:38:54 +05:30
|
|
|
return unmatched;
|
|
|
|
}
|