summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2024-05-19 17:42:34 +0200
committerJulian Andres Klode <julian.klode@canonical.com>2024-05-24 17:01:55 +0200
commitacb77872861834d3c5b98ca2e81e0336a388e9f0 (patch)
treef276d3082cfc2d3ded7bf6dc556113b733437154
parentb5997949909ee9d5e9981c8311aea97c7b2620fd (diff)
solver3: Try candidate before installed version on upgrade
This fixes --no-strict-pinning attempting to upgrade all the versions on the system. Adjust the upgrade test case accordingly: 1) no-strict-pinning pulls in systemd despite it being pinned down due to a dependenc (this was true before this fix) 2) no-strict-pinning does not pull in the upgrade-simple because nothing depends on it (this is what the test fixes)
-rw-r--r--apt-pkg/solver3.cc11
-rwxr-xr-xtest/integration/test-apt-get-upgrade51
2 files changed, 60 insertions, 2 deletions
diff --git a/apt-pkg/solver3.cc b/apt-pkg/solver3.cc
index ab66c9501..58fb07c01 100644
--- a/apt-pkg/solver3.cc
+++ b/apt-pkg/solver3.cc
@@ -46,8 +46,15 @@ struct CompareProviders3 /*{{{*/
{
if (AV == BV)
return false;
- if (not upgrade && A->CurrentVer != 0 && A.CurrentVer() == AV)
- return true;
+ // The current version should win, unless we are upgrading and the other is the
+ // candidate.
+ // If AV is the current version, AV only wins on upgrades if BV is not the candidate.
+ if (A.CurrentVer() == AV)
+ return upgrade ? Policy.GetCandidateVer(A) != BV : true;
+ // If BV is the current version, AV only wins on upgrades if it is the candidate.
+ if (A.CurrentVer() == BV)
+ return upgrade ? Policy.GetCandidateVer(A) == AV : false;
+ // If neither are the current version, order them by priority.
if (Policy.GetPriority(AV) < Policy.GetPriority(BV))
return false;
diff --git a/test/integration/test-apt-get-upgrade b/test/integration/test-apt-get-upgrade
index 9fb2b41d1..c9e56d97d 100755
--- a/test/integration/test-apt-get-upgrade
+++ b/test/integration/test-apt-get-upgrade
@@ -167,3 +167,54 @@ Conf upgrade-with-conflict (2.0 unstable [all])
Conf new-dep (1.0 stable [all])
Conf upgrade-simple (2.0 unstable [all])
Conf upgrade-with-new-dep (2.0 unstable [all])' aptget -s dist-upgrade
+
+# --no-strict-pinning pulls in systemd due to the dependency
+testsuccessequal 'Reading package lists...
+Building dependency tree...
+Calculating upgrade...
+The following packages will be REMOVED:
+ conflicting-dep
+The following NEW packages will be installed:
+ new-dep systemd
+The following packages will be upgraded:
+ init upgrade-simple upgrade-with-conflict upgrade-with-new-dep
+4 upgraded, 2 newly installed, 1 to remove and 0 not upgraded.
+Remv conflicting-dep [1.0]
+Inst systemd (2 unstable [all])
+Conf systemd (2 unstable [all])
+Inst init [1] (2 unstable [all])
+Inst upgrade-with-conflict [1.0] (2.0 unstable [all])
+Inst new-dep (1.0 stable [all])
+Inst upgrade-simple [1.0] (2.0 unstable [all])
+Inst upgrade-with-new-dep [1.0] (2.0 unstable [all])
+Conf init (2 unstable [all])
+Conf upgrade-with-conflict (2.0 unstable [all])
+Conf new-dep (1.0 stable [all])
+Conf upgrade-simple (2.0 unstable [all])
+Conf upgrade-with-new-dep (2.0 unstable [all])' aptget -s dist-upgrade --no-strict-pinning --solver 3.0
+
+# --no-strict-pinning does not cause a package to be upgraded on its own, though.
+echo 'Package: upgrade-simple
+Pin: release unstable
+Pin-Priority: -1' > rootdir/etc/apt/preferences.d/no-strict-pinning.pref
+testsuccessequal 'Reading package lists...
+Building dependency tree...
+Calculating upgrade...
+The following packages will be REMOVED:
+ conflicting-dep
+The following NEW packages will be installed:
+ new-dep systemd
+The following packages will be upgraded:
+ init upgrade-with-conflict upgrade-with-new-dep
+3 upgraded, 2 newly installed, 1 to remove and 0 not upgraded.
+Remv conflicting-dep [1.0]
+Inst systemd (2 unstable [all])
+Conf systemd (2 unstable [all])
+Inst init [1] (2 unstable [all])
+Inst upgrade-with-conflict [1.0] (2.0 unstable [all])
+Inst new-dep (1.0 stable [all])
+Inst upgrade-with-new-dep [1.0] (2.0 unstable [all])
+Conf init (2 unstable [all])
+Conf upgrade-with-conflict (2.0 unstable [all])
+Conf new-dep (1.0 stable [all])
+Conf upgrade-with-new-dep (2.0 unstable [all])' aptget -s dist-upgrade --no-strict-pinning --solver 3.0