]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/packagemanager.cc
actually register the tempfile removal atexit
[apt.git] / apt-pkg / packagemanager.cc
index 093999bc243e66da1727838bfaf25a46f31f4200..3fdd9b6375e570997f42f27157efbe83f3d895b9 100644 (file)
@@ -25,9 +25,9 @@
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/sptr.h>
 
-#include <apti18n.h>
 #include <iostream>
-#include <fcntl.h>
+
+#include <apti18n.h>
                                                                        /*}}}*/
 using namespace std;
 
@@ -337,8 +337,9 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth)
       however if there is a loop (A depends on B, B depends on A) this will not 
       be the case, so check for dependencies before configuring. */
    bool Bad = false, Changed = false;
-   const unsigned int max_loops = _config->FindI("APT::pkgPackageManager::MaxLoopCount", 500);
+   const unsigned int max_loops = _config->FindI("APT::pkgPackageManager::MaxLoopCount", 5000);
    unsigned int i=0;
+   std::list<DepIterator> needConfigure;
    do
    {
       Changed = false;
@@ -352,7 +353,7 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth)
            continue;
         Bad = true;
 
-        // Search for dependencies which are unpacked but aren't configured yet (maybe loops)
+        // Check for dependencies that have not been unpacked, probably due to loops.
         for (DepIterator Cur = Start; true; ++Cur)
         {
            SPtrArray<Version *> VList = Cur.AllTargets();
@@ -372,51 +373,66 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth)
               }
 
               // Check if the version that is going to be installed will satisfy the dependency
-              if (Cache[DepPkg].InstallVer != *I)
+              if (Cache[DepPkg].InstallVer != *I || List->IsNow(DepPkg) == false)
                  continue;
 
-              if (List->IsFlag(DepPkg,pkgOrderList::UnPacked))
+              if (PkgLoop == true)
               {
-                 if (List->IsFlag(DepPkg,pkgOrderList::Loop) && PkgLoop)
-                 {
-                   // This dependency has already been dealt with by another SmartConfigure on Pkg
-                   Bad = false;
-                   break;
-                 }
-                 /* Check for a loop to prevent one forming
-                      If A depends on B and B depends on A, SmartConfigure will
-                      just hop between them if this is not checked. Dont remove the
-                      loop flag after finishing however as loop is already set.
-                      This means that there is another SmartConfigure call for this
-                      package and it will remove the loop flag */
+                 if (Debug)
+                    std::clog << OutputInDepth(Depth) << "Package " << Pkg << " loops in SmartConfigure" << std::endl;
+                 Bad = false;
+                 break;
+              }
+              else
+              {
+                 if (Debug)
+                    clog << OutputInDepth(Depth) << "Unpacking " << DepPkg.FullName() << " to avoid loop " << Cur << endl;
                  if (PkgLoop == false)
                     List->Flag(Pkg,pkgOrderList::Loop);
-                 if (SmartConfigure(DepPkg, Depth + 1) == true)
+                 if (SmartUnPack(DepPkg, true, Depth + 1) == true)
                  {
                     Bad = false;
                     if (List->IsFlag(DepPkg,pkgOrderList::Loop) == false)
-                       Changed = true;
+                       Changed = true;
                  }
                  if (PkgLoop == false)
-                   List->RmFlag(Pkg,pkgOrderList::Loop);
-                 // If SmartConfigure was succesfull, Bad is false, so break
+                    List->RmFlag(Pkg,pkgOrderList::Loop);
                  if (Bad == false)
                     break;
               }
-              else if (List->IsFlag(DepPkg,pkgOrderList::Configured))
-              {
-                 Bad = false;
-                 break;
-              }
            }
-           if (Cur == End)
+
+           if (Cur == End || Bad == false)
               break;
-         }
+        }
 
         if (Bad == false)
            continue;
 
