]> git.saurik.com Git - apt.git/blob - apt-pkg/depcache.h
* merged with apt--main and apt--fixes
[apt.git] / apt-pkg / depcache.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: depcache.h,v 1.14 2001/02/20 07:03:17 jgg Exp $
4 /* ######################################################################
5
6 DepCache - Dependency Extension data for the cache
7
8 This class stores the cache data and a set of extension structures for
9 monitoring the current state of all the packages. It also generates and
10 caches the 'install' state of many things. This refers to the state of the
11 package after an install has been run.
12
13 The StateCache::State field can be -1,0,1,2 which is <,=,>,no current.
14 StateCache::Mode is which of the 3 fields is active.
15
16 This structure is important to support the readonly status of the cache
17 file. When the data is saved the cache will be refereshed from our
18 internal rep and written to disk. Then the actual persistant data
19 files will be put on the disk.
20
21 Each dependency is compared against 3 target versions to produce to
22 3 dependency results.
23 Now - Compared using the Currently install version
24 Install - Compared using the install version (final state)
25 CVer - (Candidate Verion) Compared using the Candidate Version
26 The candidate and now results are used to decide wheather a package
27 should be automatically installed or if it should be left alone.
28
29 Remember, the Candidate Version is selected based on the distribution
30 settings for the Package. The Install Version is selected based on the
31 state (Delete, Keep, Install) field and can be either the Current Version
32 or the Candidate version.
33
34 The Candidate version is what is shown the 'Install Version' field.
35
36 ##################################################################### */
37 /*}}}*/
38 #ifndef PKGLIB_DEPCACHE_H
39 #define PKGLIB_DEPCACHE_H
40
41 #ifdef __GNUG__
42 #pragma interface "apt-pkg/depcache.h"
43 #endif
44
45 #include <apt-pkg/pkgcache.h>
46 #include <apt-pkg/progress.h>
47
48 class pkgDepCache : protected pkgCache::Namespace
49 {
50 public:
51
52 // These flags are used in DepState
53 enum DepFlags {DepNow = (1 << 0),DepInstall = (1 << 1),DepCVer = (1 << 2),
54 DepGNow = (1 << 3),DepGInstall = (1 << 4),DepGCVer = (1 << 5)};
55
56 // These flags are used in StateCache::DepState
57 enum DepStateFlags {DepNowPolicy = (1 << 0), DepNowMin = (1 << 1),
58 DepInstPolicy = (1 << 2), DepInstMin = (1 << 3),
59 DepCandPolicy = (1 << 4), DepCandMin = (1 << 5)};
60
61 // These flags are used in StateCache::iFlags
62 enum InternalFlags {AutoKept = (1 << 0), Purge = (1 << 1), ReInstall = (1 << 2)};
63
64 enum VersionTypes {NowVersion, InstallVersion, CandidateVersion};
65 enum ModeList {ModeDelete = 0, ModeKeep = 1, ModeInstall = 2};
66 struct StateCache
67 {
68 // Epoch stripped text versions of the two version fields
69 const char *CandVersion;
70 const char *CurVersion;
71
72 // Pointer to the candidate install version.
73 Version *CandidateVer;
74
75 // Pointer to the install version.
76 Version *InstallVer;
77
78 // Copy of Package::Flags
79 unsigned short Flags;
80 unsigned short iFlags; // Internal flags
81
82 // Traversal status and state for automatic removal
83 unsigned char DirtyState;
84 unsigned char AutomaticRemove;
85
86 // Various tree indicators
87 signed char Status; // -1,0,1,2
88 unsigned char Mode; // ModeList
89 unsigned char DepState; // DepState Flags
90
91 // Update of candidate version
92 const char *StripEpoch(const char *Ver);
93 void Update(PkgIterator Pkg,pkgCache &Cache);
94
95 // Various test members for the current status of the package
96 inline bool NewInstall() const {return Status == 2 && Mode == ModeInstall;};
97 inline bool Delete() const {return Mode == ModeDelete;};
98 inline bool Keep() const {return Mode == ModeKeep;};
99 inline bool Upgrade() const {return Status > 0 && Mode == ModeInstall;};
100 inline bool Upgradable() const {return Status >= 1;};
101 inline bool Downgrade() const {return Status < 0 && Mode == ModeInstall;};
102 inline bool Held() const {return Status != 0 && Keep();};
103 inline bool NowBroken() const {return (DepState & DepNowMin) != DepNowMin;};
104 inline bool InstBroken() const {return (DepState & DepInstMin) != DepInstMin;};
105 inline bool Install() const {return Mode == ModeInstall;};
106 inline unsigned char Dirty() const {return DirtyState;};
107 inline VerIterator InstVerIter(pkgCache &Cache)
108 {return VerIterator(Cache,InstallVer);};
109 inline VerIterator CandidateVerIter(pkgCache &Cache)
110 {return VerIterator(Cache,CandidateVer);};
111 };
112
113 // Helper functions
114 void BuildGroupOrs(VerIterator const &V);
115 void UpdateVerState(PkgIterator Pkg);
116
117 // User Policy control
118 class Policy
119 {
120 public:
121
122 virtual VerIterator GetCandidateVer(PkgIterator Pkg);
123 virtual bool IsImportantDep(DepIterator Dep);
124
125 virtual ~Policy() {};
126 };
127
128 protected:
129
130 // State information
131 pkgCache *Cache;
132 StateCache *PkgState;
133 unsigned char *DepState;
134
135 double iUsrSize;
136 double iDownloadSize;
137 unsigned long iInstCount;
138 unsigned long iDelCount;
139 unsigned long iKeepCount;
140 unsigned long iBrokenCount;
141 unsigned long iBadCount;
142
143 Policy *delLocalPolicy; // For memory clean up..
144 Policy *LocalPolicy;
145
146 // Check for a matching provides
147 bool CheckDep(DepIterator Dep,int Type,PkgIterator &Res);
148 inline bool CheckDep(DepIterator Dep,int Type)
149 {
150 PkgIterator Res(*this,0);
151 return CheckDep(Dep,Type,Res);
152 }
153
154 // Computes state information for deps and versions (w/o storing)
155 unsigned char DependencyState(DepIterator &D);
156 unsigned char VersionState(DepIterator D,unsigned char Check,
157 unsigned char SetMin,
158 unsigned char SetPolicy);
159
160 // Recalculates various portions of the cache, call after changing something
161 void Update(DepIterator Dep); // Mostly internal
162 void Update(PkgIterator const &P);
163
164 // Count manipulators
165 void AddSizes(const PkgIterator &Pkg,signed long Mult = 1);
166 inline void RemoveSizes(const PkgIterator &Pkg) {AddSizes(Pkg,-1);};
167 void AddStates(const PkgIterator &Pkg,int Add = 1);
168 inline void RemoveStates(const PkgIterator &Pkg) {AddStates(Pkg,-1);};
169
170 public:
171
172 // Legacy.. We look like a pkgCache
173 inline operator pkgCache &() {return *Cache;};
174 inline Header &Head() {return *Cache->HeaderP;};
175 inline PkgIterator PkgBegin() {return Cache->PkgBegin();};
176 inline PkgIterator FindPkg(string const &Name) {return Cache->FindPkg(Name);};
177
178 inline pkgCache &GetCache() {return *Cache;};
179 inline pkgVersioningSystem &VS() {return *Cache->VS;};
180
181 // Policy implementation
182 inline VerIterator GetCandidateVer(PkgIterator Pkg) {return LocalPolicy->GetCandidateVer(Pkg);};
183 inline bool IsImportantDep(DepIterator Dep) {return LocalPolicy->IsImportantDep(Dep);};
184 inline Policy &GetPolicy() {return *LocalPolicy;};
185
186 // Accessors
187 inline StateCache &operator [](PkgIterator const &I) {return PkgState[I->ID];};
188 inline unsigned char &operator [](DepIterator const &I) {return DepState[I->ID];};
189
190 // Manipulators
191 void MarkKeep(PkgIterator const &Pkg,bool Soft = false);
192 void MarkDelete(PkgIterator const &Pkg,bool Purge = false);
193 void MarkInstall(PkgIterator const &Pkg,bool AutoInst = true,
194 unsigned long Depth = 0);
195 void SetReInstall(PkgIterator const &Pkg,bool To);
196 void SetCandidateVersion(VerIterator TargetVer);
197 void SetDirty(PkgIterator const &Pkg, pkgCache::State::PkgRemoveState To);
198
199 // This is for debuging
200 void Update(OpProgress *Prog = 0);
201
202 // read persistent states
203 bool readStateFile(OpProgress *prog);
204 bool writeStateFile(OpProgress *prog);
205
206 // Size queries
207 inline double UsrSize() {return iUsrSize;};
208 inline double DebSize() {return iDownloadSize;};
209 inline unsigned long DelCount() {return iDelCount;};
210 inline unsigned long KeepCount() {return iKeepCount;};
211 inline unsigned long InstCount() {return iInstCount;};
212 inline unsigned long BrokenCount() {return iBrokenCount;};
213 inline unsigned long BadCount() {return iBadCount;};
214
215 bool Init(OpProgress *Prog);
216
217 pkgDepCache(pkgCache *Cache,Policy *Plcy = 0);
218 virtual ~pkgDepCache();
219 };
220
221 #endif