algorithms.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: algorithms.h,v 1.7 1999/07/09 04:11:34 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. // Header section: pkglib
  23. #ifndef PKGLIB_ALGORITHMS_H
  24. #define PKGLIB_ALGORITHMS_H
  25. #ifdef __GNUG__
  26. #pragma interface "apt-pkg/algorithms.h"
  27. #endif
  28. #include <apt-pkg/packagemanager.h>
  29. #include <apt-pkg/depcache.h>
  30. class pkgSimulate : public pkgPackageManager
  31. {
  32. protected:
  33. unsigned char *Flags;
  34. pkgDepCache Sim;
  35. // The Actuall installation implementation
  36. virtual bool Install(PkgIterator Pkg,string File);
  37. virtual bool Configure(PkgIterator Pkg);
  38. virtual bool Remove(PkgIterator Pkg,bool Purge);
  39. void ShortBreaks();
  40. public:
  41. pkgSimulate(pkgDepCache &Cache);
  42. };
  43. class pkgProblemResolver
  44. {
  45. pkgDepCache &Cache;
  46. typedef pkgCache::PkgIterator PkgIterator;
  47. typedef pkgCache::VerIterator VerIterator;
  48. typedef pkgCache::DepIterator DepIterator;
  49. typedef pkgCache::PrvIterator PrvIterator;
  50. typedef pkgCache::Version Version;
  51. typedef pkgCache::Package Package;
  52. enum Flags {Protected = (1 << 0), PreInstalled = (1 << 1),
  53. Upgradable = (1 << 2), ReInstateTried = (1 << 3),
  54. ToRemove = (1 << 4)};
  55. signed short *Scores;
  56. unsigned char *Flags;
  57. bool Debug;
  58. // Sort stuff
  59. static pkgProblemResolver *This;
  60. static int ScoreSort(const void *a,const void *b);
  61. struct PackageKill
  62. {
  63. PkgIterator Pkg;
  64. DepIterator Dep;
  65. };
  66. void MakeScores();
  67. bool DoUpgrade(pkgCache::PkgIterator Pkg);
  68. public:
  69. inline void Protect(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= Protected;};
  70. inline void Remove(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= ToRemove;};
  71. // Try to intelligently resolve problems by installing and removing packages
  72. bool Resolve(bool BrokenFix = false);
  73. // Try to resolve problems only by using keep
  74. bool ResolveByKeep();
  75. void InstallProtect();
  76. pkgProblemResolver(pkgDepCache &Cache);
  77. };
  78. bool pkgDistUpgrade(pkgDepCache &Cache);
  79. bool pkgApplyStatus(pkgDepCache &Cache);
  80. bool pkgFixBroken(pkgDepCache &Cache);
  81. bool pkgAllUpgrade(pkgDepCache &Cache);
  82. bool pkgMinimizeUpgrade(pkgDepCache &Cache);
  83. #endif