apt: apt-pkg/algorithms.h Source File

apt 2.3.15 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 {Protected = (1 << 0), PreInstalled = (1 << 1),
107 Upgradable = (1 << 2), ReInstateTried = (1 << 3),
108 ToRemove = (1 << 4)};
109 int *Scores;
110 unsigned char *Flags;
111 bool Debug;
112
113 // Sort stuff
114 APT_HIDDEN int ScoreSort(Package const *A, Package const *B) APT_PURE;
115
116 struct APT_PUBLIC PackageKill
117 {
118 PkgIterator Pkg;
119 DepIterator Dep;
120 };
121
122 APT_HIDDEN void MakeScores();
123 APT_HIDDEN bool DoUpgrade(pkgCache::PkgIterator Pkg);
124
125 protected:
126 bool InstOrNewPolicyBroken(pkgCache::PkgIterator Pkg);
127
128 public:
129
130 inline void Protect(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= Protected; Cache.MarkProtected(Pkg);};
131 inline void Remove(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= ToRemove;};
132 inline void Clear(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] &= ~(Protected | ToRemove);};
133
134 // Try to intelligently resolve problems by installing and removing packages
135 bool Resolve(bool BrokenFix = false, OpProgress * const Progress = NULL);
136 APT_HIDDEN bool ResolveInternal(bool const BrokenFix = false);
137
138 // Try to resolve problems only by using keep
139 bool ResolveByKeep(OpProgress * const Progress = NULL);
140 APT_HIDDEN bool ResolveByKeepInternal();
141
142 explicit pkgProblemResolver(pkgDepCache *Cache);
143 virtual ~pkgProblemResolver();
144};
145 /*}}}*/
146APT_PUBLIC bool pkgApplyStatus(pkgDepCache &Cache);
147APT_PUBLIC bool pkgFixBroken(pkgDepCache &Cache);
148
149APT_PUBLIC void pkgPrioSortList(pkgCache &Cache,pkgCache::Version **List);
150
151namespace APT
152{
153namespace KernelAutoRemoveHelper
154{
155// Public for linking to apt-private, but no A{P,B}I guarantee.
156APT_PUBLIC std::unique_ptr<APT::CacheFilter::Matcher> GetProtectedKernelsFilter(pkgCache *cache, bool returnRemove = false);
157std::string GetProtectedKernelsRegex(pkgCache *cache, bool ReturnRemove = false);
158std::string getUname(std::string const &packageName);
159
160} // namespace KernelAutoRemoveHelper
161
162} // namespace APT
163
164#endif
cachefilter.h
APT::Progress::PackageManager
Definition: install-progress.h:18
OpProgress
Definition: progress.h:30
pkgCache
Definition: cacheiterators.h:48
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