private-cacheset.cc 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include <apt-pkg/cachefile.h>
  2. #include <apt-pkg/pkgcache.h>
  3. #include <apt-pkg/depcache.h>
  4. #include <apt-pkg/strutl.h>
  5. #include "private-cacheset.h"
  6. bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile,
  7. LocalitySortedVersionSet &output_set,
  8. OpProgress &progress)
  9. {
  10. Matcher null_matcher = Matcher();
  11. return GetLocalitySortedVersionSet(CacheFile, output_set,
  12. null_matcher, progress);
  13. }
  14. bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile,
  15. LocalitySortedVersionSet &output_set,
  16. Matcher &matcher,
  17. OpProgress &progress)
  18. {
  19. pkgCache *Cache = CacheFile.GetPkgCache();
  20. pkgDepCache *DepCache = CacheFile.GetDepCache();
  21. int Done=0;
  22. progress.SubProgress(Cache->Head().PackageCount, _("Sorting"));
  23. for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; ++P)
  24. {
  25. if (Done%500 == 0)
  26. progress.Progress(Done);
  27. Done++;
  28. if ((matcher)(P) == false)
  29. continue;
  30. // exclude virtual pkgs
  31. if (P.VersionList() == 0)
  32. continue;
  33. pkgDepCache::StateCache &state = (*DepCache)[P];
  34. if (_config->FindB("APT::Cmd::Installed") == true)
  35. {
  36. if (P.CurrentVer() != NULL)
  37. {
  38. output_set.insert(P.CurrentVer());
  39. }
  40. }
  41. else if (_config->FindB("APT::Cmd::Upgradable") == true)
  42. {
  43. if(P.CurrentVer() && state.Upgradable())
  44. {
  45. pkgPolicy *policy = CacheFile.GetPolicy();
  46. output_set.insert(policy->GetCandidateVer(P));
  47. }
  48. }
  49. else if (_config->FindB("APT::Cmd::Manual-Installed") == true)
  50. {
  51. if (P.CurrentVer() &&
  52. ((*DepCache)[P].Flags & pkgCache::Flag::Auto) == false)
  53. {
  54. pkgPolicy *policy = CacheFile.GetPolicy();
  55. output_set.insert(policy->GetCandidateVer(P));
  56. }
  57. }
  58. else
  59. {
  60. pkgPolicy *policy = CacheFile.GetPolicy();
  61. output_set.insert(policy->GetCandidateVer(P));
  62. }
  63. }
  64. progress.Done();
  65. return true;
  66. }