From 067c17312418937b6fc81cbba78349ce2566f942 Mon Sep 17 00:00:00 2001 From: Timo Teräs Date: Sun, 25 Dec 2022 14:57:47 +0200 Subject: solver: prioritize user specified action on mentioned packages Force preference on the user specified action on commandline. This allows upgrading packages which would otherwise be kept back due to partial update preferring to keep top level dependency on the installed version. fixes #7531 --- src/apk_database.h | 1 + src/solver.c | 4 ++++ test/basic17.installed | 13 +++++++++++++ test/basic17.repo | 26 ++++++++++++++++++++++++++ test/basic17.test | 9 +++++++++ test/basic18.test | 9 +++++++++ 6 files changed, 62 insertions(+) create mode 100644 test/basic17.installed create mode 100644 test/basic17.repo create mode 100644 test/basic17.test create mode 100644 test/basic18.test diff --git a/src/apk_database.h b/src/apk_database.h index 917ee35..1947df0 100644 --- a/src/apk_database.h +++ b/src/apk_database.h @@ -101,6 +101,7 @@ struct apk_name { unsigned is_dependency : 1; unsigned auto_select_virtual: 1; unsigned priority : 2; + unsigned solver_flags_set : 1; unsigned int foreach_genid; union { struct apk_solver_name_state ss; diff --git a/src/solver.c b/src/solver.c index 2548de7..8021df2 100644 --- a/src/solver.c +++ b/src/solver.c @@ -51,6 +51,7 @@ void apk_solver_set_name_flags(struct apk_name *name, { struct apk_provider *p; + name->solver_flags_set = 1; foreach_array_item(p, name->providers) { struct apk_package *pkg = p->pkg; dbg_printf("marking '" PKG_VER_FMT "' = 0x%04x / 0x%04x\n", @@ -1030,6 +1031,9 @@ static int compare_name_dequeue(const struct apk_name *a, const struct apk_name { int r; + r = !!(a->solver_flags_set) - !!(b->solver_flags_set); + if (r) return -r; + r = (int)a->priority - (int)b->priority; if (r) return r; diff --git a/test/basic17.installed b/test/basic17.installed new file mode 100644 index 0000000..ce66f47 --- /dev/null +++ b/test/basic17.installed @@ -0,0 +1,13 @@ +C:Q1EyN5AdpAOBJWKMR89pp/C66o+OE= +P:a +V:1 +S:1 +I:1 +D:b=1 + +C:Q1C4uoV7SdMdDhYg4OCVmI71D8HIA= +P:b +V:1 +S:1 +I:1 + diff --git a/test/basic17.repo b/test/basic17.repo new file mode 100644 index 0000000..cac8d9e --- /dev/null +++ b/test/basic17.repo @@ -0,0 +1,26 @@ +C:Q1EyN5AdpAOBJWKMR89pp/C66o+OE= +P:a +V:1 +S:1 +I:1 +D:b=1 + +C:Q1eVpkasfqZAukAXFYbgwt4xAMZWU= +P:a +V:2 +S:1 +I:1 +D:b=2 + +C:Q1C4uoV7SdMdDhYg4OCVmI71D8HIA= +P:b +V:1 +S:1 +I:1 + +C:Q1hdUpqRv5mYgJEqW52UmVsvmyysE= +P:b +V:2 +S:1 +I:1 + diff --git a/test/basic17.test b/test/basic17.test new file mode 100644 index 0000000..3d0b7fc --- /dev/null +++ b/test/basic17.test @@ -0,0 +1,9 @@ +@ARGS +--test-repo basic17.repo +--test-instdb basic17.installed +--test-world b +add --upgrade a +@EXPECT +(1/2) Upgrading b (1 -> 2) +(2/2) Upgrading a (1 -> 2) +OK: 0 MiB in 2 packages diff --git a/test/basic18.test b/test/basic18.test new file mode 100644 index 0000000..ff8d6b8 --- /dev/null +++ b/test/basic18.test @@ -0,0 +1,9 @@ +@ARGS +--test-repo basic17.repo +--test-instdb basic17.installed +--test-world a +add --latest b +@EXPECT +(1/2) Upgrading b (1 -> 2) +(2/2) Upgrading a (1 -> 2) +OK: 0 MiB in 2 packages -- cgit v1.2.3-70-g09d2