]> git.saurik.com Git - apt.git/blame - apt-pkg/depcache.h
* use mark-and-sweep from aptitude now as GC algorithm
[apt.git] / apt-pkg / depcache.h
CommitLineData
6c139d6e
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
b2e465d6 3// $Id: depcache.h,v 1.14 2001/02/20 07:03:17 jgg Exp $
6c139d6e
AL
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 /*}}}*/
6c139d6e
AL
38#ifndef PKGLIB_DEPCACHE_H
39#define PKGLIB_DEPCACHE_H
40
41#ifdef __GNUG__
094a497d 42#pragma interface "apt-pkg/depcache.h"
6c139d6e
AL
43#endif
44
094a497d 45#include <apt-pkg/pkgcache.h>
a246f2dc 46#include <apt-pkg/progress.h>
6c139d6e 47
b2e465d6 48class pkgDepCache : protected pkgCache::Namespace
6c139d6e
AL
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
d0c59649 62 enum InternalFlags {AutoKept = (1 << 0), Purge = (1 << 1), ReInstall = (1 << 2)};
6c139d6e
AL
63
64 enum VersionTypes {NowVersion, InstallVersion, CandidateVersion};
65 enum ModeList {ModeDelete = 0, ModeKeep = 1, ModeInstall = 2};
0a57c0f0
MV
66
67 // Flags for the GC
68 enum ChangedReason {Manual, UserAuto, Libapt, FromResolver, PkgIsUnused};
69
6c139d6e
AL
70 struct StateCache
71 {
72 // Epoch stripped text versions of the two version fields
73 const char *CandVersion;
74 const char *CurVersion;
75
76 // Pointer to the candidate install version.
77 Version *CandidateVer;
78
79 // Pointer to the install version.
80 Version *InstallVer;
b2e465d6
AL
81
82 // Copy of Package::Flags
83 unsigned short Flags;
84 unsigned short iFlags; // Internal flags
6c139d6e 85
0a57c0f0
MV
86 // mark and sweep flags
87 ChangedReason InstallReason;
88#if 0
89 ChangedReason RemoveReason;
90#endif
91 bool Marked;
92 bool Garbage;
afb1e2e3 93
6c139d6e
AL
94 // Various tree indicators
95 signed char Status; // -1,0,1,2
96 unsigned char Mode; // ModeList
97 unsigned char DepState; // DepState Flags
98
6c139d6e
AL
99 // Update of candidate version
100 const char *StripEpoch(const char *Ver);
101 void Update(PkgIterator Pkg,pkgCache &Cache);
102
103 // Various test members for the current status of the package
104 inline bool NewInstall() const {return Status == 2 && Mode == ModeInstall;};
105 inline bool Delete() const {return Mode == ModeDelete;};
106 inline bool Keep() const {return Mode == ModeKeep;};
107 inline bool Upgrade() const {return Status > 0 && Mode == ModeInstall;};
0a8e3465 108 inline bool Upgradable() const {return Status >= 1;};
6321777b 109 inline bool Downgrade() const {return Status < 0 && Mode == ModeInstall;};
6c139d6e
AL
110 inline bool Held() const {return Status != 0 && Keep();};
111 inline bool NowBroken() const {return (DepState & DepNowMin) != DepNowMin;};
112 inline bool InstBroken() const {return (DepState & DepInstMin) != DepInstMin;};
113 inline bool Install() const {return Mode == ModeInstall;};
114 inline VerIterator InstVerIter(pkgCache &Cache)
115 {return VerIterator(Cache,InstallVer);};
116 inline VerIterator CandidateVerIter(pkgCache &Cache)
117 {return VerIterator(Cache,CandidateVer);};
118 };
119
120 // Helper functions
121 void BuildGroupOrs(VerIterator const &V);
122 void UpdateVerState(PkgIterator Pkg);
123
b2e465d6
AL
124 // User Policy control
125 class Policy
126 {
127 public:
128
129 virtual VerIterator GetCandidateVer(PkgIterator Pkg);
130 virtual bool IsImportantDep(DepIterator Dep);
131
132 virtual ~Policy() {};
133 };
134
6c139d6e
AL
135 protected:
136
137 // State information
b2e465d6 138 pkgCache *Cache;
6c139d6e
AL
139 StateCache *PkgState;
140 unsigned char *DepState;
141
b2e465d6
AL
142 double iUsrSize;
143 double iDownloadSize;
a6568219
AL
144 unsigned long iInstCount;
145 unsigned long iDelCount;
146 unsigned long iKeepCount;
147 unsigned long iBrokenCount;
148 unsigned long iBadCount;
b2e465d6
AL
149
150 Policy *delLocalPolicy; // For memory clean up..
151 Policy *LocalPolicy;
152
6c139d6e
AL
153 // Check for a matching provides
154 bool CheckDep(DepIterator Dep,int Type,PkgIterator &Res);
155 inline bool CheckDep(DepIterator Dep,int Type)
156 {
b2e465d6 157 PkgIterator Res(*this,0);
6c139d6e 158 return CheckDep(Dep,Type,Res);
b2e465d6 159 }
6c139d6e
AL
160
161 // Computes state information for deps and versions (w/o storing)
162 unsigned char DependencyState(DepIterator &D);
163 unsigned char VersionState(DepIterator D,unsigned char Check,
164 unsigned char SetMin,
165 unsigned char SetPolicy);
166
167 // Recalculates various portions of the cache, call after changing something
168 void Update(DepIterator Dep); // Mostly internal
169 void Update(PkgIterator const &P);
170
171 // Count manipulators
b2e465d6 172 void AddSizes(const PkgIterator &Pkg,signed long Mult = 1);
6c139d6e
AL
173 inline void RemoveSizes(const PkgIterator &Pkg) {AddSizes(Pkg,-1);};
174 void AddStates(const PkgIterator &Pkg,int Add = 1);
175 inline void RemoveStates(const PkgIterator &Pkg) {AddStates(Pkg,-1);};
b2e465d6 176
6c139d6e
AL
177 public:
178
b2e465d6
AL
179 // Legacy.. We look like a pkgCache
180 inline operator pkgCache &() {return *Cache;};
181 inline Header &Head() {return *Cache->HeaderP;};
182 inline PkgIterator PkgBegin() {return Cache->PkgBegin();};
183 inline PkgIterator FindPkg(string const &Name) {return Cache->FindPkg(Name);};
184
185 inline pkgCache &GetCache() {return *Cache;};
186 inline pkgVersioningSystem &VS() {return *Cache->VS;};
187
6c139d6e 188 // Policy implementation
b2e465d6
AL
189 inline VerIterator GetCandidateVer(PkgIterator Pkg) {return LocalPolicy->GetCandidateVer(Pkg);};
190 inline bool IsImportantDep(DepIterator Dep) {return LocalPolicy->IsImportantDep(Dep);};
191 inline Policy &GetPolicy() {return *LocalPolicy;};
192
6c139d6e
AL
193 // Accessors
194 inline StateCache &operator [](PkgIterator const &I) {return PkgState[I->ID];};
195 inline unsigned char &operator [](DepIterator const &I) {return DepState[I->ID];};
196
197 // Manipulators
198 void MarkKeep(PkgIterator const &Pkg,bool Soft = false);
d556d1a1 199 void MarkDelete(PkgIterator const &Pkg,bool Purge = false);
b2e465d6
AL
200 void MarkInstall(PkgIterator const &Pkg,bool AutoInst = true,
201 unsigned long Depth = 0);
d0c59649 202 void SetReInstall(PkgIterator const &Pkg,bool To);
6321777b 203 void SetCandidateVersion(VerIterator TargetVer);
6c139d6e
AL
204
205 // This is for debuging
a246f2dc 206 void Update(OpProgress *Prog = 0);
a83d884d
MV
207
208 // read persistent states
209 bool readStateFile(OpProgress *prog);
210 bool writeStateFile(OpProgress *prog);
e331f6ed 211
6c139d6e 212 // Size queries
b2e465d6
AL
213 inline double UsrSize() {return iUsrSize;};
214 inline double DebSize() {return iDownloadSize;};
a6568219
AL
215 inline unsigned long DelCount() {return iDelCount;};
216 inline unsigned long KeepCount() {return iKeepCount;};
217 inline unsigned long InstCount() {return iInstCount;};
218 inline unsigned long BrokenCount() {return iBrokenCount;};
219 inline unsigned long BadCount() {return iBadCount;};
b2e465d6
AL
220
221 bool Init(OpProgress *Prog);
6c139d6e 222
b2e465d6 223 pkgDepCache(pkgCache *Cache,Policy *Plcy = 0);
6c139d6e
AL
224 virtual ~pkgDepCache();
225};
226
227#endif