"Fossies" - the Fresh Open Source Software Archive

Member "apt-1.9.4/apt-pkg/packagemanager.cc" (19 Sep 2019, 41460 Bytes) of package /linux/misc/apt-1.9.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "packagemanager.cc" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.8.2_vs_1.9.2.

    1 // -*- mode: cpp; mode: fold -*-
    2 // Description                              /*{{{*/
    3 /* ######################################################################
    4 
    5    Package Manager - Abstacts the package manager
    6 
    7    More work is needed in the area of transitioning provides, ie exim
    8    replacing smail. This can cause interesting side effects.
    9 
   10    Other cases involving conflicts+replaces should be tested. 
   11    
   12    ##################################################################### */
   13                                     /*}}}*/
   14 // Include Files                            /*{{{*/
   15 #include <config.h>
   16 
   17 #include <apt-pkg/acquire-item.h>
   18 #include <apt-pkg/algorithms.h>
   19 #include <apt-pkg/configuration.h>
   20 #include <apt-pkg/depcache.h>
   21 #include <apt-pkg/edsp.h>
   22 #include <apt-pkg/error.h>
   23 #include <apt-pkg/install-progress.h>
   24 #include <apt-pkg/macros.h>
   25 #include <apt-pkg/orderlist.h>
   26 #include <apt-pkg/packagemanager.h>
   27 #include <apt-pkg/pkgcache.h>
   28 #include <apt-pkg/prettyprinters.h>
   29 #include <apt-pkg/strutl.h>
   30 #include <apt-pkg/version.h>
   31 
   32 #include <iostream>
   33 #include <list>
   34 #include <string>
   35 #include <stddef.h>
   36 
   37 #include <apti18n.h>
   38                                     /*}}}*/
   39 using namespace std;
   40 
   41 bool pkgPackageManager::SigINTStop = false;
   42 
   43 // PM::PackageManager - Constructor                 /*{{{*/
   44 // ---------------------------------------------------------------------
   45 /* */
   46 pkgPackageManager::pkgPackageManager(pkgDepCache *pCache) : Cache(*pCache),
   47                                 List(NULL), Res(Incomplete), d(NULL)
   48 {
   49    FileNames = new string[Cache.Head().PackageCount];
   50    Debug = _config->FindB("Debug::pkgPackageManager",false);
   51    NoImmConfigure = !_config->FindB("APT::Immediate-Configure",true);
   52    ImmConfigureAll = _config->FindB("APT::Immediate-Configure-All",false);
   53 }
   54                                     /*}}}*/
   55 // PM::PackageManager - Destructor                  /*{{{*/
   56 // ---------------------------------------------------------------------
   57 /* */
   58 pkgPackageManager::~pkgPackageManager()
   59 {
   60    delete List;
   61    delete [] FileNames;
   62 }
   63                                     /*}}}*/
   64 // PM::GetArchives - Queue the archives for download            /*{{{*/
   65 // ---------------------------------------------------------------------
   66 /* */
   67 bool pkgPackageManager::GetArchives(pkgAcquire *Owner,pkgSourceList *Sources,
   68                     pkgRecords *Recs)
   69 {
   70    if (CreateOrderList() == false)
   71       return false;
   72    
   73    bool const ordering =
   74     _config->FindB("PackageManager::UnpackAll",true) ?
   75         List->OrderUnpack() : List->OrderCritical();
   76    if (ordering == false)
   77       return _error->Error("Internal ordering error");
   78 
   79    for (pkgOrderList::iterator I = List->begin(); I != List->end(); ++I)
   80    {
   81       PkgIterator Pkg(Cache,*I);
   82       FileNames[Pkg->ID] = string();
   83       
   84       // Skip packages to erase
   85       if (Cache[Pkg].Delete() == true)
   86      continue;
   87 
   88       // Skip Packages that need configure only.
   89       if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure && 
   90       Cache[Pkg].Keep() == true)
   91      continue;
   92 
   93       // Skip already processed packages
   94       if (List->IsNow(Pkg) == false)
   95      continue;
   96 
   97       new pkgAcqArchive(Owner,Sources,Recs,Cache[Pkg].InstVerIter(Cache),
   98             FileNames[Pkg->ID]);
   99    }
  100 
  101    return true;
  102 }
  103                                     /*}}}*/
  104 // PM::FixMissing - Keep all missing packages               /*{{{*/
  105 // ---------------------------------------------------------------------
  106 /* This is called to correct the installation when packages could not
  107    be downloaded. */
  108 bool pkgPackageManager::FixMissing()
  109 {   
  110    pkgDepCache::ActionGroup group(Cache);
  111    pkgProblemResolver Resolve(&Cache);
  112    List->SetFileList(FileNames);
  113 
  114    bool Bad = false;
  115    for (PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
  116    {
  117       if (List->IsMissing(I) == false)
  118      continue;
  119    
  120       // Okay, this file is missing and we need it. Mark it for keep 
  121       Bad = true;
  122       Cache.MarkKeep(I, false, false);
  123    }
  124  
  125    // We have to empty the list otherwise it will not have the new changes
  126    delete List;
  127    List = 0;
  128    
  129    if (Bad == false)
  130       return true;
  131    
  132    // Now downgrade everything that is broken
  133    return Resolve.ResolveByKeep() == true && Cache.BrokenCount() == 0;   
  134 }
  135                                     /*}}}*/
  136 // PM::ImmediateAdd - Add the immediate flag recursively        /*{{{*/
  137 // ---------------------------------------------------------------------
  138 /* This adds the immediate flag to the pkg and recursively to the
  139    dependencies
  140  */
  141 void pkgPackageManager::ImmediateAdd(PkgIterator I, bool UseInstallVer, unsigned const int &Depth)
  142 {
  143    DepIterator D;
  144    
  145    if(UseInstallVer)
  146    {
  147       if(Cache[I].InstallVer == 0)
  148      return;
  149       D = Cache[I].InstVerIter(Cache).DependsList(); 
  150    } else {
  151       if (I->CurrentVer == 0)
  152      return;
  153       D = I.CurrentVer().DependsList(); 
  154    }
  155 
  156    for ( /* nothing */  ; D.end() == false; ++D)
  157       if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends)
  158       {
  159      if(!List->IsFlag(D.TargetPkg(), pkgOrderList::Immediate))
  160      {
  161         if(Debug)
  162            clog << OutputInDepth(Depth) << "ImmediateAdd(): Adding Immediate flag to " << APT::PrettyPkg(&Cache, D.TargetPkg()) << " cause of " << D.DepType() << " " << I.FullName() << endl;
  163         List->Flag(D.TargetPkg(),pkgOrderList::Immediate);
  164         ImmediateAdd(D.TargetPkg(), UseInstallVer, Depth + 1);
  165      }
  166       }
  167    return;
  168 }
  169                                     /*}}}*/
  170 // PM::CreateOrderList - Create the ordering class          /*{{{*/
  171 // ---------------------------------------------------------------------
  172 /* This populates the ordering list with all the packages that are
  173    going to change. */
  174 bool pkgPackageManager::CreateOrderList()
  175 {
  176    if (List != 0)
  177       return true;
  178    
  179    delete List;
  180    List = new pkgOrderList(&Cache);
  181 
  182    if (Debug && ImmConfigureAll) 
  183       clog << "CreateOrderList(): Adding Immediate flag for all packages because of APT::Immediate-Configure-All" << endl;
  184    
  185    // Generate the list of affected packages and sort it
  186    for (PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
  187    {
  188       // Ignore no-version packages
  189       if (I->VersionList == 0)
  190      continue;
  191       
  192       // Mark the package and its dependents for immediate configuration
  193       if ((((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential) &&
  194       NoImmConfigure == false) || ImmConfigureAll)
  195       {
  196      if(Debug && !ImmConfigureAll)
  197         clog << "CreateOrderList(): Adding Immediate flag for " << I.FullName() << endl;
  198      List->Flag(I,pkgOrderList::Immediate);
  199      
  200      if (!ImmConfigureAll) {
  201         // Look for other install packages to make immediate configurea
  202         ImmediateAdd(I, true);
  203       
  204         // And again with the current version.
  205         ImmediateAdd(I, false);
  206      }
  207       }
  208       
  209       // Not interesting
  210       if ((Cache[I].Keep() == true || 
  211       Cache[I].InstVerIter(Cache) == I.CurrentVer()) && 
  212       I.State() == pkgCache::PkgIterator::NeedsNothing &&
  213       (Cache[I].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall &&
  214       (I.Purge() != false || Cache[I].Mode != pkgDepCache::ModeDelete ||
  215        (Cache[I].iFlags & pkgDepCache::Purge) != pkgDepCache::Purge))
  216      continue;
  217       
  218       // Append it to the list
  219       List->push_back(I);      
  220    }
  221    
  222    return true;
  223 }
  224                                     /*}}}*/
  225 // PM::DepAlwaysTrue - Returns true if this dep is irrelevant       /*{{{*/
  226 // ---------------------------------------------------------------------
  227 /* The restriction on provides is to eliminate the case when provides
  228    are transitioning between valid states [ie exim to smail] */
  229 bool pkgPackageManager::DepAlwaysTrue(DepIterator D)
  230 {
  231    if (D.TargetPkg()->ProvidesList != 0)
  232       return false;
  233    
  234    if ((Cache[D] & pkgDepCache::DepInstall) != 0 &&
  235        (Cache[D] & pkgDepCache::DepNow) != 0)
  236       return true;
  237    return false;
  238 }
  239                                     /*}}}*/
  240 // PM::CheckRConflicts - Look for reverse conflicts         /*{{{*/
  241 // ---------------------------------------------------------------------
  242 /* This looks over the reverses for a conflicts line that needs early
  243    removal. */
  244 bool pkgPackageManager::CheckRConflicts(PkgIterator Pkg,DepIterator D,
  245                     const char *Ver)
  246 {
  247    for (;D.end() == false; ++D)
  248    {
  249       if (D->Type != pkgCache::Dep::Conflicts &&
  250       D->Type != pkgCache::Dep::Obsoletes)
  251      continue;
  252 
  253       // The package hasn't been changed
  254       if (List->IsNow(Pkg) == false)
  255      continue;
  256       
  257       // Ignore self conflicts, ignore conflicts from irrelevant versions
  258       if (D.IsIgnorable(Pkg) || D.ParentVer() != D.ParentPkg().CurrentVer())
  259      continue;
  260       
  261       if (Cache.VS().CheckDep(Ver,D->CompareOp,D.TargetVer()) == false)
  262      continue;
  263 
  264       if (EarlyRemove(D.ParentPkg(), &D) == false)
  265      return _error->Error("Reverse conflicts early remove for package '%s' failed",
  266                   Pkg.FullName().c_str());
  267    }
  268    return true;
  269 }
  270                                     /*}}}*/
  271 // PM::CheckRBreaks - Look for reverse breaks               /*{{{*/
  272 bool pkgPackageManager::CheckRBreaks(PkgIterator const &Pkg, DepIterator D,
  273                      const char * const Ver)
  274 {
  275    for (;D.end() == false; ++D)
  276    {
  277       if (D->Type != pkgCache::Dep::DpkgBreaks)
  278      continue;
  279 
  280       PkgIterator const DP = D.ParentPkg();
  281       if (Cache[DP].Delete() == false)
  282      continue;
  283 
  284       // Ignore self conflicts, ignore conflicts from irrelevant versions
  285       if (D.IsIgnorable(Pkg) || D.ParentVer() != DP.CurrentVer())
  286      continue;
  287 
  288       if (Cache.VS().CheckDep(Ver, D->CompareOp, D.TargetVer()) == false)
  289      continue;
  290 
  291       // no earlyremove() here as user has already agreed to the permanent removal
  292       if (SmartRemove(DP) == false)
  293      return _error->Error("Internal Error, Could not early remove %s (%d)",DP.FullName().c_str(), 4);
  294    }
  295    return true;
  296 }
  297                                     /*}}}*/
  298 // PM::ConfigureAll - Run the all out configuration         /*{{{*/
  299 // ---------------------------------------------------------------------
  300 /* This configures every package. It is assumed they are all unpacked and
  301    that the final configuration is valid. This is also used to catch packages
  302    that have not been configured when using ImmConfigureAll */
  303 bool pkgPackageManager::ConfigureAll()
  304 {
  305    pkgOrderList OList(&Cache);
  306    
  307    // Populate the order list
  308    for (pkgOrderList::iterator I = List->begin(); I != List->end(); ++I)
  309       if (List->IsFlag(pkgCache::PkgIterator(Cache,*I),
  310                pkgOrderList::UnPacked) == true)
  311      OList.push_back(*I);
  312    
  313    if (OList.OrderConfigure() == false)
  314       return false;
  315 
  316    std::string const conf = _config->Find("PackageManager::Configure", "smart");
  317    bool const ConfigurePkgs = (ImmConfigureAll || conf == "all");
  318 
  319    // Perform the configuring
  320    for (pkgOrderList::iterator I = OList.begin(); I != OList.end(); ++I)
  321    {
  322       PkgIterator Pkg(Cache,*I);
  323       
  324       /* Check if the package has been configured, this can happen if SmartConfigure
  325          calls its self */ 
  326       if (List->IsFlag(Pkg,pkgOrderList::Configured)) continue;
  327 
  328       if (ConfigurePkgs == true && SmartConfigure(Pkg, 0) == false) {
  329          if (ImmConfigureAll)
  330             _error->Error(_("Could not perform immediate configuration on '%s'. "
  331             "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.FullName().c_str(),1);
  332          else
  333             _error->Error("Internal error, packages left unconfigured. %s",Pkg.FullName().c_str());
  334      return false;
  335       }
  336       
  337       List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States);
  338    }
  339    
  340    return true;
  341 }
  342                                     /*}}}*/
  343 // PM::NonLoopingSmart - helper to avoid loops while calling Smart methods /*{{{*/
  344 // -----------------------------------------------------------------------
  345 /* ensures that a loop of the form A depends B, B depends A (and similar)
  346    is not leading us down into infinite recursion segfault land */
  347 bool pkgPackageManager::NonLoopingSmart(SmartAction const action, pkgCache::PkgIterator &Pkg,
  348       pkgCache::PkgIterator DepPkg, int const Depth, bool const PkgLoop,
  349       bool * const Bad, bool * const Changed)
  350 {
  351    if (PkgLoop == false)
  352       List->Flag(Pkg,pkgOrderList::Loop);
  353    bool success = false;
  354    switch(action)
  355    {
  356       case UNPACK_IMMEDIATE: success = SmartUnPack(DepPkg, true, Depth + 1); break;
  357       case UNPACK: success = SmartUnPack(DepPkg, false, Depth + 1); break;
  358       case CONFIGURE: success = SmartConfigure(DepPkg, Depth + 1); break;
  359    }
  360    if (PkgLoop == false)
  361       List->RmFlag(Pkg,pkgOrderList::Loop);
  362 
  363    if (success == false)
  364       return false;
  365 
  366    if (Bad != NULL)
  367       *Bad = false;
  368    if (Changed != NULL && List->IsFlag(DepPkg,pkgOrderList::Loop) == false)
  369       *Changed = true;
  370    return true;
  371 }
  372                                     /*}}}*/
  373 // PM::SmartConfigure - Perform immediate configuration of the pkg  /*{{{*/
  374 // ---------------------------------------------------------------------
  375 /* This function tries to put the system in a state where Pkg can be configured.
  376    This involves checking each of Pkg's dependencies and unpacking and
  377    configuring packages where needed. */
  378 bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth)
  379 {
  380    // If this is true, only check and correct and dependencies without the Loop flag
  381    bool const PkgLoop = List->IsFlag(Pkg,pkgOrderList::Loop);
  382 
  383    if (Debug) {
  384       VerIterator InstallVer = VerIterator(Cache,Cache[Pkg].InstallVer);
  385       clog << OutputInDepth(Depth) << "SmartConfigure " << Pkg.FullName() << " (" << InstallVer.VerStr() << ")";
  386       if (PkgLoop)
  387         clog << " (Only Correct Dependencies)";
  388       clog << endl;
  389    }
  390 
  391    VerIterator const instVer = Cache[Pkg].InstVerIter(Cache);
  392 
  393    /* Because of the ordered list, most dependencies should be unpacked,
  394       however if there is a loop (A depends on B, B depends on A) this will not
  395       be the case, so check for dependencies before configuring. */
  396    bool Bad = false, Changed = false;
  397    const unsigned int max_loops = _config->FindI("APT::pkgPackageManager::MaxLoopCount", 5000);
  398    unsigned int i=0;
  399    std::list<DepIterator> needConfigure;
  400    do
  401    {
  402       // Check each dependency and see if anything needs to be done
  403       // so that it can be configured
  404       Changed = false;
  405       for (DepIterator D = instVer.DependsList(); D.end() == false; )
  406       {
  407      // Compute a single dependency element (glob or)
  408      pkgCache::DepIterator Start, End;
  409      D.GlobOr(Start,End);
  410 
  411      if (End->Type != pkgCache::Dep::Depends && End->Type != pkgCache::Dep::PreDepends)
  412         continue;
  413      Bad = true;
  414 
  415          // the first pass checks if we its all good, i.e. if we have
  416          // to do anything at all
  417      for (DepIterator Cur = Start; true; ++Cur)
  418      {
  419         std::unique_ptr<Version *[]> VList(Cur.AllTargets());
  420 
  421         for (Version **I = VList.get(); *I != 0; ++I)
  422         {
  423            VerIterator Ver(Cache,*I);
  424            PkgIterator DepPkg = Ver.ParentPkg();
  425 
  426            // Check if the current version of the package is available and will satisfy this dependency
  427            if (DepPkg.CurrentVer() == Ver && List->IsNow(DepPkg) == true &&
  428            List->IsFlag(DepPkg,pkgOrderList::Removed) == false &&
  429            DepPkg.State() == PkgIterator::NeedsNothing &&
  430            (Cache[DepPkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)
  431            {
  432           Bad = false;
  433           break;
  434            }
  435 
  436            // Check if the version that is going to be installed will satisfy the dependency
  437            if (Cache[DepPkg].InstallVer != *I || List->IsNow(DepPkg) == false)
  438           continue;
  439 
  440            if (PkgLoop == true)
  441            {
  442           if (Debug)
  443              std::clog << OutputInDepth(Depth) << "Package " << APT::PrettyPkg(&Cache, Pkg) << " loops in SmartConfigure";
  444           if (List->IsFlag(DepPkg,pkgOrderList::UnPacked))
  445              Bad = false;
  446           else if (Debug)
  447              std::clog << ", but it isn't unpacked yet";
  448           if (Debug)
  449              std::clog << std::endl;
  450            }
  451         }
  452 
  453             if (Cur == End || Bad == false)
  454            break;
  455          }
  456 
  457          // this dependency is in a good state, so we can stop
  458          if (Bad == false)
  459          {
  460             if (Debug)
  461                std::clog << OutputInDepth(Depth) << "Found ok dep " << APT::PrettyPkg(&Cache, Start.TargetPkg()) << std::endl;
  462             continue;
  463          }
  464 
  465      // Check for dependencies that have not been unpacked, 
  466          // probably due to loops.
  467      for (DepIterator Cur = Start; true; ++Cur)
  468      {
  469         std::unique_ptr<Version *[]> VList(Cur.AllTargets());
  470 
  471         for (Version **I = VList.get(); *I != 0; ++I)
  472         {
  473            VerIterator Ver(Cache,*I);
  474            PkgIterator DepPkg = Ver.ParentPkg();
  475 
  476            // Check if the current version of the package is available and will satisfy this dependency
  477            if (DepPkg.CurrentVer() == Ver && List->IsNow(DepPkg) == true &&
  478            List->IsFlag(DepPkg,pkgOrderList::Removed) == false &&
  479            DepPkg.State() == PkgIterator::NeedsNothing &&
  480            (Cache[DepPkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)
  481                   continue;
  482 
  483            // Check if the version that is going to be installed will satisfy the dependency
  484            if (Cache[DepPkg].InstallVer != *I || List->IsNow(DepPkg) == false)
  485           continue;
  486 
  487            if (PkgLoop == true)
  488            {
  489           if (Debug)
  490              std::clog << OutputInDepth(Depth) << "Package " << APT::PrettyPkg(&Cache, Pkg) << " loops in SmartConfigure";
  491           if (List->IsFlag(DepPkg,pkgOrderList::UnPacked))
  492              Bad = false;
  493           else if (Debug)
  494              std::clog << ", but it isn't unpacked yet";
  495           if (Debug)
  496              std::clog << std::endl;
  497            }
  498            else
  499            {
  500           if (Debug)
  501              clog << OutputInDepth(Depth) << "Unpacking " << DepPkg.FullName() << " to avoid loop " << APT::PrettyDep(&Cache, Cur) << endl;
  502           if (NonLoopingSmart(UNPACK_IMMEDIATE, Pkg, DepPkg, Depth, PkgLoop, &Bad, &Changed) == false)
  503              return false;
  504            }
  505                // at this point we either unpacked a Dep or we are in a loop,
  506                // no need to unpack a second one
  507            break;
  508         }
  509 
  510         if (Cur == End || Bad == false)
  511            break;
  512      }
  513 
  514      if (Bad == false)
  515         continue;
  516 
  517      needConfigure.push_back(Start);
  518       }
  519       if (i++ > max_loops)
  520          return _error->Error("Internal error: MaxLoopCount reached in SmartUnPack (1) for %s, aborting", Pkg.FullName().c_str());
  521    } while (Changed == true);
  522 
  523    // now go over anything that needs configuring
  524    Bad = false, Changed = false, i = 0;
  525    do
  526    {
  527       Changed = false;
  528       for (std::list<DepIterator>::const_iterator D = needConfigure.begin(); D != needConfigure.end(); ++D)
  529       {
  530      // Compute a single dependency element (glob or) without modifying D
  531      pkgCache::DepIterator Start, End;
  532      {
  533         pkgCache::DepIterator Discard = *D;
  534         Discard.GlobOr(Start,End);
  535      }
  536 
  537      if (End->Type != pkgCache::Dep::Depends && End->Type != pkgCache::Dep::PreDepends)
  538         continue;
  539      Bad = true;
  540 
  541      // Search for dependencies which are unpacked but aren't configured yet (maybe loops)
  542      for (DepIterator Cur = Start; true; ++Cur)
  543      {
  544         std::unique_ptr<Version *[]> VList(Cur.AllTargets());
  545 
  546         for (Version **I = VList.get(); *I != 0; ++I)
  547         {
  548            VerIterator Ver(Cache,*I);
  549            PkgIterator DepPkg = Ver.ParentPkg();
  550 
  551            // Check if the version that is going to be installed will satisfy the dependency
  552            if (Cache[DepPkg].InstallVer != *I)
  553           continue;
  554 
  555            if (List->IsFlag(DepPkg,pkgOrderList::UnPacked))
  556            {
  557           if (List->IsFlag(DepPkg,pkgOrderList::Loop) && PkgLoop)
  558           {
  559             // This dependency has already been dealt with by another SmartConfigure on Pkg
  560             Bad = false;
  561             break;
  562           }
  563           if (Debug)
  564              std::clog << OutputInDepth(Depth) << "Configure already unpacked " << APT::PrettyPkg(&Cache, DepPkg) << std::endl;
  565           if (NonLoopingSmart(CONFIGURE, Pkg, DepPkg, Depth, PkgLoop, &Bad, &Changed) == false)
  566              return false;
  567           break;
  568 
  569            }
  570            else if (List->IsFlag(DepPkg,pkgOrderList::Configured))
  571            {
  572           Bad = false;
  573           break;
  574            }
  575         }
  576         if (Cur == End || Bad == false)
  577            break;
  578          }
  579 
  580 
  581      if (Bad == true && Changed == false && Debug == true)
  582         std::clog << OutputInDepth(Depth) << "Could not satisfy " << APT::PrettyDep(&Cache, *D) << std::endl;
  583       }
  584       if (i++ > max_loops)
  585          return _error->Error("Internal error: MaxLoopCount reached in SmartUnPack (2) for %s, aborting", Pkg.FullName().c_str());
  586    } while (Changed == true);
  587 
  588    if (Bad == true)
  589       return _error->Error(_("Could not configure '%s'. "),Pkg.FullName().c_str());
  590 
  591    // Check for reverse conflicts.
  592    if (CheckRBreaks(Pkg,Pkg.RevDependsList(), instVer.VerStr()) == false)
  593       return false;
  594 
  595    for (PrvIterator P = instVer.ProvidesList(); P.end() == false; ++P)
  596       if (Pkg->Group != P.OwnerPkg()->Group)
  597      CheckRBreaks(Pkg,P.ParentPkg().RevDependsList(),P.ProvideVersion());
  598 
  599    if (PkgLoop) return true;
  600 
  601    static std::string const conf = _config->Find("PackageManager::Configure", "smart");
  602    static bool const ConfigurePkgs = (conf == "all" || conf == "smart");
  603 
  604    if (List->IsFlag(Pkg,pkgOrderList::Configured))
  605       return _error->Error("Internal configure error on '%s'.", Pkg.FullName().c_str());
  606 
  607    if (ConfigurePkgs == true && Configure(Pkg) == false)
  608       return false;
  609 
  610    List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States);
  611 
  612    if ((Cache[Pkg].InstVerIter(Cache)->MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same)
  613       for (PkgIterator P = Pkg.Group().PackageList();
  614        P.end() == false; P = Pkg.Group().NextPkg(P))
  615       {
  616      if (Pkg == P || List->IsFlag(P,pkgOrderList::Configured) == true ||
  617          List->IsFlag(P,pkgOrderList::UnPacked) == false ||
  618          Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer &&
  619           (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall))
  620         continue;
  621      if (SmartConfigure(P, (Depth +1)) == false)
  622         return false;
  623       }
  624 
  625    // Sanity Check
  626    if (List->IsFlag(Pkg,pkgOrderList::Configured) == false)
  627       return _error->Error(_("Could not configure '%s'. "),Pkg.FullName().c_str());
  628 
  629    return true;
  630 }
  631                                     /*}}}*/
  632 // PM::EarlyRemove - Perform removal of packages before their time  /*{{{*/
  633 // ---------------------------------------------------------------------
  634 /* This is called to deal with conflicts arising from unpacking */
  635 bool pkgPackageManager::EarlyRemove(PkgIterator Pkg, DepIterator const * const Dep)
  636 {
  637    if (List->IsNow(Pkg) == false)
  638       return true;
  639 
  640    // Already removed it
  641    if (List->IsFlag(Pkg,pkgOrderList::Removed) == true)
  642       return true;
  643 
  644    // Woops, it will not be re-installed!
  645    if (List->IsFlag(Pkg,pkgOrderList::InList) == false)
  646       return false;
  647 
  648    // these breaks on M-A:same packages can be dealt with. They 'loop' by design
  649    if (Dep != NULL && (*Dep)->Type == pkgCache::Dep::DpkgBreaks && Dep->IsMultiArchImplicit() == true)
  650       return true;
  651 
  652    // Essential packages get special treatment
  653    bool IsEssential = false;
  654    if ((Pkg->Flags & pkgCache::Flag::Essential) != 0 ||
  655        (Pkg->Flags & pkgCache::Flag::Important) != 0)
  656       IsEssential = true;
  657 
  658    /* Check for packages that are the dependents of essential packages and
  659       promote them too */
  660    if (Pkg->CurrentVer != 0)
  661    {
  662       for (pkgCache::DepIterator D = Pkg.RevDependsList(); D.end() == false &&
  663        IsEssential == false; ++D)
  664      if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends)
  665         if ((D.ParentPkg()->Flags & pkgCache::Flag::Essential) != 0 ||
  666             (D.ParentPkg()->Flags & pkgCache::Flag::Important) != 0)
  667            IsEssential = true;
  668    }
  669 
  670    if (IsEssential == true)
  671    {
  672       if (_config->FindB("APT::Force-LoopBreak",false) == false)
  673      return _error->Error(_("This installation run will require temporarily "
  674                 "removing the essential package %s due to a "
  675                 "Conflicts/Pre-Depends loop. This is often bad, "
  676                 "but if you really want to do it, activate the "
  677                 "APT::Force-LoopBreak option."),Pkg.FullName().c_str());
  678    }
  679    // dpkg will auto-deconfigure it, no need for the big remove hammer
  680    else if (Dep != NULL && (*Dep)->Type == pkgCache::Dep::DpkgBreaks)
  681       return true;
  682 
  683    bool Res = SmartRemove(Pkg);
  684    if (Cache[Pkg].Delete() == false)
  685       List->Flag(Pkg,pkgOrderList::Removed,pkgOrderList::States);
  686 
  687    return Res;
  688 }
  689                                     /*}}}*/
  690 // PM::SmartRemove - Removal Helper                 /*{{{*/
  691 // ---------------------------------------------------------------------
  692 /* */
  693 bool pkgPackageManager::SmartRemove(PkgIterator Pkg)
  694 {
  695    if (List->IsNow(Pkg) == false)
  696       return true;
  697 
  698    List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States);
  699 
  700    return Remove(Pkg,(Cache[Pkg].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge);
  701 }
  702                                     /*}}}*/
  703 // PM::SmartUnPack - Install helper                 /*{{{*/
  704 // ---------------------------------------------------------------------
  705 /* This puts the system in a state where it can Unpack Pkg, if Pkg is already
  706    unpacked, or when it has been unpacked, if Immediate==true it configures it. */
  707 bool pkgPackageManager::SmartUnPack(PkgIterator Pkg)
  708 {
  709    return SmartUnPack(Pkg, true, 0);
  710 }
  711 bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int const Depth)
  712 {
  713    bool PkgLoop = List->IsFlag(Pkg,pkgOrderList::Loop);
  714 
  715    if (Debug) {
  716       clog << OutputInDepth(Depth) << "SmartUnPack " << Pkg.FullName();
  717       VerIterator InstallVer = VerIterator(Cache,Cache[Pkg].InstallVer);
  718       if (Pkg.CurrentVer() == 0)
  719         clog << " (install version " << InstallVer.VerStr() << ")";
  720       else
  721         clog << " (replace version " << Pkg.CurrentVer().VerStr() << " with " << InstallVer.VerStr() << ")";
  722       if (PkgLoop)
  723         clog << " (Only Perform PreUnpack Checks)";
  724       if (Immediate)
  725      clog << " immediately";
  726       clog << endl;
  727    }
  728 
  729    VerIterator const instVer = Cache[Pkg].InstVerIter(Cache);
  730 
  731    /* PreUnpack Checks: This loop checks and attempts to rectify any problems that would prevent the package being unpacked.
  732       It addresses: PreDepends, Conflicts, Obsoletes and Breaks (DpkgBreaks). Any resolutions that do not require it should
  733       avoid configuration (calling SmartUnpack with Immediate=true), this is because when unpacking some packages with
  734       complex dependency structures, trying to configure some packages while breaking the loops can complicate things.
  735       This will be either dealt with if the package is configured as a dependency of Pkg (if and when Pkg is configured),
  736       or by the ConfigureAll call at the end of the for loop in OrderInstall. */
  737    bool SomethingBad = false, Changed = false;
  738    bool couldBeTemporaryRemoved = Depth != 0 && List->IsFlag(Pkg,pkgOrderList::Removed) == false;
  739    const unsigned int max_loops = _config->FindI("APT::pkgPackageManager::MaxLoopCount", 5000);
  740    unsigned int i = 0;
  741    do 
  742    {
  743       Changed = false;
  744       for (DepIterator D = instVer.DependsList(); D.end() == false; )
  745       {
  746      // Compute a single dependency element (glob or)
  747      pkgCache::DepIterator Start, End;
  748      D.GlobOr(Start,End);
  749 
  750      if (End->Type == pkgCache::Dep::PreDepends)
  751          {
  752         bool Bad = true;
  753         if (Debug)
  754            clog << OutputInDepth(Depth) << "PreDepends order for " << Pkg.FullName() << std::endl;
  755 
  756         // Look for easy targets: packages that are already okay
  757         for (DepIterator Cur = Start; Bad == true; ++Cur)
  758         {
  759            std::unique_ptr<Version *[]> VList(Cur.AllTargets());
  760            for (Version **I = VList.get(); *I != 0; ++I)
  761            {
  762           VerIterator Ver(Cache,*I);
  763           PkgIterator Pkg = Ver.ParentPkg();
  764 
  765           // See if the current version is ok
  766           if (Pkg.CurrentVer() == Ver && List->IsNow(Pkg) == true &&
  767               Pkg.State() == PkgIterator::NeedsNothing &&
  768               (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)
  769           {
  770              Bad = false;
  771              if (Debug)
  772             clog << OutputInDepth(Depth) << "Found ok package " << Pkg.FullName() << endl;
  773              break;
  774           }
  775            }
  776            if (Cur == End)
  777           break;
  778         }
  779 
  780         // Look for something that could be configured.
  781         for (DepIterator Cur = Start; Bad == true && Cur.end() == false; ++Cur)
  782         {
  783            std::unique_ptr<Version *[]> VList(Cur.AllTargets());
  784            for (Version **I = VList.get(); *I != 0; ++I)
  785            {
  786           VerIterator Ver(Cache,*I);
  787           PkgIterator DepPkg = Ver.ParentPkg();
  788 
  789           // Not the install version
  790           if (Cache[DepPkg].InstallVer != *I)
  791              continue;
  792 
  793           if (Cache[DepPkg].Keep() == true && DepPkg.State() == PkgIterator::NeedsNothing &&
  794             (Cache[DepPkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)
  795              continue;
  796 
  797           if (List->IsFlag(DepPkg,pkgOrderList::Configured))
  798           {
  799              Bad = false;
  800              break;
  801           }
  802 
  803           // check if it needs unpack or if configure is enough
  804           if (List->IsFlag(DepPkg,pkgOrderList::UnPacked) == false)
  805           {
  806              // two packages pre-depending on each other can't be handled sanely
  807              if (List->IsFlag(DepPkg,pkgOrderList::Loop) && PkgLoop)
  808              {
  809             // this isn't an error as there is potential for something else to satisfy it
  810             // (like a provides or an or-group member)
  811             if (Debug)
  812                clog << OutputInDepth(Depth) << "Unpack loop detected between " << DepPkg.FullName() << " and " << Pkg.FullName() << endl;
  813             continue;
  814              }
  815 
  816              if (Debug)
  817             clog << OutputInDepth(Depth) << "Trying to SmartUnpack " << DepPkg.FullName() << endl;
  818              if (NonLoopingSmart(UNPACK_IMMEDIATE, Pkg, DepPkg, Depth, PkgLoop, &Bad, &Changed) == false)
  819             return false;
  820           }
  821           else
  822           {
  823              if (Debug)
  824             clog << OutputInDepth(Depth) << "Trying to SmartConfigure " << DepPkg.FullName() << endl;
  825              if (NonLoopingSmart(CONFIGURE, Pkg, DepPkg, Depth, PkgLoop, &Bad, &Changed) == false)
  826             return false;
  827           }
  828           break;
  829            }
  830         }
  831 
  832         if (Bad == true)
  833            SomethingBad = true;
  834      }
  835      else if (End->Type == pkgCache::Dep::Conflicts ||
  836           End->Type == pkgCache::Dep::Obsoletes ||
  837           End->Type == pkgCache::Dep::DpkgBreaks)
  838      {
  839         std::unique_ptr<Version *[]> VList(End.AllTargets());
  840         for (Version **I = VList.get(); *I != 0; ++I)
  841         {
  842            VerIterator Ver(Cache,*I);
  843            PkgIterator ConflictPkg = Ver.ParentPkg();
  844            if (ConflictPkg.CurrentVer() != Ver)
  845            {
  846           if (Debug)
  847              std::clog << OutputInDepth(Depth) << "Ignore not-installed version " << Ver.VerStr() << " of " << ConflictPkg.FullName() << " for " << APT::PrettyDep(&Cache, End) << std::endl;
  848           continue;
  849            }
  850 
  851            if (List->IsNow(ConflictPkg) == false)
  852            {
  853           if (Debug)
  854              std::clog << OutputInDepth(Depth) << "Ignore already dealt-with version " << Ver.VerStr() << " of " << ConflictPkg.FullName() << " for " << APT::PrettyDep(&Cache, End) << std::endl;
  855           continue;
  856            }
  857 
  858            if (List->IsFlag(ConflictPkg,pkgOrderList::Removed) == true)
  859            {
  860           if (Debug)
  861              clog << OutputInDepth(Depth) << "Ignoring " << APT::PrettyDep(&Cache, End) << " as " << ConflictPkg.FullName() << "was temporarily removed" << endl;
  862           continue;
  863            }
  864 
  865            if (List->IsFlag(ConflictPkg,pkgOrderList::Loop) && PkgLoop)
  866            {
  867           if (End->Type == pkgCache::Dep::DpkgBreaks && End.IsMultiArchImplicit() == true)
  868           {
  869              if (Debug)
  870             clog << OutputInDepth(Depth) << "Because dependency is MultiArchImplicit we ignored looping on: " << APT::PrettyPkg(&Cache, ConflictPkg) << endl;
  871              continue;
  872           }
  873           if (Debug)
  874           {
  875              if (End->Type == pkgCache::Dep::DpkgBreaks)
  876             clog << OutputInDepth(Depth) << "Because of breaks knot, deconfigure " << ConflictPkg.FullName() << " temporarily" << endl;
  877              else
  878             clog << OutputInDepth(Depth) << "Because of conflict knot, removing " << ConflictPkg.FullName() << " temporarily" << endl;
  879           }
  880           if (EarlyRemove(ConflictPkg, &End) == false)
  881              return _error->Error("Internal Error, Could not early remove %s (%d)",ConflictPkg.FullName().c_str(), 3);
  882           SomethingBad = true;
  883           continue;
  884            }
  885 
  886            if (Cache[ConflictPkg].Delete() == false)
  887            {
  888           if (Debug)
  889           {
  890              clog << OutputInDepth(Depth) << "Unpacking " << ConflictPkg.FullName() << " to avoid " << APT::PrettyDep(&Cache, End);
  891              if (PkgLoop == true)
  892             clog << " (Looping)";
  893              clog << std::endl;
  894           }
  895           // we would like to avoid temporary removals and all that at best via a simple unpack
  896           _error->PushToStack();
  897           if (NonLoopingSmart(UNPACK, Pkg, ConflictPkg, Depth, PkgLoop, NULL, &Changed) == false)
  898           {
  899              // but if it fails ignore this failure and look for alternative ways of solving
  900              if (Debug)
  901              {
  902             clog << OutputInDepth(Depth) << "Avoidance unpack of " << ConflictPkg.FullName() << " failed for " << APT::PrettyDep(&Cache, End) << " ignoring:" << std::endl;
  903             _error->DumpErrors(std::clog, GlobalError::DEBUG, false);
  904              }
  905              _error->RevertToStack();
  906              // ignorance can only happen if a) one of the offenders is already gone
  907              if (List->IsFlag(ConflictPkg,pkgOrderList::Removed) == true)
  908              {
  909             if (Debug)
  910                clog << OutputInDepth(Depth) << "But " << ConflictPkg.FullName() << " was temporarily removed in the meantime to satisfy " << APT::PrettyDep(&Cache, End) << endl;
  911              }
  912              else if (List->IsFlag(Pkg,pkgOrderList::Removed) == true)
  913              {
  914             if (Debug)
  915                clog << OutputInDepth(Depth) << "But " << Pkg.FullName() << " was temporarily removed in the meantime to satisfy " <<  APT::PrettyDep(&Cache, End) << endl;
  916              }
  917              // or b) we can make one go (removal or dpkg auto-deconfigure)
  918              else
  919              {
  920             if (Debug)
  921                clog << OutputInDepth(Depth) << "So temporary remove/deconfigure " << ConflictPkg.FullName() << " to satisfy " <<  APT::PrettyDep(&Cache, End) << endl;
  922             if (EarlyRemove(ConflictPkg, &End) == false)
  923                return _error->Error("Internal Error, Could not early remove %s (%d)",ConflictPkg.FullName().c_str(), 2);
  924              }
  925           }
  926           else
  927              _error->MergeWithStack();
  928            }
  929            else
  930            {
  931           if (Debug)
  932              clog << OutputInDepth(Depth) << "Removing " << ConflictPkg.FullName() << " now to avoid " << APT::PrettyDep(&Cache, End) << endl;
  933           // no earlyremove() here as user has already agreed to the permanent removal
  934           if (SmartRemove(ConflictPkg) == false)
  935              return _error->Error("Internal Error, Could not early remove %s (%d)",ConflictPkg.FullName().c_str(), 1);
  936            }
  937         }
  938      }
  939       }
  940       if (i++ > max_loops)
  941          return _error->Error("Internal error: APT::pkgPackageManager::MaxLoopCount reached in SmartConfigure for %s, aborting", Pkg.FullName().c_str());
  942    } while (Changed == true);
  943 
  944    if (SomethingBad == true)
  945       return _error->Error("Couldn't configure %s, probably a dependency cycle.", Pkg.FullName().c_str());
  946 
  947    if (couldBeTemporaryRemoved == true && List->IsFlag(Pkg,pkgOrderList::Removed) == true)
  948    {
  949       if (Debug)
  950      std::clog << OutputInDepth(Depth) << "Prevent unpack as " << APT::PrettyPkg(&Cache, Pkg) << " is currently temporarily removed" << std::endl;
  951       return true;
  952    }
  953 
  954    // Check for reverse conflicts.
  955    if (CheckRConflicts(Pkg,Pkg.RevDependsList(),
  956            instVer.VerStr()) == false)
  957                   return false;
  958    
  959    for (PrvIterator P = instVer.ProvidesList();
  960     P.end() == false; ++P)
  961       if (Pkg->Group != P.OwnerPkg()->Group)
  962      CheckRConflicts(Pkg,P.ParentPkg().RevDependsList(),P.ProvideVersion());
  963 
  964    if (PkgLoop)
  965       return true;
  966 
  967    List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States);
  968 
  969    if (Immediate == true && (instVer->MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same)
  970    {
  971       /* Do lockstep M-A:same unpacking in two phases:
  972      First unpack all installed architectures, then the not installed.
  973      This way we avoid that M-A: enabled packages are installed before
  974      their older non-M-A enabled packages are replaced by newer versions */
  975       bool const installed = Pkg->CurrentVer != 0;
  976       if (installed == true &&
  977       (instVer != Pkg.CurrentVer() ||
  978        ((Cache[Pkg].iFlags & pkgDepCache::ReInstall) == pkgDepCache::ReInstall)) &&
  979       Install(Pkg,FileNames[Pkg->ID]) == false)
  980      return false;
  981       for (PkgIterator P = Pkg.Group().PackageList();
  982        P.end() == false; P = Pkg.Group().NextPkg(P))
  983       {
  984      if (P->CurrentVer == 0 || P == Pkg || List->IsFlag(P,pkgOrderList::UnPacked) == true ||
  985          Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer &&
  986           (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall))
  987         continue;
  988      if (SmartUnPack(P, false, Depth + 1) == false)
  989         return false;
  990       }
  991       if (installed == false && Install(Pkg,FileNames[Pkg->ID]) == false)
  992      return false;
  993       for (PkgIterator P = Pkg.Group().PackageList();
  994        P.end() == false; P = Pkg.Group().NextPkg(P))
  995       {
  996      if (P->CurrentVer != 0 || P == Pkg || List->IsFlag(P,pkgOrderList::UnPacked) == true ||
  997          List->IsFlag(P,pkgOrderList::Configured) == true ||
  998          Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer &&
  999           (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall))
 1000         continue;
 1001      if (SmartUnPack(P, false, Depth + 1) == false)
 1002         return false;
 1003       }
 1004    }
 1005    // packages which are already unpacked don't need to be unpacked again
 1006    else if ((instVer != Pkg.CurrentVer() ||
 1007          ((Cache[Pkg].iFlags & pkgDepCache::ReInstall) == pkgDepCache::ReInstall)) &&
 1008         Install(Pkg,FileNames[Pkg->ID]) == false)
 1009       return false;
 1010 
 1011    if (Immediate == true) {
 1012       // Perform immediate configuration of the package. 
 1013          if (SmartConfigure(Pkg, Depth + 1) == false)
 1014             _error->Error(_("Could not perform immediate configuration on '%s'. "
 1015                "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.FullName().c_str(),2);
 1016    }
 1017    
 1018    return true;
 1019 }
 1020                                     /*}}}*/
 1021 // PM::OrderInstall - Installation ordering routine         /*{{{*/
 1022 // ---------------------------------------------------------------------
 1023 /* */
 1024 pkgPackageManager::OrderResult pkgPackageManager::OrderInstall()
 1025 {
 1026    if (CreateOrderList() == false)
 1027       return Failed;
 1028 
 1029    Reset();
 1030 
 1031    if (Debug == true)
 1032       clog << "Beginning to order" << endl;
 1033 
 1034    std::string const planner = _config->Find("APT::Planner", "internal");
 1035    unsigned int flags = 0;
 1036    if (_config->FindB("APT::Immediate-Configure", true) == false)
 1037       flags |= EIPP::Request::NO_IMMEDIATE_CONFIGURATION;
 1038    else if (_config->FindB("APT::Immediate-Configure-All", false))
 1039       flags |= EIPP::Request::IMMEDIATE_CONFIGURATION_ALL;
 1040    else if (_config->FindB("APT::Force-LoopBreak", false))
 1041       flags |= EIPP::Request::ALLOW_TEMPORARY_REMOVE_OF_ESSENTIALS;
 1042    auto const ret = EIPP::OrderInstall(planner.c_str(), this, flags, nullptr);
 1043    if (planner != "internal")
 1044       return ret ? Completed : Failed;
 1045 
 1046    bool const ordering =
 1047     _config->FindB("PackageManager::UnpackAll",true) ?
 1048         List->OrderUnpack(FileNames) : List->OrderCritical();
 1049    if (ordering == false)
 1050    {
 1051       _error->Error("Internal ordering error");
 1052       return Failed;
 1053    }
 1054 
 1055    if (Debug == true)
 1056       clog << "Done ordering" << endl;
 1057 
 1058    bool DoneSomething = false;
 1059    for (pkgOrderList::iterator I = List->begin(); I != List->end(); ++I)
 1060    {
 1061       PkgIterator Pkg(Cache,*I);
 1062 
 1063       if (List->IsNow(Pkg) == false)
 1064       {
 1065      if (Debug == true)
 1066         clog << "Skipping already done " << Pkg.FullName() << endl;
 1067      continue;
 1068       }
 1069 
 1070       if (List->IsMissing(Pkg) == true)
 1071       {
 1072      if (Debug == true)
 1073         clog << "Sequence completed at " << Pkg.FullName() << endl;
 1074      if (DoneSomething == false)
 1075      {
 1076         _error->Error("Internal Error, ordering was unable to handle the media swap");
 1077         return Failed;
 1078      }   
 1079      return Incomplete;
 1080       }
 1081       
 1082       // Sanity check
 1083       if (Cache[Pkg].Keep() == true && 
 1084       Pkg.State() == pkgCache::PkgIterator::NeedsNothing &&
 1085       (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)
 1086       {
 1087      _error->Error("Internal Error, trying to manipulate a kept package (%s)",Pkg.FullName().c_str());
 1088      return Failed;
 1089       }
 1090       
 1091       // Perform a delete or an install
 1092       if (Cache[Pkg].Delete() == true)
 1093       {
 1094      if (SmartRemove(Pkg) == false)
 1095         return Failed;
 1096       }
 1097       else
 1098      if (SmartUnPack(Pkg,List->IsFlag(Pkg,pkgOrderList::Immediate),0) == false)
 1099         return Failed;
 1100       DoneSomething = true;
 1101       
 1102       if (ImmConfigureAll) {
 1103          /* ConfigureAll here to pick up and packages left unconfigured because they were unpacked in the
 1104             "PreUnpack Checks" section */
 1105          if (!ConfigureAll())
 1106             return Failed; 
 1107       }
 1108    }
 1109 
 1110    // Final run through the configure phase
 1111    if (ConfigureAll() == false)
 1112       return Failed;
 1113 
 1114    // Sanity check
 1115    for (pkgOrderList::iterator I = List->begin(); I != List->end(); ++I)
 1116    {
 1117       if (List->IsFlag(*I,pkgOrderList::Configured) == false)
 1118       {
 1119      _error->Error("Internal error, packages left unconfigured. %s",
 1120                PkgIterator(Cache,*I).FullName().c_str());
 1121      return Failed;
 1122       }
 1123    }
 1124      
 1125    return Completed;
 1126 }
 1127 // PM::DoInstallPostFork - Does install part that happens after the fork /*{{{*/
 1128 // ---------------------------------------------------------------------
 1129 pkgPackageManager::OrderResult 
 1130 pkgPackageManager::DoInstallPostFork(APT::Progress::PackageManager *progress)
 1131 {
 1132    bool goResult;
 1133    auto simulation = dynamic_cast<pkgSimulate*>(this);
 1134    if (simulation == nullptr)
 1135       goResult = Go(progress);
 1136    else
 1137       goResult = simulation->Go2(progress);
 1138    if(goResult == false) 
 1139       return Failed;
 1140    
 1141    return Res;
 1142 }
 1143                                     /*}}}*/ 
 1144 // PM::DoInstall - Does the installation                /*{{{*/
 1145 // ---------------------------------------------------------------------
 1146 /* This uses the filenames in FileNames and the information in the
 1147    DepCache to perform the installation of packages.*/
 1148 pkgPackageManager::OrderResult 
 1149 pkgPackageManager::DoInstall(APT::Progress::PackageManager *progress)
 1150 {
 1151    if(DoInstallPreFork() == Failed)
 1152       return Failed;
 1153    
 1154    return DoInstallPostFork(progress);
 1155 }
 1156                                     /*}}}*/