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