Implement shlib checks for all pkg revdeps in the transaction.

Added three new test cases to verify its correctness.
This commit is contained in:
Juan RP 2014-09-12 11:49:34 +02:00
parent b306adf52b
commit 39aca1bbc9
8 changed files with 249 additions and 76 deletions

View File

@ -310,22 +310,22 @@ exec_transaction(struct xbps_handle *xhp, int maxcols, bool yes, bool drun)
print_array(array); print_array(array);
fprintf(stderr, "Transaction aborted due to unresolved dependencies.\n"); fprintf(stderr, "Transaction aborted due to unresolved dependencies.\n");
} }
} else if (rv == ENOEXEC) {
array = xbps_dictionary_get(xhp->transd, "missing_shlibs"); array = xbps_dictionary_get(xhp->transd, "missing_shlibs");
if (xbps_array_count(array)) { if (xbps_array_count(array)) {
/* missing shlibs */ /* missing shlibs */
print_array(array); print_array(array);
fprintf(stderr, "Transaction aborted due to unresolved shlibs.\n"); fprintf(stderr, "Transaction aborted due to unresolved shlibs.\n");
} }
goto out;
} else if (rv == EAGAIN) { } else if (rv == EAGAIN) {
/* conflicts */ /* conflicts */
array = xbps_dictionary_get(xhp->transd, "conflicts"); array = xbps_dictionary_get(xhp->transd, "conflicts");
print_array(array); print_array(array);
fprintf(stderr, "Transaction aborted due to conflicting packages.\n"); fprintf(stderr, "Transaction aborted due to conflicting packages.\n");
goto out; } else {
xbps_dbg_printf(xhp, "Empty transaction dictionary: %s\n",
strerror(errno));
} }
xbps_dbg_printf(xhp, "Empty transaction dictionary: %s\n",
strerror(errno));
goto out; goto out;
} }
xbps_dbg_printf(xhp, "Dictionary before transaction happens:\n"); xbps_dbg_printf(xhp, "Dictionary before transaction happens:\n");

View File

@ -48,7 +48,7 @@
* *
* This header documents the full API for the XBPS Library. * This header documents the full API for the XBPS Library.
*/ */
#define XBPS_API_VERSION "20140909" #define XBPS_API_VERSION "20140912"
#ifndef XBPS_VERSION #ifndef XBPS_VERSION
#define XBPS_VERSION "UNSET" #define XBPS_VERSION "UNSET"
@ -1160,6 +1160,8 @@ int xbps_transaction_autoremove_pkgs(struct xbps_handle *xhp);
* previously called. * previously called.
* @retval ENODEV if there are missing dependencies in transaction ("missing_deps" * @retval ENODEV if there are missing dependencies in transaction ("missing_deps"
* array of strings object in xhp->transd dictionary). * array of strings object in xhp->transd dictionary).
* @retval ENOEXEC if there are unresolved shared libraries in transaction ("missing_shlibs"
* array of strings object in xhp->transd dictionary).
* @retval EAGAIN if there are package conflicts in transaction ("conflicts" * @retval EAGAIN if there are package conflicts in transaction ("conflicts"
* array of strings object in xhp->transd dictionary). * array of strings object in xhp->transd dictionary).
* @retval ENOSPC Not enough free space on target rootdir to continue with the * @retval ENOSPC Not enough free space on target rootdir to continue with the

View File

@ -228,8 +228,10 @@ vpkg_user_conf(struct xbps_handle *xhp,
continue; continue;
} }
} }
#ifdef FULLDEBUG
xbps_dbg_printf(xhp, "matched vpkg `%s' with `%s (provides %s)`\n", xbps_dbg_printf(xhp, "matched vpkg `%s' with `%s (provides %s)`\n",
vpkg, pkg, vpkgver); vpkg, pkg, vpkgver);
#endif
free(vpkgname); free(vpkgname);
found = true; found = true;
break; break;

View File

