]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/packagemanager.cc
Cleanup includes after running iwyu
[apt.git] / apt-pkg / packagemanager.cc
index 101912f9d107f55114ac45a91e56c0659861178a..06ec986ed7c535bad37361fbdb39f133191cd686 100644 (file)
@@ -23,7 +23,6 @@
 #include <apt-pkg/acquire-item.h>
 #include <apt-pkg/algorithms.h>
 #include <apt-pkg/configuration.h>
-#include <apt-pkg/sptr.h>
 #include <apt-pkg/macros.h>
 #include <apt-pkg/pkgcache.h>
 #include <apt-pkg/cacheiterators.h>
@@ -45,7 +44,7 @@ bool pkgPackageManager::SigINTStop = false;
 // ---------------------------------------------------------------------
 /* */
 pkgPackageManager::pkgPackageManager(pkgDepCache *pCache) : Cache(*pCache),
-                                                           List(NULL), Res(Incomplete)
+                                                           List(NULL), Res(Incomplete), d(NULL)
 {
    FileNames = new string[Cache.Head().PackageCount];
    Debug = _config->FindB("Debug::pkgPackageManager",false);
@@ -390,9 +389,9 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth)
          // to do anything at all
         for (DepIterator Cur = Start; true; ++Cur)
         {
-           SPtrArray<Version *> VList = Cur.AllTargets();
+           std::unique_ptr<Version *> VList(Cur.AllTargets());
 
-           for (Version **I = VList; *I != 0; ++I)
+           for (Version **I = VList.get(); *I != 0; ++I)
            {
               VerIterator Ver(Cache,*I);
               PkgIterator DepPkg = Ver.ParentPkg();
@@ -400,7 +399,8 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth)
               // Check if the current version of the package is available and will satisfy this dependency
               if (DepPkg.CurrentVer() == Ver && List->IsNow(DepPkg) == true &&
                   List->IsFlag(DepPkg,pkgOrderList::Removed) == false &&
-                  DepPkg.State() == PkgIterator::NeedsNothing)
+                  DepPkg.State() == PkgIterator::NeedsNothing &&
+                  (Cache[DepPkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)
               {
                  Bad = false;
                  break;
@@ -413,8 +413,13 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth)
               if (PkgLoop == true)
               {
                  if (Debug)
-                    std::clog << OutputInDepth(Depth) << "Package " << Pkg << " loops in SmartConfigure" << std::endl;
-                 Bad = false;
+                    std::clog << OutputInDepth(Depth) << "Package " << Pkg << " loops in SmartConfigure";
+                 if (List->IsFlag(DepPkg,pkgOrderList::UnPacked))
+                    Bad = false;
+                 else if (Debug)
+                    std::clog << ", but it isn't unpacked yet";
+                 if (Debug)
+                    std::clog << std::endl;
               }
            }
 
@@ -426,7 +431,7 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth)
          if (Bad == false)
          {
             if (Debug)
-               std::clog << OutputInDepth(Depth) << "Found ok dep " << D.TargetPkg() << std::endl;
+               std::clog << OutputInDepth(Depth) << "Found ok dep " << Start.TargetPkg() << std::endl;
             continue;
          }
 
