diff options
| author | Julian Andres Klode <julian.klode@canonical.com> | 2024-02-12 14:48:48 +0100 |
|---|---|---|
| committer | Julian Andres Klode <julian.klode@canonical.com> | 2024-02-13 14:27:27 +0100 |
| commit | a8352c2859a6f84b36fa5cd0af89231cb656b1ce (patch) | |
| tree | 69ba18aec6b6a49efd85ef746feb752afc90a780 /apt-pkg/depcache.cc | |
| parent | 26e0e9b76fb06afe5250eeb8e5b3d069d4793432 (diff) | |
Add public phased update API
This moves the functions of the PhasedUpgrader class into
various other classes so they can be publicly exposed.
This introduces three new functions:
pkgDepCache::PhasingApplied() tells you whether phasing should
be applied to the package.
pkgProblemResolver::KeepPhasedUpdates() keeps back updates that
have phasing applied.
pkgCache::VerIterator::IsSecurityUpdate() determines whether this
version contains security fixes.
Diffstat (limited to 'apt-pkg/depcache.cc')
| -rw-r--r-- | apt-pkg/depcache.cc | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index 322bf1bbe..c965781a4 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -30,11 +30,12 @@ #include <algorithm> #include <iostream> -#include <memory> -#include <sstream> #include <iterator> #include <list> +#include <memory> +#include <random> #include <set> +#include <sstream> #include <string> #include <unordered_map> #include <utility> @@ -141,6 +142,7 @@ struct pkgDepCache::Private { std::unique_ptr<InRootSetFunc> inRootSetFunc; std::unique_ptr<APT::CacheFilter::Matcher> IsAVersionedKernelPackage, IsProtectedKernelPackage; + std::string machineID; }; pkgDepCache::pkgDepCache(pkgCache *const pCache, Policy *const Plcy) : group_level(0), Cache(pCache), PkgState(0), DepState(0), iUsrSize(0), iDownloadSize(0), iInstCount(0), iDelCount(0), iKeepCount(0), @@ -148,6 +150,7 @@ pkgDepCache::pkgDepCache(pkgCache *const pCache, Policy *const Plcy) : group_lev { DebugMarker = _config->FindB("Debug::pkgDepCache::Marker", false); DebugAutoInstall = _config->FindB("Debug::pkgDepCache::AutoInstall", false); + d->machineID = APT::Configuration::getMachineID(); delLocalPolicy = 0; LocalPolicy = Plcy; if (LocalPolicy == 0) @@ -2562,3 +2565,51 @@ bool pkgDepCache::MarkAndSweep() return false; } /*}}}*/ + +// DepCache::PhasingApplied /*{{{*/ +// Check if this version is a phased update that should be ignored, not considering whether +// it is a security update. +static bool IsIgnoredPhasedUpdate(std::string machineID, pkgCache::VerIterator const &Ver) +{ + if (_config->FindB("APT::Get::Phase-Policy", false)) + return false; + + // The order and fallbacks for the always/never checks come from update-manager and exist + // to preserve compatibility. + if (_config->FindB("APT::Get::Always-Include-Phased-Updates", + _config->FindB("Update-Manager::Always-Include-Phased-Updates", false))) + return false; + + if (_config->FindB("APT::Get::Never-Include-Phased-Updates", + _config->FindB("Update-Manager::Never-Include-Phased-Updates", false))) + return true; + + if (machineID.empty() // no machine-id + || getenv("SOURCE_DATE_EPOCH") != nullptr // reproducible build - always include + || APT::Configuration::isChroot()) + return false; + + std::string seedStr = std::string(Ver.SourcePkgName()) + "-" + Ver.SourceVerStr() + "-" + machineID; + std::seed_seq seed(seedStr.begin(), seedStr.end()); + std::minstd_rand rand(seed); + std::uniform_int_distribution<unsigned int> dist(0, 100); + + return dist(rand) > Ver.PhasedUpdatePercentage(); +} + +bool pkgDepCache::PhasingApplied(pkgCache::PkgIterator Pkg) const +{ + if (Pkg->CurrentVer == 0) + return false; + if ((*this)[Pkg].CandidateVer == 0) + return false; + if ((*this)[Pkg].CandidateVerIter(*Cache).PhasedUpdatePercentage() == 100) + return false; + if ((*this)[Pkg].CandidateVerIter(*Cache).IsSecurityUpdate()) + return false; + if (!IsIgnoredPhasedUpdate(d->machineID, (*this)[Pkg].CandidateVerIter(*Cache))) + return false; + + return true; +} + /*}}}*/ |
