]> git.saurik.com Git - apt.git/commitdiff
edsp: use an ID mapping for the internal solver
authorDavid Kalnischkies <david@kalnischkies.de>
Sat, 4 Jun 2016 16:45:01 +0000 (18:45 +0200)
committerDavid Kalnischkies <david@kalnischkies.de>
Sat, 4 Jun 2016 16:45:01 +0000 (18:45 +0200)
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.

apt-pkg/edsp.cc
apt-pkg/edsp/edsplistparser.cc
apt-pkg/pkgsystem.cc
apt-pkg/pkgsystem.h
test/integration/test-external-dependency-solver-protocol

index 2aaffcfc707d31ee88a8d16bbd8b1996f6e8c6ce..f8925072e9bd7d06c30e8b2e15dd54d390d52a1a 100644 (file)
@@ -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;
 
index 82799205ebfa04558be2a943d6ad3c414a25aa7a..f35000e0ee34bd1c7d11f18519b3dac6c3b8ee42 100644 (file)
@@ -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);
 }
                                                                        /*}}}*/
index 53015022150f51f89231e7a0607607501944d6a0..b1c6cc1eaa03672769556e6cb884637501ce5d54 100644 (file)
@@ -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() {}
index 55bdeec708c02c53f4b07268314cc5568a45cdd8..affaa5c9af9bb86261d3447b053a663c66c5d4f3 100644 (file)
@@ -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.
index 6b76fd55c92c17947a53fcb6f7170ff0d39370d4..4b13edc0948fafa57e72773aece99235947b5586 100755 (executable)
@@ -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