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)  

private-cachefile.cc
Go to the documentation of this file.
1 // Include files /*{{{*/
2 #include <config.h>
3 
4 #include <apt-pkg/algorithms.h>
5 #include <apt-pkg/cacheset.h>
6 #include <apt-pkg/configuration.h>
7 #include <apt-pkg/depcache.h>
8 #include <apt-pkg/error.h>
9 #include <apt-pkg/pkgcache.h>
10 #include <apt-pkg/upgrade.h>
11 
14 
15 #include <cstdlib>
16 #include <ostream>
17 #include <string.h>
18 
19 #include <apti18n.h>
20  /*}}}*/
21 
22 using namespace std;
23 
24 static bool SortPackagesByName(pkgCache * const Owner,
26 {
27  if (A == 0)
28  return false;
29  if (B == 0 || A == B)
30  return true;
31  pkgCache::Group const * const GA = Owner->GrpP + A;
32  pkgCache::Group const * const GB = Owner->GrpP + B;
33  return strcmp(Owner->StrP + GA->Name, Owner->StrP + GB->Name) <= 0;
34 }
36  PackageUniverse{Cache}, List(Cache.UniverseList)
37 {
38 }
40 {
41  if (List.empty() == false)
42  return;
43  pkgCache * const Owner = data();
44  // In Multi-Arch systems Grps are easier to sort than Pkgs
45  std::vector<map_pointer<pkgCache::Group>> GrpList;
46  List.reserve(Owner->Head().GroupCount);
47  for (pkgCache::GrpIterator I{Owner->GrpBegin()}; I.end() != true; ++I)
48  GrpList.emplace_back(I - Owner->GrpP);
49  std::stable_sort(GrpList.begin(), GrpList.end(), std::bind( &SortPackagesByName, Owner, std::placeholders::_1, std::placeholders::_2 ));
50  List.reserve(Owner->Head().PackageCount);
51  for (auto G : GrpList)
52  {
53  pkgCache::GrpIterator const Grp(*Owner, Owner->GrpP + G);
54  for (pkgCache::PkgIterator P = Grp.PackageList(); P.end() != true; P = Grp.NextPkg(P))
55  List.emplace_back(P - Owner->PkgP);
56  }
57 }
58 // CacheFile::CheckDeps - Open the cache file /*{{{*/
59 // ---------------------------------------------------------------------
60 /* This routine generates the caches and then opens the dependency cache
61  and verifies that the system is OK. */
62 bool CacheFile::CheckDeps(bool AllowBroken)
63 {
64  bool FixBroken = _config->FindB("APT::Get::Fix-Broken",false);
65 
66  if (_error->PendingError() == true)
67  return false;
68 
69  // Check that the system is OK
70  if (DCache->DelCount() != 0 || DCache->InstCount() != 0)
71  return _error->Error("Internal error, non-zero counts");
72 
73  // Apply corrections for half-installed packages
74  if (pkgApplyStatus(*DCache) == false)
75  return false;
76 
77  if (_config->FindB("APT::Get::Fix-Policy-Broken",false) == true)
78  {
79  FixBroken = true;
80  if ((DCache->PolicyBrokenCount() > 0))
81  {
82  // upgrade all policy-broken packages with ForceImportantDeps=True
83  for (pkgCache::PkgIterator I = Cache->PkgBegin(); !I.end(); ++I)
84  if ((*DCache)[I].NowPolicyBroken() == true)
85  DCache->MarkInstall(I,true,0, false, true);
86  }
87  }
88 
89  // Nothing is broken
90  if (DCache->BrokenCount() == 0 || AllowBroken == true)
91  return true;
92 
93  // Attempt to fix broken things
94  if (FixBroken == true)
95  {
96  c1out << _("Correcting dependencies...") << flush;
97  if (pkgFixBroken(*DCache) == false || DCache->BrokenCount() != 0)
98  {
99  c1out << _(" failed.") << endl;
100  ShowBroken(c1out,*this,true);
101 
102  return _error->Error(_("Unable to correct dependencies"));
103  }
104  if (pkgMinimizeUpgrade(*DCache) == false)
105  return _error->Error(_("Unable to minimize the upgrade set"));
106 
107  c1out << _(" Done") << endl;
108  }
109  else
110  {
111  c1out << _("You might want to run 'apt --fix-broken install' to correct these.") << endl;
112  ShowBroken(c1out,*this,true);
113  return _error->Error(_("Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution)."));
114  }
115 
116  return true;
117 }
118  /*}}}*/
static bool std::string const metaIndex const *const pkgAcqMetaClearSig *const pkgAcquire::Item *const I
bool pkgFixBroken(pkgDepCache &Cache)
Definition: algorithms.cc:381
bool pkgApplyStatus(pkgDepCache &Cache)
Definition: algorithms.cc:313
pkgCache * data() const
Definition: cacheset.h:660
bool CheckDeps(bool AllowBroken=false)
std::vector< map_pointer< pkgCache::Package > > & List
SortedPackageUniverse(CacheFile &Cache)
pkgDepCache * DCache
Definition: cachefile.h:42
pkgCache * Cache
Definition: cachefile.h:41
unsigned long InstCount()
Definition: depcache.h:496
bool MarkInstall(PkgIterator const &Pkg, bool AutoInst=true, unsigned long Depth=0, bool FromUser=true, bool ForceImportantDeps=false)
Definition: depcache.cc:1560
unsigned long DelCount()
Definition: depcache.h:494
unsigned long BrokenCount()
Definition: depcache.h:497
unsigned long PolicyBrokenCount()
Definition: depcache.h:498
Configuration * _config
pkgCache - Structure definitions for the cache file
static bool SortPackagesByName(pkgCache *const Owner, map_pointer< pkgCache::Group > const A, map_pointer< pkgCache::Group > const B)
void ShowBroken(ostream &out, CacheFile &Cache, bool const Now)
APT_PUBLIC std::ostream c1out
groups architecture depending packages together
Definition: pkgcache.h:415
map_stringitem_t Name
Name of the group.
Definition: pkgcache.h:417
bool pkgMinimizeUpgrade(pkgDepCache &Cache)
Definition: upgrade.cc:227