packagemanager.cc 23 KB

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