Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions lib/package_fulldeptree.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,33 @@ addDepn(struct item *item, struct item *xitem)
xitem->dbase = depn;
}

static void
add_deps_recursive(struct item *item, bool first)
{
struct depn *dep;
xbps_string_t str;

if (xbps_match_string_in_array(result, item->pkgver))
return;

for (dep = item->dbase; dep; dep = dep->dnext)
add_deps_recursive(dep->item, false);

if (first)
return;

str = xbps_string_create_cstring(item->pkgver);
assert(str);
xbps_array_add_first(result, str);
xbps_object_release(str);
}

/*
* Recursively calculate all dependencies.
*/
static struct item *
ordered_depends(struct xbps_handle *xhp, xbps_dictionary_t pkgd, bool rpool)
ordered_depends(struct xbps_handle *xhp, xbps_dictionary_t pkgd, bool rpool,
size_t depth)
{
xbps_array_t rdeps, provides;
xbps_string_t str;
Expand All @@ -134,6 +156,12 @@ ordered_depends(struct xbps_handle *xhp, xbps_dictionary_t pkgd, bool rpool)

pkgn = xbps_pkg_name(pkgver);
assert(pkgn);
item = lookupItem(pkgn);
if (item) {
add_deps_recursive(item, depth == 0);
return item;
}

item = addItem(rdeps, pkgn);
item->pkgver = pkgver;
assert(item);
Expand Down Expand Up @@ -173,9 +201,11 @@ ordered_depends(struct xbps_handle *xhp, xbps_dictionary_t pkgd, bool rpool)
continue;
}
xitem = lookupItem(curdepname);
if (xitem == NULL)
xitem = ordered_depends(xhp, curpkgd, rpool);

if (xitem) {
add_deps_recursive(xitem, false);
continue;
}
xitem = ordered_depends(xhp, curpkgd, rpool, depth+1);
if (xitem == NULL) {
/* package depends on missing dependencies */
xbps_dbg_printf(xhp, "%s: missing dependency '%s'\n", pkgver, curdep);
Expand All @@ -187,7 +217,7 @@ ordered_depends(struct xbps_handle *xhp, xbps_dictionary_t pkgd, bool rpool)
free(curdepname);
}
/* all deps were processed, add item to head */
if (!xbps_match_string_in_array(result, item->pkgver)) {
if (depth > 0 && !xbps_match_string_in_array(result, item->pkgver)) {
str = xbps_string_create_cstring(item->pkgver);
assert(str);
xbps_array_add_first(result, str);
Expand All @@ -213,7 +243,7 @@ xbps_get_pkg_fulldeptree(struct xbps_handle *xhp, const char *pkg, bool rpool)
((pkgd = xbps_pkgdb_get_virtualpkg(xhp, pkg)) == NULL))
return NULL;
}
if (ordered_depends(xhp, pkgd, rpool) == NULL)
if (ordered_depends(xhp, pkgd, rpool, 0) == NULL)
return NULL;

return result;
Expand Down
2 changes: 1 addition & 1 deletion lib/package_orphans.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
*/

xbps_array_t
xbps_find_pkg_orphans(struct xbps_handle *xhp, xbps_array_t orphans_user UNUSED)
xbps_find_pkg_orphans(struct xbps_handle *xhp, xbps_array_t orphans_user)
{
xbps_array_t rdeps, reqby, array = NULL;
xbps_dictionary_t pkgd, deppkgd;
Expand Down
1 change: 1 addition & 0 deletions tests/xbps/libxbps/find_pkg_orphans/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ static const char expected_output[] =
"xbps-triggers-1.0_1\n";

static const char expected_output_all[] =
"orphan2-0_1\n"
"unexistent-pkg-0_1\n"
"orphan1-0_1\n"
"orphan0-0_1\n";
Expand Down
17 changes: 17 additions & 0 deletions tests/xbps/libxbps/find_pkg_orphans/pkgdb-0.38.plist
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,23 @@
<true/>
<key>pkgver</key>
<string>orphan1-0_1</string>
<key>run_depends</key>
<array>
<string>orphan0&gt;=0_1</string>
</array>
<key>state</key>
<string>installed</string>
</dict>
<key>orphan2</key>
<dict>
<key>automatic-install</key>
<true/>
<key>pkgver</key>
<string>orphan2-0_1</string>
<key>run_depends</key>
<array>
<string>orphan0&gt;=0_1</string>
</array>
<key>state</key>
<string>installed</string>
</dict>
Expand Down
4 changes: 2 additions & 2 deletions tests/xbps/libxbps/shell/incorrect_deps_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ incorrect_dep_dups_body() {

out=$(xbps-query -C empty.conf -r root --fulldeptree -x B)
set -- $out
atf_check_equal $# 2
atf_check_equal "$1 $2" "B-1.0_1 A-1.0_1"
atf_check_equal $# 1
atf_check_equal "$1" "A-1.0_1"
}

atf_test_case missing_deps
Expand Down