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/pkgcachegen.cc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'apt-pkg/pkgcachegen.cc') diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index 7d93db4b4..3358441ee 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -251,6 +251,15 @@ bool pkgCacheGenerator::MergeList(ListParser &List, if (PackageName.empty() == true) return false; + // Package is excluded + if (exclude.find(PackageName) != exclude.end()) + continue; + + // Includes are specified, this is the total set of packages to include, + // so we need to skip the package if it is not in the include list. + if (not include.empty() && include.find(PackageName) == include.end()) + continue; + Counter++; if (Counter % 100 == 0 && Progress != 0) Progress->Progress(List.Offset()); @@ -1332,6 +1341,7 @@ bool pkgCacheGenerator::SelectFile(std::string const &File, pkgIndexFile const &Index, std::string const &Architecture, std::string const &Component, + const IndexTarget *Target, unsigned long const Flags) { CurrentFile = nullptr; @@ -1374,6 +1384,22 @@ bool pkgCacheGenerator::SelectFile(std::string const &File, Cache.HeaderP->FileList = map_pointer{NarrowOffset(CurrentFile - Cache.PkgFileP)}; Cache.HeaderP->PackageFileCount++; + include.clear(); + exclude.clear(); + if (Target) + { + if (auto inc = Target->Options.find("INCLUDE"); inc != Target->Options.end()) + { + auto v = VectorizeString(inc->second, ' '); + include.insert(v.begin(), v.end()); + } + if (auto exc = Target->Options.find("EXCLUDE"); exc != Target->Options.end()) + { + auto v = VectorizeString(exc->second, ' '); + exclude.insert(v.begin(), v.end()); + } + } + if (Progress != 0) Progress->SubProgress(Index.Size()); return true; -- cgit v1.2.3-70-g09d2