private-cacheset.cc 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. APT::VersionContainerInterface * const vci,
  14. OpProgress * const progress)
  15. {
  16. Matcher null_matcher = Matcher();
  17. return GetLocalitySortedVersionSet(CacheFile, vci,
  18. null_matcher, progress);
  19. }
  20. bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile,
  21. APT::VersionContainerInterface * const vci,
  22. Matcher &matcher,
  23. OpProgress * const progress)
  24. {
  25. pkgCache *Cache = CacheFile.GetPkgCache();
  26. pkgDepCache *DepCache = CacheFile.GetDepCache();
  27. APT::CacheSetHelper helper(false);
  28. int Done=0;
  29. if (progress != NULL)
  30. progress->SubProgress(Cache->Head().PackageCount, _("Sorting"));
  31. bool const insertCurrentVer = _config->FindB("APT::Cmd::Installed", false);
  32. bool const insertUpgradable = _config->FindB("APT::Cmd::Upgradable", false);
  33. bool const insertManualInstalled = _config->FindB("APT::Cmd::Manual-Installed", false);
  34. for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; ++P)
  35. {
  36. if (progress != NULL)
  37. {
  38. if (Done % 500 == 0)
  39. progress->Progress(Done);
  40. ++Done;
  41. }
  42. // exclude virtual pkgs
  43. if (P->VersionList == 0)
  44. continue;
  45. if ((matcher)(P) == false)
  46. continue;
  47. pkgDepCache::StateCache &state = (*DepCache)[P];
  48. if (insertCurrentVer == true)
  49. {
  50. if (P->CurrentVer != 0)
  51. vci->FromPackage(vci, CacheFile, P, APT::CacheSetHelper::INSTALLED, helper);
  52. }
  53. else if (insertUpgradable == true)
  54. {
  55. if(P.CurrentVer() && state.Upgradable())
  56. vci->FromPackage(vci, CacheFile, P, APT::CacheSetHelper::CANDIDATE, helper);
  57. }
  58. else if (insertManualInstalled == true)
  59. {
  60. if (P.CurrentVer() &&
  61. ((*DepCache)[P].Flags & pkgCache::Flag::Auto) == false)
  62. vci->FromPackage(vci, CacheFile, P, APT::CacheSetHelper::CANDIDATE, helper);
  63. }
  64. else
  65. {
  66. if (vci->FromPackage(vci, CacheFile, P, APT::CacheSetHelper::CANDIDATE, helper) == false)
  67. {
  68. // no candidate, this may happen for packages in
  69. // dpkg "deinstall ok config-file" state - we pick the first ver
  70. // (which should be the only one)
  71. vci->insert(P.VersionList());
  72. }
  73. }
  74. }
  75. if (progress != NULL)
  76. progress->Done();
  77. return true;
  78. }