apt @VERSION@
|
00001 // -*- mode: cpp; mode: fold -*- 00002 // Description /*{{{*/ 00003 // $Id: algorithms.h,v 1.10 2001/05/22 04:17:41 jgg Exp $ 00004 /* ###################################################################### 00005 00006 Algorithms - A set of misc algorithms 00007 00008 This simulate class displays what the ordering code has done and 00009 analyses it with a fresh new dependency cache. In this way we can 00010 see all of the effects of an upgrade run. 00011 00012 pkgDistUpgrade computes an upgrade that causes as many packages as 00013 possible to move to the newest verison. 00014 00015 pkgApplyStatus sets the target state based on the content of the status 00016 field in the status file. It is important to get proper crash recovery. 00017 00018 pkgFixBroken corrects a broken system so that it is in a sane state. 00019 00020 pkgAllUpgrade attempts to upgade as many packages as possible but 00021 without installing new packages. 00022 00023 The problem resolver class contains a number of complex algorithms 00024 to try to best-guess an upgrade state. It solves the problem of 00025 maximizing the number of install state packages while having no broken 00026 packages. 00027 00028 ##################################################################### */ 00029 /*}}}*/ 00030 #ifndef PKGLIB_ALGORITHMS_H 00031 #define PKGLIB_ALGORITHMS_H 00032 00033 00034 #include <apt-pkg/packagemanager.h> 00035 #include <apt-pkg/depcache.h> 00036 #include <apt-pkg/acquire.h> 00037 00038 #include <iostream> 00039 00040 using std::ostream; 00041 00042 class pkgSimulate : public pkgPackageManager /*{{{*/ 00043 { 00044 protected: 00045 00046 class Policy : public pkgDepCache::Policy 00047 { 00048 pkgDepCache *Cache; 00049 public: 00050 00051 virtual VerIterator GetCandidateVer(PkgIterator const &Pkg) 00052 { 00053 return (*Cache)[Pkg].CandidateVerIter(*Cache); 00054 } 00055 00056 Policy(pkgDepCache *Cache) : Cache(Cache) {}; 00057 }; 00058 00059 unsigned char *Flags; 00060 00061 Policy iPolicy; 00062 pkgDepCache Sim; 00063 pkgDepCache::ActionGroup group; 00064 00065 // The Actuall installation implementation 00066 virtual bool Install(PkgIterator Pkg,string File); 00067 virtual bool Configure(PkgIterator Pkg); 00068 virtual bool Remove(PkgIterator Pkg,bool Purge); 00069 00070 private: 00071 void ShortBreaks(); 00072 void Describe(PkgIterator iPkg,ostream &out,bool Current,bool Candidate); 00073 00074 public: 00075 00076 pkgSimulate(pkgDepCache *Cache); 00077 }; 00078 /*}}}*/ 00079 class pkgProblemResolver /*{{{*/ 00080 { 00082 void *d; 00083 00084 pkgDepCache &Cache; 00085 typedef pkgCache::PkgIterator PkgIterator; 00086 typedef pkgCache::VerIterator VerIterator; 00087 typedef pkgCache::DepIterator DepIterator; 00088 typedef pkgCache::PrvIterator PrvIterator; 00089 typedef pkgCache::Version Version; 00090 typedef pkgCache::Package Package; 00091 00092 enum Flags {Protected = (1 << 0), PreInstalled = (1 << 1), 00093 Upgradable = (1 << 2), ReInstateTried = (1 << 3), 00094 ToRemove = (1 << 4)}; 00095 int *Scores; 00096 unsigned char *Flags; 00097 bool Debug; 00098 00099 // Sort stuff 00100 static pkgProblemResolver *This; 00101 static int ScoreSort(const void *a,const void *b); 00102 00103 struct PackageKill 00104 { 00105 PkgIterator Pkg; 00106 DepIterator Dep; 00107 }; 00108 00109 void MakeScores(); 00110 bool DoUpgrade(pkgCache::PkgIterator Pkg); 00111 00112 bool ResolveInternal(bool const BrokenFix = false); 00113 bool ResolveByKeepInternal(); 00114 00115 protected: 00116 bool InstOrNewPolicyBroken(pkgCache::PkgIterator Pkg); 00117 00118 public: 00119 00120 inline void Protect(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= Protected; Cache.MarkProtected(Pkg);}; 00121 inline void Remove(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= ToRemove;}; 00122 inline void Clear(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] &= ~(Protected | ToRemove);}; 00123 00124 // Try to intelligently resolve problems by installing and removing packages 00125 bool Resolve(bool BrokenFix = false); 00126 00127 // Try to resolve problems only by using keep 00128 bool ResolveByKeep(); 00129 00130 // Install all protected packages 00131 void InstallProtect(); 00132 00133 pkgProblemResolver(pkgDepCache *Cache); 00134 ~pkgProblemResolver(); 00135 }; 00136 /*}}}*/ 00137 bool pkgDistUpgrade(pkgDepCache &Cache); 00138 bool pkgApplyStatus(pkgDepCache &Cache); 00139 bool pkgFixBroken(pkgDepCache &Cache); 00140 bool pkgAllUpgrade(pkgDepCache &Cache); 00141 bool pkgMinimizeUpgrade(pkgDepCache &Cache); 00142 00143 void pkgPrioSortList(pkgCache &Cache,pkgCache::Version **List); 00144 00145 bool ListUpdate(pkgAcquireStatus &progress, pkgSourceList &List, int PulseInterval=0); 00146 00147 #endif