private-update.cc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // Include files /*{{{*/
  2. #include<config.h>
  3. #include <apt-pkg/acquire-item.h>
  4. #include <apt-pkg/cachefile.h>
  5. #include <apt-pkg/cmndline.h>
  6. #include <apt-pkg/error.h>
  7. #include <apt-pkg/fileutl.h>
  8. #include <apt-pkg/sourcelist.h>
  9. #include <apt-pkg/update.h>
  10. #include <apt-pkg/acquire.h>
  11. #include <apt-pkg/configuration.h>
  12. #include <apt-private/acqprogress.h>
  13. #include <apt-private/private-cachefile.h>
  14. #include <apt-private/private-download.h>
  15. #include <apt-private/private-output.h>
  16. #include <apt-private/private-update.h>
  17. #include <ostream>
  18. #include <string>
  19. #include <apti18n.h>
  20. /*}}}*/
  21. // DoUpdate - Update the package lists /*{{{*/
  22. // ---------------------------------------------------------------------
  23. /* */
  24. bool DoUpdate(CommandLine &CmdL)
  25. {
  26. if (CmdL.FileSize() != 1)
  27. return _error->Error(_("The update command takes no arguments"));
  28. CacheFile Cache;
  29. // Get the source list
  30. if (Cache.BuildSourceList() == false)
  31. return false;
  32. pkgSourceList *List = Cache.GetSourceList();
  33. // Just print out the uris an exit if the --print-uris flag was used
  34. if (_config->FindB("APT::Get::Print-URIs") == true)
  35. {
  36. // force a hashsum for compatibility reasons
  37. _config->CndSet("Acquire::ForceHash", "md5sum");
  38. // Populate it with the source selection and get all Indexes
  39. // (GetAll=true)
  40. aptAcquireWithTextStatus Fetcher;
  41. if (List->GetIndexes(&Fetcher,true) == false)
  42. return false;
  43. std::string compExt = APT::Configuration::getCompressionTypes()[0];
  44. pkgAcquire::UriIterator I = Fetcher.UriBegin();
  45. for (; I != Fetcher.UriEnd(); ++I)
  46. {
  47. std::string FileName = flNotDir(I->Owner->DestFile);
  48. if(compExt.empty() == false &&
  49. APT::String::Endswith(FileName, compExt))
  50. FileName = FileName.substr(0, FileName.size() - compExt.size() - 1);
  51. c1out << '\'' << I->URI << "' " << FileName << ' ' <<
  52. std::to_string(I->Owner->FileSize) << ' ' << I->Owner->HashSum() << std::endl;
  53. }
  54. return true;
  55. }
  56. // do the work
  57. if (_config->FindB("APT::Get::Download",true) == true)
  58. {
  59. AcqTextStatus Stat(std::cout, ScreenWidth,_config->FindI("quiet",0));
  60. ListUpdate(Stat, *List);
  61. }
  62. // Rebuild the cache.
  63. if (_config->FindB("pkgCacheFile::Generate", true) == true)
  64. {
  65. pkgCacheFile::RemoveCaches();
  66. if (Cache.BuildCaches() == false)
  67. return false;
  68. }
  69. // show basic stats (if the user whishes)
  70. if (_config->FindB("APT::Cmd::Show-Update-Stats", false) == true)
  71. {
  72. int upgradable = 0;
  73. if (Cache.Open() == false)
  74. return false;
  75. for (pkgCache::PkgIterator I = Cache->PkgBegin(); I.end() != true; ++I)
  76. {
  77. pkgDepCache::StateCache &state = Cache[I];
  78. if (I->CurrentVer != 0 && state.Upgradable() && state.CandidateVer != NULL)
  79. upgradable++;
  80. }
  81. const char *msg = P_(
  82. "%i package can be upgraded. Run 'apt list --upgradable' to see it.\n",
  83. "%i packages can be upgraded. Run 'apt list --upgradable' to see them.\n",
  84. upgradable);
  85. if (upgradable == 0)
  86. c1out << _("All packages are up to date.") << std::endl;
  87. else
  88. ioprintf(c1out, msg, upgradable);
  89. }
  90. return true;
  91. }
  92. /*}}}*/