packagemanager.cc 42 KB

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