private-cachefile.cc 3.2 KB

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