]> git.saurik.com Git - apt.git/blame - apt-pkg/depcache.h
Configuration fixes
[apt.git] / apt-pkg / depcache.h
CommitLineData
6c139d6e
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
981d20eb 3// $Id: depcache.h,v 1.8 1998/12/08 01:34:10 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 /*}}}*/
38// Header section: pkglib
39#ifndef PKGLIB_DEPCACHE_H
40#define PKGLIB_DEPCACHE_H
41
42#ifdef __GNUG__
094a497d 43#pragma interface "apt-pkg/depcache.h"
6c139d6e
AL
44#endif
45
094a497d 46#include <apt-pkg/pkgcache.h>
a246f2dc 47#include <apt-pkg/progress.h>
6c139d6e
AL
48
49class pkgDepCache : public pkgCache
50{
51 public:
52
53 // These flags are used in DepState
54 enum DepFlags {DepNow = (1 << 0),DepInstall = (1 << 1),DepCVer = (1 << 2),
55 DepGNow = (1 << 3),DepGInstall = (1 << 4),DepGCVer = (1 << 5)};
56
57 // These flags are used in StateCache::DepState
58 enum DepStateFlags {DepNowPolicy = (1 << 0), DepNowMin = (1 << 1),
59 DepInstPolicy = (1 << 2), DepInstMin = (1 << 3),
60 DepCandPolicy = (1 << 4), DepCandMin = (1 << 5)};
61
62 // These flags are used in StateCache::iFlags
63 enum InternalFlags {AutoKept = (1 << 0)};
64
65 enum VersionTypes {NowVersion, InstallVersion, CandidateVersion};
66 enum ModeList {ModeDelete = 0, ModeKeep = 1, ModeInstall = 2};
67 struct StateCache
68 {
69 // Epoch stripped text versions of the two version fields
70 const char *CandVersion;
71 const char *CurVersion;
72
73 // Pointer to the candidate install version.
74 Version *CandidateVer;
75
76 // Pointer to the install version.
77 Version *InstallVer;
78
79 // Various tree indicators
80 signed char Status; // -1,0,1,2
81 unsigned char Mode; // ModeList
82 unsigned char DepState; // DepState Flags
83
84 // Copy of Package::Flags
85 unsigned short Flags;
86 unsigned short iFlags; // Internal flags
87
88 // Update of candidate version
89 const char *StripEpoch(const char *Ver);
90 void Update(PkgIterator Pkg,pkgCache &Cache);
91
92 // Various test members for the current status of the package
93 inline bool NewInstall() const {return Status == 2 && Mode == ModeInstall;};
94 inline bool Delete() const {return Mode == ModeDelete;};
95 inline bool Keep() const {return Mode == ModeKeep;};
96 inline bool Upgrade() const {return Status > 0 && Mode == ModeInstall;};
0a8e3465 97 inline bool Upgradable() const {return Status >= 1;};
6c139d6e
AL
98 inline bool Downgrade() const {return Status < 0;};
99 inline bool Held() const {return Status != 0 && Keep();};
100 inline bool NowBroken() const {return (DepState & DepNowMin) != DepNowMin;};
101 inline bool InstBroken() const {return (DepState & DepInstMin) != DepInstMin;};
102 inline bool Install() const {return Mode == ModeInstall;};
103 inline VerIterator InstVerIter(pkgCache &Cache)
104 {return VerIterator(Cache,InstallVer);};
105 inline VerIterator CandidateVerIter(pkgCache &Cache)
106 {return VerIterator(Cache,CandidateVer);};
107 };
108
109 // Helper functions
110 void BuildGroupOrs(VerIterator const &V);
111 void UpdateVerState(PkgIterator Pkg);
112
a246f2dc 113 bool Init(OpProgress *Prog);
6c139d6e
AL
114
115 protected:
116
117 // State information
118 StateCache *PkgState;
119 unsigned char *DepState;
120
a6568219
AL
121 signed long iUsrSize;
122 unsigned long iDownloadSize;
123 unsigned long iInstCount;
124 unsigned long iDelCount;
125 unsigned long iKeepCount;
126 unsigned long iBrokenCount;
127 unsigned long iBadCount;
6c139d6e
AL
128
129 // Check for a matching provides
130 bool CheckDep(DepIterator Dep,int Type,PkgIterator &Res);
131 inline bool CheckDep(DepIterator Dep,int Type)
132 {
133 PkgIterator Res(*this);
134 return CheckDep(Dep,Type,Res);
135 }
136
137 // Computes state information for deps and versions (w/o storing)
138 unsigned char DependencyState(DepIterator &D);
139 unsigned char VersionState(DepIterator D,unsigned char Check,
140 unsigned char SetMin,
141 unsigned char SetPolicy);
142
143 // Recalculates various portions of the cache, call after changing something
144 void Update(DepIterator Dep); // Mostly internal
145 void Update(PkgIterator const &P);
146
147 // Count manipulators
148 void AddSizes(const PkgIterator &Pkg,long Mult = 1);
149 inline void RemoveSizes(const PkgIterator &Pkg) {AddSizes(Pkg,-1);};
150 void AddStates(const PkgIterator &Pkg,int Add = 1);
151 inline void RemoveStates(const PkgIterator &Pkg) {AddStates(Pkg,-1);};
152
153 public:
154
155 // Policy implementation
156 virtual VerIterator GetCandidateVer(PkgIterator Pkg);
157 virtual bool IsImportantDep(DepIterator Dep);
158
159 // Accessors
160 inline StateCache &operator [](PkgIterator const &I) {return PkgState[I->ID];};
161 inline unsigned char &operator [](DepIterator const &I) {return DepState[I->ID];};
162
163 // Manipulators
164 void MarkKeep(PkgIterator const &Pkg,bool Soft = false);
165 void MarkDelete(PkgIterator const &Pkg);
166 void MarkInstall(PkgIterator const &Pkg,bool AutoInst = true);
167
168 // This is for debuging
a246f2dc 169 void Update(OpProgress *Prog = 0);
e331f6ed 170
6c139d6e 171 // Size queries
a6568219
AL
172 inline signed long UsrSize() {return iUsrSize;};
173 inline unsigned long DebSize() {return iDownloadSize;};
174 inline unsigned long DelCount() {return iDelCount;};
175 inline unsigned long KeepCount() {return iKeepCount;};
176 inline unsigned long InstCount() {return iInstCount;};
177 inline unsigned long BrokenCount() {return iBrokenCount;};
178 inline unsigned long BadCount() {return iBadCount;};
6c139d6e 179
a246f2dc 180 pkgDepCache(MMap &Map,OpProgress &Prog);
981d20eb 181 pkgDepCache(MMap &Map);
6c139d6e
AL
182 virtual ~pkgDepCache();
183};
184
185#endif