packagemanager.cc 41 KB

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