]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/packagemanager.cc
more debug output in SmartConfigure
[apt.git] / apt-pkg / packagemanager.cc
index 155408bb45506404b19551e21be2d299ddd626d3..019a1db1fc556ee555d7742bedc47c8da1a7567e 100644 (file)
    ##################################################################### */
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
-#ifdef __GNUG__
-#pragma implementation "apt-pkg/packagemanager.h"
-#endif
-
 #include <apt-pkg/packagemanager.h>
 #include <apt-pkg/orderlist.h>
 #include <apt-pkg/depcache.h>
@@ -29,8 +25,8 @@
     
 #include <apti18n.h>    
 #include <iostream>
+#include <fcntl.h> 
                                                                        /*}}}*/
-
 using namespace std;
 
 // PM::PackageManager - Constructor                                    /*{{{*/
@@ -95,9 +91,10 @@ bool pkgPackageManager::GetArchives(pkgAcquire *Owner,pkgSourceList *Sources,
    be downloaded. */
 bool pkgPackageManager::FixMissing()
 {   
+   pkgDepCache::ActionGroup group(Cache);
    pkgProblemResolver Resolve(&Cache);
    List->SetFileList(FileNames);
-   
+
    bool Bad = false;
    for (PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
    {
@@ -106,7 +103,7 @@ bool pkgPackageManager::FixMissing()
    
       // Okay, this file is missing and we need it. Mark it for keep 
       Bad = true;
-      Cache.MarkKeep(I);
+      Cache.MarkKeep(I, false, false);
    }
  
    // We have to empty the list otherwise it will not have the new changes
@@ -120,7 +117,40 @@ bool pkgPackageManager::FixMissing()
    return Resolve.ResolveByKeep() == true && Cache.BrokenCount() == 0;   
 }
                                                                        /*}}}*/
+// PM::ImmediateAdd - Add the immediate flag recursivly                        /*{{{*/
+// ---------------------------------------------------------------------
+/* This adds the immediate flag to the pkg and recursively to the
+   dependendies 
+ */
+void pkgPackageManager::ImmediateAdd(PkgIterator I, bool UseInstallVer)
+{
+   DepIterator D;
+   
+   if(UseInstallVer)
+   {
+      if(Cache[I].InstallVer == 0)
+        return;
+      D = Cache[I].InstVerIter(Cache).DependsList(); 
+   } else {
+      if (I->CurrentVer == 0)
+        return;
+      D = I.CurrentVer().DependsList(); 
+   }
 
+   for ( /* nothing */  ; D.end() == false; D++)
+      if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends)
+      {
+        if(!List->IsFlag(D.TargetPkg(), pkgOrderList::Immediate))
+        {
+           if(Debug)
+              clog << "ImmediateAdd(): Adding Immediate flag to " << I.Name() << endl;
+           List->Flag(D.TargetPkg(),pkgOrderList::Immediate);
+           ImmediateAdd(D.TargetPkg(), UseInstallVer);
+        }
+      }
+   return;
+}
+                                                                       /*}}}*/
 // PM::CreateOrderList - Create the ordering class                     /*{{{*/
 // ---------------------------------------------------------------------
 /* This populates the ordering list with all the packages that are
@@ -147,21 +177,15 @@ bool pkgPackageManager::CreateOrderList()
           (I->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important) &&
          NoImmConfigure == false)
       {
+        if(Debug)
+           clog << "CreateOrderList(): Adding Immediate flag for " << I.Name() << endl;
         List->Flag(I,pkgOrderList::Immediate);
-        
-        // Look for other packages to make immediate configurea
-        if (Cache[I].InstallVer != 0)
-           for (DepIterator D = Cache[I].InstVerIter(Cache).DependsList(); 
-                D.end() == false; D++)
-              if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends)
-                 List->Flag(D.TargetPkg(),pkgOrderList::Immediate);
+
+        // Look for other install packages to make immediate configurea
+        ImmediateAdd(I, true);
         
         // And again with the current version.
-        if (I->CurrentVer != 0)
-           for (DepIterator D = I.CurrentVer().DependsList(); 
-                D.end() == false; D++)
-              if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends)
-                 List->Flag(D.TargetPkg(),pkgOrderList::Immediate);
+        ImmediateAdd(I, false);
       }
       
       // Not interesting
@@ -263,6 +287,9 @@ bool pkgPackageManager::ConfigureAll()
    of it's dependents. */
 bool pkgPackageManager::SmartConfigure(PkgIterator Pkg)
 {
+   if (Debug == true)
+      clog << "SmartConfigure " << Pkg.Name() << endl;
+
    pkgOrderList OList(&Cache);
 
    if (DepAdd(OList,Pkg) == false)
@@ -276,6 +303,9 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg)
    {
       PkgIterator Pkg(Cache,*I);
       
+      if (Debug == true)
+        clog << "  SmartConfigure on" << Pkg.Name() << endl;
+
       if (Configure(Pkg) == false)
         return false;
       
@@ -453,6 +483,9 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg)
       
       while (End->Type == pkgCache::Dep::PreDepends)
       {
+        if (Debug == true)
+           clog << "PreDepends order for " << Pkg.Name() << std::endl;
+
         // Look for possible ok targets.
         SPtrArray<Version *> VList = Start.AllTargets();
         bool Bad = true;
@@ -466,6 +499,8 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg)
                Pkg.State() == PkgIterator::NeedsNothing)
            {
               Bad = false;
+              if (Debug == true)
+                 clog << "Found ok package " << Pkg.Name() << endl;
               continue;
            }
         }
