packagemanager.cc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  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 interesing side effects.
  8. Other cases involving conflicts+replaces should be tested.
  9. ##################################################################### */
  10. /*}}}*/
  11. // Include Files /*{{{*/
  12. #include <apt-pkg/packagemanager.h>
  13. #include <apt-pkg/orderlist.h>
  14. #include <apt-pkg/depcache.h>
  15. #include <apt-pkg/error.h>
  16. #include <apt-pkg/version.h>
  17. #include <apt-pkg/acquire-item.h>
  18. #include <apt-pkg/algorithms.h>
  19. #include <apt-pkg/configuration.h>
  20. #include <apt-pkg/sptr.h>
  21. #include <apti18n.h>
  22. #include <iostream>
  23. #include <fcntl.h>
  24. using namespace std;
  25. // PM::PackageManager - Constructor /*{{{*/
  26. // ---------------------------------------------------------------------
  27. /* */
  28. pkgPackageManager::pkgPackageManager(pkgDepCache *pCache) : Cache(*pCache)
  29. {
  30. FileNames = new string[Cache.Head().PackageCount];
  31. List = 0;
  32. Debug = _config->FindB("Debug::pkgPackageManager",false);
  33. }
  34. /*}}}*/
  35. // PM::PackageManager - Destructor /*{{{*/
  36. // ---------------------------------------------------------------------
  37. /* */
  38. pkgPackageManager::~pkgPackageManager()
  39. {
  40. delete List;
  41. delete [] FileNames;
  42. }
  43. /*}}}*/
  44. // PM::GetArchives - Queue the archives for download /*{{{*/
  45. // ---------------------------------------------------------------------
  46. /* */
  47. bool pkgPackageManager::GetArchives(pkgAcquire *Owner,pkgSourceList *Sources,
  48. pkgRecords *Recs)
  49. {
  50. if (CreateOrderList() == false)
  51. return false;
  52. if (List->OrderUnpack() == false)
  53. return _error->Error("Internal ordering error");
  54. for (pkgOrderList::iterator I = List->begin(); I != List->end(); I++)
  55. {
  56. PkgIterator Pkg(Cache,*I);
  57. FileNames[Pkg->ID] = string();
  58. // Skip packages to erase
  59. if (Cache[Pkg].Delete() == true)
  60. continue;
  61. // Skip Packages that need configure only.
  62. if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure &&
  63. Cache[Pkg].Keep() == true)
  64. continue;
  65. // Skip already processed packages
  66. if (List->IsNow(Pkg) == false)
  67. continue;
  68. new pkgAcqArchive(Owner,Sources,Recs,Cache[Pkg].InstVerIter(Cache),
  69. FileNames[Pkg->ID]);
  70. }
  71. return true;
  72. }
  73. /*}}}*/
  74. // PM::FixMissing - Keep all missing packages /*{{{*/
  75. // ---------------------------------------------------------------------
  76. /* This is called to correct the installation when packages could not
  77. be downloaded. */
  78. bool pkgPackageManager::FixMissing()
  79. {
  80. pkgDepCache::ActionGroup group(Cache);
  81. pkgProblemResolver Resolve(&Cache);
  82. List->SetFileList(FileNames);
  83. bool Bad = false;
  84. for (PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
  85. {
  86. if (List->IsMissing(I) == false)
  87. continue;
  88. // Okay, this file is missing and we need it. Mark it for keep
  89. Bad = true;
  90. Cache.MarkKeep(I, false, false);
  91. }
  92. // We have to empty the list otherwise it will not have the new changes
  93. delete List;
  94. List = 0;
  95. if (Bad == false)
  96. return true;
  97. // Now downgrade everything that is broken
  98. return Resolve.ResolveByKeep() == true && Cache.BrokenCount() == 0;
  99. }
  100. /*}}}*/
  101. // PM::ImmediateAdd - Add the immediate flag recursivly /*{{{*/
  102. // ---------------------------------------------------------------------
  103. /* This adds the immediate flag to the pkg and recursively to the
  104. dependendies
  105. */
  106. void pkgPackageManager::ImmediateAdd(PkgIterator I, bool UseInstallVer)
  107. {
  108. DepIterator D;
  109. if(UseInstallVer)
  110. {
  111. if(Cache[I].InstallVer == 0)
  112. return;
  113. D = Cache[I].InstVerIter(Cache).DependsList();
  114. } else {
  115. if (I->CurrentVer == 0)
  116. return;
  117. D = I.CurrentVer().DependsList();
  118. }
  119. for ( /* nothing */ ; D.end() == false; D++)
  120. if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends)
  121. {
  122. if(!List->IsFlag(D.TargetPkg(), pkgOrderList::Immediate))
  123. {
  124. if(Debug)
  125. clog << "ImmediateAdd(): Adding Immediate flag to " << I.Name() << endl;
  126. List->Flag(D.TargetPkg(),pkgOrderList::Immediate);
  127. ImmediateAdd(D.TargetPkg(), UseInstallVer);
  128. }
  129. }
  130. return;
  131. }
  132. /*}}}*/
  133. // PM::CreateOrderList - Create the ordering class /*{{{*/
  134. // ---------------------------------------------------------------------
  135. /* This populates the ordering list with all the packages that are
  136. going to change. */
  137. bool pkgPackageManager::CreateOrderList()
  138. {
  139. if (List != 0)
  140. return true;
  141. delete List;
  142. List = new pkgOrderList(&Cache);
  143. bool NoImmConfigure = !_config->FindB("APT::Immediate-Configure",true);
  144. // Generate the list of affected packages and sort it
  145. for (PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
  146. {
  147. // Ignore no-version packages
  148. if (I->VersionList == 0)
  149. continue;
  150. // Mark the package and its dependends for immediate configuration
  151. if (((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential ||
  152. (I->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important) &&
  153. NoImmConfigure == false)
  154. {
  155. if(Debug)
  156. clog << "CreateOrderList(): Adding Immediate flag for " << I.Name() << endl;
  157. List->Flag(I,pkgOrderList::Immediate);
  158. // Look for other install packages to make immediate configurea
  159. ImmediateAdd(I, true);
  160. // And again with the current version.
  161. ImmediateAdd(I, false);
  162. }
  163. // Not interesting
  164. if ((Cache[I].Keep() == true ||
  165. Cache[I].InstVerIter(Cache) == I.CurrentVer()) &&
  166. I.State() == pkgCache::PkgIterator::NeedsNothing &&
  167. (Cache[I].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall &&
  168. (I.Purge() != false || Cache[I].Mode != pkgDepCache::ModeDelete ||
  169. (Cache[I].iFlags & pkgDepCache::Purge) != pkgDepCache::Purge))
  170. continue;
  171. // Append it to the list
  172. List->push_back(I);
  173. }
  174. return true;
  175. }
  176. /*}}}*/
  177. // PM::DepAlwaysTrue - Returns true if this dep is irrelevent /*{{{*/
  178. // ---------------------------------------------------------------------
  179. /* The restriction on provides is to eliminate the case when provides
  180. are transitioning between valid states [ie exim to smail] */
  181. bool pkgPackageManager::DepAlwaysTrue(DepIterator D)
  182. {
  183. if (D.TargetPkg()->ProvidesList != 0)
  184. return false;
  185. if ((Cache[D] & pkgDepCache::DepInstall) != 0 &&
  186. (Cache[D] & pkgDepCache::DepNow) != 0)
  187. return true;
  188. return false;
  189. }
  190. /*}}}*/
  191. // PM::CheckRConflicts - Look for reverse conflicts /*{{{*/
  192. // ---------------------------------------------------------------------
  193. /* This looks over the reverses for a conflicts line that needs early
  194. removal. */
  195. bool pkgPackageManager::CheckRConflicts(PkgIterator Pkg,DepIterator D,
  196. const char *Ver)
  197. {
  198. for (;D.end() == false; D++)
  199. {
  200. if (D->Type != pkgCache::Dep::Conflicts &&
  201. D->Type != pkgCache::Dep::Obsoletes)
  202. continue;
  203. // The package hasnt been changed
  204. if (List->IsNow(Pkg) == false)
  205. continue;
  206. // Ignore self conflicts, ignore conflicts from irrelevent versions
  207. if (D.ParentPkg() == Pkg || D.ParentVer() != D.ParentPkg().CurrentVer())
  208. continue;
  209. if (Cache.VS().CheckDep(Ver,D->CompareOp,D.TargetVer()) == false)
  210. continue;
  211. if (EarlyRemove(D.ParentPkg()) == false)
  212. return _error->Error("Reverse conflicts early remove for package '%s' failed",
  213. Pkg.Name());
  214. }
  215. return true;
  216. }
  217. /*}}}*/
  218. // PM::ConfigureAll - Run the all out configuration /*{{{*/
  219. // ---------------------------------------------------------------------
  220. /* This configures every package. It is assumed they are all unpacked and
  221. that the final configuration is valid. */
  222. bool pkgPackageManager::ConfigureAll()
  223. {
  224. pkgOrderList OList(&Cache);
  225. // Populate the order list
  226. for (pkgOrderList::iterator I = List->begin(); I != List->end(); I++)
  227. if (List->IsFlag(pkgCache::PkgIterator(Cache,*I),
  228. pkgOrderList::UnPacked) == true)
  229. OList.push_back(*I);
  230. if (OList.OrderConfigure() == false)
  231. return false;
  232. // Perform the configuring
  233. for (pkgOrderList::iterator I = OList.begin(); I != OList.end(); I++)
  234. {
  235. PkgIterator Pkg(Cache,*I);
  236. if (Configure(Pkg) == false)
  237. return false;
  238. List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States);
  239. }
  240. return true;
  241. }
  242. /*}}}*/
  243. // PM::SmartConfigure - Perform immediate configuration of the pkg /*{{{*/
  244. // ---------------------------------------------------------------------
  245. /* This routine scheduals the configuration of the given package and all
  246. of it's dependents. */
  247. bool pkgPackageManager::SmartConfigure(PkgIterator Pkg)
  248. {
  249. pkgOrderList OList(&Cache);
  250. if (DepAdd(OList,Pkg) == false)
  251. return false;
  252. if (OList.OrderConfigure() == false)
  253. return false;
  254. // Perform the configuring
  255. for (pkgOrderList::iterator I = OList.begin(); I != OList.end(); I++)
  256. {
  257. PkgIterator Pkg(Cache,*I);
  258. if (Configure(Pkg) == false)
  259. return false;
  260. List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States);
  261. }
  262. // Sanity Check
  263. if (List->IsFlag(Pkg,pkgOrderList::Configured) == false)
  264. return _error->Error("Internal error, could not immediate configure %s",Pkg.Name());
  265. return true;
  266. }
  267. /*}}}*/
  268. // PM::DepAdd - Add all dependents to the oder list /*{{{*/
  269. // ---------------------------------------------------------------------
  270. /* This recursively adds all dependents to the order list */
  271. bool pkgPackageManager::DepAdd(pkgOrderList &OList,PkgIterator Pkg,int Depth)
  272. {
  273. if (OList.IsFlag(Pkg,pkgOrderList::Added) == true)
  274. return true;
  275. if (List->IsFlag(Pkg,pkgOrderList::Configured) == true)
  276. return true;
  277. if (List->IsFlag(Pkg,pkgOrderList::UnPacked) == false)
  278. return false;
  279. // Put the package on the list
  280. OList.push_back(Pkg);
  281. OList.Flag(Pkg,pkgOrderList::Added);
  282. Depth++;
  283. // Check the dependencies to see if they are all satisfied.
  284. bool Bad = false;
  285. for (DepIterator D = Cache[Pkg].InstVerIter(Cache).DependsList(); D.end() == false;)
  286. {
  287. if (D->Type != pkgCache::Dep::Depends && D->Type != pkgCache::Dep::PreDepends)
  288. {
  289. D++;
  290. continue;
  291. }
  292. // Grok or groups
  293. Bad = true;
  294. for (bool LastOR = true; D.end() == false && LastOR == true; D++)
  295. {
  296. LastOR = (D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or;
  297. if (Bad == false)
  298. continue;
  299. SPtrArray<Version *> VList = D.AllTargets();
  300. for (Version **I = VList; *I != 0 && Bad == true; I++)
  301. {
  302. VerIterator Ver(Cache,*I);
  303. PkgIterator Pkg = Ver.ParentPkg();
  304. // See if the current version is ok
  305. if (Pkg.CurrentVer() == Ver && List->IsNow(Pkg) == true &&
  306. Pkg.State() == PkgIterator::NeedsNothing)
  307. {
  308. Bad = false;
  309. continue;
  310. }
  311. // Not the install version
  312. if (Cache[Pkg].InstallVer != *I ||
  313. (Cache[Pkg].Keep() == true && Pkg.State() == PkgIterator::NeedsNothing))
  314. continue;
  315. if (List->IsFlag(Pkg,pkgOrderList::UnPacked) == true)
  316. Bad = !DepAdd(OList,Pkg,Depth);
  317. if (List->IsFlag(Pkg,pkgOrderList::Configured) == true)
  318. Bad = false;
  319. }
  320. }
  321. if (Bad == true)
  322. {
  323. OList.Flag(Pkg,0,pkgOrderList::Added);
  324. OList.pop_back();
  325. Depth--;
  326. return false;
  327. }
  328. }
  329. Depth--;
  330. return true;
  331. }
  332. /*}}}*/
  333. // PM::EarlyRemove - Perform removal of packages before their time /*{{{*/
  334. // ---------------------------------------------------------------------
  335. /* This is called to deal with conflicts arising from unpacking */
  336. bool pkgPackageManager::EarlyRemove(PkgIterator Pkg)
  337. {
  338. if (List->IsNow(Pkg) == false)
  339. return true;
  340. // Already removed it
  341. if (List->IsFlag(Pkg,pkgOrderList::Removed) == true)
  342. return true;
  343. // Woops, it will not be re-installed!
  344. if (List->IsFlag(Pkg,pkgOrderList::InList) == false)
  345. return false;
  346. // Essential packages get special treatment
  347. bool IsEssential = false;
  348. if ((Pkg->Flags & pkgCache::Flag::Essential) != 0)
  349. IsEssential = true;
  350. /* Check for packages that are the dependents of essential packages and
  351. promote them too */
  352. if (Pkg->CurrentVer != 0)
  353. {
  354. for (DepIterator D = Pkg.RevDependsList(); D.end() == false &&
  355. IsEssential == false; D++)
  356. if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends)
  357. if ((D.ParentPkg()->Flags & pkgCache::Flag::Essential) != 0)
  358. IsEssential = true;
  359. }
  360. if (IsEssential == true)
  361. {
  362. if (_config->FindB("APT::Force-LoopBreak",false) == false)
  363. return _error->Error(_("This installation run will require temporarily "
  364. "removing the essential package %s due to a "
  365. "Conflicts/Pre-Depends loop. This is often bad, "
  366. "but if you really want to do it, activate the "
  367. "APT::Force-LoopBreak option."),Pkg.Name());
  368. }
  369. bool Res = SmartRemove(Pkg);
  370. if (Cache[Pkg].Delete() == false)
  371. List->Flag(Pkg,pkgOrderList::Removed,pkgOrderList::States);
  372. return Res;
  373. }
  374. /*}}}*/
  375. // PM::SmartRemove - Removal Helper /*{{{*/
  376. // ---------------------------------------------------------------------
  377. /* */
  378. bool pkgPackageManager::SmartRemove(PkgIterator Pkg)
  379. {
  380. if (List->IsNow(Pkg) == false)
  381. return true;
  382. List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States);
  383. return Remove(Pkg,(Cache[Pkg].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge);
  384. }
  385. /*}}}*/
  386. // PM::SmartUnPack - Install helper /*{{{*/
  387. // ---------------------------------------------------------------------
  388. /* This performs the task of handling pre-depends. */
  389. bool pkgPackageManager::SmartUnPack(PkgIterator Pkg)
  390. {
  391. // Check if it is already unpacked
  392. if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure &&
  393. Cache[Pkg].Keep() == true)
  394. {
  395. List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States);
  396. if (List->IsFlag(Pkg,pkgOrderList::Immediate) == true)
  397. if (SmartConfigure(Pkg) == false)
  398. return _error->Error("Internal Error, Could not perform immediate configuration (1) on %s",Pkg.Name());
  399. return true;
  400. }
  401. /* See if this packages install version has any predependencies
  402. that are not met by 'now' packages. */
  403. for (DepIterator D = Cache[Pkg].InstVerIter(Cache).DependsList();
  404. D.end() == false; )
  405. {
  406. // Compute a single dependency element (glob or)
  407. pkgCache::DepIterator Start;
  408. pkgCache::DepIterator End;
  409. D.GlobOr(Start,End);
  410. while (End->Type == pkgCache::Dep::PreDepends)
  411. {
  412. // Look for possible ok targets.
  413. SPtrArray<Version *> VList = Start.AllTargets();
  414. bool Bad = true;
  415. for (Version **I = VList; *I != 0 && Bad == true; I++)
  416. {
  417. VerIterator Ver(Cache,*I);
  418. PkgIterator Pkg = Ver.ParentPkg();
  419. // See if the current version is ok
  420. if (Pkg.CurrentVer() == Ver && List->IsNow(Pkg) == true &&
  421. Pkg.State() == PkgIterator::NeedsNothing)
  422. {
  423. Bad = false;
  424. continue;
  425. }
  426. }
  427. // Look for something that could be configured.
  428. for (Version **I = VList; *I != 0 && Bad == true; I++)
  429. {
  430. VerIterator Ver(Cache,*I);
  431. PkgIterator Pkg = Ver.ParentPkg();
  432. // Not the install version
  433. if (Cache[Pkg].InstallVer != *I ||
  434. (Cache[Pkg].Keep() == true && Pkg.State() == PkgIterator::NeedsNothing))
  435. continue;
  436. Bad = !SmartConfigure(Pkg);
  437. }
  438. /* If this or element did not match then continue on to the
  439. next or element until a matching element is found */
  440. if (Bad == true)
  441. {
  442. // This triggers if someone make a pre-depends/depend loop.
  443. if (Start == End)
  444. return _error->Error("Couldn't configure pre-depend %s for %s, "
  445. "probably a dependency cycle.",
  446. End.TargetPkg().Name(),Pkg.Name());
  447. Start++;
  448. }
  449. else
  450. break;
  451. }
  452. if (End->Type == pkgCache::Dep::Conflicts ||
  453. End->Type == pkgCache::Dep::Obsoletes)
  454. {
  455. /* Look for conflicts. Two packages that are both in the install
  456. state cannot conflict so we don't check.. */
  457. SPtrArray<Version *> VList = End.AllTargets();
  458. for (Version **I = VList; *I != 0; I++)
  459. {
  460. VerIterator Ver(Cache,*I);
  461. PkgIterator Pkg = Ver.ParentPkg();
  462. // See if the current version is conflicting
  463. if (Pkg.CurrentVer() == Ver && List->IsNow(Pkg) == true)
  464. {
  465. if (EarlyRemove(Pkg) == false)
  466. return _error->Error("Internal Error, Could not early remove %s",Pkg.Name());
  467. }
  468. }
  469. }
  470. }
  471. // Check for reverse conflicts.
  472. if (CheckRConflicts(Pkg,Pkg.RevDependsList(),
  473. Cache[Pkg].InstVerIter(Cache).VerStr()) == false)
  474. return false;
  475. for (PrvIterator P = Cache[Pkg].InstVerIter(Cache).ProvidesList();
  476. P.end() == false; P++)
  477. CheckRConflicts(Pkg,P.ParentPkg().RevDependsList(),P.ProvideVersion());
  478. if (Install(Pkg,FileNames[Pkg->ID]) == false)
  479. return false;
  480. List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States);
  481. // Perform immedate configuration of the package.
  482. if (List->IsFlag(Pkg,pkgOrderList::Immediate) == true)
  483. if (SmartConfigure(Pkg) == false)
  484. return _error->Error("Internal Error, Could not perform immediate configuration (2) on %s",Pkg.Name());
  485. return true;
  486. }
  487. /*}}}*/
  488. // PM::OrderInstall - Installation ordering routine /*{{{*/
  489. // ---------------------------------------------------------------------
  490. /* */
  491. pkgPackageManager::OrderResult pkgPackageManager::OrderInstall()
  492. {
  493. if (CreateOrderList() == false)
  494. return Failed;
  495. Reset();
  496. if (Debug == true)
  497. clog << "Begining to order" << endl;
  498. if (List->OrderUnpack(FileNames) == false)
  499. {
  500. _error->Error("Internal ordering error");
  501. return Failed;
  502. }
  503. if (Debug == true)
  504. clog << "Done ordering" << endl;
  505. bool DoneSomething = false;
  506. for (pkgOrderList::iterator I = List->begin(); I != List->end(); I++)
  507. {
  508. PkgIterator Pkg(Cache,*I);
  509. if (List->IsNow(Pkg) == false)
  510. {
  511. if (Debug == true)
  512. clog << "Skipping already done " << Pkg.Name() << endl;
  513. continue;
  514. }
  515. if (List->IsMissing(Pkg) == true)
  516. {
  517. if (Debug == true)
  518. clog << "Sequence completed at " << Pkg.Name() << endl;
  519. if (DoneSomething == false)
  520. {
  521. _error->Error("Internal Error, ordering was unable to handle the media swap");
  522. return Failed;
  523. }
  524. return Incomplete;
  525. }
  526. // Sanity check
  527. if (Cache[Pkg].Keep() == true &&
  528. Pkg.State() == pkgCache::PkgIterator::NeedsNothing &&
  529. (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)
  530. {
  531. _error->Error("Internal Error, trying to manipulate a kept package (%s)",Pkg.Name());
  532. return Failed;
  533. }
  534. // Perform a delete or an install
  535. if (Cache[Pkg].Delete() == true)
  536. {
  537. if (SmartRemove(Pkg) == false)
  538. return Failed;
  539. }
  540. else
  541. if (SmartUnPack(Pkg) == false)
  542. return Failed;
  543. DoneSomething = true;
  544. }
  545. // Final run through the configure phase
  546. if (ConfigureAll() == false)
  547. return Failed;
  548. // Sanity check
  549. for (pkgOrderList::iterator I = List->begin(); I != List->end(); I++)
  550. {
  551. if (List->IsFlag(*I,pkgOrderList::Configured) == false)
  552. {
  553. _error->Error("Internal error, packages left unconfigured. %s",
  554. PkgIterator(Cache,*I).Name());
  555. return Failed;
  556. }
  557. }
  558. return Completed;
  559. }
  560. /*}}}*/
  561. // PM::DoInstallPostFork - Does install part that happens after the fork /*{{{*/
  562. // ---------------------------------------------------------------------
  563. pkgPackageManager::OrderResult
  564. pkgPackageManager::DoInstallPostFork(int statusFd)
  565. {
  566. if(statusFd > 0)
  567. // FIXME: use SetCloseExec here once it taught about throwing
  568. // exceptions instead of doing _exit(100) on failure
  569. fcntl(statusFd,F_SETFD,FD_CLOEXEC);
  570. bool goResult = Go(statusFd);
  571. if(goResult == false)
  572. return Failed;
  573. return Res;
  574. };
  575. // PM::DoInstall - Does the installation /*{{{*/
  576. // ---------------------------------------------------------------------
  577. /* This uses the filenames in FileNames and the information in the
  578. DepCache to perform the installation of packages.*/
  579. pkgPackageManager::OrderResult pkgPackageManager::DoInstall(int statusFd)
  580. {
  581. if(DoInstallPreFork() == Failed)
  582. return Failed;
  583. return DoInstallPostFork(statusFd);
  584. }
  585. /*}}}*/