private-cacheset.cc 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include <config.h>
  2. #include <apt-pkg/cachefile.h>
  3. #include <apt-pkg/pkgcache.h>
  4. #include <apt-pkg/depcache.h>
  5. #include <apt-pkg/cacheiterators.h>
  6. #include <apt-pkg/configuration.h>
  7. #include <apt-pkg/progress.h>
  8. #include <apt-pkg/policy.h>
  9. #include <apt-private/private-cacheset.h>
  10. #include <stddef.h>
  11. #include <apti18n.h>
  12. bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile,
  13. LocalitySortedVersionSet &output_set,
  14. OpProgress &progress)
  15. {
  16. Matcher null_matcher = Matcher();
  17. return GetLocalitySortedVersionSet(CacheFile, output_set,
  18. null_matcher, progress);
  19. }
  20. bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile,
  21. LocalitySortedVersionSet &output_set,
  22. Matcher &matcher,
  23. OpProgress &progress)
  24. {
  25. pkgCache *Cache = CacheFile.GetPkgCache();
  26. pkgDepCache *DepCache = CacheFile.GetDepCache();
  27. int Done=0;
  28. progress.SubProgress(Cache->Head().PackageCount, _("Sorting"));
  29. for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; ++P)
  30. {
  31. if (Done%500 == 0)
  32. progress.Progress(Done);
  33. Done++;
  34. if ((matcher)(P) == false)
  35. continue;
  36. // exclude virtual pkgs
  37. if (P.VersionList() == 0)
  38. continue;
  39. pkgDepCache::StateCache &state = (*DepCache)[P];
  40. if (_config->FindB("APT::Cmd::Installed") == true)
  41. {
  42. if (P.CurrentVer() != NULL)
  43. {
  44. output_set.insert(P.CurrentVer());
  45. }
  46. }
  47. else if (_config->FindB("APT::Cmd::Upgradable") == true)
  48. {
  49. if(P.CurrentVer() && state.Upgradable())
  50. {
  51. pkgPolicy *policy = CacheFile.GetPolicy();
  52. output_set.insert(policy->GetCandidateVer(P));
  53. }
  54. }
  55. else if (_config->FindB("APT::Cmd::Manual-Installed") == true)
  56. {
  57. if (P.CurrentVer() &&
  58. ((*DepCache)[P].Flags & pkgCache::Flag::Auto) == false)
  59. {
  60. pkgPolicy *policy = CacheFile.GetPolicy();
  61. output_set.insert(policy->GetCandidateVer(P));
  62. }
  63. }
  64. else
  65. {
  66. pkgPolicy *policy = CacheFile.GetPolicy();
  67. if (policy->GetCandidateVer(P).IsGood())
  68. output_set.insert(policy->GetCandidateVer(P));
  69. else
  70. // no candidate, this may happen for packages in
  71. // dpkg "deinstall ok config-file" state - we pick the first ver
  72. // (which should be the only one)
  73. output_set.insert(P.VersionList());
  74. }
  75. }
  76. progress.Done();
  77. return true;
  78. }