@ -290,8 +290,11 @@ xbps_transaction_prepare(struct xbps_handle *xhp)
xhp->transd = NULL; xhp->transd = NULL;
return rv; return rv;
} }
/*
* Check for unresolved shared libraries.
*/
if (xbps_transaction_shlibs(xhp)) if (xbps_transaction_shlibs(xhp))
return ENODEV; return ENOEXEC;
/* /*
* Sort package dependencies if necessary. * Sort package dependencies if necessary.

View File

@ -43,67 +43,102 @@
* Abort transaction if such case is found. * Abort transaction if such case is found.
*/ */
static bool static bool
shlib_in_pkgdb(struct xbps_handle *xhp, const char *pkgver, const char *shlib) shlib_trans_matched(struct xbps_handle *xhp, const char *pkgver, const char *shlib)
{ {
xbps_object_iterator_t iter; xbps_array_t unsorted, shrequires;
xbps_object_t obj; xbps_dictionary_t pkgd;
bool found = false; const char *tract;
char *pkgname;
if (!xbps_dictionary_count(xhp->pkgdb)) pkgname = xbps_pkg_name(pkgver);
return found; assert(pkgname);
iter = xbps_dictionary_iterator(xhp->pkgdb); unsorted = xbps_dictionary_get(xhp->transd, "unsorted_deps");
assert(iter); if ((pkgd = xbps_find_pkg_in_array(unsorted, pkgname)) == NULL) {
free(pkgname);
while ((obj = xbps_object_iterator_next(iter))) { return false;
xbps_array_t shprovides;
xbps_dictionary_t pkgd;
const char *curpkgver;
pkgd = xbps_dictionary_get_keysym(xhp->pkgdb, obj);
shprovides = xbps_dictionary_get(pkgd, "shlib-provides");
if (!shprovides)
continue;
if (xbps_match_string_in_array(shprovides, shlib)) {
/* shlib matched */
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &curpkgver);
xbps_dbg_printf(xhp, "[trans] %s requires `%s': "
"matched by `%s' (pkgdb)\n", pkgver, shlib, curpkgver);
found = true;
break;
}
} }
xbps_object_iterator_release(iter); free(pkgname);
return found;
xbps_dictionary_get_cstring_nocopy(pkgd, "transaction", &tract);
if (strcmp(tract, "update"))
return false;
shrequires = xbps_dictionary_get(pkgd, "shlib-requires");
if (!shrequires)
return false;
return xbps_match_string_in_array(shrequires, shlib);
} }
static bool static bool
shlib_in_transaction(struct xbps_handle *xhp, const char *pkgver, const char *shlib) shlib_matched(struct xbps_handle *xhp, xbps_array_t mshlibs,
const char *pkgver, const char *shlib)
{ {
xbps_array_t unsorted; xbps_array_t revdeps;
const char *shlibver;
char *pkgname, *shlibname;
bool found = true;
unsorted = xbps_dictionary_get(xhp->transd, "unsorted_deps"); pkgname = xbps_pkg_name(pkgver);
for (unsigned int i = 0; i < xbps_array_count(unsorted); i++) { assert(pkgname);
xbps_array_t shprovides; revdeps = xbps_pkgdb_get_pkg_revdeps(xhp, pkgname);
xbps_object_t obj; free(pkgname);
if (!revdeps)
return true;
obj = xbps_array_get(unsorted, i); shlibver = strchr(shlib, '.');
shprovides = xbps_dictionary_get(obj, "shlib-provides"); shlibname = strdup(shlib);
if (!shprovides) shlibname[strlen(shlib) - strlen(shlibver)] = '\0';
continue; assert(shlibname);
if (xbps_match_string_in_array(shprovides, shlib)) {
/* shlib matched */
const char *curpkgver;
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &curpkgver); /* Iterate over its revdeps and match the provided shlib */
xbps_dbg_printf(xhp, "[trans] %s requires `%s': " for (unsigned int i = 0; i < xbps_array_count(revdeps); i++) {
"matched by `%s' (trans)\n", pkgver, shlib, curpkgver); xbps_array_t shrequires;
return true; xbps_dictionary_t pkgd;
const char *rpkgver;
xbps_array_get_cstring_nocopy(revdeps, i, &rpkgver);
pkgd = xbps_pkgdb_get_pkg(xhp, rpkgver);
shrequires = xbps_dictionary_get(pkgd, "shlib-requires");
for (unsigned int x = 0; x < xbps_array_count(shrequires); x++) {
const char *rshlib, *rshlibver;
char *rshlibname;
xbps_array_get_cstring_nocopy(shrequires, x, &rshlib);
rshlibver = strchr(rshlib, '.');
rshlibname = strdup(rshlib);
rshlibname[strlen(rshlib) - strlen(rshlibver)] = '\0';
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(xhp, 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);
} }
} }
return false; free(shlibname);
return found;
} }
bool HIDDEN bool HIDDEN
xbps_transaction_shlibs(struct xbps_handle *xhp) xbps_transaction_shlibs(struct xbps_handle *xhp)
{ {
@ -112,44 +147,48 @@ xbps_transaction_shlibs(struct xbps_handle *xhp)
mshlibs = xbps_dictionary_get(xhp->transd, "missing_shlibs"); mshlibs = xbps_dictionary_get(xhp->transd, "missing_shlibs");
unsorted = xbps_dictionary_get(xhp->transd, "unsorted_deps"); unsorted = xbps_dictionary_get(xhp->transd, "unsorted_deps");
for (unsigned int i = 0; i < xbps_array_count(unsorted); i++) { for (unsigned int i = 0; i < xbps_array_count(unsorted); i++) {
xbps_array_t shrequires; xbps_array_t shprovides;
xbps_object_t obj; xbps_object_t obj, pkgd;
const char *pkgver, *tract; const char *pkgver, *tract;
char *pkgname;
obj = xbps_array_get(unsorted, i); obj = xbps_array_get(unsorted, i);
/* /*
* Only process pkgs that are being installed or updated. * If pkg does not have 'shlib-provides' obj, pass to next one.
*/
if ((shprovides = xbps_dictionary_get(obj, "shlib-provides")) == NULL)
continue;
/*
* Only process pkgs that are being updated.
*/ */
xbps_dictionary_get_cstring_nocopy(obj, "transaction", &tract); xbps_dictionary_get_cstring_nocopy(obj, "transaction", &tract);
if (strcmp(tract, "install") && strcmp(tract, "update")) if (strcmp(tract, "update"))
continue; continue;
/* /*
* If pkg does not have 'shlib-requires' obj, pass to next one. * If there's no change in shlib-provides, pass to next one.
*/
if ((shrequires = xbps_dictionary_get(obj, "shlib-requires")) == NULL)
continue;
/*
* Check if all required shlibs are provided by:
* - an installed pkg
* - a pkg in the transaction
*/ */
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
for (unsigned int x = 0; x < xbps_array_count(shrequires); x++) { pkgname = xbps_pkg_name(pkgver);
assert(pkgname);
pkgd = xbps_pkgdb_get_pkg(xhp, pkgname);
assert(pkgd);
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; const char *shlib;
xbps_array_get_cstring_nocopy(shrequires, x, &shlib); xbps_array_get_cstring_nocopy(shprovides, x, &shlib);
if ((!shlib_in_pkgdb(xhp, pkgver, shlib)) && /*
(!shlib_in_transaction(xhp, pkgver, shlib))) { * Check that all shlibs provided by this pkg are used by
char *buf; * its revdeps.
*/
buf = xbps_xasprintf("%s: needs `%s' shlib, not" if (!shlib_matched(xhp, mshlibs, pkgver, shlib))
" provided by any pkg!", pkgver, shlib);
xbps_dbg_printf(xhp, "%s\n", buf);
xbps_array_add_cstring(mshlibs, buf);
free(buf);
unmatched = true; unmatched = true;
}
} }
} }
return unmatched; return unmatched;

View File

@ -22,6 +22,7 @@ atf_test_program{name="incorrect_deps_test"}
atf_test_program{name="vpkg_test"} atf_test_program{name="vpkg_test"}
atf_test_program{name="install_test"} atf_test_program{name="install_test"}
atf_test_program{name="preserve_files_test"} atf_test_program{name="preserve_files_test"}
atf_test_program{name="update_shlibs"}
include('config/Kyuafile') include('config/Kyuafile')
include('find_pkg_orphans/Kyuafile') include('find_pkg_orphans/Kyuafile')

View File

@ -5,6 +5,7 @@ TESTSHELL = conf_files_test issue6_test issue18_test issue20_test remove_test
TESTSHELL+= replace_test installmode_test obsoletefiles_test TESTSHELL+= replace_test installmode_test obsoletefiles_test
TESTSHELL+= issue31_test scripts_test incorrect_deps_test TESTSHELL+= issue31_test scripts_test incorrect_deps_test
TESTSHELL+= vpkg_test install_test preserve_files_test TESTSHELL+= vpkg_test install_test preserve_files_test
TESTSHELL+= update_shlibs
include ../Makefile.inc include ../Makefile.inc
include $(TOPDIR)/mk/test.mk include $(TOPDIR)/mk/test.mk

View File

@ -0,0 +1,125 @@
#!/usr/bin/env atf-sh
#
# 1st case:
# - A is updated and contains a soname bump
# - A revdeps are broken
# - ENOEXEC expected (unresolved shlibs)
atf_test_case shlib_bump
shlib_bump_head() {
atf_set "descr" "Tests for pkg updates: update pkg with soname bump"
}
shlib_bump_body() {
mkdir -p repo pkg_A pkg_B
cd repo
xbps-create -A noarch -n A-1.0_1 -s "A pkg" --shlib-provides "libfoo.so.1" ../pkg_A
atf_check_equal $? 0
xbps-create -A noarch -n B-1.0_1 -s "B pkg" --dependencies "A>=0" --shlib-requires "libfoo.so.1" ../pkg_B
atf_check_equal $? 0
xbps-rindex -a *.xbps
atf_check_equal $? 0
cd ..
xbps-install -C empty.conf -r root --repository=$PWD/repo -yvd B
atf_check_equal $? 0
cd repo
xbps-create -A noarch -n A-2.0_1 -s "A pkg" --shlib-provides "libfoo.so.2" ../pkg_A
atf_check_equal $? 0
xbps-rindex -a *.xbps
atf_check_equal $? 0
cd ..
# returns ENOEXEC if there are unresolved shlibs
xbps-install -C empty.conf -r root --repository=$PWD/repo -yuvd A
atf_check_equal $? 8
}
# 2nd case:
# - A is updated and contains a soname bump
# - A revdeps are broken but there are updates in transaction
atf_test_case shlib_bump_revdep_in_trans
shlib_bump_revdep_in_trans_head() {
atf_set "descr" "Tests for pkg updates: update pkg with soname bump, updated revdep in trans"
}
shlib_bump_revdep_in_trans_body() {
mkdir -p repo pkg_A pkg_B
cd repo
xbps-create -A noarch -n A-1.0_1 -s "A pkg" --shlib-provides "libfoo.so.1" ../pkg_A
atf_check_equal $? 0
xbps-create -A noarch -n B-1.0_1 -s "B pkg" --dependencies "A>=1.0" --shlib-requires "libfoo.so.1" ../pkg_B
atf_check_equal $? 0
xbps-rindex -a *.xbps
atf_check_equal $? 0
cd ..
xbps-install -C empty.conf -r root --repository=$PWD/repo -yvd B
atf_check_equal $? 0
cd repo
xbps-create -A noarch -n A-2.0_1 -s "A pkg" --shlib-provides "libfoo.so.2" ../pkg_A
atf_check_equal $? 0
xbps-create -A noarch -n B-2.0_1 -s "B pkg" --dependencies "A>=0" --shlib-requires "libfoo.so.2" ../pkg_B
atf_check_equal $? 0
xbps-rindex -a *.xbps
atf_check_equal $? 0
cd ..
xbps-install -C empty.conf -r root --repository=$PWD/repo -yuvd
atf_check_equal $? 0
res=$(xbps-query -C empty.conf -r root -p pkgver A)
atf_check_equal $res A-2.0_1
res=$(xbps-query -C empty.conf -r root -p pkgver B)
atf_check_equal $res B-2.0_1
}
# 3rd case:
# - A is updated and contains a soname bump
# - A revdeps are broken and there are broken updates in transaction
# - ENOEXEC expected (unresolved shlibs)
atf_test_case shlib_bump_incomplete_revdep_in_trans
shlib_bump_incomplete_revdep_in_trans_head() {
atf_set "descr" "Tests for pkg updates: update pkg with soname bump, updated revdep in trans with unresolved shlibs"
}
shlib_bump_incomplete_revdep_in_trans_body() {
mkdir -p repo pkg_A pkg_B
cd repo
xbps-create -A noarch -n A-1.0_1 -s "A pkg" --shlib-provides "libfoo.so.1" ../pkg_A
atf_check_equal $? 0
xbps-create -A noarch -n B-1.0_1 -s "B pkg" --dependencies "A>=1.0" --shlib-requires "libfoo.so.1" ../pkg_B
atf_check_equal $? 0
xbps-rindex -a *.xbps
atf_check_equal $? 0
cd ..
xbps-install -C empty.conf -r root --repository=$PWD/repo -yvd B
atf_check_equal $? 0
cd repo
xbps-create -A noarch -n A-2.0_1 -s "A pkg" --shlib-provides "libfoo.so.2" ../pkg_A
atf_check_equal $? 0
xbps-create -A noarch -n B-1.1_1 -s "B pkg" --dependencies "A>=0" --shlib-requires "libfoo.so.1" ../pkg_B
atf_check_equal $? 0
xbps-rindex -a *.xbps
atf_check_equal $? 0
cd ..
xbps-install -C empty.conf -r root --repository=$PWD/repo -yuvd
atf_check_equal $? 8
}
atf_init_test_cases() {
atf_add_test_case shlib_bump
atf_add_test_case shlib_bump_incomplete_revdep_in_trans
atf_add_test_case shlib_bump_revdep_in_trans
}