You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

767 lines
24 KiB

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