depcache.cc 22 KB

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