merged from debian-sid
[ntk/apt.git] / apt-pkg / algorithms.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: algorithms.h,v 1.10 2001/05/22 04:17:41 jgg Exp $
4 /* ######################################################################
5
6 Algorithms - A set of misc algorithms
7
8 This simulate class displays what the ordering code has done and
9 analyses it with a fresh new dependency cache. In this way we can
10 see all of the effects of an upgrade run.
11
12 pkgDistUpgrade computes an upgrade that causes as many packages as
13 possible to move to the newest verison.
14
15 pkgApplyStatus sets the target state based on the content of the status
16 field in the status file. It is important to get proper crash recovery.
17
18 pkgFixBroken corrects a broken system so that it is in a sane state.
19
20 pkgAllUpgrade attempts to upgade as many packages as possible but
21 without installing new packages.
22
23 The problem resolver class contains a number of complex algorithms
24 to try to best-guess an upgrade state. It solves the problem of
25 maximizing the number of install state packages while having no broken
26 packages.
27
28 ##################################################################### */
29 /*}}}*/
30 #ifndef PKGLIB_ALGORITHMS_H
31 #define PKGLIB_ALGORITHMS_H
32
33
34 #include <apt-pkg/packagemanager.h>
35 #include <apt-pkg/depcache.h>
36 #include <apt-pkg/acquire.h>
37
38 #include <iostream>
39
40 using std::ostream;
41
42 class pkgSimulate : public pkgPackageManager /*{{{*/
43 {
44 protected:
45
46 class Policy : public pkgDepCache::Policy
47 {
48 pkgDepCache *Cache;
49 public:
50
51 virtual VerIterator GetCandidateVer(PkgIterator const &Pkg)
52 {
53 return (*Cache)[Pkg].CandidateVerIter(*Cache);
54 }
55
56 Policy(pkgDepCache *Cache) : Cache(Cache) {};
57 };
58
59 unsigned char *Flags;
60
61 Policy iPolicy;
62 pkgDepCache Sim;
63 pkgDepCache::ActionGroup group;
64
65 // The Actuall installation implementation
66 virtual bool Install(PkgIterator Pkg,string File);
67 virtual bool Configure(PkgIterator Pkg);
68 virtual bool Remove(PkgIterator Pkg,bool Purge);
69
70 private:
71 void ShortBreaks();
72 void Describe(PkgIterator iPkg,ostream &out,bool Current,bool Candidate);
73
74 public:
75
76 pkgSimulate(pkgDepCache *Cache);
77 };
78 /*}}}*/
79 class pkgProblemResolver /*{{{*/
80 {
81 /** \brief dpointer placeholder (for later in case we need it) */
82 void *d;
83
84 pkgDepCache &Cache;
85 typedef pkgCache::PkgIterator PkgIterator;
86 typedef pkgCache::VerIterator VerIterator;
87 typedef pkgCache::DepIterator DepIterator;
88 typedef pkgCache::PrvIterator PrvIterator;
89 typedef pkgCache::Version Version;
90 typedef pkgCache::Package Package;
91
92 enum Flags {Protected = (1 << 0), PreInstalled = (1 << 1),
93 Upgradable = (1 << 2), ReInstateTried = (1 << 3),
94 ToRemove = (1 << 4)};
95 signed short *Scores;
96 unsigned char *Flags;
97 bool Debug;
98
99 // Sort stuff
100 static pkgProblemResolver *This;
101 static int ScoreSort(const void *a,const void *b);
102
103 struct PackageKill
104 {
105 PkgIterator Pkg;
106 DepIterator Dep;
107 };
108
109 void MakeScores();
110 bool DoUpgrade(pkgCache::PkgIterator Pkg);
111
112 bool ResolveInternal(bool const BrokenFix = false);
113 bool ResolveByKeepInternal();
114
115 public:
116
117 inline void Protect(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= Protected; Cache.MarkProtected(Pkg);};
118 inline void Remove(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= ToRemove;};
119 inline void Clear(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] &= ~(Protected | ToRemove);};
120
121 // Try to intelligently resolve problems by installing and removing packages
122 bool Resolve(bool BrokenFix = false);
123
124 // Try to resolve problems only by using keep
125 bool ResolveByKeep();
126
127 // Install all protected packages
128 void InstallProtect();
129
130 pkgProblemResolver(pkgDepCache *Cache);
131 ~pkgProblemResolver();
132 };
133 /*}}}*/
134 bool pkgDistUpgrade(pkgDepCache &Cache);
135 bool pkgApplyStatus(pkgDepCache &Cache);
136 bool pkgFixBroken(pkgDepCache &Cache);
137 bool pkgAllUpgrade(pkgDepCache &Cache);
138 bool pkgMinimizeUpgrade(pkgDepCache &Cache);
139
140 void pkgPrioSortList(pkgCache &Cache,pkgCache::Version **List);
141
142 bool ListUpdate(pkgAcquireStatus &progress, pkgSourceList &List, int PulseInterval=0);
143
144 #endif