]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/packagemanager.cc
fix some more ABI issues, abicheck is happy now
[apt.git] / apt-pkg / packagemanager.cc
index b93bf6ab9e5fb2302c24a5e70838d6448fcd7352..3fdd9b6375e570997f42f27157efbe83f3d895b9 100644 (file)
@@ -26,7 +26,6 @@
 #include <apt-pkg/sptr.h>
 
 #include <iostream>
 #include <apt-pkg/sptr.h>
 
 #include <iostream>
-#include <fcntl.h>
 
 #include <apti18n.h>
                                                                        /*}}}*/
 
 #include <apti18n.h>
                                                                        /*}}}*/
@@ -338,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;
       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;
    unsigned int i=0;
+   std::list<DepIterator> needConfigure;
    do
    {
       Changed = false;
    do
    {
       Changed = false;
@@ -353,7 +353,7 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth)
            continue;
         Bad = true;
 
            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();
         for (DepIterator Cur = Start; true; ++Cur)
         {
            SPtrArray<Version *> VList = Cur.AllTargets();
@@ -373,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
               }
 
               // 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;
 
                  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 (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)
                  {
                     Bad = false;
                     if (List->IsFlag(DepPkg,pkgOrderList::Loop) == false)
-                       Changed = true;
+                       Changed = true;
                  }
                  if (PkgLoop == false)
                  }
                  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;
               }
                  if (Bad == false)
                     break;
               }
-              else if (List->IsFlag(DepPkg,pkgOrderList::Configured))
-              {
-                 Bad = false;
-                 break;
-              }
            }
            }
-           if (Cur == End)
+
+           if (Cur == End || Bad == false)
               break;
               break;
-         }
+        }
 
         if (Bad == false)
            continue;
 
 
         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();
         for (DepIterator Cur = Start; true; ++Cur)
         {
            SPtrArray<Version *> VList = Cur.AllTargets();
@@ -428,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
               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;
 
                  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 (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)
                  {
                     Bad = false;
                     if (List->IsFlag(DepPkg,pkgOrderList::Loop) == false)
-                       Changed = true;
+                       Changed = true;
                  }
                  if (PkgLoop == false)
                  }
                  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;
               }
                  if (Bad == false)
                     break;
               }
+              else if (List->IsFlag(DepPkg,pkgOrderList::Configured))
+              {
+                 Bad = false;
+                 break;
+              }
            }
            }
-
-           if (Cur == End)
+           if (Cur == End || Bad == false)
               break;
               break;
-        }
+         }
+
 
         if (Bad == true && Changed == false && Debug == true)
 
         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)
       }
       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) {
    } while (Changed == true);
    
    if (Bad) {
@@ -492,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 ||
           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;
             Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer &&
              (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall))
            continue;
@@ -602,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;
       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 
    {
    unsigned int i = 0;
    do 
    {
@@ -856,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;
         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))
         return false;
       for (PkgIterator P = Pkg.Group().PackageList();
           P.end() == false; P = Pkg.Group().NextPkg(P))
@@ -874,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 ||
           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;
             Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer &&
              (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall))
            continue;
@@ -882,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
       }
    }
    // 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) {
       return false;
 
    if (Immediate == true) {
@@ -995,33 +1026,79 @@ pkgPackageManager::OrderResult pkgPackageManager::OrderInstall()
    }
         
    return Completed;
    }
         
    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 
 }
                                                                        /*}}}*/
 // 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.*/
 // 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;
    
 {
    if(DoInstallPreFork() == Failed)
       return Failed;
    
-   return DoInstallPostFork(statusFd);
+   return DoInstallPostFork(progress);
 }
 }
+#endif
                                                                        /*}}}*/       
                                                                        /*}}}*/