From 20739359fa936c0851a4c0f37667526d98c22761 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 28 Jun 2022 14:53:14 +0200 Subject: policy: Do not override negative pins with 1 due to phasing If a package is already pinned to a negative value, we should not override this with a positive 1. This causes packages to be installable that were pinned to -1, which is not intended. For this, implement phasing as a ceiling of 1 for the pin instead of a fixed 1 value. An alternative would have been to fix it to NEVER_PIN, but that would mean entirely NEW packages would not be installable while phasing which is not the intention either. LP: #1978125 --- apt-pkg/policy.cc | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/policy.cc b/apt-pkg/policy.cc index fcb7299f4..5fcc11b66 100644 --- a/apt-pkg/policy.cc +++ b/apt-pkg/policy.cc @@ -288,6 +288,9 @@ void pkgPolicy::CreatePin(pkgVersionMatch::MatchType Type,string Name, // Returns true if this update is excluded by phasing. static inline bool ExcludePhased(std::string machineID, pkgCache::VerIterator const &Ver) { + if (Ver.PhasedUpdatePercentage() == 100) + return false; + // FIXME: We have migrated to a legacy implementation until LP: #1929082 is fixed if (not _config->FindB("APT::Get::Phase-Policy", false)) return false; @@ -316,11 +319,9 @@ static inline bool ExcludePhased(std::string machineID, pkgCache::VerIterator co } APT_PURE signed short pkgPolicy::GetPriority(pkgCache::VerIterator const &Ver, bool ConsiderFiles) { - if (Ver.PhasedUpdatePercentage() != 100) - { - if (ExcludePhased(d->machineID, Ver)) - return 1; - } + auto ceiling = std::numeric_limits::max(); + if (ExcludePhased(d->machineID, Ver)) + ceiling = 1; if (VerPins[Ver->ID].Type != pkgVersionMatch::None) { // If all sources are never pins, the never pin wins. @@ -328,10 +329,10 @@ APT_PURE signed short pkgPolicy::GetPriority(pkgCache::VerIterator const &Ver, b return NEVER_PIN; for (pkgCache::VerFileIterator file = Ver.FileList(); file.end() == false; file++) if (GetPriority(file.File()) != NEVER_PIN) - return VerPins[Ver->ID].Priority; + return std::min((int)VerPins[Ver->ID].Priority, ceiling); } if (!ConsiderFiles) - return 0; + return std::min(0, ceiling); // priorities are short ints, but we want to pick a value outside the valid range here auto priority = std::numeric_limits::min(); @@ -348,7 +349,7 @@ APT_PURE signed short pkgPolicy::GetPriority(pkgCache::VerIterator const &Ver, b priority = std::max(priority, GetPriority(file.File())); } - return priority == std::numeric_limits::min() ? 0 : priority; + return std::min(priority == std::numeric_limits::min() ? 0 : priority, ceiling); } APT_PURE signed short pkgPolicy::GetPriority(pkgCache::PkgFileIterator const &File) { -- cgit v1.2.3-70-g09d2