private-update.cc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. pkgAcquire::UriIterator I = Fetcher.UriBegin();
  48. for (; I != Fetcher.UriEnd(); ++I)
  49. c1out << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' <<
  50. I->Owner->FileSize << ' ' << I->Owner->HashSum() << std::endl;
  51. return true;
  52. }
  53. // do the work
  54. if (_config->FindB("APT::Get::Download",true) == true)
  55. ListUpdate(Stat, *List);
  56. // Rebuild the cache.
  57. if (_config->FindB("pkgCacheFile::Generate", true) == true)
  58. {
  59. pkgCacheFile::RemoveCaches();
  60. if (Cache.BuildCaches() == false)
  61. return false;
  62. }
  63. // show basic stats (if the user whishes)
  64. if (_config->FindB("APT::Cmd::Show-Update-Stats", false) == true)
  65. {
  66. int upgradable = 0;
  67. Cache.Open();
  68. for (pkgCache::PkgIterator I = Cache->PkgBegin(); I.end() != true; ++I)
  69. {
  70. pkgDepCache::StateCache &state = Cache[I];
  71. if (I->CurrentVer != 0 && state.Upgradable() && state.CandidateVer != NULL)
  72. upgradable++;
  73. }
  74. const char *msg = P_(
  75. "%i package can be upgraded. Run 'apt list --upgradable' to see it.\n",
  76. "%i packages can be upgraded. Run 'apt list --upgradable' to see them.\n",
  77. upgradable);
  78. if (upgradable == 0)
  79. c1out << _("All packages are up to date.") << std::endl;
  80. else
  81. ioprintf(c1out, msg, upgradable);
  82. }
  83. return true;
  84. }
  85. /*}}}*/