|
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 { 00081 pkgDepCache &Cache; 00082 typedef pkgCache::PkgIterator PkgIterator; 00083 typedef pkgCache::VerIterator VerIterator; 00084 typedef pkgCache::DepIterator DepIterator; 00085 typedef pkgCache::PrvIterator PrvIterator; 00086 typedef pkgCache::Version Version; 00087 typedef pkgCache::Package Package; 00088 00089 enum Flags {Protected = (1 << 0), PreInstalled = (1 << 1), 00090 Upgradable = (1 << 2), ReInstateTried = (1 << 3), 00091 ToRemove = (1 << 4)}; 00092 signed short *Scores; 00093 unsigned char *Flags; 00094 bool Debug; 00095 00096 // Sort stuff 00097 static pkgProblemResolver *This; 00098 static int ScoreSort(const void *a,const void *b); 00099 00100 struct PackageKill 00101 { 00102 PkgIterator Pkg; 00103 DepIterator Dep; 00104 }; 00105 00106 void MakeScores(); 00107 bool DoUpgrade(pkgCache::PkgIterator Pkg); 00108 00109 protected: 00110 bool InstOrNewPolicyBroken(pkgCache::PkgIterator Pkg); 00111 00112 public: 00113 00114 inline void Protect(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= Protected; Cache.MarkProtected(Pkg);}; 00115 inline void Remove(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= ToRemove;}; 00116 inline void Clear(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] &= ~(Protected | ToRemove);}; 00117 00118 // Try to intelligently resolve problems by installing and removing packages 00119 bool Resolve(bool BrokenFix = false); 00120 00121 // Try to resolve problems only by using keep 00122 bool ResolveByKeep(); 00123 00124 // Install all protected packages 00125 void InstallProtect(); 00126 00127 pkgProblemResolver(pkgDepCache *Cache); 00128 ~pkgProblemResolver(); 00129 }; 00130 /*}}}*/ 00131 bool pkgDistUpgrade(pkgDepCache &Cache); 00132 bool pkgApplyStatus(pkgDepCache &Cache); 00133 bool pkgFixBroken(pkgDepCache &Cache); 00134 bool pkgAllUpgrade(pkgDepCache &Cache); 00135 bool pkgMinimizeUpgrade(pkgDepCache &Cache); 00136 00137 void pkgPrioSortList(pkgCache &Cache,pkgCache::Version **List); 00138 00139 bool ListUpdate(pkgAcquireStatus &progress, pkgSourceList &List, int PulseInterval=0); 00140 00141 #endif
1.7.4