apt  2.2.4
About: Apt (Advanced Package Tool) is a management system for software packages (Debian/Ubuntu). Release series 2.2.
  Fossies Dox: apt-2.2.4.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

algorithms.h
Go to the documentation of this file.
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 
46 class pkgSimulatePrivate;
48 {
50  protected:
51 
53  {
55  public:
56 
58  {
59  return (*Cache)[Pkg].CandidateVerIter(*Cache);
60  }
61 
62  explicit Policy(pkgDepCache *Cache) : Cache(Cache) {};
63  };
64 
65  unsigned char *Flags;
66 
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 
76 public:
77  bool Go(APT::Progress::PackageManager * progress) override;
78 
79 private:
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  /*}}}*/
93 {
94  private:
95  /** \brief dpointer placeholder (for later in case we need it) */
96  void * const d;
97 
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 
117  {
120  };
121 
122  APT_HIDDEN void MakeScores();
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  /*}}}*/
147 APT_PUBLIC bool pkgFixBroken(pkgDepCache &Cache);
148 
150 
151 namespace APT
152 {
153 namespace KernelAutoRemoveHelper
154 {
155 // Public for linking to apt-private, but no A{P,B}I guarantee.
156 APT_PUBLIC std::unique_ptr<APT::CacheFilter::Matcher> GetProtectedKernelsFilter(pkgCache *cache, bool returnRemove = false);
157 std::string GetProtectedKernelsRegex(pkgCache *cache, bool ReturnRemove = false);
158 std::string getUname(std::string const &packageName);
159 
160 } // namespace KernelAutoRemoveHelper
161 
162 } // namespace APT
163 
164 #endif
APT_PUBLIC bool pkgFixBroken(pkgDepCache &Cache)
Definition: algorithms.cc:381
APT_PUBLIC bool pkgApplyStatus(pkgDepCache &Cache)
Definition: algorithms.cc:313
APT_PUBLIC void pkgPrioSortList(pkgCache &Cache, pkgCache::Version **List)
Definition: algorithms.cc:1448
pkgCache::PkgIterator PkgIterator
Definition: pkgcache.h:829
pkgCache::VerIterator VerIterator
Definition: pkgcache.h:830
Represents an active action group.
Definition: depcache.h:166
void MarkProtected(PkgIterator const &Pkg)
Definition: depcache.h:416
virtual bool Configure(PkgIterator)
virtual bool Remove(PkgIterator, bool=false)
virtual bool Install(PkgIterator, std::string)
virtual bool Go(APT::Progress::PackageManager *)
pkgCache::Package Package
Definition: algorithms.h:104
unsigned char * Flags
Definition: algorithms.h:110
void Clear(pkgCache::PkgIterator Pkg)
Definition: algorithms.h:132
pkgDepCache & Cache
Definition: algorithms.h:98
pkgCache::PrvIterator PrvIterator
Definition: algorithms.h:102
void Remove(pkgCache::PkgIterator Pkg)
Definition: algorithms.h:131
pkgCache::PkgIterator PkgIterator
Definition: algorithms.h:99
void Protect(pkgCache::PkgIterator Pkg)
Definition: algorithms.h:130
pkgCache::VerIterator VerIterator
Definition: algorithms.h:100
pkgCache::DepIterator DepIterator
Definition: algorithms.h:101
pkgCache::Version Version
Definition: algorithms.h:103
void *const d
dpointer placeholder (for later in case we need it)
Definition: algorithms.h:96
pkgDepCache * Cache
Definition: algorithms.h:54
virtual VerIterator GetCandidateVer(PkgIterator const &Pkg) APT_OVERRIDE
Definition: algorithms.h:57
Policy(pkgDepCache *Cache)
Definition: algorithms.h:62
unsigned char * Flags
Definition: algorithms.h:65
pkgDepCache::ActionGroup group
Definition: algorithms.h:69
pkgDepCache Sim
Definition: algorithms.h:68
Policy iPolicy
Definition: algorithms.h:67
pkgSimulatePrivate *const d
Definition: algorithms.h:49
#define APT_OVERRIDE
Definition: macros.h:111
#define APT_PURE
Definition: macros.h:56
#define APT_PUBLIC
Definition: macros.h:77
#define APT_HIDDEN
Definition: macros.h:78
std::unique_ptr< APT::CacheFilter::Matcher > GetProtectedKernelsFilter(pkgCache *cache, bool returnRemove)
Definition: algorithms.cc:1625
std::string GetProtectedKernelsRegex(pkgCache *cache, bool ReturnRemove)
Definition: algorithms.cc:1498
std::string getUname(std::string const &packageName)
Definition: algorithms.cc:1464
pkgCache - Structure definitions for the cache file
bool DoUpgrade(CommandLine &CmdL)
contains information for a single unique package
Definition: pkgcache.h:450
information for a single version of a package
Definition: pkgcache.h:625