]>
git.saurik.com Git - apt.git/blob - apt-pkg/depcache.h
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: depcache.h,v 1.14 2001/02/20 07:03:17 jgg Exp $
4 /* ######################################################################
6 DepCache - Dependency Extension data for the cache
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.
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.
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.
21 Each dependency is compared against 3 target versions to produce to
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.
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.
34 The Candidate version is what is shown the 'Install Version' field.
36 ##################################################################### */
38 #ifndef PKGLIB_DEPCACHE_H
39 #define PKGLIB_DEPCACHE_H
42 #include <apt-pkg/pkgcache.h>
43 #include <apt-pkg/progress.h>
45 class pkgDepCache
: protected pkgCache::Namespace
49 // These flags are used in DepState
50 enum DepFlags
{DepNow
= (1 << 0),DepInstall
= (1 << 1),DepCVer
= (1 << 2),
51 DepGNow
= (1 << 3),DepGInstall
= (1 << 4),DepGCVer
= (1 << 5)};
53 // These flags are used in StateCache::DepState
54 enum DepStateFlags
{DepNowPolicy
= (1 << 0), DepNowMin
= (1 << 1),
55 DepInstPolicy
= (1 << 2), DepInstMin
= (1 << 3),
56 DepCandPolicy
= (1 << 4), DepCandMin
= (1 << 5)};
58 // These flags are used in StateCache::iFlags
59 enum InternalFlags
{AutoKept
= (1 << 0), Purge
= (1 << 1), ReInstall
= (1 << 2)};
61 enum VersionTypes
{NowVersion
, InstallVersion
, CandidateVersion
};
62 enum ModeList
{ModeDelete
= 0, ModeKeep
= 1, ModeInstall
= 2};
65 // Epoch stripped text versions of the two version fields
66 const char *CandVersion
;
67 const char *CurVersion
;
69 // Pointer to the candidate install version.
70 Version
*CandidateVer
;
72 // Pointer to the install version.
75 // Copy of Package::Flags
77 unsigned short iFlags
; // Internal flags
79 // Various tree indicators
80 signed char Status
; // -1,0,1,2
81 unsigned char Mode
; // ModeList
82 unsigned char DepState
; // DepState Flags
84 // Update of candidate version
85 const char *StripEpoch(const char *Ver
);
86 void Update(PkgIterator Pkg
,pkgCache
&Cache
);
88 // Various test members for the current status of the package
89 inline bool NewInstall() const {return Status
== 2 && Mode
== ModeInstall
;};
90 inline bool Delete() const {return Mode
== ModeDelete
;};
91 inline bool Keep() const {return Mode
== ModeKeep
;};
92 inline bool Upgrade() const {return Status
> 0 && Mode
== ModeInstall
;};
93 inline bool Upgradable() const {return Status
>= 1;};
94 inline bool Downgrade() const {return Status
< 0 && Mode
== ModeInstall
;};
95 inline bool Held() const {return Status
!= 0 && Keep();};
96 inline bool NowBroken() const {return (DepState
& DepNowMin
) != DepNowMin
;};
97 inline bool InstBroken() const {return (DepState
& DepInstMin
) != DepInstMin
;};
98 inline bool Install() const {return Mode
== ModeInstall
;};
99 inline VerIterator
InstVerIter(pkgCache
&Cache
)
100 {return VerIterator(Cache
,InstallVer
);};
101 inline VerIterator
CandidateVerIter(pkgCache
&Cache
)
102 {return VerIterator(Cache
,CandidateVer
);};
106 void BuildGroupOrs(VerIterator
const &V
);
107 void UpdateVerState(PkgIterator Pkg
);
109 // User Policy control
114 virtual VerIterator
GetCandidateVer(PkgIterator Pkg
);
115 virtual bool IsImportantDep(DepIterator Dep
);
117 virtual ~Policy() {};
124 StateCache
*PkgState
;
125 unsigned char *DepState
;
128 double iDownloadSize
;
129 unsigned long iInstCount
;
130 unsigned long iDelCount
;
131 unsigned long iKeepCount
;
132 unsigned long iBrokenCount
;
133 unsigned long iBadCount
;
135 Policy
*delLocalPolicy
; // For memory clean up..
138 // Check for a matching provides
139 bool CheckDep(DepIterator Dep
,int Type
,PkgIterator
&Res
);
140 inline bool CheckDep(DepIterator Dep
,int Type
)
142 PkgIterator
Res(*this,0);
143 return CheckDep(Dep
,Type
,Res
);
146 // Computes state information for deps and versions (w/o storing)
147 unsigned char DependencyState(DepIterator
&D
);
148 unsigned char VersionState(DepIterator D
,unsigned char Check
,
149 unsigned char SetMin
,
150 unsigned char SetPolicy
);
152 // Recalculates various portions of the cache, call after changing something
153 void Update(DepIterator Dep
); // Mostly internal
154 void Update(PkgIterator
const &P
);
156 // Count manipulators
157 void AddSizes(const PkgIterator
&Pkg
,signed long Mult
= 1);
158 inline void RemoveSizes(const PkgIterator
&Pkg
) {AddSizes(Pkg
,-1);};
159 void AddStates(const PkgIterator
&Pkg
,int Add
= 1);
160 inline void RemoveStates(const PkgIterator
&Pkg
) {AddStates(Pkg
,-1);};
164 // Legacy.. We look like a pkgCache
165 inline operator pkgCache
&() {return *Cache
;};
166 inline Header
&Head() {return *Cache
->HeaderP
;};
167 inline PkgIterator
PkgBegin() {return Cache
->PkgBegin();};
168 inline PkgIterator
FindPkg(string
const &Name
) {return Cache
->FindPkg(Name
);};
170 inline pkgCache
&GetCache() {return *Cache
;};
171 inline pkgVersioningSystem
&VS() {return *Cache
->VS
;};
173 // Policy implementation
174 inline VerIterator
GetCandidateVer(PkgIterator Pkg
) {return LocalPolicy
->GetCandidateVer(Pkg
);};
175 inline bool IsImportantDep(DepIterator Dep
) {return LocalPolicy
->IsImportantDep(Dep
);};
176 inline Policy
&GetPolicy() {return *LocalPolicy
;};
179 inline StateCache
&operator [](PkgIterator
const &I
) {return PkgState
[I
->ID
];};
180 inline unsigned char &operator [](DepIterator
const &I
) {return DepState
[I
->ID
];};
183 void MarkKeep(PkgIterator
const &Pkg
,bool Soft
= false);
184 void MarkDelete(PkgIterator
const &Pkg
,bool Purge
= false);
185 void MarkInstall(PkgIterator
const &Pkg
,bool AutoInst
= true,
186 unsigned long Depth
= 0);
187 void SetReInstall(PkgIterator
const &Pkg
,bool To
);
188 void SetCandidateVersion(VerIterator TargetVer
);
190 // This is for debuging
191 void Update(OpProgress
*Prog
= 0);
194 inline double UsrSize() {return iUsrSize
;};
195 inline double DebSize() {return iDownloadSize
;};
196 inline unsigned long DelCount() {return iDelCount
;};
197 inline unsigned long KeepCount() {return iKeepCount
;};
198 inline unsigned long InstCount() {return iInstCount
;};
199 inline unsigned long BrokenCount() {return iBrokenCount
;};
200 inline unsigned long BadCount() {return iBadCount
;};
202 bool Init(OpProgress
*Prog
);
204 pkgDepCache(pkgCache
*Cache
,Policy
*Plcy
= 0);
205 virtual ~pkgDepCache();