apt: apt-pkg/algorithms.h Source File

apt 2.7.5 commandline package manager

algorithms.h
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
3/* ######################################################################
4
5 Algorithms - A set of misc algorithms
6
7 This simulate class displays what the ordering code has done and
8 analyses it with a fresh new dependency cache. In this way we can
9 see all of the effects of an upgrade run.
10
11 pkgDistUpgrade computes an upgrade that causes as many packages as
12 possible to move to the newest version.
13
14 pkgApplyStatus sets the target state based on the content of the status
15 field in the status file. It is important to get proper crash recovery.
16
17 pkgFixBroken corrects a broken system so that it is in a sane state.
18
19 pkgAllUpgrade attempts to upgrade as many packages as possible but
20 without installing new packages.
21
22 The problem resolver class contains a number of complex algorithms
23 to try to best-guess an upgrade state. It solves the problem of
24 maximizing the number of install state packages while having no broken
25 packages.
26
27 ##################################################################### */
28 /*}}}*/
29#ifndef PKGLIB_ALGORITHMS_H
30#define PKGLIB_ALGORITHMS_H
31
32#include <apt-pkg/cachefilter.h>
33#include <apt-pkg/depcache.h>
34#include <apt-pkg/packagemanager.h>
35#include <apt-pkg/pkgcache.h>
36
37#include <iostream>
38#include <memory>
39#include <string>
40
41#include <apt-pkg/macros.h>
42
43
44
45
46class pkgSimulatePrivate;
47 class APT_PUBLIC pkgSimulate : public pkgPackageManager /*{{{*/
48{
49 pkgSimulatePrivate * const d;
50 protected:
51
52 class APT_PUBLIC Policy : public pkgDepCache::Policy
53 {
54 pkgDepCache *Cache;
55 public:
56
57 virtual VerIterator GetCandidateVer(PkgIterator const &Pkg) APT_OVERRIDE
58 {
59 return (*Cache)[Pkg].CandidateVerIter(*Cache);
60 }
61
62 explicit Policy(pkgDepCache *Cache) : Cache(Cache) {};
63 };
64
65 unsigned char *Flags;
66
67 Policy iPolicy;
68 pkgDepCache Sim;
69 pkgDepCache::ActionGroup group;
70
71 // The Actual installation implementation
72 virtual bool Install(PkgIterator Pkg,std::string File) APT_OVERRIDE;
73 virtual bool Configure(PkgIterator Pkg) APT_OVERRIDE;
74 virtual bool Remove(PkgIterator Pkg,bool Purge) APT_OVERRIDE;
75
76public:
77 bool Go(APT::Progress::PackageManager * progress) override;
78
79private:
80 APT_HIDDEN void ShortBreaks();
81 APT_HIDDEN void Describe(PkgIterator iPkg,std::ostream &out,bool Current,bool Candidate);
82 APT_HIDDEN bool RealInstall(PkgIterator Pkg,std::string File);
83 APT_HIDDEN bool RealConfigure(PkgIterator Pkg);
84 APT_HIDDEN bool RealRemove(PkgIterator Pkg,bool Purge);
85
86 public:
87
88 explicit pkgSimulate(pkgDepCache *Cache);
89 virtual ~pkgSimulate();
90};
91 /*}}}*/
92 class APT_PUBLIC pkgProblemResolver /*{{{*/
93{
94 private:
96 void * const d;
97
98 pkgDepCache &Cache;
99 typedef pkgCache::PkgIterator PkgIterator;
100 typedef pkgCache::VerIterator VerIterator;
101 typedef pkgCache::DepIterator DepIterator;
102 typedef pkgCache::PrvIterator PrvIterator;
103 typedef pkgCache::Version Version;
104 typedef pkgCache::Package Package;
105
106 enum Flags
107 {
108 Protected = (1 << 0),
109 PreInstalled = (1 << 1),
110 Upgradable = (1 << 2),
111 ReInstateTried = (1 << 3),
112 ToRemove = (1 << 4),
113 BrokenPolicyAllowed = (1 << 5)
114 };
115 int *Scores;
116 unsigned char *Flags;
117 bool Debug;
118
119 // Sort stuff
120 APT_HIDDEN int ScoreSort(Package const *A, Package const *B) APT_PURE;
121
122 struct APT_PUBLIC PackageKill
123 {
124 PkgIterator Pkg;
125 DepIterator Dep;
126 };
127
128 APT_HIDDEN void MakeScores();
129 APT_HIDDEN bool DoUpgrade(pkgCache::PkgIterator Pkg);
130
131 protected:
132 bool InstOrNewPolicyBroken(pkgCache::PkgIterator Pkg);
133
134 public:
135
136 inline void Protect(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= Protected; Cache.MarkProtected(Pkg);};
137 inline void Remove(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= ToRemove;};
138 inline void Clear(pkgCache::PkgIterator Pkg) { Flags[Pkg->ID] &= ~(Protected | ToRemove | BrokenPolicyAllowed); };
139#ifdef APT_COMPILING_APT
140 inline void AllowBrokenPolicy(pkgCache::PkgIterator Pkg) { Flags[Pkg->ID] |= BrokenPolicyAllowed; };
141#endif
142
143 // Try to intelligently resolve problems by installing and removing packages
144 bool Resolve(bool BrokenFix = false, OpProgress * const Progress = NULL);
145 APT_HIDDEN bool ResolveInternal(bool const BrokenFix = false);
146
147 // Try to resolve problems only by using keep
148 bool ResolveByKeep(OpProgress * const Progress = NULL);
149 APT_HIDDEN bool ResolveByKeepInternal();
150
151 explicit pkgProblemResolver(pkgDepCache *Cache);
152 virtual ~pkgProblemResolver();
153};
154 /*}}}*/
155APT_PUBLIC bool pkgApplyStatus(pkgDepCache &Cache);
156APT_PUBLIC bool pkgFixBroken(pkgDepCache &Cache);
157
158APT_PUBLIC void pkgPrioSortList(pkgCache &Cache,pkgCache::Version **List);
159
160namespace APT
161{
162namespace KernelAutoRemoveHelper
163{
164// Public for linking to apt-private, but no A{P,B}I guarantee.
165APT_PUBLIC std::unique_ptr<APT::CacheFilter::Matcher> GetProtectedKernelsFilter(pkgCache *cache, bool returnRemove = false);
166std::string GetProtectedKernelsRegex(pkgCache *cache, bool ReturnRemove = false);
167std::string getUname(std::string const &packageName);
168
169} // namespace KernelAutoRemoveHelper
170
171} // namespace APT
172
173#endif
cachefilter.h
APT::Progress::PackageManager
Definition install-progress.h:18
OpProgress
Definition progress.h:30
pkgCache
Definition cacheiterators.h:47
pkgDepCache::ActionGroup
Represents an active action group.
Definition depcache.h:141
pkgDepCache::Policy
Definition depcache.h:249
pkgDepCache
Definition depcache.h:62
pkgPackageManager
Definition packagemanager.h:48
pkgProblemResolver
Definition algorithms.h:93
pkgSimulatePrivate
Definition algorithms.cc:50
pkgSimulate::Policy
Definition algorithms.h:53
pkgSimulate
Definition algorithms.h:48
pkgcache.h
pkgCache - Structure definitions for the cache file
pkgCache::Package
contains information for a single unique package
Definition pkgcache.h:450
pkgCache::Version
information for a single version of a package
Definition pkgcache.h:625