depcache.cc 22 KB

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