You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

107 lines
3.2 KiB

  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. if (_config->FindB("pkgCacheFile::Generate", true) == false)
  63. return true;
  64. // Rebuild the cache.
  65. pkgCacheFile::RemoveCaches();
  66. if (Cache.BuildCaches() == false)
  67. return false;
  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. if (Cache.Open() == false)
  73. return false;
  74. for (pkgCache::PkgIterator I = Cache->PkgBegin(); I.end() != true; ++I)
  75. {
  76. pkgDepCache::StateCache &state = Cache[I];
  77. if (I->CurrentVer != 0 && state.Upgradable() && state.CandidateVer != NULL)
  78. upgradable++;
  79. }
  80. const char *msg = P_(
  81. "%i package can be upgraded. Run 'apt list --upgradable' to see it.\n",
  82. "%i packages can be upgraded. Run 'apt list --upgradable' to see them.\n",
  83. upgradable);
  84. if (upgradable == 0)
  85. c1out << _("All packages are up to date.") << std::endl;
  86. else
  87. ioprintf(c1out, msg, upgradable);
  88. }
  89. return true;
  90. }
  91. /*}}}*/