show our broken packages message in 'apt' solver
authorDavid Kalnischkies <david@kalnischkies.de>
Tue, 17 Jun 2014 15:45:33 +0000 (17:45 +0200)
committerDavid Kalnischkies <david@kalnischkies.de>
Wed, 18 Jun 2014 09:17:18 +0000 (11:17 +0200)
apt-private/private-output.cc
apt-private/private-output.h
cmdline/apt-internal-solver.cc
cmdline/makefile

index 8f190a5..158bd5c 100644 (file)
@@ -344,129 +344,141 @@ bool ShowList(ostream &out,string Title,string List,string VersionsList)
            Depends: libldap2 (>= 2.0.2-2) but it is not going to be installed
            Depends: libsasl7 but it is not going to be installed   
  */
-void ShowBroken(ostream &out,CacheFile &Cache,bool Now)
+static void ShowBrokenPackage(ostream &out, pkgCacheFile * const Cache, pkgCache::PkgIterator const &Pkg, bool const Now)
 {
-   if (Cache->BrokenCount() == 0)
+   if (Now == true)
+   {
+      if ((*Cache)[Pkg].NowBroken() == false)
+        return;
+   }
+   else
+   {
+      if ((*Cache)[Pkg].InstBroken() == false)
+        return;
+   }
+
+   // Print out each package and the failed dependencies
+   out << " " << Pkg.FullName(true) << " :";
+   unsigned const Indent = Pkg.FullName(true).size() + 3;
+   bool First = true;
+   pkgCache::VerIterator Ver;
+
+   if (Now == true)
+      Ver = Pkg.CurrentVer();
+   else
+      Ver = (*Cache)[Pkg].InstVerIter(*Cache);
+
+   if (Ver.end() == true)
+   {
+      out << endl;
       return;
+   }
 
-   out << _("The following packages have unmet dependencies:") << endl;
-   for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
+   for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false;)
    {
-      pkgCache::PkgIterator I(Cache,Cache.List[J]);
-      
+      // Compute a single dependency element (glob or)
+      pkgCache::DepIterator Start;
+      pkgCache::DepIterator End;
+      D.GlobOr(Start,End); // advances D
+
+      if ((*Cache)->IsImportantDep(End) == false)
+        continue;
+
       if (Now == true)
       {
-        if (Cache[I].NowBroken() == false)
+        if (((*Cache)[End] & pkgDepCache::DepGNow) == pkgDepCache::DepGNow)
            continue;
       }
       else
       {
-        if (Cache[I].InstBroken() == false)
+        if (((*Cache)[End] & pkgDepCache::DepGInstall) == pkgDepCache::DepGInstall)
            continue;
       }
-      
-      // Print out each package and the failed dependencies
-      out << " " << I.FullName(true) << " :";
-      unsigned const Indent = I.FullName(true).size() + 3;
-      bool First = true;
-      pkgCache::VerIterator Ver;
-      
-      if (Now == true)
-        Ver = I.CurrentVer();
-      else
-        Ver = Cache[I].InstVerIter(Cache);
-      
-      if (Ver.end() == true)
-      {
-        out << endl;
-        continue;
-      }
-      
-      for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false;)
+
+      bool FirstOr = true;
+      while (1)
       {
-        // Compute a single dependency element (glob or)
-        pkgCache::DepIterator Start;
-        pkgCache::DepIterator End;
-        D.GlobOr(Start,End); // advances D
+        if (First == false)
+           for (unsigned J = 0; J != Indent; J++)
+              out << ' ';
+        First = false;
 
-        if (Cache->IsImportantDep(End) == false)
-           continue;
-        
-        if (Now == true)
+        if (FirstOr == false)
         {
-           if ((Cache[End] & pkgDepCache::DepGNow) == pkgDepCache::DepGNow)
-              continue;
+           for (unsigned J = 0; J != strlen(End.DepType()) + 3; J++)
+              out << ' ';
         }
         else
+           out << ' ' << End.DepType() << ": ";
+        FirstOr = false;
+
+        out << Start.TargetPkg().FullName(true);
+
+        // Show a quick summary of the version requirements
+        if (Start.TargetVer() != 0)
+           out << " (" << Start.CompType() << " " << Start.TargetVer() << ")";
+
+        /* Show a summary of the target package if possible. In the case
+           of virtual packages we show nothing */
+        pkgCache::PkgIterator Targ = Start.TargetPkg();
+        if (Targ->ProvidesList == 0)
         {
-           if ((Cache[End] & pkgDepCache::DepGInstall) == pkgDepCache::DepGInstall)
-              continue;
-        }
-        
-        bool FirstOr = true;
-        while (1)
-        {
-           if (First == false)
-              for (unsigned J = 0; J != Indent; J++)
-                 out << ' ';
-           First = false;
+           out << ' ';
+           pkgCache::VerIterator Ver = (*Cache)[Targ].InstVerIter(*Cache);
+           if (Now == true)
+              Ver = Targ.CurrentVer();
 
-           if (FirstOr == false)
+           if (Ver.end() == false)
            {
-              for (unsigned J = 0; J != strlen(End.DepType()) + 3; J++)
-                 out << ' ';
+              if (Now == true)
+                 ioprintf(out,_("but %s is installed"),Ver.VerStr());
+              else
+                 ioprintf(out,_("but %s is to be installed"),Ver.VerStr());
            }
            else
-              out << ' ' << End.DepType() << ": ";
-           FirstOr = false;
-           
-           out << Start.TargetPkg().FullName(true);
-        
-           // Show a quick summary of the version requirements
-           if (Start.TargetVer() != 0)
-              out << " (" << Start.CompType() << " " << Start.TargetVer() << ")";
-           
-           /* Show a summary of the target package if possible. In the case
-              of virtual packages we show nothing */    
-           pkgCache::PkgIterator Targ = Start.TargetPkg();
-           if (Targ->ProvidesList == 0)
            {
-              out << ' ';
-              pkgCache::VerIterator Ver = Cache[Targ].InstVerIter(Cache);
-              if (Now == true)
-                 Ver = Targ.CurrentVer();
-                   
-              if (Ver.end() == false)
+              if ((*Cache)[Targ].CandidateVerIter(*Cache).end() == true)
               {
-                 if (Now == true)
-                    ioprintf(out,_("but %s is installed"),Ver.VerStr());
+                 if (Targ->ProvidesList == 0)
+                    out << _("but it is not installable");
                  else
-                    ioprintf(out,_("but %s is to be installed"),Ver.VerStr());
-              }               
+                    out << _("but it is a virtual package");
+              }
               else
-              {
-                 if (Cache[Targ].CandidateVerIter(Cache).end() == true)
-                 {
-                    if (Targ->ProvidesList == 0)
-                       out << _("but it is not installable");
-                    else
-                       out << _("but it is a virtual package");
-                 }               
-                 else
-                    out << (Now?_("but it is not installed"):_("but it is not going to be installed"));
-              }               
+                 out << (Now?_("but it is not installed"):_("but it is not going to be installed"));
            }
-           
-           if (Start != End)
-              out << _(" or");
-           out << endl;
-           
-           if (Start == End)
-              break;
-           ++Start;
-        }       
-      }            
-   }   
+        }
+
+        if (Start != End)
+           out << _(" or");
+        out << endl;
+
+        if (Start == End)
+           break;
+        ++Start;
+      }
+   }
+}
+void ShowBroken(ostream &out, CacheFile &Cache, bool const Now)
+{
+   if (Cache->BrokenCount() == 0)
+      return;
+
+   out << _("The following packages have unmet dependencies:") << endl;
+   for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
+   {
+      pkgCache::PkgIterator const I(Cache,Cache.List[J]);
+      ShowBrokenPackage(out, &Cache, I, Now);
+   }
+}
+void ShowBroken(ostream &out, pkgCacheFile &Cache, bool const Now)
+{
+   if (Cache->BrokenCount() == 0)
+      return;
+
+   out << _("The following packages have unmet dependencies:") << endl;
+   for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; ++Pkg)
+      ShowBrokenPackage(out, &Cache, Pkg, Now);
 }
                                                                        /*}}}*/
 // ShowNew - Show packages to newly install                            /*{{{*/