-        // Check for dependencies that have not been unpacked, probably due to loops.
+        needConfigure.push_back(Start);
+      }
+      if (i++ > max_loops)
+         return _error->Error("Internal error: MaxLoopCount reached in SmartUnPack (1) for %s, aborting", Pkg.FullName().c_str());
+   } while (Changed == true);
+
+   Bad = false, Changed = false, i = 0;
+   do
+   {
+      Changed = false;
+      for (std::list<DepIterator>::const_iterator D = needConfigure.begin(); D != needConfigure.end(); ++D)
+      {
+        // Compute a single dependency element (glob or) without modifying D
+        pkgCache::DepIterator Start, End;
+        {
+           pkgCache::DepIterator Discard = *D;
+           Discard.GlobOr(Start,End);
+        }
+
+        if (End->Type != pkgCache::Dep::Depends)
+           continue;
+        Bad = true;
+
+        // Search for dependencies which are unpacked but aren't configured yet (maybe loops)
         for (DepIterator Cur = Start; true; ++Cur)
         {
            SPtrArray<Version *> VList = Cur.AllTargets();
@@ -427,44 +443,53 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth)
               PkgIterator DepPkg = Ver.ParentPkg();
 
               // Check if the version that is going to be installed will satisfy the dependency
-              if (Cache[DepPkg].InstallVer != *I || List->IsNow(DepPkg) == false)
+              if (Cache[DepPkg].InstallVer != *I)
                  continue;
 
-              if (PkgLoop == true)
-              {
-                 if (Debug)
-                    std::clog << OutputInDepth(Depth) << "Package " << Pkg << " loops in SmartConfigure" << std::endl;
-                 Bad = false;
-                 break;
-              }
-              else
+              if (List->IsFlag(DepPkg,pkgOrderList::UnPacked))
               {
-                 if (Debug)
-                    clog << OutputInDepth(Depth) << "Unpacking " << DepPkg.FullName() << " to avoid loop " << Cur << endl;
+                 if (List->IsFlag(DepPkg,pkgOrderList::Loop) && PkgLoop)
+                 {
+                   // This dependency has already been dealt with by another SmartConfigure on Pkg
+                   Bad = false;
+                   break;
+                 }
+                 /* Check for a loop to prevent one forming
+                      If A depends on B and B depends on A, SmartConfigure will
+                      just hop between them if this is not checked. Dont remove the
+                      loop flag after finishing however as loop is already set.
+                      This means that there is another SmartConfigure call for this
+                      package and it will remove the loop flag */
                  if (PkgLoop == false)
                     List->Flag(Pkg,pkgOrderList::Loop);
-                 if (SmartUnPack(DepPkg, true, Depth + 1) == true)
+                 if (SmartConfigure(DepPkg, Depth + 1) == true)
                  {
                     Bad = false;
                     if (List->IsFlag(DepPkg,pkgOrderList::Loop) == false)
-                       Changed = true;
+                       Changed = true;
                  }
                  if (PkgLoop == false)
-                    List->RmFlag(Pkg,pkgOrderList::Loop);
+                   List->RmFlag(Pkg,pkgOrderList::Loop);
+                 // If SmartConfigure was succesfull, Bad is false, so break
                  if (Bad == false)
                     break;
               }
+              else if (List->IsFlag(DepPkg,pkgOrderList::Configured))
+              {
+                 Bad = false;
+                 break;
+              }
            }
-
-           if (Cur == End)
+           if (Cur == End || Bad == false)
               break;
-        }
+         }
+
 
         if (Bad == true && Changed == false && Debug == true)
-           std::clog << OutputInDepth(Depth) << "Could not satisfy " << Start << std::endl;
+           std::clog << OutputInDepth(Depth) << "Could not satisfy " << *D << std::endl;
       }
       if (i++ > max_loops)
