From 93416f3227685c390c7ab579981efde526134181 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 29 Jan 2025 19:01:06 +0100 Subject: Add 'Include'/'Exclude' options to limit packages used from a repository 'Include' allows limiting a repository to a allowlist of packages, 'Exclude' allows removing packages from a repository. Implementation wise this is not the nicest as it goes via the IndexTarget options, so we first parse our option value into a vector, then we turn the vector into a string, and then vectorize it again. That said, we support both "," and " " as separators due to the construction (we split by "," then we join using " "). Gbp-Dch: full --- apt-pkg/deb/debmetaindex.cc | 56 +++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 17 deletions(-) (limited to 'apt-pkg/deb/debmetaindex.cc') diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index c53b00881..c040b76b9 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -111,6 +111,8 @@ class APT_HIDDEN debReleaseIndexPrivate /*{{{*/ std::vector const Languages; bool const UsePDiffs; std::string const UseByHash; + std::optional> const include; + std::optional> const exclude; }; std::vector DebEntries; @@ -375,6 +377,10 @@ static void GetIndexTargetsFor(char const * const Type, std::string const &URI, Options.insert(std::make_pair("COMPRESSIONTYPES", CompressionTypes)); Options.insert(std::make_pair("KEEPCOMPRESSEDAS", KeepCompressedAs)); Options.insert(std::make_pair("SOURCESENTRY", E->sourcesEntry)); + if (auto include = E->include) + Options.insert(std::make_pair("INCLUDE", APT::String::Join(*include, " "))); + if (auto exclude = E->exclude) + Options.insert(std::make_pair("EXCLUDE", APT::String::Join(*exclude, " "))); bool IsOpt = IsOptional; { @@ -425,22 +431,36 @@ std::vector debReleaseIndex::GetIndexTargets() const return IndexTargets; } /*}}}*/ -void debReleaseIndex::AddComponent(std::string const &sourcesEntry, /*{{{*/ - bool const isSrc, std::string const &Name, - std::vector const &Targets, - std::vector const &Architectures, - std::vector Languages, - bool const usePDiffs, std::string const &useByHash) +bool debReleaseIndex::AddComponent(std::string const &sourcesEntry, /*{{{*/ + bool const isSrc, std::string const &Name, + std::vector const &Targets, + std::vector const &Architectures, + std::vector Languages, + bool const usePDiffs, std::string const &useByHash, + std::optional> const &include, + std::optional> const &exclude) { + if (include && exclude) + return _error->Error("Both 'Include' and 'Exclude' specified in %s", sourcesEntry.c_str()); if (Languages.empty() == true) Languages.push_back("none"); debReleaseIndexPrivate::debSectionEntry const entry = { - sourcesEntry, Name, Targets, Architectures, Languages, usePDiffs, useByHash + sourcesEntry, + Name, + Targets, + Architectures, + Languages, + usePDiffs, + useByHash, + include, + exclude, }; if (isSrc) d->DebSrcEntries.push_back(entry); else d->DebEntries.push_back(entry); + + return true; } /*}}}*/ std::string debReleaseIndex::ArchiveURI(std::string const &File) const /*{{{*/ @@ -1403,16 +1423,18 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/ } auto const entry = Options.find("sourceslist-entry"); - Deb->AddComponent( - entry->second, - IsSrc, - Section, - parsePlusMinusTargetOptions(Name, Options), - parsePlusMinusArchOptions("arch", Options), - parsePlusMinusOptions("lang", Options, APT::Configuration::getLanguages(true)), - UsePDiffs, - UseByHash - ); + if (not Deb->AddComponent( + entry->second, + IsSrc, + Section, + parsePlusMinusTargetOptions(Name, Options), + parsePlusMinusArchOptions("arch", Options), + parsePlusMinusOptions("lang", Options, APT::Configuration::getLanguages(true)), + UsePDiffs, + UseByHash, + getDefaultSetOf("include", Options), + getDefaultSetOf("exclude", Options))) + return false; if (Deb->SetTrusted(GetTriStateOption(Options, "trusted")) == false || Deb->SetCheckValidUntil(GetTriStateOption(Options, "check-valid-until")) == false || -- cgit v1.2.3-70-g09d2