depcache.cc 22 KB

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