summaryrefslogtreecommitdiff
path: root/apt-pkg/edsp.cc
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2025-03-13 15:15:58 +0100
committerJulian Andres Klode <julian.klode@canonical.com>2025-03-20 10:26:51 +0100
commit11917fa559c6c9bc5b0993b435f295de06bd161c (patch)
tree91e394b7818411f22c7dc05e385b02f5a4d0ad2d /apt-pkg/edsp.cc
parentc8b8f563ec2ff0f006a6d77469eaa656050f1fcc (diff)
edsp: Add functionality to only write relevant packages
Add a variant of WriteLimitedScenario that does not take a pkgset, but creates one on the fly based on the transitive closure of installed packages, to be installed packages, and their dependencies and provides. This includes more packages than strictly necessary, i.e. we do not really need to include foo just because a package we want to install Conflicts with it, but oh well, this is easy to read. Trying to extend the filtering is hard as the dependencies being written are also filtered...
Diffstat (limited to 'apt-pkg/edsp.cc')
-rw-r--r--apt-pkg/edsp.cc30
1 files changed, 30 insertions, 0 deletions
diff --git a/apt-pkg/edsp.cc b/apt-pkg/edsp.cc
index 88569d3c4..2e6ef6271 100644
--- a/apt-pkg/edsp.cc
+++ b/apt-pkg/edsp.cc
@@ -327,6 +327,36 @@ bool EDSP::WriteLimitedScenario(pkgDepCache &Cache, FileFd &output,
Progress->Done();
return Okay;
}
+
+static void MarkPackage(std::vector<bool> &pkgset, pkgCache::PkgIterator pkg)
+{
+ if (pkgset[pkg->ID])
+ return;
+ pkgset[pkg->ID] = true;
+ for (auto ver = pkg.VersionList(); not ver.end(); ++ver)
+ {
+ for (auto P = ver.ProvidesList(); not P.end(); ++P)
+ MarkPackage(pkgset, P.ParentPkg());
+ for (auto D = ver.DependsList(); not D.end(); ++D)
+ {
+ std::unique_ptr<pkgCache::Version *[]> targets(D.AllTargets());
+ for (size_t i = 0; targets[i] != 0; ++i)
+ MarkPackage(pkgset, pkgCache::VerIterator(*ver.Cache(), targets[i]).ParentPkg());
+
+ MarkPackage(pkgset, D.TargetPkg());
+ }
+ }
+}
+
+bool EDSP::WriteLimitedScenario(pkgDepCache &Cache, FileFd &output,
+ OpProgress *Progress)
+{
+ std::vector<bool> pkgset(Cache.Head().PackageCount);
+ for (auto Pkg = Cache.PkgBegin(); not Pkg.end(); ++Pkg)
+ if (Cache[Pkg].Install() || Pkg->CurrentVer)
+ MarkPackage(pkgset, Pkg);
+ return WriteLimitedScenario(Cache, output, pkgset, Progress);
+}
/*}}}*/
// EDSP::WriteRequest - to the given file descriptor /*{{{*/
bool EDSP::WriteRequest(pkgDepCache &Cache, FileFd &output,