00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef PKGLIB_DEPCACHE_H
00039 #define PKGLIB_DEPCACHE_H
00040
00041 #include <apt-pkg/configuration.h>
00042 #include <apt-pkg/pkgcache.h>
00043 #include <apt-pkg/progress.h>
00044 #include <apt-pkg/error.h>
00045
00046 #include <vector>
00047 #include <memory>
00048 #include <set>
00049
00050 class pkgDepCache : protected pkgCache::Namespace
00051 {
00052 public:
00053
00055 class InRootSetFunc
00056 {
00057 public:
00058 virtual bool InRootSet(const pkgCache::PkgIterator &pkg) {return false;};
00059 virtual ~InRootSetFunc() {};
00060 };
00061
00062 private:
00079 void MarkPackage(const pkgCache::PkgIterator &pkg,
00080 const pkgCache::VerIterator &ver,
00081 bool const &follow_recommends,
00082 bool const &follow_suggests);
00083
00097 bool MarkRequired(InRootSetFunc &rootFunc);
00098
00108 bool Sweep();
00109
00110 public:
00111
00112
00113 enum DepFlags {DepNow = (1 << 0),DepInstall = (1 << 1),DepCVer = (1 << 2),
00114 DepGNow = (1 << 3),DepGInstall = (1 << 4),DepGCVer = (1 << 5)};
00115
00116
00117 enum DepStateFlags {DepNowPolicy = (1 << 0), DepNowMin = (1 << 1),
00118 DepInstPolicy = (1 << 2), DepInstMin = (1 << 3),
00119 DepCandPolicy = (1 << 4), DepCandMin = (1 << 5)};
00120
00121
00122 enum InternalFlags {AutoKept = (1 << 0), Purge = (1 << 1), ReInstall = (1 << 2)};
00123
00124 enum VersionTypes {NowVersion, InstallVersion, CandidateVersion};
00125 enum ModeList {ModeDelete = 0, ModeKeep = 1, ModeInstall = 2};
00126
00150 class ActionGroup
00151 {
00152 pkgDepCache &cache;
00153
00154 bool released;
00155
00157 ActionGroup(const ActionGroup &other);
00158 public:
00167 ActionGroup(pkgDepCache &cache);
00168
00173 void release();
00174
00180 ~ActionGroup();
00181 };
00182
00186 class DefaultRootSetFunc : public InRootSetFunc, public Configuration::MatchAgainstConfig
00187 {
00188 public:
00189 DefaultRootSetFunc() : Configuration::MatchAgainstConfig("APT::NeverAutoRemove") {};
00190 virtual ~DefaultRootSetFunc() {};
00191
00192 bool InRootSet(const pkgCache::PkgIterator &pkg) { return pkg.end() == false && Match(pkg.Name()); };
00193 };
00194
00195 struct StateCache
00196 {
00197
00198 const char *CandVersion;
00199 const char *CurVersion;
00200
00201
00202 Version *CandidateVer;
00203
00204
00205 Version *InstallVer;
00206
00207
00208 unsigned short Flags;
00209 unsigned short iFlags;
00210
00212 bool Marked;
00213
00220 bool Garbage;
00221
00222
00223 signed char Status;
00224 unsigned char Mode;
00225 unsigned char DepState;
00226
00227
00228 const char *StripEpoch(const char *Ver);
00229 void Update(PkgIterator Pkg,pkgCache &Cache);
00230
00231
00232 inline bool NewInstall() const {return Status == 2 && Mode == ModeInstall;};
00233 inline bool Delete() const {return Mode == ModeDelete;};
00234 inline bool Keep() const {return Mode == ModeKeep;};
00235 inline bool Upgrade() const {return Status > 0 && Mode == ModeInstall;};
00236 inline bool Upgradable() const {return Status >= 1;};
00237 inline bool Downgrade() const {return Status < 0 && Mode == ModeInstall;};
00238 inline bool Held() const {return Status != 0 && Keep();};
00239 inline bool NowBroken() const {return (DepState & DepNowMin) != DepNowMin;};
00240 inline bool NowPolicyBroken() const {return (DepState & DepNowPolicy) != DepNowPolicy;};
00241 inline bool InstBroken() const {return (DepState & DepInstMin) != DepInstMin;};
00242 inline bool InstPolicyBroken() const {return (DepState & DepInstPolicy) != DepInstPolicy;};
00243 inline bool Install() const {return Mode == ModeInstall;};
00244 inline VerIterator InstVerIter(pkgCache &Cache)
00245 {return VerIterator(Cache,InstallVer);};
00246 inline VerIterator CandidateVerIter(pkgCache &Cache)
00247 {return VerIterator(Cache,CandidateVer);};
00248 };
00249
00250
00251 void BuildGroupOrs(VerIterator const &V);
00252 void UpdateVerState(PkgIterator Pkg);
00253
00254
00255 class Policy
00256 {
00257 public:
00258
00259 virtual VerIterator GetCandidateVer(PkgIterator const &Pkg);
00260 virtual bool IsImportantDep(DepIterator const &Dep);
00261
00262 virtual ~Policy() {};
00263 };
00264
00265 private:
00269 int group_level;
00270
00271 friend class ActionGroup;
00272
00273 protected:
00274
00275
00276 pkgCache *Cache;
00277 StateCache *PkgState;
00278 unsigned char *DepState;
00279
00281 signed long long iUsrSize;
00283 unsigned long long iDownloadSize;
00284 unsigned long iInstCount;
00285 unsigned long iDelCount;
00286 unsigned long iKeepCount;
00287 unsigned long iBrokenCount;
00288 unsigned long iPolicyBrokenCount;
00289 unsigned long iBadCount;
00290
00291 bool DebugMarker;
00292 bool DebugAutoInstall;
00293
00294 Policy *delLocalPolicy;
00295 Policy *LocalPolicy;
00296
00297
00298 bool CheckDep(DepIterator Dep,int Type,PkgIterator &Res);
00299 inline bool CheckDep(DepIterator Dep,int Type)
00300 {
00301 PkgIterator Res(*this,0);
00302 return CheckDep(Dep,Type,Res);
00303 }
00304
00305
00306 unsigned char DependencyState(DepIterator &D);
00307 unsigned char VersionState(DepIterator D,unsigned char Check,
00308 unsigned char SetMin,
00309 unsigned char SetPolicy);
00310
00311
00312 void Update(DepIterator Dep);
00313 void Update(PkgIterator const &P);
00314
00315
00316 void AddSizes(const PkgIterator &Pkg, bool const &Invert = false);
00317 inline void RemoveSizes(const PkgIterator &Pkg) {AddSizes(Pkg, true);};
00318 void AddSizes(const PkgIterator &Pkg,signed long Mult) __deprecated;
00319 void AddStates(const PkgIterator &Pkg,int Add = 1);
00320 inline void RemoveStates(const PkgIterator &Pkg) {AddStates(Pkg,-1);};
00321
00322 public:
00323
00324
00325 inline operator pkgCache &() {return *Cache;};
00326 inline Header &Head() {return *Cache->HeaderP;};
00327 inline GrpIterator GrpBegin() {return Cache->GrpBegin();};
00328 inline PkgIterator PkgBegin() {return Cache->PkgBegin();};
00329 inline GrpIterator FindGrp(string const &Name) {return Cache->FindGrp(Name);};
00330 inline PkgIterator FindPkg(string const &Name) {return Cache->FindPkg(Name);};
00331 inline PkgIterator FindPkg(string const &Name, string const &Arch) {return Cache->FindPkg(Name, Arch);};
00332
00333 inline pkgCache &GetCache() {return *Cache;};
00334 inline pkgVersioningSystem &VS() {return *Cache->VS;};
00335
00336
00337 inline VerIterator GetCandidateVer(PkgIterator const &Pkg) {return LocalPolicy->GetCandidateVer(Pkg);};
00338 inline bool IsImportantDep(DepIterator Dep) {return LocalPolicy->IsImportantDep(Dep);};
00339 inline Policy &GetPolicy() {return *LocalPolicy;};
00340
00341
00342 inline StateCache &operator [](PkgIterator const &I) {return PkgState[I->ID];};
00343 inline unsigned char &operator [](DepIterator const &I) {return DepState[I->ID];};
00344
00353 virtual InRootSetFunc *GetRootSetFunc();
00354
00357 virtual bool MarkFollowsRecommends();
00358
00361 virtual bool MarkFollowsSuggests();
00362
00372 bool MarkAndSweep(InRootSetFunc &rootFunc)
00373 {
00374 return MarkRequired(rootFunc) && Sweep();
00375 }
00376
00377 bool MarkAndSweep()
00378 {
00379 std::auto_ptr<InRootSetFunc> f(GetRootSetFunc());
00380 if(f.get() != NULL)
00381 return MarkAndSweep(*f.get());
00382 else
00383 return false;
00384 }
00385
00388
00389 void MarkKeep(PkgIterator const &Pkg, bool Soft = false,
00390 bool FromUser = true, unsigned long Depth = 0);
00391 void MarkDelete(PkgIterator const &Pkg, bool Purge = false,
00392 unsigned long Depth = 0, bool FromUser = true);
00393 void MarkInstall(PkgIterator const &Pkg,bool AutoInst = true,
00394 unsigned long Depth = 0, bool FromUser = true,
00395 bool ForceImportantDeps = false);
00396
00397 void SetReInstall(PkgIterator const &Pkg,bool To);
00398 void SetCandidateVersion(VerIterator TargetVer, bool const &Pseudo = true);
00399
00401 void MarkAuto(const PkgIterator &Pkg, bool Auto);
00402
00403
00420 virtual bool IsInstallOk(const PkgIterator &Pkg,bool AutoInst = true,
00421 unsigned long Depth = 0, bool FromUser = true);
00422
00439 virtual bool IsDeleteOk(const PkgIterator &Pkg,bool Purge = false,
00440 unsigned long Depth = 0, bool FromUser = true);
00441
00442
00443 bool readStateFile(OpProgress *prog);
00444 bool writeStateFile(OpProgress *prog, bool InstalledOnly=true);
00445
00446
00447 inline signed long long UsrSize() {return iUsrSize;};
00448 inline unsigned long long DebSize() {return iDownloadSize;};
00449 inline unsigned long DelCount() {return iDelCount;};
00450 inline unsigned long KeepCount() {return iKeepCount;};
00451 inline unsigned long InstCount() {return iInstCount;};
00452 inline unsigned long BrokenCount() {return iBrokenCount;};
00453 inline unsigned long PolicyBrokenCount() {return iPolicyBrokenCount;};
00454 inline unsigned long BadCount() {return iBadCount;};
00455
00456 bool Init(OpProgress *Prog);
00457
00458 void Update(OpProgress *Prog = 0);
00459
00460 pkgDepCache(pkgCache *Cache,Policy *Plcy = 0);
00461 virtual ~pkgDepCache();
00462
00463 private:
00464
00465 bool RemovePseudoInstalledPkg(PkgIterator &Pkg, std::set<unsigned long> &recheck);
00466 bool ReInstallPseudoForGroup(unsigned long const &Grp, std::set<unsigned long> &recheck);
00467 bool ReInstallPseudoForGroup(pkgCache::PkgIterator const &P, std::set<unsigned long> &recheck);
00468 };
00469
00470 #endif