index 9633d0c..6f3a964 100644 (file)
@@ -28,7 +28,8 @@ void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records,
 
 
 // helper to describe global state
-APT_PUBLIC void ShowBroken(std::ostream &out,CacheFile &Cache,bool Now);
+APT_PUBLIC void ShowBroken(std::ostream &out, CacheFile &Cache, bool const Now);
+APT_PUBLIC void ShowBroken(std::ostream &out, pkgCacheFile &Cache, bool const Now);
 
 APT_PUBLIC bool ShowList(std::ostream &out, std::string Title, std::string List,
               std::string VersionsList);
index e4cdf63..5fda7b6 100644 (file)
 #include <apt-pkg/depcache.h>
 #include <apt-pkg/pkgcache.h>
 #include <apt-pkg/cacheiterators.h>
+#include <apt-private/private-output.h>
 
 #include <string.h>
 #include <iostream>
+#include <sstream>
 #include <list>
 #include <string>
 #include <unistd.h>
@@ -168,18 +170,20 @@ int main(int argc,const char *argv[])                                     /*{{{*/
 
        EDSP::WriteProgress(60, "Call problemresolver on current scenario…", output);
 
+       std::string failure;
        if (upgrade == true) {
-               if (pkgAllUpgrade(CacheFile) == false) {
-                       EDSP::WriteError("ERR_UNSOLVABLE_UPGRADE", "An upgrade error occurred", output);
-                       return 0;
-               }
+               if (pkgAllUpgrade(CacheFile) == false)
+                       failure = "ERR_UNSOLVABLE_UPGRADE";
        } else if (distUpgrade == true) {
-               if (pkgDistUpgrade(CacheFile) == false) {
-                       EDSP::WriteError("ERR_UNSOLVABLE_DIST_UPGRADE", "An dist-upgrade error occurred", output);
-                       return 0;
-               }
-       } else if (Fix.Resolve() == false) {
-               EDSP::WriteError("ERR_UNSOLVABLE", "An error occurred", output);
+               if (pkgDistUpgrade(CacheFile) == false)
+                       failure = "ERR_UNSOLVABLE_DIST_UPGRADE";
+       } else if (Fix.Resolve() == false)
+               failure = "ERR_UNSOLVABLE";
+
+       if (failure.empty() == false) {
+               std::ostringstream broken;
+               ShowBroken(broken, CacheFile, false);
+               EDSP::WriteError(failure.c_str(), broken.str(), output);
                return 0;
        }
 
