apt
1.5
|
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 00037 #include <iostream> 00038 00039 #ifndef APT_8_CLEANER_HEADERS 00040 #include <apt-pkg/acquire.h> 00041 using std::ostream; 00042 #endif 00043 00044 class pkgAcquireStatus; 00045 00046 class pkgSimulate : public pkgPackageManager /*{{{*/ 00047 { 00048 protected: 00049 00050 class Policy : public pkgDepCache::Policy 00051 { 00052 pkgDepCache *Cache; 00053 public: 00054 00055 virtual VerIterator GetCandidateVer(PkgIterator const &Pkg) 00056 { 00057 return (*Cache)[Pkg].CandidateVerIter(*Cache); 00058 } 00059 00060 Policy(pkgDepCache *Cache) : Cache(Cache) {}; 00061 }; 00062 00063 unsigned char *Flags; 00064 00065 Policy iPolicy; 00066 pkgDepCache Sim; 00067 pkgDepCache::ActionGroup group; 00068 00069 // The Actuall installation implementation 00070 virtual bool Install(PkgIterator Pkg,std::string File); 00071 virtual bool Configure(PkgIterator Pkg); 00072 virtual bool Remove(PkgIterator Pkg,bool Purge); 00073 00074 private: 00075 void ShortBreaks(); 00076 void Describe(PkgIterator iPkg,std::ostream &out,bool Current,bool Candidate); 00077 00078 public: 00079 00080 pkgSimulate(pkgDepCache *Cache); 00081 }; 00082 /*}}}*/ 00083 class pkgProblemResolver /*{{{*/ 00084 { 00086 void *d; 00087 00088 pkgDepCache &Cache; 00089 typedef pkgCache::PkgIterator PkgIterator; 00090 typedef pkgCache::VerIterator VerIterator; 00091 typedef pkgCache::DepIterator DepIterator; 00092 typedef pkgCache::PrvIterator PrvIterator; 00093 typedef pkgCache::Version Version; 00094 typedef pkgCache::Package Package; 00095 00096 enum Flags {Protected = (1 << 0), PreInstalled = (1 << 1), 00097 Upgradable = (1 << 2), ReInstateTried = (1 << 3), 00098 ToRemove = (1 << 4)}; 00099 int *Scores; 00100 unsigned char *Flags; 00101 bool Debug; 00102 00103 // Sort stuff 00104 static pkgProblemResolver *This; 00105 static int ScoreSort(const void *a,const void *b); 00106 00107 struct PackageKill 00108 { 00109 PkgIterator Pkg; 00110 DepIterator Dep; 00111 }; 00112 00113 void MakeScores(); 00114 bool DoUpgrade(pkgCache::PkgIterator Pkg); 00115 00116 bool ResolveInternal(bool const BrokenFix = false); 00117 bool ResolveByKeepInternal(); 00118 00119 protected: 00120 bool InstOrNewPolicyBroken(pkgCache::PkgIterator Pkg); 00121 00122 public: 00123 00124 inline void Protect(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= Protected; Cache.MarkProtected(Pkg);}; 00125 inline void Remove(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= ToRemove;}; 00126 inline void Clear(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] &= ~(Protected | ToRemove);}; 00127 00128 // Try to intelligently resolve problems by installing and removing packages 00129 bool Resolve(bool BrokenFix = false); 00130 00131 // Try to resolve problems only by using keep 00132 bool ResolveByKeep(); 00133 00134 // Install all protected packages 00135 void InstallProtect(); 00136 00137 pkgProblemResolver(pkgDepCache *Cache); 00138 ~pkgProblemResolver(); 00139 }; 00140 /*}}}*/ 00141 bool pkgDistUpgrade(pkgDepCache &Cache); 00142 bool pkgApplyStatus(pkgDepCache &Cache); 00143 bool pkgFixBroken(pkgDepCache &Cache); 00144 bool pkgAllUpgrade(pkgDepCache &Cache); 00145 bool pkgMinimizeUpgrade(pkgDepCache &Cache); 00146 00147 void pkgPrioSortList(pkgCache &Cache,pkgCache::Version **List); 00148 00149 bool ListUpdate(pkgAcquireStatus &progress, pkgSourceList &List, int PulseInterval=0); 00150 bool AcquireUpdate(pkgAcquire &Fetcher, int const PulseInterval = 0, 00151 bool const RunUpdateScripts = true, bool const ListCleanup = true); 00152 00153 #endif