private-update.cc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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(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;
  41. if (Fetcher.Setup(&Stat) == false)
  42. return false;
  43. // Populate it with the source selection and get all Indexes
  44. // (GetAll=true)
  45. if (List->GetIndexes(&Fetcher,true) == false)
  46. return false;
  47. std::string compExt = APT::Configuration::getCompressionTypes()[0];
  48. pkgAcquire::UriIterator I = Fetcher.UriBegin();
  49. for (; I != Fetcher.UriEnd(); ++I)
  50. {
  51. std::string FileName = flNotDir(I->Owner->DestFile);
  52. if(compExt.empty() == false &&
  53. APT::String::Endswith(FileName, compExt))
  54. FileName = FileName.substr(0, FileName.size() - compExt.size() - 1);
  55. c1out << '\'' << I->URI << "' " << FileName << ' ' <<
  56. I->Owner->FileSize << ' ' << I->Owner->HashSum() << std::endl;
  57. }
  58. return true;
  59. }
  60. // do the work
  61. if (_config->FindB("APT::Get::Download",true) == true)
  62. ListUpdate(Stat, *List);
  63. // Rebuild the cache.
  64. if (_config->FindB("pkgCacheFile::Generate", true) == true)
  65. {
  66. pkgCacheFile::RemoveCaches();
  67. if (Cache.BuildCaches() == false)
  68. return false;
  69. }
  70. // show basic stats (if the user whishes)
  71. if (_config->FindB("APT::Cmd::Show-Update-Stats", false) == true)
  72. {
  73. int upgradable = 0;
  74. Cache.Open();
  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. /*}}}*/