depcache.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: depcache.h,v 1.6 1998/11/13 07:08:58 jgg Exp $
  4. /* ######################################################################
  5. DepCache - Dependency Extension data for the cache
  6. This class stores the cache data and a set of extension structures for
  7. monitoring the current state of all the packages. It also generates and
  8. caches the 'install' state of many things. This refers to the state of the
  9. package after an install has been run.
  10. The StateCache::State field can be -1,0,1,2 which is <,=,>,no current.
  11. StateCache::Mode is which of the 3 fields is active.
  12. This structure is important to support the readonly status of the cache
  13. file. When the data is saved the cache will be refereshed from our
  14. internal rep and written to disk. Then the actual persistant data
  15. files will be put on the disk.
  16. Each dependency is compared against 3 target versions to produce to
  17. 3 dependency results.
  18. Now - Compared using the Currently install version
  19. Install - Compared using the install version (final state)
  20. CVer - (Candidate Verion) Compared using the Candidate Version
  21. The candidate and now results are used to decide wheather a package
  22. should be automatically installed or if it should be left alone.
  23. Remember, the Candidate Version is selected based on the distribution
  24. settings for the Package. The Install Version is selected based on the
  25. state (Delete, Keep, Install) field and can be either the Current Version
  26. or the Candidate version.
  27. The Candidate version is what is shown the 'Install Version' field.
  28. ##################################################################### */
  29. /*}}}*/
  30. // Header section: pkglib
  31. #ifndef PKGLIB_DEPCACHE_H
  32. #define PKGLIB_DEPCACHE_H
  33. #ifdef __GNUG__
  34. #pragma interface "apt-pkg/depcache.h"
  35. #endif
  36. #include <apt-pkg/pkgcache.h>
  37. #include <apt-pkg/progress.h>
  38. class pkgDepCache : public pkgCache
  39. {
  40. public:
  41. // These flags are used in DepState
  42. enum DepFlags {DepNow = (1 << 0),DepInstall = (1 << 1),DepCVer = (1 << 2),
  43. DepGNow = (1 << 3),DepGInstall = (1 << 4),DepGCVer = (1 << 5)};
  44. // These flags are used in StateCache::DepState
  45. enum DepStateFlags {DepNowPolicy = (1 << 0), DepNowMin = (1 << 1),
  46. DepInstPolicy = (1 << 2), DepInstMin = (1 << 3),
  47. DepCandPolicy = (1 << 4), DepCandMin = (1 << 5)};
  48. // These flags are used in StateCache::iFlags
  49. enum InternalFlags {AutoKept = (1 << 0)};
  50. enum VersionTypes {NowVersion, InstallVersion, CandidateVersion};
  51. enum ModeList {ModeDelete = 0, ModeKeep = 1, ModeInstall = 2};
  52. struct StateCache
  53. {
  54. // Epoch stripped text versions of the two version fields
  55. const char *CandVersion;
  56. const char *CurVersion;
  57. // Pointer to the candidate install version.
  58. Version *CandidateVer;
  59. // Pointer to the install version.
  60. Version *InstallVer;
  61. // Various tree indicators
  62. signed char Status; // -1,0,1,2
  63. unsigned char Mode; // ModeList
  64. unsigned char DepState; // DepState Flags
  65. // Copy of Package::Flags
  66. unsigned short Flags;
  67. unsigned short iFlags; // Internal flags
  68. // Update of candidate version
  69. const char *StripEpoch(const char *Ver);
  70. void Update(PkgIterator Pkg,pkgCache &Cache);
  71. // Various test members for the current status of the package
  72. inline bool NewInstall() const {return Status == 2 && Mode == ModeInstall;};
  73. inline bool Delete() const {return Mode == ModeDelete;};
  74. inline bool Keep() const {return Mode == ModeKeep;};
  75. inline bool Upgrade() const {return Status > 0 && Mode == ModeInstall;};
  76. inline bool Upgradable() const {return Status >= 1;};
  77. inline bool Downgrade() const {return Status < 0;};
  78. inline bool Held() const {return Status != 0 && Keep();};
  79. inline bool NowBroken() const {return (DepState & DepNowMin) != DepNowMin;};
  80. inline bool InstBroken() const {return (DepState & DepInstMin) != DepInstMin;};
  81. inline bool Install() const {return Mode == ModeInstall;};
  82. inline VerIterator InstVerIter(pkgCache &Cache)
  83. {return VerIterator(Cache,InstallVer);};
  84. inline VerIterator CandidateVerIter(pkgCache &Cache)
  85. {return VerIterator(Cache,CandidateVer);};
  86. };
  87. // Helper functions
  88. void BuildGroupOrs(VerIterator const &V);
  89. void UpdateVerState(PkgIterator Pkg);
  90. bool Init(OpProgress *Prog);
  91. protected:
  92. // State information
  93. StateCache *PkgState;
  94. unsigned char *DepState;
  95. signed long iUsrSize;
  96. unsigned long iDownloadSize;
  97. unsigned long iInstCount;
  98. unsigned long iDelCount;
  99. unsigned long iKeepCount;
  100. unsigned long iBrokenCount;
  101. unsigned long iBadCount;
  102. // Check for a matching provides
  103. bool CheckDep(DepIterator Dep,int Type,PkgIterator &Res);
  104. inline bool CheckDep(DepIterator Dep,int Type)
  105. {
  106. PkgIterator Res(*this);
  107. return CheckDep(Dep,Type,Res);
  108. }
  109. // Computes state information for deps and versions (w/o storing)
  110. unsigned char DependencyState(DepIterator &D);
  111. unsigned char VersionState(DepIterator D,unsigned char Check,
  112. unsigned char SetMin,
  113. unsigned char SetPolicy);
  114. // Recalculates various portions of the cache, call after changing something
  115. void Update(DepIterator Dep); // Mostly internal
  116. void Update(PkgIterator const &P);
  117. // Count manipulators
  118. void AddSizes(const PkgIterator &Pkg,long Mult = 1);
  119. inline void RemoveSizes(const PkgIterator &Pkg) {AddSizes(Pkg,-1);};
  120. void AddStates(const PkgIterator &Pkg,int Add = 1);
  121. inline void RemoveStates(const PkgIterator &Pkg) {AddStates(Pkg,-1);};
  122. public:
  123. // Policy implementation
  124. virtual VerIterator GetCandidateVer(PkgIterator Pkg);
  125. virtual bool IsImportantDep(DepIterator Dep);
  126. // Accessors
  127. inline StateCache &operator [](PkgIterator const &I) {return PkgState[I->ID];};
  128. inline unsigned char &operator [](DepIterator const &I) {return DepState[I->ID];};
  129. // Manipulators
  130. void MarkKeep(PkgIterator const &Pkg,bool Soft = false);
  131. void MarkDelete(PkgIterator const &Pkg);
  132. void MarkInstall(PkgIterator const &Pkg,bool AutoInst = true);
  133. // This is for debuging
  134. void Update(OpProgress *Prog = 0);
  135. // Size queries
  136. inline signed long UsrSize() {return iUsrSize;};
  137. inline unsigned long DebSize() {return iDownloadSize;};
  138. inline unsigned long DelCount() {return iDelCount;};
  139. inline unsigned long KeepCount() {return iKeepCount;};
  140. inline unsigned long InstCount() {return iInstCount;};
  141. inline unsigned long BrokenCount() {return iBrokenCount;};
  142. inline unsigned long BadCount() {return iBadCount;};
  143. pkgDepCache(MMap &Map,OpProgress &Prog);
  144. virtual ~pkgDepCache();
  145. };
  146. #endif