diff options
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; +} + /*}}}*/ |
