apt 3.0.3
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
47class APT_PUBLIC pkgSimulate : public pkgPackageManager /*{{{*/
48{
49 std::unique_ptr<pkgSimulatePrivate> const d;
50 protected:
51
52 class APT_PUBLIC Policy : public pkgDepCache::Policy
53 {
54 pkgDepCache *Cache;
55 public:
56
57 VerIterator GetCandidateVer(PkgIterator const &Pkg) override
58 {
59 return (*Cache)[Pkg].CandidateVerIter(*Cache);
60 }
61
62 explicit Policy(pkgDepCache *Cache) : Cache(Cache) {};
63 };
64
65 std::unique_ptr<unsigned char[]> Flags;
66
67 Policy iPolicy;
68 pkgDepCache Sim;
70
71 // The Actual installation implementation
72 bool Install(PkgIterator Pkg, std::string File) override;
73 bool Configure(PkgIterator Pkg) override;
74 bool Remove(PkgIterator Pkg, bool Purge) override;
75
76 public:
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 /*}}}*/
92class 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;
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 std::unique_ptr<int[]> Scores;
116 std::unique_ptr<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 bool KeepPhasedUpdates();
144
145 // Try to intelligently resolve problems by installing and removing packages
146 bool Resolve(bool BrokenFix = false, OpProgress * const Progress = NULL);
147 APT_HIDDEN bool ResolveInternal(bool const BrokenFix = false);
148
149 // Try to resolve problems only by using keep
150 bool ResolveByKeep(OpProgress * const Progress = NULL);
151 APT_HIDDEN bool ResolveByKeepInternal();
152
153 explicit pkgProblemResolver(pkgDepCache *Cache);
154 virtual ~pkgProblemResolver();
155};
156 /*}}}*/
157APT_PUBLIC bool pkgApplyStatus(pkgDepCache &Cache);
158APT_PUBLIC bool pkgFixBroken(pkgDepCache &Cache);
159
160APT_PUBLIC void pkgPrioSortList(pkgCache &Cache,pkgCache::Version **List);
161
162namespace APT
163{
164namespace KernelAutoRemoveHelper
165{
166// Public for linking to apt-private, but no A{P,B}I guarantee.
167APT_PUBLIC std::unique_ptr<APT::CacheFilter::Matcher> GetProtectedKernelsFilter(pkgCache *cache, bool returnRemove = false);
168std::string GetProtectedKernelsRegex(pkgCache *cache, bool ReturnRemove = false);
169std::string getUname(std::string const &packageName);
170
171} // namespace KernelAutoRemoveHelper
172
173} // namespace APT
174
175#endif
Definition install-progress.h:18
Definition progress.h:30
Definition cacheiterators.h:47
Represents an active action group.
Definition depcache.h:142
Definition depcache.h:250
Definition depcache.h:63
Definition packagemanager.h:49
Definition algorithms.h:93
Definition algorithms.cc:49
Definition algorithms.h:53
Definition algorithms.h:48
pkgCache - Structure definitions for the cache file
contains information for a single unique package
Definition pkgcache.h:460
information for a single version of a package
Definition pkgcache.h:652