-         return _error->Error("Internal error: MaxLoopCount reached in SmartUnPack for %s, aborting", Pkg.FullName().c_str());
+         return _error->Error("Internal error: MaxLoopCount reached in SmartUnPack (2) for %s, aborting", Pkg.FullName().c_str());
    } while (Changed == true);
    
    if (Bad) {
@@ -491,6 +516,7 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth)
           P.end() == false; P = Pkg.Group().NextPkg(P))
       {
         if (Pkg == P || List->IsFlag(P,pkgOrderList::Configured) == true ||
+            List->IsFlag(P,pkgOrderList::UnPacked) == false ||
             Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer &&
              (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall))
            continue;
@@ -601,7 +627,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c
       This will be either dealt with if the package is configured as a dependency of Pkg (if and when Pkg is configured),
       or by the ConfigureAll call at the end of the for loop in OrderInstall. */
    bool Changed = false;
-   const unsigned int max_loops = _config->FindI("APT::pkgPackageManager::MaxLoopCount", 500);
+   const unsigned int max_loops = _config->FindI("APT::pkgPackageManager::MaxLoopCount", 5000);
    unsigned int i = 0;
    do 
    {
@@ -621,7 +647,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c
            // Look for easy targets: packages that are already okay
            for (DepIterator Cur = Start; Bad == true; ++Cur)
            {
-              SPtrArray<Version *> VList = Start.AllTargets();
+              SPtrArray<Version *> VList = Cur.AllTargets();
               for (Version **I = VList; *I != 0; ++I)
               {
                  VerIterator Ver(Cache,*I);
@@ -642,9 +668,9 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c
            }
 
            // Look for something that could be configured.
-           for (DepIterator Cur = Start; Bad == true; ++Cur)
+           for (DepIterator Cur = Start; Bad == true && Cur.end() == false; ++Cur)
            {
-              SPtrArray<Version *> VList = Start.AllTargets();
+              SPtrArray<Version *> VList = Cur.AllTargets();
               for (Version **I = VList; *I != 0; ++I)
               {
                  VerIterator Ver(Cache,*I);
@@ -784,7 +810,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c
                           VerIterator V(Cache,*I);
                           PkgIterator P = V.ParentPkg();
                           // we are checking for installation as an easy 'protection' against or-groups and (unchosen) providers
-                          if (P->CurrentVer == 0 || P != Pkg || (P.CurrentVer() != V && Cache[P].InstallVer != V))
+                          if (P != Pkg || (P.CurrentVer() != V && Cache[P].InstallVer != V))
                              continue;
                           circle = true;
                           break;
@@ -855,7 +881,10 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c
         This way we avoid that M-A: enabled packages are installed before
         their older non-M-A enabled packages are replaced by newer versions */
       bool const installed = Pkg->CurrentVer != 0;
-      if (installed == true && Install(Pkg,FileNames[Pkg->ID]) == false)
+      if (installed == true &&
+         (instVer != Pkg.CurrentVer() ||
+          ((Cache[Pkg].iFlags & pkgDepCache::ReInstall) == pkgDepCache::ReInstall)) &&
+         Install(Pkg,FileNames[Pkg->ID]) == false)
         return false;
       for (PkgIterator P = Pkg.Group().PackageList();
           P.end() == false; P = Pkg.Group().NextPkg(P))
@@ -873,6 +902,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c
           P.end() == false; P = Pkg.Group().NextPkg(P))
       {
         if (P->CurrentVer != 0 || P == Pkg || List->IsFlag(P,pkgOrderList::UnPacked) == true ||
+            List->IsFlag(P,pkgOrderList::Configured) == true ||
             Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer &&
              (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall))
            continue;
@@ -881,7 +911,9 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c
       }
    }
    // packages which are already unpacked don't need to be unpacked again
-   else if (Pkg.State() != pkgCache::PkgIterator::NeedsConfigure && Install(Pkg,FileNames[Pkg->ID]) == false)
+   else if ((instVer != Pkg.CurrentVer() ||
+            ((Cache[Pkg].iFlags & pkgDepCache::ReInstall) == pkgDepCache::ReInstall)) &&
+           Install(Pkg,FileNames[Pkg->ID]) == false)
       return false;
 
    if (Immediate == true) {
@@ -994,33 +1026,79 @@ pkgPackageManager::OrderResult pkgPackageManager::OrderInstall()
    }
         
    return Completed;
+}
+// PM::DoInstallPostFork - compat /*{{{*/
+// ---------------------------------------------------------------------
+                                                                       /*}}}*/
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
+pkgPackageManager::OrderResult
+pkgPackageManager::DoInstallPostFork(int statusFd)
+{
+   APT::Progress::PackageManager *progress = new
+      APT::Progress::PackageManagerProgressFd(statusFd);
+   pkgPackageManager::OrderResult res = DoInstallPostFork(progress);
+   delete progress;
+   return res;
 }
                                                                        /*}}}*/
 // PM::DoInstallPostFork - Does install part that happens after the fork /*{{{*/
 // ---------------------------------------------------------------------
 pkgPackageManager::OrderResult 
-pkgPackageManager::DoInstallPostFork(int statusFd)
+pkgPackageManager::DoInstallPostFork(APT::Progress::PackageManager *progress)
 {
-      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;
+   bool goResult = Go(progress);
+   if(goResult == false) 
+      return Failed;
+   
+   return Res;
 };
+#else
+pkgPackageManager::OrderResult
+pkgPackageManager::DoInstallPostFork(int statusFd)
+{
+   bool goResult = Go(statusFd);
+   if(goResult == false) 
+      return Failed;
+   
+   return Res;
+}
+#endif
+                                                                       /*}}}*/ 
+// PM::DoInstall - Does the installation                               /*{{{*/
+// ---------------------------------------------------------------------
+/* compat */
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
+pkgPackageManager::OrderResult 
+pkgPackageManager::DoInstall(int statusFd)
+{
+    APT::Progress::PackageManager *progress = new
+       APT::Progress::PackageManagerProgressFd(statusFd);
+    OrderResult res = DoInstall(progress);
+    delete progress;
+    return res;
+ }
+#else
+pkgPackageManager::OrderResult pkgPackageManager::DoInstall(int statusFd)
+{
+   if(DoInstallPreFork() == Failed)
+      return Failed;
 
+   return DoInstallPostFork(statusFd);
+}
+#endif
+                                                                       /*}}}*/ 
 // 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 statusFd)
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
+pkgPackageManager::OrderResult 
+pkgPackageManager::DoInstall(APT::Progress::PackageManager *progress)
 {
    if(DoInstallPreFork() == Failed)
       return Failed;
    
-   return DoInstallPostFork(statusFd);
+   return DoInstallPostFork(progress);
 }
+#endif
                                                                        /*}}}*/