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

138 lines
3.9 KiB

  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: algorithms.h,v 1.10 2001/05/22 04:17:41 jgg Exp $
  4. /* ######################################################################
  5. Algorithms - A set of misc algorithms
  6. This simulate class displays what the ordering code has done and
  7. analyses it with a fresh new dependency cache. In this way we can
  8. see all of the effects of an upgrade run.
  9. pkgDistUpgrade computes an upgrade that causes as many packages as
  10. possible to move to the newest verison.
  11. pkgApplyStatus sets the target state based on the content of the status
  12. field in the status file. It is important to get proper crash recovery.
  13. pkgFixBroken corrects a broken system so that it is in a sane state.
  14. pkgAllUpgrade attempts to upgade as many packages as possible but
  15. without installing new packages.
  16. The problem resolver class contains a number of complex algorithms
  17. to try to best-guess an upgrade state. It solves the problem of
  18. maximizing the number of install state packages while having no broken
  19. packages.
  20. ##################################################################### */
  21. /*}}}*/
  22. #ifndef PKGLIB_ALGORITHMS_H
  23. #define PKGLIB_ALGORITHMS_H
  24. #include <apt-pkg/packagemanager.h>
  25. #include <apt-pkg/depcache.h>
  26. #include <apt-pkg/acquire.h>
  27. #include <iostream>
  28. using std::ostream;
  29. class pkgSimulate : public pkgPackageManager
  30. {
  31. protected:
  32. class Policy : public pkgDepCache::Policy
  33. {
  34. pkgDepCache *Cache;
  35. public:
  36. virtual VerIterator GetCandidateVer(PkgIterator Pkg)
  37. {
  38. return (*Cache)[Pkg].CandidateVerIter(*Cache);
  39. }
  40. Policy(pkgDepCache *Cache) : Cache(Cache) {};
  41. };
  42. unsigned char *Flags;
  43. Policy iPolicy;
  44. pkgDepCache Sim;
  45. // The Actuall installation implementation
  46. virtual bool Install(PkgIterator Pkg,string File);
  47. virtual bool Configure(PkgIterator Pkg);
  48. virtual bool Remove(PkgIterator Pkg,bool Purge);
  49. private:
  50. void ShortBreaks();
  51. void Describe(PkgIterator iPkg,ostream &out,bool Current,bool Candidate);
  52. public:
  53. pkgSimulate(pkgDepCache *Cache);
  54. };
  55. class pkgProblemResolver
  56. {
  57. pkgDepCache &Cache;
  58. typedef pkgCache::PkgIterator PkgIterator;
  59. typedef pkgCache::VerIterator VerIterator;
  60. typedef pkgCache::DepIterator DepIterator;
  61. typedef pkgCache::PrvIterator PrvIterator;
  62. typedef pkgCache::Version Version;
  63. typedef pkgCache::Package Package;
  64. enum Flags {Protected = (1 << 0), PreInstalled = (1 << 1),
  65. Upgradable = (1 << 2), ReInstateTried = (1 << 3),
  66. ToRemove = (1 << 4)};
  67. signed short *Scores;
  68. unsigned char *Flags;
  69. bool Debug;
  70. // Sort stuff
  71. static pkgProblemResolver *This;
  72. static int ScoreSort(const void *a,const void *b);
  73. struct PackageKill
  74. {
  75. PkgIterator Pkg;
  76. DepIterator Dep;
  77. };
  78. void MakeScores();
  79. bool DoUpgrade(pkgCache::PkgIterator Pkg);
  80. public:
  81. inline void Protect(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= Protected;};
  82. inline void Remove(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= ToRemove;};
  83. inline void Clear(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] &= ~(Protected | ToRemove);};
  84. // Try to intelligently resolve problems by installing and removing packages
  85. bool Resolve(bool BrokenFix = false);
  86. // Try to resolve problems only by using keep
  87. bool ResolveByKeep();
  88. // Install all protected packages
  89. void InstallProtect();
  90. pkgProblemResolver(pkgDepCache *Cache);
  91. ~pkgProblemResolver();
  92. };
  93. bool pkgDistUpgrade(pkgDepCache &Cache);
  94. bool pkgApplyStatus(pkgDepCache &Cache);
  95. bool pkgFixBroken(pkgDepCache &Cache);
  96. bool pkgAllUpgrade(pkgDepCache &Cache);
  97. bool pkgMinimizeUpgrade(pkgDepCache &Cache);
  98. void pkgPrioSortList(pkgCache &Cache,pkgCache::Version **List);
  99. bool ListUpdate(pkgAcquireStatus &progress, pkgSourceList &List, int PulseInterval=0);
  100. #endif