packagemanager.cc 23 KB

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