packagemanager.cc 22 KB

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