Skip to content

Commit e02fc4c

Browse files
committed
lib: allow installin/updating indirect cylic deps
1 parent 630b413 commit e02fc4c

2 files changed

Lines changed: 48 additions & 20 deletions

File tree

lib/transaction_pkg_deps.c

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ add_missing_reqdep(struct xbps_handle *xhp, const char *reqpkg)
111111
static int
112112
repo_deps(struct xbps_handle *xhp,
113113
xbps_array_t pkgs, /* array of pkgs */
114+
xbps_array_t queued, /* queued packages */
114115
xbps_dictionary_t pkg_repod, /* pkg repo dictionary */
115116
unsigned short *depth) /* max recursion depth */
116117
{
@@ -182,8 +183,19 @@ repo_deps(struct xbps_handle *xhp,
182183
continue;
183184
}
184185
/*
185-
* Pass 2: check if required dependency has been already
186-
* added in the transaction dictionary.
186+
* Pass 2: check if required dependency is currently queued or
187+
* has been already added in the transaction dictionary.
188+
*/
189+
if ((curpkgd = xbps_find_pkg_in_array(queued, reqpkg, 0)) ||
190+
(curpkgd = xbps_find_virtualpkg_in_array(xhp, queued, reqpkg, 0))) {
191+
xbps_trans_type_t ttype_q = xbps_transaction_pkg_type(curpkgd);
192+
xbps_dictionary_get_cstring_nocopy(curpkgd, "pkgver", &pkgver_q);
193+
xbps_dbg_printf_append(" (%s queued %d)\n", pkgver_q, ttype_q);
194+
continue;
195+
}
196+
/*
197+
* Pass 3: check if required dependency has been already added
198+
* in the transaction dictionary.
187199
*/
188200
if ((curpkgd = xbps_find_pkg_in_array(pkgs, reqpkg, 0)) ||
189201
(curpkgd = xbps_find_virtualpkg_in_array(xhp, pkgs, reqpkg, 0))) {
@@ -195,7 +207,7 @@ repo_deps(struct xbps_handle *xhp,
195207
}
196208
}
197209
/*
198-
* Pass 3: check if required dependency is already installed
210+
* Pass 4: check if required dependency is already installed
199211
* and its version is fully matched.
200212
*/
201213
if ((curpkgd = xbps_pkgdb_get_pkg(xhp, pkgname)) == NULL) {
@@ -341,7 +353,7 @@ repo_deps(struct xbps_handle *xhp,
341353
continue;
342354
}
343355
/*
344-
* Pass 4: find required dependency in repository pool.
356+
* Pass 5: find required dependency in repository pool.
345357
* If dependency does not match add pkg into the missing
346358
* deps array and pass to next one.
347359
*/
@@ -431,6 +443,10 @@ repo_deps(struct xbps_handle *xhp,
431443
if (error)
432444
break;
433445
}
446+
447+
if (!xbps_array_add(queued, repopkgd))
448+
return -xbps_error_oom();
449+
434450
pkg_rdeps = xbps_dictionary_get(repopkgd, "run_depends");
435451
if (xbps_array_count(pkg_rdeps)) {
436452
/*
@@ -444,7 +460,7 @@ repo_deps(struct xbps_handle *xhp,
444460
xbps_dbg_printf_append("%s: finding dependencies:\n", pkgver_q);
445461
}
446462
(*depth)++;
447-
rv = repo_deps(xhp, pkgs, repopkgd, depth);
463+
rv = repo_deps(xhp, pkgs, queued, repopkgd, depth);
448464
if (rv != 0) {
449465
xbps_dbg_printf("Error checking %s for rundeps: %s\n", reqpkg, strerror(rv));
450466
break;
@@ -455,6 +471,9 @@ repo_deps(struct xbps_handle *xhp,
455471
} else if (xbps_dictionary_get(curpkgd, "hold")) {
456472
ttype = XBPS_TRANS_HOLD;
457473
}
474+
475+
xbps_array_remove(queued, xbps_array_count(queued) - 1);
476+
458477
/*
459478
* All deps were processed, store pkg in transaction.
460479
*/
@@ -483,16 +502,27 @@ xbps_transaction_pkg_deps(struct xbps_handle *xhp,
483502
{
484503
const char *pkgver;
485504
unsigned short depth = 0;
505+
xbps_array_t queued;
506+
int rv;
486507

487508
assert(xhp);
488509
assert(pkgs);
489510
assert(pkg_repod);
490511

491-
xbps_dictionary_get_cstring_nocopy(pkg_repod, "pkgver", &pkgver);
512+
queued = xbps_array_create();
513+
if (!queued)
514+
return -xbps_error_oom();
515+
516+
if (!xbps_dictionary_get_cstring_nocopy(pkg_repod, "pkgver", &pkgver))
517+
return EINVAL;
518+
492519
xbps_dbg_printf("Finding required dependencies for '%s':\n", pkgver);
520+
493521
/*
494522
* This will find direct and indirect deps, if any of them is not
495523
* there it will be added into the missing_deps array.
496524
*/
497-
return repo_deps(xhp, pkgs, pkg_repod, &depth);
525+
rv = repo_deps(xhp, pkgs, queued, pkg_repod, &depth);
526+
xbps_object_release(queued);
527+
return rv;
498528
}

tests/xbps/libxbps/shell/cyclic_deps_test.sh

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,20 @@ cyclic_dep_vpkg2_head() {
3636
}
3737

3838
cyclic_dep_vpkg2_body() {
39-
mkdir some_repo
40-
mkdir -p pkg_A/usr/bin pkg_B/usr/bin pkg_C/usr/bin pkg_D/usr/bin
41-
cd some_repo
42-
xbps-create -A noarch -n A-1.0_1 -s "A pkg" --provides "libGL-7.11_1" --dependencies "xserver-abi-video<20" ../pkg_A
43-
atf_check_equal $? 0
44-
xbps-create -A noarch -n B-1.0_1 -s "B pkg" --dependencies "libGL>=7.11" --provides "xserver-abi-video-19_1" ../pkg_B
45-
atf_check_equal $? 0
46-
xbps-create -A noarch -n C-1.0_1 -s "C pkg" --dependencies "libGL>=7.11" ../pkg_C
47-
atf_check_equal $? 0
39+
mkdir -p some_repo pkg_A/usr/bin pkg_B/usr/bin pkg_C/usr/bin pkg_D/usr/bin
4840

49-
xbps-rindex -d -a $PWD/*.xbps
50-
atf_check_equal $? 0
41+
cd some_repo
42+
atf_check -o ignore -- xbps-create -A noarch -n A-1.0_1 -s "A pkg" --provides "libGL-7.11_1" --dependencies "xserver-abi-video<20" ../pkg_A
43+
atf_check -o ignore -- xbps-create -A noarch -n B-1.0_1 -s "B pkg" --dependencies "libGL>=7.11" --provides "xserver-abi-video-19_1" ../pkg_B
44+
atf_check -o ignore -- xbps-create -A noarch -n C-1.0_1 -s "C pkg" --dependencies "libGL>=7.11" ../pkg_C
45+
atf_check -o ignore -e ignore -- xbps-rindex -d -a $PWD/*.xbps
5146
cd ..
5247

53-
xbps-install -r root --repository=$PWD/some_repo -dy C
54-
atf_check_equal $? 40
48+
atf_check \
49+
-o match:"A-1\.0_1 install" \
50+
-o match:"B-1\.0_1 install" \
51+
-o match:"C-1\.0_1 install" \
52+
-- xbps-install -r root --repository=$PWD/some_repo -ny C
5553
}
5654

5755
atf_test_case cyclic_dep_full

0 commit comments

Comments
 (0)