]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/packagemanager.cc
move the status-fd progress reporting out of the pkgDPkgPM class, at this point,...
[apt.git] / apt-pkg / packagemanager.cc
index d2d2753a8fbe5d8f12fe9157344e89a0d0e715a5..32bc5284ef730f51c878ffca408a99cff174c19e 100644 (file)
@@ -338,8 +338,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;
@@ -353,7 +354,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();
@@ -373,51 +374,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();
@@ -428,44 +444,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) {
@@ -492,6 +517,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;
@@ -602,7 +628,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 
    {
@@ -856,7 +882,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))
@@ -874,6 +903,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;
@@ -1002,28 +1032,32 @@ pkgPackageManager::OrderResult pkgPackageManager::OrderInstall()
 // PM::DoInstallPostFork - Does install part that happens after the fork /*{{{*/
 // ---------------------------------------------------------------------
 pkgPackageManager::OrderResult 
-pkgPackageManager::DoInstallPostFork(int statusFd)
+pkgPackageManager::DoInstallPostFork(APT::Progress::PackageManager *progress)
 {
+// FIXME: port to new structure
+#if 0
       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);
+#endif
+      bool goResult = Go(progress);
       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 statusFd)
+pkgPackageManager::OrderResult 
+pkgPackageManager::DoInstall(APT::Progress::PackageManager *progress)
 {
    if(DoInstallPreFork() == Failed)
       return Failed;
    
-   return DoInstallPostFork(statusFd);
+   return DoInstallPostFork(progress);
 }
                                                                        /*}}}*/