depcache.cc 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: depcache.cc,v 1.13 1998/12/22 07:58:50 jgg Exp $
  4. /* ######################################################################
  5. Dependency Cache - Caches Dependency information.
  6. ##################################################################### */
  7. /*}}}*/
  8. // Include Files /*{{{*/
  9. #ifdef __GNUG__
  10. #pragma implementation "apt-pkg/depcache.h"
  11. #endif
  12. #include <apt-pkg/depcache.h>
  13. #include <apt-pkg/configuration.h>
  14. #include <apt-pkg/version.h>
  15. #include <apt-pkg/error.h>
  16. /*}}}*/
  17. // DepCache::pkgDepCache - Constructors /*{{{*/
  18. // ---------------------------------------------------------------------
  19. /* */
  20. pkgDepCache::pkgDepCache(MMap &Map,OpProgress &Prog) :
  21. pkgCache(Map), PkgState(0), DepState(0)
  22. {
  23. if (_error->PendingError() == false)
  24. Init(&Prog);
  25. }
  26. pkgDepCache::pkgDepCache(MMap &Map) :
  27. pkgCache(Map), PkgState(0), DepState(0)
  28. {
  29. if (_error->PendingError() == false)
  30. Init(0);
  31. }
  32. /*}}}*/
  33. // DepCache::~pkgDepCache - Destructor /*{{{*/
  34. // ---------------------------------------------------------------------
  35. /* */
  36. pkgDepCache::~pkgDepCache()
  37. {
  38. delete [] PkgState;
  39. delete [] DepState;
  40. }
  41. /*}}}*/
  42. // DepCache::Init - Generate the initial extra structures. /*{{{*/
  43. // ---------------------------------------------------------------------
  44. /* This allocats the extension buffers and initializes them. */
  45. bool pkgDepCache::Init(OpProgress *Prog)
  46. {
  47. delete [] PkgState;
  48. delete [] DepState;
  49. PkgState = new StateCache[Head().PackageCount];
  50. DepState = new unsigned char[Head().DependsCount];
  51. memset(PkgState,0,sizeof(*PkgState)*Head().PackageCount);
  52. memset(DepState,0,sizeof(*DepState)*Head().DependsCount);
  53. if (Prog != 0)
  54. {
  55. Prog->OverallProgress(0,2*Head().PackageCount,Head().PackageCount,
  56. "Building Dependency Tree");
  57. Prog->SubProgress(Head().PackageCount,"Candidate Versions");
  58. }
  59. /* Set the current state of everything. In this state all of the
  60. packages are kept exactly as is. See AllUpgrade */
  61. int Done = 0;
  62. for (PkgIterator I = PkgBegin(); I.end() != true; I++,Done++)
  63. {
  64. if (Prog != 0)
  65. Prog->Progress(Done);
  66. // Find the proper cache slot
  67. StateCache &State = PkgState[I->ID];
  68. State.iFlags = 0;
  69. // Figure out the install version
  70. State.CandidateVer = GetCandidateVer(I);
  71. State.InstallVer = I.CurrentVer();
  72. State.Mode = ModeKeep;
  73. State.Update(I,*this);
  74. }
  75. if (Prog != 0)
  76. {
  77. Prog->OverallProgress(Head().PackageCount,2*Head().PackageCount,
  78. Head().PackageCount,
  79. "Building Dependency Tree");
  80. Prog->SubProgress(Head().PackageCount,"Dependency Generation");
  81. }
  82. Update(Prog);
  83. return true;
  84. }
  85. /*}}}*/
  86. // DepCache::GetCandidateVer - Returns the Candidate install version /*{{{*/
  87. // ---------------------------------------------------------------------
  88. /* The default just returns the target version if it exists or the
  89. highest version. */
  90. pkgDepCache::VerIterator pkgDepCache::GetCandidateVer(PkgIterator Pkg)
  91. {
  92. // Try to use an explicit target
  93. if (Pkg->TargetVer == 0)
  94. {
  95. string DistHack = _config->Find("to");
  96. /* If disthack is set then we look for a dist by that name to install
  97. from */
  98. if (DistHack.empty() == false)
  99. {
  100. for (VerIterator I = Pkg.VersionList(); I.end() == false; I++)
  101. {
  102. for (VerFileIterator J = I.FileList(); J.end() == false; J++)
  103. if ((J.File()->Flags & Flag::NotSource) == 0 &&
  104. (J.File()->Flags & Flag::NotAutomatic) == 0 &&
  105. J.File().Archive() == DistHack)
  106. return I;
  107. }
  108. // Hmm, target is current if there is no alternative.
  109. if (Pkg->CurrentVer != 0)
  110. return Pkg.CurrentVer();
  111. }
  112. else
  113. {
  114. /* Not source/not automatic versions cannot be a candidate version
  115. unless they are already installed */
  116. for (VerIterator I = Pkg.VersionList(); I.end() == false; I++)
  117. {
  118. if (Pkg.CurrentVer() == I)
  119. return I;
  120. for (VerFileIterator J = I.FileList(); J.end() == false; J++)
  121. if ((J.File()->Flags & Flag::NotSource) == 0 &&
  122. (J.File()->Flags & Flag::NotAutomatic) == 0)
  123. return I;
  124. }
  125. }
  126. return VerIterator(*this,0);
  127. }
  128. else
  129. return Pkg.TargetVer();
  130. }
  131. /*}}}*/
  132. // DepCache::IsImportantDep - True if the dependency is important /*{{{*/
  133. // ---------------------------------------------------------------------
  134. /* */
  135. bool pkgDepCache::IsImportantDep(DepIterator Dep)
  136. {
  137. return Dep.IsCritical();
  138. }
  139. /*}}}*/
  140. // DepCache::CheckDep - Checks a single dependency /*{{{*/
  141. // ---------------------------------------------------------------------
  142. /* This first checks the dependency against the main target package and
  143. then walks along the package provides list and checks if each provides
  144. will be installed then checks the provides against the dep. Res will be
  145. set to the package which was used to satisfy the dep. */
  146. bool pkgDepCache::CheckDep(DepIterator Dep,int Type,PkgIterator &Res)
  147. {
  148. Res = Dep.TargetPkg();
  149. /* Check simple depends. A depends -should- never self match but
  150. we allow it anyhow because dpkg does. Technically it is a packaging
  151. bug. Conflicts may never self match */
  152. if (Dep.TargetPkg() != Dep.ParentPkg() || Dep->Type != Dep::Conflicts)
  153. {
  154. PkgIterator Pkg = Dep.TargetPkg();
  155. // Check the base package
  156. if (Type == NowVersion && Pkg->CurrentVer != 0)
  157. if (pkgCheckDep(Dep.TargetVer(),
  158. Pkg.CurrentVer().VerStr(),Dep->CompareOp) == true)
  159. return true;
  160. if (Type == InstallVersion && PkgState[Pkg->ID].InstallVer != 0)
  161. if (pkgCheckDep(Dep.TargetVer(),
  162. PkgState[Pkg->ID].InstVerIter(*this).VerStr(),
  163. Dep->CompareOp) == true)
  164. return true;
  165. if (Type == CandidateVersion && PkgState[Pkg->ID].CandidateVer != 0)
  166. if (pkgCheckDep(Dep.TargetVer(),
  167. PkgState[Pkg->ID].CandidateVerIter(*this).VerStr(),
  168. Dep->CompareOp) == true)
  169. return true;
  170. }
  171. // Check the providing packages
  172. PrvIterator P = Dep.TargetPkg().ProvidesList();
  173. PkgIterator Pkg = Dep.ParentPkg();
  174. for (; P.end() != true; P++)
  175. {
  176. /* Provides may never be applied against the same package if it is
  177. a conflicts. See the comment above. */
  178. if (P.OwnerPkg() == Pkg && Dep->Type == Dep::Conflicts)
  179. continue;
  180. // Check if the provides is a hit
  181. if (Type == NowVersion)
  182. {
  183. if (P.OwnerPkg().CurrentVer() != P.OwnerVer())
  184. continue;
  185. }
  186. if (Type == InstallVersion)
  187. {
  188. StateCache &State = PkgState[P.OwnerPkg()->ID];
  189. if (State.InstallVer != (Version *)P.OwnerVer())
  190. continue;
  191. }
  192. if (Type == CandidateVersion)
  193. {
  194. StateCache &State = PkgState[P.OwnerPkg()->ID];
  195. if (State.CandidateVer != (Version *)P.OwnerVer())
  196. continue;
  197. }
  198. // Compare the versions.
  199. if (pkgCheckDep(Dep.TargetVer(),P.ProvideVersion(),Dep->CompareOp) == true)
  200. {
  201. Res = P.OwnerPkg();
  202. return true;
  203. }
  204. }
  205. return false;
  206. }
  207. /*}}}*/
  208. // DepCache::AddSizes - Add the packages sizes to the counters /*{{{*/
  209. // ---------------------------------------------------------------------
  210. /* Call with Mult = -1 to preform the inverse opration */
  211. void pkgDepCache::AddSizes(const PkgIterator &Pkg,long Mult)
  212. {
  213. StateCache &P = PkgState[Pkg->ID];
  214. if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure)
  215. {
  216. iUsrSize += Mult*P.InstVerIter(*this)->InstalledSize;
  217. return;
  218. }
  219. // Compute the size data
  220. if (P.NewInstall() == true)
  221. {
  222. iUsrSize += Mult*P.InstVerIter(*this)->InstalledSize;
  223. iDownloadSize += Mult*P.InstVerIter(*this)->Size;
  224. return;
  225. }
  226. // Upgrading
  227. if (Pkg->CurrentVer != 0 && P.InstallVer != (Version *)Pkg.CurrentVer() &&
  228. P.InstallVer != 0)
  229. {
  230. iUsrSize += Mult*((signed)P.InstVerIter(*this)->InstalledSize -
  231. (signed)Pkg.CurrentVer()->InstalledSize);
  232. iDownloadSize += Mult*P.InstVerIter(*this)->Size;
  233. return;
  234. }
  235. // Reinstall
  236. if (Pkg.State() == pkgCache::PkgIterator::NeedsUnpack &&
  237. P.Delete() == false)
  238. {
  239. iDownloadSize += Mult*P.InstVerIter(*this)->Size;
  240. return;
  241. }
  242. // Removing
  243. if (Pkg->CurrentVer != 0 && P.InstallVer == 0)
  244. {
  245. iUsrSize -= Mult*Pkg.CurrentVer()->InstalledSize;
  246. return;
  247. }
  248. }
  249. /*}}}*/
  250. // DepCache::AddStates - Add the package to the state counter /*{{{*/
  251. // ---------------------------------------------------------------------
  252. /* This routine is tricky to use, you must make sure that it is never
  253. called twice for the same package. This means the Remove/Add section
  254. should be as short as possible and not encompass any code that will
  255. calld Remove/Add itself. Remember, dependencies can be circular so
  256. while processing a dep for Pkg it is possible that Add/Remove
  257. will be called on Pkg */
  258. void pkgDepCache::AddStates(const PkgIterator &Pkg,int Add)
  259. {
  260. StateCache &State = PkgState[Pkg->ID];
  261. // The Package is broken
  262. if ((State.DepState & DepInstMin) != DepInstMin)
  263. iBrokenCount += Add;
  264. // Bad state
  265. if (Pkg.State() != PkgIterator::NeedsNothing)
  266. iBadCount += Add;
  267. // Not installed
  268. if (Pkg->CurrentVer == 0)
  269. {
  270. if (State.Mode == ModeInstall)
  271. iInstCount += Add;
  272. return;
  273. }
  274. // Installed, no upgrade
  275. if (State.Upgradable() == false)
  276. {
  277. if (State.Mode == ModeDelete)
  278. iDelCount += Add;
  279. if (State.Mode == ModeInstall)
  280. iInstCount += Add;
  281. return;
  282. }
  283. // Alll 3 are possible
  284. if (State.Mode == ModeDelete)
  285. iDelCount += Add;
  286. if (State.Mode == ModeKeep)
  287. iKeepCount += Add;
  288. if (State.Mode == ModeInstall)
  289. iInstCount += Add;
  290. }
  291. /*}}}*/
  292. // DepCache::BuildGroupOrs - Generate the Or group dep data /*{{{*/
  293. // ---------------------------------------------------------------------
  294. /* The or group results are stored in the last item of the or group. This
  295. allows easy detection of the state of a whole or'd group. */
  296. void pkgDepCache::BuildGroupOrs(VerIterator const &V)
  297. {
  298. unsigned char Group = 0;
  299. for (DepIterator D = V.DependsList(); D.end() != true; D++)
  300. {
  301. // Build the dependency state.
  302. unsigned char &State = DepState[D->ID];
  303. /* Invert for Conflicts. We have to do this twice to get the
  304. right sense for a conflicts group */
  305. if (D->Type == Dep::Conflicts)
  306. State = ~State;
  307. // Add to the group if we are within an or..
  308. State &= 0x7;
  309. Group |= State;
  310. State |= Group << 3;
  311. if ((D->CompareOp & Dep::Or) != Dep::Or)
  312. Group = 0;
  313. // Invert for Conflicts
  314. if (D->Type == Dep::Conflicts)
  315. State = ~State;
  316. }
  317. }
  318. /*}}}*/
  319. // DepCache::VersionState - Perform a pass over a dependency list /*{{{*/
  320. // ---------------------------------------------------------------------
  321. /* This is used to run over a dependency list and determine the dep
  322. state of the list, filtering it through both a Min check and a Policy
  323. check. The return result will have SetMin/SetPolicy low if a check
  324. fails. It uses the DepState cache for it's computations. */
  325. unsigned char pkgDepCache::VersionState(DepIterator D,unsigned char Check,
  326. unsigned char SetMin,
  327. unsigned char SetPolicy)
  328. {
  329. unsigned char Dep = 0xFF;
  330. while (D.end() != true)
  331. {
  332. // Compute a single dependency element (glob or)
  333. DepIterator Start = D;
  334. unsigned char State = 0;
  335. for (bool LastOR = true; D.end() == false && LastOR == true; D++)
  336. {
  337. State |= DepState[D->ID];
  338. LastOR = (D->CompareOp & Dep::Or) == Dep::Or;
  339. }
  340. // Minimum deps that must be satisfied to have a working package
  341. if (Start.IsCritical() == true)
  342. if ((State & Check) != Check)
  343. Dep &= ~SetMin;
  344. // Policy deps that must be satisfied to install the package
  345. if (IsImportantDep(Start) == true &&
  346. (State & Check) != Check)
  347. Dep &= ~SetPolicy;
  348. }
  349. return Dep;
  350. }
  351. /*}}}*/
  352. // DepCache::DependencyState - Compute the 3 results for a dep /*{{{*/
  353. // ---------------------------------------------------------------------
  354. /* This is the main dependency computation bit. It computes the 3 main
  355. results for a dependencys, Now, Install and Candidate. Callers must
  356. invert the result if dealing with conflicts. */
  357. unsigned char pkgDepCache::DependencyState(DepIterator &D)
  358. {
  359. unsigned char State = 0;
  360. if (CheckDep(D,NowVersion) == true)
  361. State |= DepNow;
  362. if (CheckDep(D,InstallVersion) == true)
  363. State |= DepInstall;
  364. if (CheckDep(D,CandidateVersion) == true)
  365. State |= DepCVer;
  366. return State;
  367. }
  368. /*}}}*/
  369. // DepCache::UpdateVerState - Compute the Dep member of the state /*{{{*/
  370. // ---------------------------------------------------------------------
  371. /* This determines the combined dependency representation of a package
  372. for its two states now and install. This is done by using the pre-generated
  373. dependency information. */
  374. void pkgDepCache::UpdateVerState(PkgIterator Pkg)
  375. {
  376. // Empty deps are always true
  377. StateCache &State = PkgState[Pkg->ID];
  378. State.DepState = 0xFF;
  379. // Check the Current state
  380. if (Pkg->CurrentVer != 0)
  381. {
  382. DepIterator D = Pkg.CurrentVer().DependsList();
  383. State.DepState &= VersionState(D,DepNow,DepNowMin,DepNowPolicy);
  384. }
  385. /* Check the candidate state. We do not compare against the whole as
  386. a candidate state but check the candidate version against the
  387. install states */
  388. if (State.CandidateVer != 0)
  389. {
  390. DepIterator D = State.CandidateVerIter(*this).DependsList();
  391. State.DepState &= VersionState(D,DepInstall,DepCandMin,DepCandPolicy);
  392. }
  393. // Check target state which can only be current or installed
  394. if (State.InstallVer != 0)
  395. {
  396. DepIterator D = State.InstVerIter(*this).DependsList();
  397. State.DepState &= VersionState(D,DepInstall,DepInstMin,DepInstPolicy);
  398. }
  399. }
  400. /*}}}*/
  401. // DepCache::Update - Figure out all the state information /*{{{*/
  402. // ---------------------------------------------------------------------
  403. /* This will figure out the state of all the packages and all the
  404. dependencies based on the current policy. */
  405. void pkgDepCache::Update(OpProgress *Prog)
  406. {
  407. iUsrSize = 0;
  408. iDownloadSize = 0;
  409. iDelCount = 0;
  410. iInstCount = 0;
  411. iKeepCount = 0;
  412. iBrokenCount = 0;
  413. iBadCount = 0;
  414. // Perform the depends pass
  415. int Done = 0;
  416. for (PkgIterator I = PkgBegin(); I.end() != true; I++,Done++)
  417. {
  418. if (Prog != 0 && Done%20 == 0)
  419. Prog->Progress(Done);
  420. for (VerIterator V = I.VersionList(); V.end() != true; V++)
  421. {
  422. unsigned char Group = 0;
  423. for (DepIterator D = V.DependsList(); D.end() != true; D++)
  424. {
  425. // Build the dependency state.
  426. unsigned char &State = DepState[D->ID];
  427. State = DependencyState(D);;
  428. // Add to the group if we are within an or..
  429. Group |= State;
  430. State |= Group << 3;
  431. if ((D->CompareOp & Dep::Or) != Dep::Or)
  432. Group = 0;
  433. // Invert for Conflicts
  434. if (D->Type == Dep::Conflicts)
  435. State = ~State;
  436. }
  437. }
  438. // Compute the pacakge dependency state and size additions
  439. AddSizes(I);
  440. UpdateVerState(I);
  441. AddStates(I);
  442. }
  443. if (Prog != 0)
  444. Prog->Progress(Done);
  445. }
  446. /*}}}*/
  447. // DepCache::Update - Update the deps list of a package /*{{{*/
  448. // ---------------------------------------------------------------------
  449. /* This is a helper for update that only does the dep portion of the scan.
  450. It is mainly ment to scan reverse dependencies. */
  451. void pkgDepCache::Update(DepIterator D)
  452. {
  453. // Update the reverse deps
  454. for (;D.end() != true; D++)
  455. {
  456. unsigned char &State = DepState[D->ID];
  457. State = DependencyState(D);
  458. // Invert for Conflicts
  459. if (D->Type == Dep::Conflicts)
  460. State = ~State;
  461. RemoveStates(D.ParentPkg());
  462. BuildGroupOrs(D.ParentVer());
  463. UpdateVerState(D.ParentPkg());
  464. AddStates(D.ParentPkg());
  465. }
  466. }
  467. /*}}}*/
  468. // DepCache::Update - Update the related deps of a package /*{{{*/
  469. // ---------------------------------------------------------------------
  470. /* This is called whenever the state of a package changes. It updates
  471. all cached dependencies related to this package. */
  472. void pkgDepCache::Update(PkgIterator const &Pkg)
  473. {
  474. // Recompute the dep of the package
  475. RemoveStates(Pkg);
  476. UpdateVerState(Pkg);
  477. AddStates(Pkg);
  478. // Update the reverse deps
  479. Update(Pkg.RevDependsList());
  480. // Update the provides map for the current ver
  481. if (Pkg->CurrentVer != 0)
  482. for (PrvIterator P = Pkg.CurrentVer().ProvidesList();
  483. P.end() != true; P++)
  484. Update(P.ParentPkg().RevDependsList());
  485. // Update the provides map for the candidate ver
  486. for (PrvIterator P = PkgState[Pkg->ID].CandidateVerIter(*this).ProvidesList();
  487. P.end() != true; P++)
  488. Update(P.ParentPkg().RevDependsList());
  489. }
  490. /*}}}*/
  491. // DepCache::MarkKeep - Put the package in the keep state /*{{{*/
  492. // ---------------------------------------------------------------------
  493. /* */
  494. void pkgDepCache::MarkKeep(PkgIterator const &Pkg,bool Soft)
  495. {
  496. // Simplifies other routines.
  497. if (Pkg.end() == true)
  498. return;
  499. /* We changed the soft state all the time so the UI is a bit nicer
  500. to use */
  501. StateCache &P = PkgState[Pkg->ID];
  502. if (Soft == true)
  503. P.iFlags |= AutoKept;
  504. else
  505. P.iFlags &= ~AutoKept;
  506. // Check that it is not already kept
  507. if (P.Mode == ModeKeep)
  508. return;
  509. // We dont even try to keep virtual packages..
  510. if (Pkg->VersionList == 0)
  511. return;
  512. P.Flags &= ~Flag::Auto;
  513. RemoveSizes(Pkg);
  514. RemoveStates(Pkg);
  515. P.Mode = ModeKeep;
  516. if (Pkg->CurrentVer == 0)
  517. P.InstallVer = 0;
  518. else
  519. P.InstallVer = Pkg.CurrentVer();
  520. AddStates(Pkg);
  521. Update(Pkg);
  522. AddSizes(Pkg);
  523. }
  524. /*}}}*/
  525. // DepCache::MarkDelete - Put the package in the delete state /*{{{*/
  526. // ---------------------------------------------------------------------
  527. /* */
  528. void pkgDepCache::MarkDelete(PkgIterator const &Pkg)
  529. {
  530. // Simplifies other routines.
  531. if (Pkg.end() == true)
  532. return;
  533. // Check that it is not already marked for delete
  534. StateCache &P = PkgState[Pkg->ID];
  535. P.iFlags &= ~AutoKept;
  536. if (P.Mode == ModeDelete || P.InstallVer == 0)
  537. return;
  538. // We dont even try to delete virtual packages..
  539. if (Pkg->VersionList == 0)
  540. return;
  541. RemoveSizes(Pkg);
  542. RemoveStates(Pkg);
  543. if (Pkg->CurrentVer == 0)
  544. P.Mode = ModeKeep;
  545. else
  546. P.Mode = ModeDelete;
  547. P.InstallVer = 0;
  548. P.Flags &= Flag::Auto;
  549. AddStates(Pkg);
  550. Update(Pkg);
  551. AddSizes(Pkg);
  552. }
  553. /*}}}*/
  554. // DepCache::MarkInstall - Put the package in the install state /*{{{*/
  555. // ---------------------------------------------------------------------
  556. /* */
  557. void pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst)
  558. {
  559. // Simplifies other routines.
  560. if (Pkg.end() == true)
  561. return;
  562. /* Check that it is not already marked for install and that it can be
  563. installed */
  564. StateCache &P = PkgState[Pkg->ID];
  565. P.iFlags &= ~AutoKept;
  566. if (P.InstBroken() == false && (P.Mode == ModeInstall ||
  567. P.CandidateVer == (Version *)Pkg.CurrentVer()))
  568. {
  569. if (P.CandidateVer == (Version *)Pkg.CurrentVer() && P.InstallVer == 0)
  570. MarkKeep(Pkg);
  571. return;
  572. }
  573. // We dont even try to install virtual packages..
  574. if (Pkg->VersionList == 0)
  575. return;
  576. /* Target the candidate version and remove the autoflag. We reset the
  577. autoflag below if this was called recursively. Otherwise the user
  578. should have the ability to de-auto a package by changing its state */
  579. RemoveSizes(Pkg);
  580. RemoveStates(Pkg);
  581. P.Mode = ModeInstall;
  582. P.InstallVer = P.CandidateVer;
  583. P.Flags &= ~Flag::Auto;
  584. if (P.CandidateVer == (Version *)Pkg.CurrentVer())
  585. P.Mode = ModeKeep;
  586. AddStates(Pkg);
  587. Update(Pkg);
  588. AddSizes(Pkg);
  589. if (AutoInst == false)
  590. return;
  591. DepIterator Dep = P.InstVerIter(*this).DependsList();
  592. for (; Dep.end() != true;)
  593. {
  594. // Grok or groups
  595. DepIterator Start = Dep;
  596. bool Result = true;
  597. for (bool LastOR = true; Dep.end() == false && LastOR == true; Dep++)
  598. {
  599. LastOR = (Dep->CompareOp & Dep::Or) == Dep::Or;
  600. if ((DepState[Dep->ID] & DepInstall) == DepInstall)
  601. Result = false;
  602. }
  603. // Dep is satisfied okay.
  604. if (Result == false)
  605. continue;
  606. /* Check if this dep should be consider for install. If it is a user
  607. defined important dep and we are installed a new package then
  608. it will be installed. Otherwise we only worry about critical deps */
  609. if (IsImportantDep(Start) == false)
  610. continue;
  611. if (Pkg->CurrentVer != 0 && Start.IsCritical() == false)
  612. continue;
  613. // Now we have to take action...
  614. PkgIterator P = Start.SmartTargetPkg();
  615. if ((DepState[Start->ID] & DepCVer) == DepCVer)
  616. {
  617. MarkInstall(P,true);
  618. // Set the autoflag, after MarkInstall because MarkInstall unsets it
  619. if (P->CurrentVer == 0)
  620. PkgState[P->ID].Flags |= Flag::Auto;
  621. continue;
  622. }
  623. // For conflicts we just de-install the package and mark as auto
  624. if (Start->Type == Dep::Conflicts)
  625. {
  626. Version **List = Start.AllTargets();
  627. for (Version **I = List; *I != 0; I++)
  628. {
  629. VerIterator Ver(*this,*I);
  630. PkgIterator Pkg = Ver.ParentPkg();
  631. MarkDelete(Pkg);
  632. PkgState[Pkg->ID].Flags |= Flag::Auto;
  633. }
  634. delete [] List;
  635. continue;
  636. }
  637. }
  638. }
  639. /*}}}*/
  640. // StateCache::Update - Compute the various static display things /*{{{*/
  641. // ---------------------------------------------------------------------
  642. /* This is called whenever the Candidate version changes. */
  643. void pkgDepCache::StateCache::Update(PkgIterator Pkg,pkgCache &Cache)
  644. {
  645. // Some info
  646. VerIterator Ver = CandidateVerIter(Cache);
  647. // Use a null string or the version string
  648. if (Ver.end() == true)
  649. CandVersion = "";
  650. else
  651. CandVersion = Ver.VerStr();
  652. // Find the current version
  653. CurVersion = "";
  654. if (Pkg->CurrentVer != 0)
  655. CurVersion = Pkg.CurrentVer().VerStr();
  656. // Strip off the epochs for display
  657. CurVersion = StripEpoch(CurVersion);
  658. CandVersion = StripEpoch(CandVersion);
  659. // Figure out if its up or down or equal
  660. Status = Ver.CompareVer(Pkg.CurrentVer());
  661. if (Pkg->CurrentVer == 0 || Pkg->VersionList == 0 || CandidateVer == 0)
  662. Status = 2;
  663. }
  664. /*}}}*/
  665. // StateCache::StripEpoch - Remove the epoch specifier from the version /*{{{*/
  666. // ---------------------------------------------------------------------
  667. /* */
  668. const char *pkgDepCache::StateCache::StripEpoch(const char *Ver)
  669. {
  670. if (Ver == 0)
  671. return 0;
  672. // Strip any epoch
  673. for (const char *I = Ver; *I != 0; I++)
  674. if (*I == ':')
  675. return I + 1;
  676. return Ver;
  677. }
  678. /*}}}*/