]>
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/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> 
  12 #include <apt-private/private-output.h> 
  13 #include <apt-private/private-cachefile.h> 
  24 // CacheFile::NameComp - QSort compare by name                          /*{{{*/ 
  25 // --------------------------------------------------------------------- 
  27 pkgCache 
*CacheFile::SortCache 
= 0; 
  28 int CacheFile::NameComp(const void *a
,const void *b
) 
  30    if (*(pkgCache::Package 
**)a 
== 0 || *(pkgCache::Package 
**)b 
== 0) 
  31       return *(pkgCache::Package 
**)a 
- *(pkgCache::Package 
**)b
; 
  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
; 
  38    return strcmp(SortCache
->StrP 
+ GA
->Name
,SortCache
->StrP 
+ GB
->Name
); 
  41 // CacheFile::Sort - Sort by name                                       /*{{{*/ 
  42 // --------------------------------------------------------------------- 
  44 void CacheFile::Sort() 
  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
) 
  54    qsort(List
,Cache
->Head().PackageCount
,sizeof(*List
),NameComp
); 
  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. */ 
  61 bool CacheFile::CheckDeps(bool AllowBroken
) 
  63    bool FixBroken 
= _config
->FindB("APT::Get::Fix-Broken",false); 
  65    if (_error
->PendingError() == true) 
  68    // Check that the system is OK 
  69    if (DCache
->DelCount() != 0 || DCache
->InstCount() != 0) 
  70       return _error
->Error("Internal error, non-zero counts"); 
  72    // Apply corrections for half-installed packages 
  73    if (pkgApplyStatus(*DCache
) == false) 
  76    if (_config
->FindB("APT::Get::Fix-Policy-Broken",false) == true) 
  79       if ((DCache
->PolicyBrokenCount() > 0)) 
  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); 
  89    if (DCache
->BrokenCount() == 0 || AllowBroken 
== true) 
  92    // Attempt to fix broken things 
  93    if (FixBroken 
== true) 
  95       c1out 
<< _("Correcting dependencies...") << flush
; 
  96       if (pkgFixBroken(*DCache
) == false || DCache
->BrokenCount() != 0) 
  98          c1out 
<< _(" failed.") << endl
; 
  99          ShowBroken(c1out
,*this,true); 
 101          return _error
->Error(_("Unable to correct dependencies")); 
 103       if (pkgMinimizeUpgrade(*DCache
) == false) 
 104          return _error
->Error(_("Unable to minimize the upgrade set")); 
 106       c1out 
<< _(" Done") << endl
; 
 110       c1out 
<< _("You might want to run 'apt-get -f install' to correct these.") << endl
; 
 111       ShowBroken(c1out
,*this,true); 
 113       return _error
->Error(_("Unmet dependencies. Try using -f."));