summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2021-09-04 16:10:50 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2021-09-04 16:20:12 +0200
commit70c669e2566d119559d2986635bb6c1d0d368073 (patch)
tree1584687e9bac78ae75bac737acb1b67a83bcdc79 /apt-pkg
parent79a675ddf3320bf640d130e592c86fefd1a460e1 (diff)
Streamline access to barbarian architecture functionality
APT is not the place this information should be stored at, but it is a good place to experiment and see what will be (not) needed in the future for a proper implementation higher up the stack. This is why "BarbarianArchitectures" is chosen instead of a more neutral and/or sensible "VeryForeign" and isn't readily exported in the API to other clients for this PoC as a to be drawn up standard will likely require potentially incompatible changes. Having a then outdated and slightly different implementation block a "good" name would be bad. The functionality itself mostly exists (ignoring bugs) since the introduction of MultiArch as we always had the risk of encountering packages of architectures not known to dpkg (forced onto the system, potentially before MultiArch) we had to deal with somehow and other edge cases. All this commit really does is allowing what could previously only be achieved with editing sources.list and some conf options via a single config option: -o APT::BarbarianArchitectures=foo,bar
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/aptconfiguration.cc22
-rw-r--r--apt-pkg/deb/debmetaindex.cc20
-rw-r--r--apt-pkg/edsp.cc7
3 files changed, 30 insertions, 19 deletions
diff --git a/apt-pkg/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc
index 671c3d553..00a97a0e7 100644
--- a/apt-pkg/aptconfiguration.cc
+++ b/apt-pkg/aptconfiguration.cc
@@ -315,13 +315,11 @@ bool Configuration::checkLanguage(std::string Lang, bool const All) {
/*}}}*/
// getArchitectures - Return Vector of preferred Architectures /*{{{*/
std::vector<std::string> const Configuration::getArchitectures(bool const &Cached) {
- using std::string;
-
- std::vector<string> static archs;
+ std::vector<std::string> static archs;
if (likely(Cached == true) && archs.empty() == false)
return archs;
- string const arch = _config->Find("APT::Architecture");
+ std::string const arch = _config->Find("APT::Architecture");
archs = _config->FindVector("APT::Architectures");
if (archs.empty() == true && _system != nullptr)
@@ -331,15 +329,13 @@ std::vector<std::string> const Configuration::getArchitectures(bool const &Cache
std::find(archs.begin(), archs.end(), arch) == archs.end())
archs.insert(archs.begin(), arch);
- // erase duplicates and empty strings
- for (std::vector<string>::reverse_iterator a = archs.rbegin();
- a != archs.rend(); ++a) {
- if (a->empty() == true || std::find(a + 1, archs.rend(), *a) != archs.rend())
- archs.erase(a.base()-1);
- if (a == archs.rend())
- break;
- }
-
+ // erase duplicates, empty strings and very foreign architectures
+ auto newend = std::remove_if(archs.begin(), archs.end(), [](auto const &a) { return a.empty(); });
+ for (auto a = archs.begin(); a != newend; ++a)
+ newend = std::remove(std::next(a), newend, *a);
+ for (auto const &f : _config->FindVector("APT::BarbarianArchitectures"))
+ newend = std::remove(archs.begin(), newend, f);
+ archs.erase(newend, archs.end());
return archs;
}
/*}}}*/
diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc
index f24a5e79e..d78cea758 100644
--- a/apt-pkg/deb/debmetaindex.cc
+++ b/apt-pkg/deb/debmetaindex.cc
@@ -18,6 +18,7 @@
#include <algorithm>
#include <map>
+#include <optional>
#include <sstream>
#include <string>
#include <utility>
@@ -966,13 +967,13 @@ pkgCache::RlsFileIterator debReleaseIndex::FindInCache(pkgCache &Cache, bool con
class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/
{
- static std::vector<std::string> getDefaultSetOf(std::string const &Name,
- std::map<std::string, std::string> const &Options, std::vector<std::string> const &defaultValues)
+ static std::optional<std::vector<std::string>> getDefaultSetOf(std::string const &Name,
+ std::map<std::string, std::string> const &Options)
{
auto const val = Options.find(Name);
if (val != Options.end())
return VectorizeString(val->second, ',');
- return defaultValues;
+ return {};
}
static std::vector<std::string> applyPlusMinusOptions(std::string const &Name,
std::map<std::string, std::string> const &Options, std::vector<std::string> &&Values)
@@ -997,12 +998,21 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/
static std::vector<std::string> parsePlusMinusOptions(std::string const &Name,
std::map<std::string, std::string> const &Options, std::vector<std::string> const &defaultValues)
{
- return applyPlusMinusOptions(Name, Options, getDefaultSetOf(Name, Options, defaultValues));
+ return applyPlusMinusOptions(Name, Options, getDefaultSetOf(Name, Options).value_or(defaultValues));
}
static std::vector<std::string> parsePlusMinusArchOptions(std::string const &Name,
std::map<std::string, std::string> const &Options)
{
- auto Values = getDefaultSetOf(Name, Options, APT::Configuration::getArchitectures());
+ std::vector<std::string> Values;
+ if (auto opt = getDefaultSetOf(Name, Options); opt.has_value())
+ Values = opt.value();
+ else
+ {
+ Values = APT::Configuration::getArchitectures();
+ auto veryforeign = _config->FindVector("APT::BarbarianArchitectures");
+ Values.reserve(Values.size() + veryforeign.size());
+ std::move(veryforeign.begin(), veryforeign.end(), std::back_inserter(Values));
+ }
// all is a very special architecture users shouldn't be concerned with explicitly
// but if the user does, do not override the choice
auto const val = Options.find(Name + "-");
diff --git a/apt-pkg/edsp.cc b/apt-pkg/edsp.cc
index 5bf23044b..b7c0d28d2 100644
--- a/apt-pkg/edsp.cc
+++ b/apt-pkg/edsp.cc
@@ -208,7 +208,10 @@ static bool WriteScenarioLimitedDependency(FileFd &output,
/*}}}*/
static bool checkKnownArchitecture(std::string const &arch) /*{{{*/
{
- return APT::Configuration::checkArchitecture(arch);
+ if (APT::Configuration::checkArchitecture(arch))
+ return true;
+ static auto const veryforeign = _config->FindVector("APT::BarbarianArchitectures");
+ return std::find(veryforeign.begin(), veryforeign.end(), arch) != veryforeign.end();
}
/*}}}*/
static bool WriteGenericRequestHeaders(FileFd &output, APT::StringView const head)/*{{{*/
@@ -217,6 +220,8 @@ static bool WriteGenericRequestHeaders(FileFd &output, APT::StringView const hea
"Architectures:");
for (auto const &a : APT::Configuration::getArchitectures())
WriteOkay(Okay, output, " ", a);
+ for (auto const &a : _config->FindVector("APT::BarbarianArchitectures"))
+ WriteOkay(Okay, output, " ", a);
return WriteOkay(Okay, output, "\n");
}
/*}}}*/