index c4a249c..b7c35dd 100644 (file)
@@ -8,49 +8,49 @@ include ../buildlib/defaults.mak
 # The apt program
 PROGRAM=apt
 SLIBS = -lapt-pkg -lapt-private $(INTLLIBS)
-LIB_MAKES = apt-pkg/makefile
+LIB_MAKES = apt-pkg/makefile apt-private/makefile
 SOURCE = apt.cc
 include $(PROGRAM_H)
 
 # The apt-cache program
 PROGRAM=apt-cache
 SLIBS = -lapt-pkg -lapt-private $(INTLLIBS)
-LIB_MAKES = apt-pkg/makefile
+LIB_MAKES = apt-pkg/makefile apt-private/makefile
 SOURCE = apt-cache.cc
 include $(PROGRAM_H)
 
 # The apt-get program
 PROGRAM=apt-get
 SLIBS = -lapt-pkg -lapt-private $(INTLLIBS)
-LIB_MAKES = apt-pkg/makefile
+LIB_MAKES = apt-pkg/makefile apt-private/makefile
 SOURCE = apt-get.cc 
 include $(PROGRAM_H)
 
 # The apt-config program
 PROGRAM=apt-config
 SLIBS = -lapt-pkg -lapt-private $(INTLLIBS)
-LIB_MAKES = apt-pkg/makefile
+LIB_MAKES = apt-pkg/makefile apt-private/makefile
 SOURCE = apt-config.cc
 include $(PROGRAM_H)
 
 # The apt-cdrom program
 PROGRAM=apt-cdrom
 SLIBS = -lapt-pkg -lapt-private $(INTLLIBS)
-LIB_MAKES = apt-pkg/makefile
+LIB_MAKES = apt-pkg/makefile apt-private/makefile
 SOURCE = apt-cdrom.cc 
 include $(PROGRAM_H)
 
 # The apt-mark program
 PROGRAM=apt-mark
 SLIBS = -lapt-pkg -lapt-private $(INTLLIBS)
-LIB_MAKES = apt-pkg/makefile
+LIB_MAKES = apt-pkg/makefile apt-private/makefile
 SOURCE = apt-mark.cc
 include $(PROGRAM_H)
 
 # The apt-helper
 PROGRAM=apt-helper
 SLIBS = -lapt-pkg -lapt-private $(INTLLIBS)
-LIB_MAKES = apt-pkg/makefile
+LIB_MAKES = apt-pkg/makefile apt-private/makefile
 SOURCE = apt-helper.cc
 include $(PROGRAM_H)
 
@@ -75,14 +75,14 @@ include $(PROGRAM_H)
 # The apt-extracttemplates program
 PROGRAM=apt-extracttemplates
 SLIBS = -lapt-pkg -lapt-inst $(INTLLIBS)
-LIB_MAKES = apt-pkg/makefile
+LIB_MAKES = apt-pkg/makefile apt-inst/makefile
 SOURCE = apt-extracttemplates.cc 
 include $(PROGRAM_H)
 
 # The internal solver acting as an external
 PROGRAM=apt-internal-solver
-SLIBS = -lapt-pkg $(INTLLIBS)
-LIB_MAKES = apt-pkg/makefile
+SLIBS = -lapt-pkg -lapt-private $(INTLLIBS)
+LIB_MAKES = apt-pkg/makefile apt-private/makefile
 SOURCE = apt-internal-solver.cc
 include $(PROGRAM_H)