depcache.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: depcache.h,v 1.1 1998/07/07 04:17:01 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 "pkglib/depcache.h"
  35. #endif
  36. #include <pkglib/pkgcache.h>
  37. class pkgDepCache : public pkgCache
  38. {
  39. public:
  40. // These flags are used in DepState
  41. enum DepFlags {DepNow = (1 << 0),DepInstall = (1 << 1),DepCVer = (1 << 2),
  42. DepGNow = (1 << 3),DepGInstall = (1 << 4),DepGCVer = (1 << 5)};
  43. // These flags are used in StateCache::DepState
  44. enum DepStateFlags {DepNowPolicy = (1 << 0), DepNowMin = (1 << 1),
  45. DepInstPolicy = (1 << 2), DepInstMin = (1 << 3),
  46. DepCandPolicy = (1 << 4), DepCandMin = (1 << 5)};
  47. // These flags are used in StateCache::iFlags
  48. enum InternalFlags {AutoKept = (1 << 0)};
  49. enum VersionTypes {NowVersion, InstallVersion, CandidateVersion};
  50. enum ModeList {ModeDelete = 0, ModeKeep = 1, ModeInstall = 2};
  51. struct StateCache
  52. {
  53. // Epoch stripped text versions of the two version fields
  54. const char *CandVersion;
  55. const char *CurVersion;
  56. // Pointer to the candidate install version.
  57. Version *CandidateVer;
  58. // Pointer to the install version.
  59. Version *InstallVer;
  60. // Various tree indicators
  61. signed char Status; // -1,0,1,2
  62. unsigned char Mode; // ModeList
  63. unsigned char DepState; // DepState Flags
  64. // Copy of Package::Flags
  65. unsigned short Flags;
  66. unsigned short iFlags; // Internal flags
  67. // Update of candidate version
  68. const char *StripEpoch(const char *Ver);
  69. void Update(PkgIterator Pkg,pkgCache &Cache);
  70. // Various test members for the current status of the package
  71. inline bool NewInstall() const {return Status == 2 && Mode == ModeInstall;};
  72. inline bool Delete() const {return Mode == ModeDelete;};
  73. inline bool Keep() const {return Mode == ModeKeep;};
  74. inline bool Upgrade() const {return Status > 0 && Mode == ModeInstall;};
  75. inline bool Upgradable() const {return Status == 1;};
  76. inline bool Downgrade() const {return Status < 0;};
  77. inline bool Held() const {return Status != 0 && Keep();};
  78. inline bool NowBroken() const {return (DepState & DepNowMin) != DepNowMin;};
  79. inline bool InstBroken() const {return (DepState & DepInstMin) != DepInstMin;};
  80. inline bool Install() const {return Mode == ModeInstall;};
  81. inline VerIterator InstVerIter(pkgCache &Cache)
  82. {return VerIterator(Cache,InstallVer);};
  83. inline VerIterator CandidateVerIter(pkgCache &Cache)
  84. {return VerIterator(Cache,CandidateVer);};
  85. };
  86. // Helper functions
  87. void BuildGroupOrs(VerIterator const &V);
  88. void UpdateVerState(PkgIterator Pkg);
  89. bool Init();
  90. protected:
  91. // State information
  92. StateCache *PkgState;
  93. unsigned char *DepState;
  94. long iUsrSize;
  95. long iDownloadSize;
  96. long iInstCount;
  97. long iDelCount;
  98. long iKeepCount;
  99. long iBrokenCount;
  100. long iBadCount;
  101. // Check for a matching provides
  102. bool CheckDep(DepIterator Dep,int Type,PkgIterator &Res);
  103. inline bool CheckDep(DepIterator Dep,int Type)
  104. {
  105. PkgIterator Res(*this);
  106. return CheckDep(Dep,Type,Res);
  107. }
  108. // Computes state information for deps and versions (w/o storing)
  109. unsigned char DependencyState(DepIterator &D);
  110. unsigned char VersionState(DepIterator D,unsigned char Check,
  111. unsigned char SetMin,
  112. unsigned char SetPolicy);
  113. // Recalculates various portions of the cache, call after changing something
  114. void Update(DepIterator Dep); // Mostly internal
  115. void Update(PkgIterator const &P);
  116. // Count manipulators
  117. void AddSizes(const PkgIterator &Pkg,long Mult = 1);
  118. inline void RemoveSizes(const PkgIterator &Pkg) {AddSizes(Pkg,-1);};
  119. void AddStates(const PkgIterator &Pkg,int Add = 1);
  120. inline void RemoveStates(const PkgIterator &Pkg) {AddStates(Pkg,-1);};
  121. public:
  122. // Policy implementation
  123. virtual VerIterator GetCandidateVer(PkgIterator Pkg);
  124. virtual bool IsImportantDep(DepIterator Dep);
  125. // Accessors
  126. inline StateCache &operator [](PkgIterator const &I) {return PkgState[I->ID];};
  127. inline unsigned char &operator [](DepIterator const &I) {return DepState[I->ID];};
  128. // Manipulators
  129. void MarkKeep(PkgIterator const &Pkg,bool Soft = false);
  130. void MarkDelete(PkgIterator const &Pkg);
  131. void MarkInstall(PkgIterator const &Pkg,bool AutoInst = true);
  132. // This is for debuging
  133. void Update();
  134. // Dep Processing for AutoKeep
  135. void ResolveConflicts(unsigned char *Touched);
  136. // Hook to keep the extra data in sync
  137. virtual bool ReMap();
  138. // Size queries
  139. inline long UsrSize() {return iUsrSize;};
  140. inline long DebSize() {return iDownloadSize;};
  141. inline long DelCount() {return iDelCount;};
  142. inline long KeepCount() {return iKeepCount;};
  143. inline long InstCount() {return iInstCount;};
  144. inline long BrokenCount() {return iBrokenCount;};
  145. inline long BadCount() {return iBadCount;};
  146. pkgDepCache(MMap &Map);
  147. virtual ~pkgDepCache();
  148. };
  149. #endif