diff options
author | David Kalnischkies <david@kalnischkies.de> | 2021-09-04 14:13:07 +0200 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2021-09-04 15:35:15 +0200 |
commit | 902d114fce257fc1d51c510ac02de42b8ff1ec0e (patch) | |
tree | a475c66c9f070452b2878a149a0ff1b877e77208 | |
parent | d3e8f980b36e2dd0e4643b0731c870639395de27 (diff) |
Refactor architecture handling in EDSP/EIPP code
This just moves code around without actually changing anything.
Gbp-Dch: Ignore
-rw-r--r-- | apt-pkg/edsp.cc | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/apt-pkg/edsp.cc b/apt-pkg/edsp.cc index 7e3993be4..5bf23044b 100644 --- a/apt-pkg/edsp.cc +++ b/apt-pkg/edsp.cc @@ -8,6 +8,7 @@ #include <config.h> #include <apt-pkg/algorithms.h> +#include <apt-pkg/aptconfiguration.h> #include <apt-pkg/cacheset.h> #include <apt-pkg/depcache.h> #include <apt-pkg/edsp.h> @@ -205,6 +206,20 @@ static bool WriteScenarioLimitedDependency(FileFd &output, return WriteOkay(Okay, output, "\n"); } /*}}}*/ +static bool checkKnownArchitecture(std::string const &arch) /*{{{*/ +{ + return APT::Configuration::checkArchitecture(arch); +} + /*}}}*/ +static bool WriteGenericRequestHeaders(FileFd &output, APT::StringView const head)/*{{{*/ +{ + bool Okay = WriteOkay(output, head, "Architecture: ", _config->Find("APT::Architecture"), "\n", + "Architectures:"); + for (auto const &a : APT::Configuration::getArchitectures()) + WriteOkay(Okay, output, " ", a); + return WriteOkay(Okay, output, "\n"); +} + /*}}}*/ static bool SkipUnavailableVersions(pkgDepCache &Cache, pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const &Ver)/*{{{*/ { /* versions which aren't current and aren't available in @@ -266,11 +281,9 @@ bool EDSP::WriteScenario(pkgDepCache &Cache, FileFd &output, OpProgress *Progres Progress->SubProgress(Cache.Head().VersionCount, _("Send scenario to solver")); decltype(Cache.Head().VersionCount) p = 0; bool Okay = output.Failed() == false; - std::vector<std::string> archs = APT::Configuration::getArchitectures(); for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false && likely(Okay); ++Pkg) { - std::string const arch = Pkg.Arch(); - if (Pkg->CurrentVer == 0 && std::find(archs.begin(), archs.end(), arch) == archs.end()) + if (Pkg->CurrentVer == 0 && not checkKnownArchitecture(Pkg.Arch())) continue; for (pkgCache::VerIterator Ver = Pkg.VersionList(); Ver.end() == false && likely(Okay); ++Ver, ++p) { @@ -341,15 +354,8 @@ bool EDSP::WriteRequest(pkgDepCache &Cache, FileFd &output, continue; req->append(" ").append(Pkg.FullName()); } - bool Okay = WriteOkay(output, "Request: EDSP 0.5\n"); - - std::vector<string> archs = APT::Configuration::getArchitectures(); - WriteOkay(Okay, output, "Architecture: ", _config->Find("APT::Architecture").c_str(), "\n", - "Architectures:"); - for (std::vector<string>::const_iterator a = archs.begin(); a != archs.end(); ++a) - WriteOkay(Okay, output, " ", *a); - WriteOkay(Okay, output, "\n"); + bool Okay = WriteGenericRequestHeaders(output, "Request: EDSP 0.5\n"); if (del.empty() == false) WriteOkay(Okay, output, "Remove:", del, "\n"); if (inst.empty() == false) @@ -863,15 +869,8 @@ bool EIPP::WriteRequest(pkgDepCache &Cache, FileFd &output, /*{{{*/ continue; req->append(" ").append(Pkg.FullName()); } - bool Okay = WriteOkay(output, "Request: EIPP 0.1\n"); - - std::vector<string> archs = APT::Configuration::getArchitectures(); - WriteOkay(Okay, output, "Architecture: ", _config->Find("APT::Architecture").c_str(), "\n", - "Architectures:"); - for (std::vector<string>::const_iterator a = archs.begin(); a != archs.end(); ++a) - WriteOkay(Okay, output, " ", *a); - WriteOkay(Okay, output, "\n"); + bool Okay = WriteGenericRequestHeaders(output, "Request: EIPP 0.1\n"); if (del.empty() == false) WriteOkay(Okay, output, "Remove:", del, "\n"); if (inst.empty() == false) @@ -934,7 +933,6 @@ bool EIPP::WriteScenario(pkgDepCache &Cache, FileFd &output, OpProgress * const Progress->SubProgress(Cache.Head().PackageCount, _("Send scenario to planner")); decltype(Cache.Head().PackageCount) p = 0; bool Okay = output.Failed() == false; - std::vector<std::string> archs = APT::Configuration::getArchitectures(); std::vector<bool> pkgset(Cache.Head().PackageCount, false); auto const MarkVersion = [&](pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const &Ver) { pkgset[Pkg->ID] = true; |