]> git.saurik.com Git - apt.git/blame_incremental - apt-private/private-cachefile.cc
add a simple unit test for acquire progress
[apt.git] / apt-private / private-cachefile.cc
... / ...
CommitLineData
1// Include files /*{{{*/
2#include<config.h>
3
4#include <apt-pkg/algorithms.h>
5#include <apt-pkg/upgrade.h>
6#include <apt-pkg/error.h>
7#include <apt-pkg/configuration.h>
8#include <apt-pkg/depcache.h>
9#include <apt-pkg/pkgcache.h>
10#include <apt-pkg/cacheiterators.h>
11
12#include <apt-private/private-output.h>
13#include <apt-private/private-cachefile.h>
14
15#include <string.h>
16#include <ostream>
17#include <cstdlib>
18
19#include <apti18n.h>
20 /*}}}*/
21
22using namespace std;
23
24// CacheFile::NameComp - QSort compare by name /*{{{*/
25// ---------------------------------------------------------------------
26/* */
27pkgCache *CacheFile::SortCache = 0;
28int CacheFile::NameComp(const void *a,const void *b)
29{
30 if (*(pkgCache::Package **)a == 0 || *(pkgCache::Package **)b == 0)
31 return *(pkgCache::Package **)a - *(pkgCache::Package **)b;
32
33 const pkgCache::Package &A = **(pkgCache::Package **)a;
34 const pkgCache::Package &B = **(pkgCache::Package **)b;
35 const pkgCache::Group * const GA = SortCache->GrpP + A.Group;
36 const pkgCache::Group * const GB = SortCache->GrpP + B.Group;
37
38 return strcmp(SortCache->StrP + GA->Name,SortCache->StrP + GB->Name);
39}
40 /*}}}*/
41// CacheFile::Sort - Sort by name /*{{{*/
42// ---------------------------------------------------------------------
43/* */
44void CacheFile::Sort()
45{
46 delete [] List;
47 List = new pkgCache::Package *[Cache->Head().PackageCount];
48 memset(List,0,sizeof(*List)*Cache->Head().PackageCount);
49 pkgCache::PkgIterator I = Cache->PkgBegin();
50 for (;I.end() != true; ++I)
51 List[I->ID] = I;
52
53 SortCache = *this;
54 qsort(List,Cache->Head().PackageCount,sizeof(*List),NameComp);
55}
56 /*}}}*/
57// CacheFile::CheckDeps - Open the cache file /*{{{*/
58// ---------------------------------------------------------------------
59/* This routine generates the caches and then opens the dependency cache
60 and verifies that the system is OK. */
61bool CacheFile::CheckDeps(bool AllowBroken)
62{
63 bool FixBroken = _config->FindB("APT::Get::Fix-Broken",false);
64
65 if (_error->PendingError() == true)
66 return false;
67
68 // Check that the system is OK
69 if (DCache->DelCount() != 0 || DCache->InstCount() != 0)
70 return _error->Error("Internal error, non-zero counts");
71
72 // Apply corrections for half-installed packages
73 if (pkgApplyStatus(*DCache) == false)
74 return false;
75
76 if (_config->FindB("APT::Get::Fix-Policy-Broken",false) == true)
77 {
78 FixBroken = true;
79 if ((DCache->PolicyBrokenCount() > 0))
80 {
81 // upgrade all policy-broken packages with ForceImportantDeps=True
82 for (pkgCache::PkgIterator I = Cache->PkgBegin(); !I.end(); ++I)
83 if ((*DCache)[I].NowPolicyBroken() == true)
84 DCache->MarkInstall(I,true,0, false, true);
85 }
86 }
87
88 // Nothing is broken
89 if (DCache->BrokenCount() == 0 || AllowBroken == true)
90 return true;
91
92 // Attempt to fix broken things
93 if (FixBroken == true)
94 {
95 c1out << _("Correcting dependencies...") << flush;
96 if (pkgFixBroken(*DCache) == false || DCache->BrokenCount() != 0)
97 {
98 c1out << _(" failed.") << endl;
99 ShowBroken(c1out,*this,true);
100
101 return _error->Error(_("Unable to correct dependencies"));
102 }
103 if (pkgMinimizeUpgrade(*DCache) == false)
104 return _error->Error(_("Unable to minimize the upgrade set"));
105
106 c1out << _(" Done") << endl;
107 }
108 else
109 {
110 c1out << _("You might want to run 'apt-get -f install' to correct these.") << endl;
111 ShowBroken(c1out,*this,true);
112
113 return _error->Error(_("Unmet dependencies. Try using -f."));
114 }
115
116 return true;
117}
118 /*}}}*/