@@ -481,6 +516,8 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg)
                (Cache[Pkg].Keep() == true && Pkg.State() == PkgIterator::NeedsNothing))
               continue;
 
+           if (Debug == true)
+              clog << "Trying to SmartConfigure " << Pkg.Name() << endl;
            Bad = !SmartConfigure(Pkg);
         }
 
@@ -593,7 +630,7 @@ pkgPackageManager::OrderResult pkgPackageManager::OrderInstall()
          Pkg.State() == pkgCache::PkgIterator::NeedsNothing &&
          (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)
       {
-        _error->Error("Internal Error, trying to manipulate a kept package");
+        _error->Error("Internal Error, trying to manipulate a kept package (%s)",Pkg.Name());
         return Failed;
       }
       
@@ -627,16 +664,31 @@ pkgPackageManager::OrderResult pkgPackageManager::OrderInstall()
    return Completed;
 }
                                                                        /*}}}*/
+// PM::DoInstallPostFork - Does install part that happens after the fork /*{{{*/
+// ---------------------------------------------------------------------
+pkgPackageManager::OrderResult 
+pkgPackageManager::DoInstallPostFork(int statusFd)
+{
+      if(statusFd > 0)
+         // FIXME: use SetCloseExec here once it taught about throwing
+        //        exceptions instead of doing _exit(100) on failure
+        fcntl(statusFd,F_SETFD,FD_CLOEXEC); 
+      bool goResult = Go(statusFd);
+      if(goResult == false) 
+        return Failed;
+
+      return Res;
+};
+
 // PM::DoInstall - Does the installation                               /*{{{*/
 // ---------------------------------------------------------------------
 /* This uses the filenames in FileNames and the information in the
    DepCache to perform the installation of packages.*/
-pkgPackageManager::OrderResult pkgPackageManager::DoInstall(int status_fd)
+pkgPackageManager::OrderResult pkgPackageManager::DoInstall(int statusFd)
 {
-   OrderResult Res = OrderInstall();
-   if (Res != Failed)
-      if (Go(status_fd) == false)
-        return Failed;
-   return Res;
+   if(DoInstallPreFork() == Failed)
+      return Failed;
+   
+   return DoInstallPostFork(statusFd);
 }
                                                                        /*}}}*/