@@ -434,9 +439,9 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth)
          // probably due to loops.
         for (DepIterator Cur = Start; true; ++Cur)
         {
-           SPtrArray<Version *> VList = Cur.AllTargets();
+           std::unique_ptr<Version *> VList(Cur.AllTargets());
 
-           for (Version **I = VList; *I != 0; ++I)
+           for (Version **I = VList.get(); *I != 0; ++I)
            {
               VerIterator Ver(Cache,*I);
               PkgIterator DepPkg = Ver.ParentPkg();
@@ -444,7 +449,8 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth)
               // Check if the current version of the package is available and will satisfy this dependency
               if (DepPkg.CurrentVer() == Ver && List->IsNow(DepPkg) == true &&
                   List->IsFlag(DepPkg,pkgOrderList::Removed) == false &&
-                  DepPkg.State() == PkgIterator::NeedsNothing)
+                  DepPkg.State() == PkgIterator::NeedsNothing &&
+                  (Cache[DepPkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)
                   continue;
 
               // Check if the version that is going to be installed will satisfy the dependency
@@ -454,8 +460,13 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth)
               if (PkgLoop == true)
               {
                  if (Debug)
-                    std::clog << OutputInDepth(Depth) << "Package " << Pkg << " loops in SmartConfigure" << std::endl;
-                 Bad = false;
+                    std::clog << OutputInDepth(Depth) << "Package " << Pkg << " loops in SmartConfigure";
+                 if (List->IsFlag(DepPkg,pkgOrderList::UnPacked))
+                    Bad = false;
+                 else if (Debug)
+                    std::clog << ", but it isn't unpacked yet";
+                 if (Debug)
+                    std::clog << std::endl;
               }
               else
               {
@@ -503,9 +514,9 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth)
         // Search for dependencies which are unpacked but aren't configured yet (maybe loops)
         for (DepIterator Cur = Start; true; ++Cur)
         {
-           SPtrArray<Version *> VList = Cur.AllTargets();
+           std::unique_ptr<Version *> VList(Cur.AllTargets());
 
-           for (Version **I = VList; *I != 0; ++I)
+           for (Version **I = VList.get(); *I != 0; ++I)
            {
               VerIterator Ver(Cache,*I);
               PkgIterator DepPkg = Ver.ParentPkg();
@@ -714,15 +725,16 @@ 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 = Cur.AllTargets();
-              for (Version **I = VList; *I != 0; ++I)
+              std::unique_ptr<Version *> VList(Cur.AllTargets());
+              for (Version **I = VList.get(); *I != 0; ++I)
               {
                  VerIterator Ver(Cache,*I);
                  PkgIterator Pkg = Ver.ParentPkg();
 
                  // See if the current version is ok
                  if (Pkg.CurrentVer() == Ver && List->IsNow(Pkg) == true &&
-                     Pkg.State() == PkgIterator::NeedsNothing)
+                     Pkg.State() == PkgIterator::NeedsNothing &&
+                     (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)
                  {
                     Bad = false;
                     if (Debug)
@@ -737,15 +749,18 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c
            // Look for something that could be configured.
            for (DepIterator Cur = Start; Bad == true && Cur.end() == false; ++Cur)
            {
-              SPtrArray<Version *> VList = Cur.AllTargets();
-              for (Version **I = VList; *I != 0; ++I)
+              std::unique_ptr<Version *[]> VList(Cur.AllTargets());
+              for (Version **I = VList.get(); *I != 0; ++I)
               {
                  VerIterator Ver(Cache,*I);
                  PkgIterator DepPkg = Ver.ParentPkg();
 
                  // Not the install version
-                 if (Cache[DepPkg].InstallVer != *I ||
-                     (Cache[DepPkg].Keep() == true && DepPkg.State() == PkgIterator::NeedsNothing))
+                 if (Cache[DepPkg].InstallVer != *I)
+                    continue;
+
+                 if (Cache[DepPkg].Keep() == true && DepPkg.State() == PkgIterator::NeedsNothing &&
+                       (Cache[DepPkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)
                     continue;
 
                  if (List->IsFlag(DepPkg,pkgOrderList::Configured))
@@ -757,6 +772,16 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c
                  // check if it needs unpack or if if configure is enough
                  if (List->IsFlag(DepPkg,pkgOrderList::UnPacked) == false)
                  {
+                    // two packages pre-depending on each other can't be handled sanely
+                    if (List->IsFlag(DepPkg,pkgOrderList::Loop) && PkgLoop)
+                    {
+                       // this isn't an error as there is potential for something else to satisfy it
+                       // (like a provides or an or-group member)
+                       if (Debug)
+                          clog << OutputInDepth(Depth) << "Unpack loop detected between " << DepPkg.FullName() << " and " << Pkg.FullName() << endl;
+                       continue;
+                    }
+
                     if (Debug)
                        clog << OutputInDepth(Depth) << "Trying to SmartUnpack " << DepPkg.FullName() << endl;
                     if (NonLoopingSmart(UNPACK_IMMEDIATE, Pkg, DepPkg, Depth, PkgLoop, &Bad, &Changed) == false)
@@ -780,8 +805,8 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c
                  End->Type == pkgCache::Dep::Obsoletes ||
                  End->Type == pkgCache::Dep::DpkgBreaks)
         {
-           SPtrArray<Version *> VList = End.AllTargets();
-           for (Version **I = VList; *I != 0; ++I)
+           std::unique_ptr<Version *[]> VList(End.AllTargets());
+           for (Version **I = VList.get(); *I != 0; ++I)
            {
               VerIterator Ver(Cache,*I);
               PkgIterator ConflictPkg = Ver.ParentPkg();
@@ -843,7 +868,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c
                     // but if it fails ignore this failure and look for alternative ways of solving
                     if (Debug)
                     {
-                       clog << OutputInDepth(Depth) << "Avoidance unpack of " << ConflictPkg.FullName() << " failed for " << End << std::endl;
+                       clog << OutputInDepth(Depth) << "Avoidance unpack of " << ConflictPkg.FullName() << " failed for " << End << " ignoring:" << std::endl;
                        _error->DumpErrors(std::clog);
                     }
                     _error->RevertToStack();
@@ -1059,7 +1084,6 @@ pkgPackageManager::OrderResult pkgPackageManager::OrderInstall()
 // PM::DoInstallPostFork - compat /*{{{*/
 // ---------------------------------------------------------------------
                                                                        /*}}}*/
-#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
 pkgPackageManager::OrderResult
 pkgPackageManager::DoInstallPostFork(int statusFd)
 {
@@ -1081,22 +1105,10 @@ pkgPackageManager::DoInstallPostFork(APT::Progress::PackageManager *progress)
    
    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)
 {
@@ -1106,21 +1118,11 @@ pkgPackageManager::DoInstall(int statusFd)
     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.*/
-#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
 pkgPackageManager::OrderResult 
 pkgPackageManager::DoInstall(APT::Progress::PackageManager *progress)
 {
@@ -1129,5 +1131,4 @@ pkgPackageManager::DoInstall(APT::Progress::PackageManager *progress)
    
    return DoInstallPostFork(progress);
 }
-#endif
                                                                        /*}}}*/