From a9a889c54d13a9cd330f5faf2691fbc70cee04e1 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sat, 15 Jun 2019 17:53:02 +0200 Subject: [PATCH] fulldeptree: return a proper error if deps can't be resolved. xbps_get_pkg_fulldeptree() now returns NULL and sets errno to ENODEV when there are missing dependencies, rather than assert()ing. Added another test case to check returned error codes. Signed-off-by: Juan RP --- bin/xbps-dgraph/main.c | 9 ++++- bin/xbps-query/show-deps.c | 15 ++++---- lib/package_fulldeptree.c | 10 ++++-- lib/package_orphans.c | 5 ++- .../xbps/libxbps/shell/incorrect_deps_test.sh | 34 +++++++++++++++++++ 5 files changed, 61 insertions(+), 12 deletions(-) diff --git a/bin/xbps-dgraph/main.c b/bin/xbps-dgraph/main.c index 3075d9ea..26e7ae9c 100644 --- a/bin/xbps-dgraph/main.c +++ b/bin/xbps-dgraph/main.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2010-2015 Juan Romero Pardines. + * Copyright (c) 2010-2019 Juan Romero Pardines. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -470,6 +470,13 @@ create_dot_graph(struct xbps_handle *xhp, } else { rdeps = xbps_pkgdb_get_pkg_fulldeptree(xhp, pkgver); } + if (rdeps == NULL) { + if (errno == ENODEV) + die("package depends on missing dependencies\n"); + else + die("package dependencies couldn't be resolved (error %d)\n", errno); + } + process_fulldeptree(xhp, f, plistd, rdeps, repomode); } else { /* diff --git a/bin/xbps-query/show-deps.c b/bin/xbps-query/show-deps.c index c453644f..258beadb 100644 --- a/bin/xbps-query/show-deps.c +++ b/bin/xbps-query/show-deps.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009-2015 Juan Romero Pardines. + * Copyright (c) 2009-2019 Juan Romero Pardines. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -38,7 +38,6 @@ show_pkg_deps(struct xbps_handle *xhp, const char *pkgname, bool repomode, bool { xbps_array_t rdeps; xbps_dictionary_t pkgd; - unsigned int cnt; if (repomode) { if (((pkgd = xbps_rpool_get_pkg(xhp, pkgname)) == NULL) && @@ -46,20 +45,20 @@ show_pkg_deps(struct xbps_handle *xhp, const char *pkgname, bool repomode, bool return errno; } else { if ((pkgd = xbps_pkgdb_get_pkg(xhp, pkgname)) == NULL) - return ENOENT; + return errno; } if (full) { if (repomode) rdeps = xbps_rpool_get_pkg_fulldeptree(xhp, pkgname); else rdeps = xbps_pkgdb_get_pkg_fulldeptree(xhp, pkgname); + + if (rdeps == NULL) + return errno; } else { rdeps = xbps_dictionary_get(pkgd, "run_depends"); } - if ((cnt = xbps_array_count(rdeps)) == 0) - return ENOENT; - - for (unsigned int i = 0; i < cnt; i++) { + for (unsigned int i = 0; i < xbps_array_count(rdeps); i++) { const char *pkgdep; xbps_array_get_cstring_nocopy(rdeps, i, &pkgdep); printf("%s\n", pkgdep); @@ -79,7 +78,7 @@ show_pkg_revdeps(struct xbps_handle *xhp, const char *pkg, bool repomode) revdeps = xbps_pkgdb_get_pkg_revdeps(xhp, pkg); if (revdeps == NULL) - return ENOENT; + return errno; for (unsigned int i = 0; i < xbps_array_count(revdeps); i++) { xbps_array_get_cstring_nocopy(revdeps, i, &pkgdep); diff --git a/lib/package_fulldeptree.c b/lib/package_fulldeptree.c index 30a6bd04..71f17663 100644 --- a/lib/package_fulldeptree.c +++ b/lib/package_fulldeptree.c @@ -156,7 +156,12 @@ ordered_depends(struct xbps_handle *xhp, xbps_dictionary_t pkgd, bool rpool) if (curpkgd == NULL) continue; } - assert(curpkgd); + if (curpkgd == NULL) { + /* package depends on missing dependencies */ + xbps_dbg_printf(xhp, "%s: missing dependency '%s'\n", pkgver, curdep); + errno = ENODEV; + return NULL; + } if ((curdepname = xbps_pkgpattern_name(curdep)) == NULL) curdepname = xbps_pkg_name(curdep); @@ -212,7 +217,8 @@ xbps_get_pkg_fulldeptree(struct xbps_handle *xhp, const char *pkg, bool rpool) ((pkgd = xbps_pkgdb_get_virtualpkg(xhp, pkg)) == NULL)) return NULL; } - (void)ordered_depends(xhp, pkgd, rpool); + if (ordered_depends(xhp, pkgd, rpool) == NULL) + return NULL; return result; } diff --git a/lib/package_orphans.c b/lib/package_orphans.c index b908c049..36d5570b 100644 --- a/lib/package_orphans.c +++ b/lib/package_orphans.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009-2015 Juan Romero Pardines. + * Copyright (c) 2009-2019 Juan Romero Pardines. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -121,6 +121,9 @@ add_orphans: pkgd = xbps_array_get(array, i); xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &curpkgver); rdeps = xbps_pkgdb_get_pkg_fulldeptree(xhp, curpkgver); + if (rdeps == NULL) + return NULL; + for (unsigned int x = 0; x < xbps_array_count(rdeps); x++) { cnt = 0; xbps_array_get_cstring_nocopy(rdeps, x, &deppkgver); diff --git a/tests/xbps/libxbps/shell/incorrect_deps_test.sh b/tests/xbps/libxbps/shell/incorrect_deps_test.sh index 27c6448d..e2643d94 100644 --- a/tests/xbps/libxbps/shell/incorrect_deps_test.sh +++ b/tests/xbps/libxbps/shell/incorrect_deps_test.sh @@ -97,9 +97,43 @@ incorrect_dep_dups_body() { atf_check_equal "$1 $2" "B-1.0_1 A-1.0_1" } +atf_test_case missing_deps + +missing_deps_head() { + atf_set "descr" "Test for package deps: pkg depends on a missing dependency in fulldeptree" +} + +missing_deps_body() { + mkdir some_repo + mkdir -p pkg_A/usr/bin pkg_B/usr/bin + cd some_repo + xbps-create -A noarch -n A-1.0_1 -s "A pkg" ../pkg_A + atf_check_equal $? 0 + xbps-create -A noarch -n B-1.0_1 -s "B pkg" --dependencies "A>=0 C>=0" ../pkg_B + atf_check_equal $? 0 + + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + cd .. + + # reverse deps + xbps-query -C empty.conf -r root --repository=some_repo -dX B + atf_check_equal $? 2 # ENOENT + + # fulldeptree repo + xbps-query -C empty.conf --repository=some_repo -r root --fulldeptree -dx B + atf_check_equal $? 19 # ENODEV + + # fulldeptree pkgdb + xbps-query -C empty.conf -r root --fulldeptree -x C + atf_check_equal $? 2 # ENOENT + +} + atf_init_test_cases() { atf_add_test_case incorrect_dep atf_add_test_case incorrect_dep_vpkg atf_add_test_case incorrect_dep_issue45 atf_add_test_case incorrect_dep_dups + atf_add_test_case missing_deps }