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