summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2022-06-28 14:53:14 +0200
committerJulian Andres Klode <julian.klode@canonical.com>2022-06-28 14:54:42 +0200
commit20739359fa936c0851a4c0f37667526d98c22761 (patch)
treedab91a932c83d1678a914a5451d01c034f2e3e28 /apt-pkg
parentdb131677bee45c86031d37d7b451e6ece692efb2 (diff)
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
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/policy.cc17
1 files changed, 9 insertions, 8 deletions
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<signed int>::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<signed int>::min();
@@ -348,7 +349,7 @@ APT_PURE signed short pkgPolicy::GetPriority(pkgCache::VerIterator const &Ver, b
priority = std::max<decltype(priority)>(priority, GetPriority(file.File()));
}
- return priority == std::numeric_limits<decltype(priority)>::min() ? 0 : priority;
+ return std::min(priority == std::numeric_limits<decltype(priority)>::min() ? 0 : priority, ceiling);
}
APT_PURE signed short pkgPolicy::GetPriority(pkgCache::PkgFileIterator const &File)
{