]>
git.saurik.com Git - apt.git/blob - apt-private/private-cachefile.cc
1 // Include files /*{{{*/
4 #include <apt-pkg/algorithms.h>
5 #include <apt-pkg/error.h>
9 #include "private-output.h"
10 #include "private-cachefile.h"
17 // CacheFile::NameComp - QSort compare by name /*{{{*/
18 // ---------------------------------------------------------------------
20 pkgCache
*CacheFile::SortCache
= 0;
21 int CacheFile::NameComp(const void *a
,const void *b
)
23 if (*(pkgCache::Package
**)a
== 0 || *(pkgCache::Package
**)b
== 0)
24 return *(pkgCache::Package
**)a
- *(pkgCache::Package
**)b
;
26 const pkgCache::Package
&A
= **(pkgCache::Package
**)a
;
27 const pkgCache::Package
&B
= **(pkgCache::Package
**)b
;
29 return strcmp(SortCache
->StrP
+ A
.Name
,SortCache
->StrP
+ B
.Name
);
32 // CacheFile::Sort - Sort by name /*{{{*/
33 // ---------------------------------------------------------------------
35 void CacheFile::Sort()
38 List
= new pkgCache::Package
*[Cache
->Head().PackageCount
];
39 memset(List
,0,sizeof(*List
)*Cache
->Head().PackageCount
);
40 pkgCache::PkgIterator I
= Cache
->PkgBegin();
41 for (;I
.end() != true; ++I
)
45 qsort(List
,Cache
->Head().PackageCount
,sizeof(*List
),NameComp
);
48 // CacheFile::CheckDeps - Open the cache file /*{{{*/
49 // ---------------------------------------------------------------------
50 /* This routine generates the caches and then opens the dependency cache
51 and verifies that the system is OK. */
52 bool CacheFile::CheckDeps(bool AllowBroken
)
54 bool FixBroken
= _config
->FindB("APT::Get::Fix-Broken",false);
56 if (_error
->PendingError() == true)
59 // Check that the system is OK
60 if (DCache
->DelCount() != 0 || DCache
->InstCount() != 0)
61 return _error
->Error("Internal error, non-zero counts");
63 // Apply corrections for half-installed packages
64 if (pkgApplyStatus(*DCache
) == false)
67 if (_config
->FindB("APT::Get::Fix-Policy-Broken",false) == true)
70 if ((DCache
->PolicyBrokenCount() > 0))
72 // upgrade all policy-broken packages with ForceImportantDeps=True
73 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); !I
.end(); ++I
)
74 if ((*DCache
)[I
].NowPolicyBroken() == true)
75 DCache
->MarkInstall(I
,true,0, false, true);
80 if (DCache
->BrokenCount() == 0 || AllowBroken
== true)
83 // Attempt to fix broken things
84 if (FixBroken
== true)
86 c1out
<< _("Correcting dependencies...") << flush
;
87 if (pkgFixBroken(*DCache
) == false || DCache
->BrokenCount() != 0)
89 c1out
<< _(" failed.") << endl
;
90 ShowBroken(c1out
,*this,true);
92 return _error
->Error(_("Unable to correct dependencies"));
94 if (pkgMinimizeUpgrade(*DCache
) == false)
95 return _error
->Error(_("Unable to minimize the upgrade set"));
97 c1out
<< _(" Done") << endl
;
101 c1out
<< _("You might want to run 'apt-get -f install' to correct these.") << endl
;
102 ShowBroken(c1out
,*this,true);
104 return _error
->Error(_("Unmet dependencies. Try using -f."));