Perform global tracking of unresolved shlibs before accepting transaction.
Rather than checking per package being installed or updated, check all installed packages to have all its shlib-requires resolved.
This commit is contained in:
parent
d11230a29d
commit
f9eef6aa0d
3
NEWS
3
NEWS
@ -1,5 +1,8 @@
|
|||||||
xbps-0.44 (???):
|
xbps-0.44 (???):
|
||||||
|
|
||||||
|
* libxbps: globally check for unresolved shared libraries before accepting
|
||||||
|
a transaction to make sure there's no broken packages.
|
||||||
|
|
||||||
* libxbps: abort package unpacking as soon as a file failed
|
* libxbps: abort package unpacking as soon as a file failed
|
||||||
to be written and return a meaningful error; close #74
|
to be written and return a meaningful error; close #74
|
||||||
https://github.com/voidlinux/xbps/issues/74
|
https://github.com/voidlinux/xbps/issues/74
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*-
|
/*-
|
||||||
* Copyright (c) 2014 Juan Romero Pardines.
|
* Copyright (c) 2014-2015 Juan Romero Pardines.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -42,168 +42,109 @@
|
|||||||
*
|
*
|
||||||
* Abort transaction if such case is found.
|
* Abort transaction if such case is found.
|
||||||
*/
|
*/
|
||||||
static bool
|
|
||||||
shlib_trans_matched(xbps_array_t pkgs, const char *pkgver, const char *shlib)
|
static void
|
||||||
|
shlib_register(xbps_dictionary_t d, const char *shlib, const char *pkgver)
|
||||||
{
|
{
|
||||||
xbps_array_t shrequires;
|
xbps_array_t array;
|
||||||
xbps_dictionary_t pkgd;
|
bool alloc = false;
|
||||||
const char *tract;
|
|
||||||
char *pkgname;
|
|
||||||
|
|
||||||
pkgname = xbps_pkg_name(pkgver);
|
if ((array = xbps_dictionary_get(d, shlib)) == NULL) {
|
||||||
assert(pkgname);
|
alloc = true;
|
||||||
|
array = xbps_array_create();
|
||||||
if ((pkgd = xbps_find_pkg_in_array(pkgs, pkgname, NULL)) == NULL) {
|
xbps_dictionary_set(d, shlib, array);
|
||||||
free(pkgname);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
free(pkgname);
|
if (!xbps_match_string_in_array(array, pkgver))
|
||||||
|
xbps_array_add_cstring_nocopy(array, pkgver);
|
||||||
xbps_dictionary_get_cstring_nocopy(pkgd, "transaction", &tract);
|
if (alloc)
|
||||||
if (strcmp(tract, "update"))
|
xbps_object_release(array);
|
||||||
return false;
|
|
||||||
|
|
||||||
shrequires = xbps_dictionary_get(pkgd, "shlib-requires");
|
|
||||||
if (!shrequires)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return xbps_match_string_in_array(shrequires, shlib);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static xbps_dictionary_t
|
||||||
shlib_matched(struct xbps_handle *xhp, xbps_array_t pkgs, xbps_array_t mshlibs,
|
collect_shlibs(struct xbps_handle *xhp, xbps_array_t pkgs, bool req)
|
||||||
const char *pkgver, const char *shlib)
|
|
||||||
{
|
{
|
||||||
xbps_array_t revdeps;
|
xbps_object_t obj;
|
||||||
const char *shlibver;
|
xbps_object_iterator_t iter;
|
||||||
char *pkgname, *shlibname;
|
xbps_dictionary_t d;
|
||||||
bool found = true;
|
|
||||||
|
|
||||||
pkgname = xbps_pkg_name(pkgver);
|
d = xbps_dictionary_create();
|
||||||
assert(pkgname);
|
assert(d);
|
||||||
revdeps = xbps_pkgdb_get_pkg_revdeps(xhp, pkgname);
|
iter = xbps_dictionary_iterator(xhp->pkgdb);
|
||||||
free(pkgname);
|
assert(iter);
|
||||||
if (!revdeps)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
shlibver = strchr(shlib, '.');
|
while ((obj = xbps_object_iterator_next(iter))) {
|
||||||
shlibname = strdup(shlib);
|
xbps_array_t shobjs;
|
||||||
shlibname[strlen(shlib) - strlen(shlibver)] = '\0';
|
|
||||||
assert(shlibname);
|
|
||||||
|
|
||||||
/* Iterate over its revdeps and match the provided shlib */
|
|
||||||
for (unsigned int i = 0; i < xbps_array_count(revdeps); i++) {
|
|
||||||
xbps_array_t shrequires;
|
|
||||||
xbps_dictionary_t pkgd;
|
xbps_dictionary_t pkgd;
|
||||||
const char *trans, *rpkgver;
|
const char *pkgname, *pkgver;
|
||||||
char *rpkgname;
|
|
||||||
|
|
||||||
xbps_array_get_cstring_nocopy(revdeps, i, &rpkgver);
|
pkgname = xbps_dictionary_keysym_cstring_nocopy(obj);
|
||||||
rpkgname = xbps_pkg_name(rpkgver);
|
|
||||||
assert(rpkgname);
|
|
||||||
/*
|
/*
|
||||||
* First check if this revdep has been queued in transaction;
|
* If there's an update for this pkg in transaction, use it.
|
||||||
* otherwise process the current installed pkg.
|
|
||||||
*/
|
*/
|
||||||
pkgd = xbps_find_pkg_in_array(pkgs, rpkgname, NULL);
|
pkgd = xbps_find_pkg_in_array(pkgs, pkgname, "update");
|
||||||
free(rpkgname);
|
if (pkgd == NULL)
|
||||||
if (pkgd) {
|
pkgd = xbps_dictionary_get_keysym(xhp->pkgdb, obj);
|
||||||
/*
|
|
||||||
* Make sure pkg in transaction is an update.
|
|
||||||
*/
|
|
||||||
xbps_dictionary_get_cstring_nocopy(pkgd, "transaction", &trans);
|
|
||||||
if (strcmp(trans, "update"))
|
|
||||||
pkgd = NULL;
|
|
||||||
}
|
|
||||||
if (!pkgd)
|
|
||||||
pkgd = xbps_pkgdb_get_pkg(xhp, rpkgver);
|
|
||||||
|
|
||||||
shrequires = xbps_dictionary_get(pkgd, "shlib-requires");
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
for (unsigned int x = 0; x < xbps_array_count(shrequires); x++) {
|
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
||||||
const char *rshlib, *rshlibver;
|
for (unsigned int i = 0; i < xbps_array_count(shobjs); i++) {
|
||||||
char *rshlibname;
|
const char *shlib;
|
||||||
|
|
||||||
xbps_array_get_cstring_nocopy(shrequires, x, &rshlib);
|
xbps_array_get_cstring_nocopy(shobjs, i, &shlib);
|
||||||
rshlibver = strchr(rshlib, '.');
|
if (req)
|
||||||
rshlibname = strdup(rshlib);
|
shlib_register(d, shlib, pkgver);
|
||||||
rshlibname[strlen(rshlib) - strlen(rshlibver)] = '\0';
|
else
|
||||||
|
xbps_dictionary_set_cstring_nocopy(d, shlib, pkgver);
|
||||||
if ((strcmp(shlibname, rshlibname) == 0) &&
|
|
||||||
(strcmp(shlibver, rshlibver))) {
|
|
||||||
/*
|
|
||||||
* The shared library version did not match the
|
|
||||||
* installed pkg; find out if there's an update
|
|
||||||
* in the transaction with the matching version.
|
|
||||||
*/
|
|
||||||
if (!shlib_trans_matched(pkgs, rpkgver, shlib)) {
|
|
||||||
char *buf;
|
|
||||||
/* shlib not matched */
|
|
||||||
buf = xbps_xasprintf("%s breaks `%s' "
|
|
||||||
"(needs `%s%s', got '%s')",
|
|
||||||
pkgver, rpkgver, shlibname,
|
|
||||||
rshlibver, shlib);
|
|
||||||
xbps_array_add_cstring(mshlibs, buf);
|
|
||||||
free(buf);
|
|
||||||
found = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free(rshlibname);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(shlibname);
|
xbps_object_iterator_release(iter);
|
||||||
|
return d;
|
||||||
return found;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool HIDDEN
|
bool HIDDEN
|
||||||
xbps_transaction_shlibs(struct xbps_handle *xhp, xbps_array_t pkgs, xbps_array_t mshlibs)
|
xbps_transaction_shlibs(struct xbps_handle *xhp, xbps_array_t pkgs, xbps_array_t mshlibs)
|
||||||
{
|
{
|
||||||
|
xbps_object_t obj;
|
||||||
|
xbps_object_iterator_t iter;
|
||||||
|
xbps_dictionary_t shrequires, shprovides;
|
||||||
bool unmatched = false;
|
bool unmatched = false;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < xbps_array_count(pkgs); i++) {
|
shrequires = collect_shlibs(xhp, pkgs, true);
|
||||||
xbps_array_t shprovides;
|
shprovides = collect_shlibs(xhp, pkgs, false);
|
||||||
xbps_object_t obj, pkgd;
|
|
||||||
const char *pkgver, *tract;
|
|
||||||
char *pkgname;
|
|
||||||
|
|
||||||
obj = xbps_array_get(pkgs, i);
|
/* iterate over shlib-requires to find unmatched shlibs */
|
||||||
/*
|
iter = xbps_dictionary_iterator(shrequires);
|
||||||
* If pkg does not have 'shlib-provides' obj, pass to next one.
|
assert(iter);
|
||||||
*/
|
|
||||||
if ((shprovides = xbps_dictionary_get(obj, "shlib-provides")) == NULL)
|
while ((obj = xbps_object_iterator_next(iter))) {
|
||||||
continue;
|
xbps_array_t array;
|
||||||
/*
|
const char *pkgver, *shlib;
|
||||||
* Only process pkgs that are being updated.
|
char *buf;
|
||||||
*/
|
|
||||||
xbps_dictionary_get_cstring_nocopy(obj, "transaction", &tract);
|
shlib = xbps_dictionary_keysym_cstring_nocopy(obj);
|
||||||
if (strcmp(tract, "update"))
|
if (xbps_dictionary_get(shprovides, shlib))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/*
|
unmatched = true;
|
||||||
* If there's no change in shlib-provides, pass to next one.
|
array = xbps_dictionary_get_keysym(shrequires, obj);
|
||||||
*/
|
for (unsigned int i = 0; i < xbps_array_count(array); i++) {
|
||||||
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
xbps_array_get_cstring_nocopy(array, i, &pkgver);
|
||||||
pkgname = xbps_pkg_name(pkgver);
|
buf = xbps_xasprintf("%s: broken, unresolvable "
|
||||||
assert(pkgname);
|
"shlib `%s'", pkgver, shlib);
|
||||||
pkgd = xbps_pkgdb_get_pkg(xhp, pkgname);
|
xbps_array_add_cstring(mshlibs, buf);
|
||||||
assert(pkgd);
|
free(buf);
|
||||||
free(pkgname);
|
|
||||||
if (xbps_array_equals(shprovides, xbps_dictionary_get(pkgd, "shlib-provides")))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
for (unsigned int x = 0; x < xbps_array_count(shprovides); x++) {
|
|
||||||
const char *shlib;
|
|
||||||
|
|
||||||
xbps_array_get_cstring_nocopy(shprovides, x, &shlib);
|
|
||||||
/*
|
|
||||||
* Check that all shlibs provided by this pkg are used by
|
|
||||||
* its revdeps.
|
|
||||||
*/
|
|
||||||
if (!shlib_matched(xhp, pkgs, mshlibs, pkgver, shlib))
|
|
||||||
unmatched = true;
|
|
||||||
}
|
}
|
||||||
|
xbps_object_release(array);
|
||||||
}
|
}
|
||||||
|
xbps_object_iterator_release(iter);
|
||||||
|
xbps_object_release(shprovides);
|
||||||
|
|
||||||
return unmatched;
|
return unmatched;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user