diff options
author | David Kalnischkies <david@kalnischkies.de> | 2016-06-04 18:45:01 +0200 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2016-06-04 18:45:01 +0200 |
commit | 307d9eb2d13ee59191b86ffec2f36ba3fffc5c20 (patch) | |
tree | 33c362f9f5326fce81ccf8bce3ad30950629ad68 | |
parent | 0cfec3ab589c6309bf284438d2148c7742cdaf10 (diff) | |
download | apt-307d9eb2d13ee59191b86ffec2f36ba3fffc5c20.tar.gz |
edsp: use an ID mapping for the internal solver
Currently an EDSP solver gets send basically all versions which means
the absolute count is the same, but that might not be true forever (and
with the skipping of rc-only versions it kinda is already) and even if
it were true, segfaulting on bad input seems wrong.
-rw-r--r-- | apt-pkg/edsp.cc | 13 | ||||
-rw-r--r-- | apt-pkg/edsp/edsplistparser.cc | 3 | ||||
-rw-r--r-- | apt-pkg/pkgsystem.cc | 24 | ||||
-rw-r--r-- | apt-pkg/pkgsystem.h | 6 | ||||
-rwxr-xr-x | test/integration/test-external-dependency-solver-protocol | 5 |
5 files changed, 42 insertions, 9 deletions
diff --git a/apt-pkg/edsp.cc b/apt-pkg/edsp.cc index 2aaffcfc7..f8925072e 100644 --- a/apt-pkg/edsp.cc +++ b/apt-pkg/edsp.cc @@ -17,6 +17,7 @@ #include <apt-pkg/edsp.h> #include <apt-pkg/tagfile.h> #include <apt-pkg/strutl.h> +#include <apt-pkg/pkgsystem.h> #include <ctype.h> #include <stddef.h> @@ -878,20 +879,20 @@ bool EDSP::WriteSolution(pkgDepCache &Cache, FILE* output) { if (Cache[Pkg].Delete() == true) { - fprintf(output, "Remove: %d\n", Pkg.CurrentVer()->ID); + fprintf(output, "Remove: %d\n", _system->GetVersionMapping(Pkg.CurrentVer()->ID)); if (Debug == true) fprintf(output, "Package: %s\nVersion: %s\n", Pkg.FullName().c_str(), Pkg.CurrentVer().VerStr()); } else if (Cache[Pkg].NewInstall() == true || Cache[Pkg].Upgrade() == true) { pkgCache::VerIterator const CandVer = Cache.GetCandidateVersion(Pkg); - fprintf(output, "Install: %d\n", CandVer->ID); + fprintf(output, "Install: %d\n", _system->GetVersionMapping(CandVer->ID)); if (Debug == true) fprintf(output, "Package: %s\nVersion: %s\n", Pkg.FullName().c_str(), CandVer.VerStr()); } else if (Cache[Pkg].Garbage == true) { - fprintf(output, "Autoremove: %d\n", Pkg.CurrentVer()->ID); + fprintf(output, "Autoremove: %d\n", _system->GetVersionMapping(Pkg.CurrentVer()->ID)); if (Debug == true) fprintf(output, "Package: %s\nVersion: %s\n", Pkg.FullName().c_str(), Pkg.CurrentVer().VerStr()); } @@ -910,11 +911,11 @@ bool EDSP::WriteSolution(pkgDepCache &Cache, FileFd &output) { std::string action; if (Cache[Pkg].Delete() == true) - WriteOkay(Okay, output, "Remove: ", Pkg.CurrentVer()->ID, "\n"); + WriteOkay(Okay, output, "Remove: ", _system->GetVersionMapping(Pkg.CurrentVer()->ID), "\n"); else if (Cache[Pkg].NewInstall() == true || Cache[Pkg].Upgrade() == true) - WriteOkay(Okay, output, "Install: ", Cache.GetCandidateVersion(Pkg)->ID, "\n"); + WriteOkay(Okay, output, "Install: ", _system->GetVersionMapping(Cache.GetCandidateVersion(Pkg)->ID), "\n"); else if (Cache[Pkg].Garbage == true) - WriteOkay(Okay, output, "Autoremove: ", Pkg.CurrentVer()->ID, "\n"); + WriteOkay(Okay, output, "Autoremove: ", _system->GetVersionMapping(Pkg.CurrentVer()->ID), "\n"); else continue; diff --git a/apt-pkg/edsp/edsplistparser.cc b/apt-pkg/edsp/edsplistparser.cc index 82799205e..f35000e0e 100644 --- a/apt-pkg/edsp/edsplistparser.cc +++ b/apt-pkg/edsp/edsplistparser.cc @@ -19,6 +19,7 @@ #include <apt-pkg/cacheiterators.h> #include <apt-pkg/tagfile.h> #include <apt-pkg/fileutl.h> +#include <apt-pkg/pkgsystem.h> /*}}}*/ @@ -47,7 +48,7 @@ edspListParser::edspListParser(FileFd *File) : debListParser(File), d(new edspLi // ListParser::NewVersion - Fill in the version structure /*{{{*/ bool edspListParser::NewVersion(pkgCache::VerIterator &Ver) { - Ver->ID = Section.FindI("APT-ID", Ver->ID); + _system->SetVersionMapping(Ver->ID, Section.FindI("APT-ID", Ver->ID)); return debListParser::NewVersion(Ver); } /*}}}*/ diff --git a/apt-pkg/pkgsystem.cc b/apt-pkg/pkgsystem.cc index 530150221..b1c6cc1ea 100644 --- a/apt-pkg/pkgsystem.cc +++ b/apt-pkg/pkgsystem.cc @@ -16,6 +16,7 @@ #include <apt-pkg/pkgsystem.h> #include <apt-pkg/macros.h> +#include <map> #include <cassert> #include <cstring> /*}}}*/ @@ -25,11 +26,19 @@ static pkgSystem *SysList[10]; pkgSystem **pkgSystem::GlobalList = SysList; unsigned long pkgSystem::GlobalListLen = 0; +class APT_HIDDEN pkgSystemPrivate /*{{{*/ +{ +public: + typedef decltype(pkgCache::Version::ID) idtype; + std::map<idtype,idtype> idmap; + pkgSystemPrivate() {} +}; + /*}}}*/ // System::pkgSystem - Constructor /*{{{*/ // --------------------------------------------------------------------- /* Add it to the global list.. */ pkgSystem::pkgSystem(char const * const label, pkgVersioningSystem * const vs) : - Label(label), VS(vs), d(NULL) + Label(label), VS(vs), d(new pkgSystemPrivate()) { assert(GlobalListLen < sizeof(SysList)/sizeof(*SysList)); SysList[GlobalListLen] = this; @@ -63,5 +72,18 @@ std::vector<std::string> pkgSystem::ArchitecturesSupported() const /*{{{*/ return {}; } /*}}}*/ +// pkgSystem::Set/GetVersionMapping - for internal/external communcation/*{{{*/ +void pkgSystem::SetVersionMapping(map_id_t const in, map_id_t const out) +{ + if (in == out) + return; + d->idmap.emplace(in, out); +} +map_id_t pkgSystem::GetVersionMapping(map_id_t const in) const +{ + auto const o = d->idmap.find(in); + return (o == d->idmap.end()) ? in : o->second; +} + /*}}}*/ pkgSystem::~pkgSystem() {} diff --git a/apt-pkg/pkgsystem.h b/apt-pkg/pkgsystem.h index 55bdeec70..affaa5c9a 100644 --- a/apt-pkg/pkgsystem.h +++ b/apt-pkg/pkgsystem.h @@ -51,6 +51,7 @@ class pkgVersioningSystem; class Configuration; class pkgIndexFile; +class pkgSystemPrivate; class pkgSystem { public: @@ -114,10 +115,13 @@ class pkgSystem */ std::vector<std::string> ArchitecturesSupported() const; + APT_HIDDEN void SetVersionMapping(map_id_t const in, map_id_t const out); + APT_HIDDEN map_id_t GetVersionMapping(map_id_t const in) const; + pkgSystem(char const * const Label, pkgVersioningSystem * const VS); virtual ~pkgSystem(); private: - void * const d; + pkgSystemPrivate * const d; }; // The environment we are operating in. diff --git a/test/integration/test-external-dependency-solver-protocol b/test/integration/test-external-dependency-solver-protocol index 6b76fd55c..4b13edc09 100755 --- a/test/integration/test-external-dependency-solver-protocol +++ b/test/integration/test-external-dependency-solver-protocol @@ -153,6 +153,11 @@ else cat solver.result msgfail fi +testsuccess grep '^APT-ID: 1$' "$APT_EDSP_DUMP_FILENAME" +sed -i -e 's#^APT-ID: 1$#APT-ID: 10000#' "$APT_EDSP_DUMP_FILENAME" +cat "$APT_EDSP_DUMP_FILENAME" | aptinternalsolver > solver.result 2>&1 || true +testsuccessequal 'Message: Done +' tail -n2 solver.result rm -f "$APT_EDSP_DUMP_FILENAME" testsuccess aptinternalsolver scenario |