private-update.cc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Include files /*{{{*/
  2. #include<config.h>
  3. #include <apt-pkg/aptconfiguration.h>
  4. #include <apt-pkg/error.h>
  5. #include <apt-pkg/cmndline.h>
  6. #include <apt-pkg/init.h>
  7. #include <apt-pkg/depcache.h>
  8. #include <apt-pkg/sourcelist.h>
  9. #include <apt-pkg/algorithms.h>
  10. #include <apt-pkg/acquire-item.h>
  11. #include <apt-pkg/strutl.h>
  12. #include <apt-pkg/fileutl.h>
  13. #include <apt-pkg/clean.h>
  14. #include <apt-pkg/srcrecords.h>
  15. #include <apt-pkg/version.h>
  16. #include <apt-pkg/cachefile.h>
  17. #include <apt-pkg/cacheset.h>
  18. #include <apt-pkg/sptr.h>
  19. #include <apt-pkg/md5.h>
  20. #include <apt-pkg/versionmatch.h>
  21. #include <apt-pkg/progress.h>
  22. #include <apt-pkg/pkgsystem.h>
  23. #include <apt-pkg/pkgrecords.h>
  24. #include <apt-pkg/indexfile.h>
  25. #include <apt-pkg/update.h>
  26. #include <sys/types.h>
  27. #include <sys/stat.h>
  28. #include <unistd.h>
  29. #include "private-cachefile.h"
  30. #include "private-output.h"
  31. #include "private-update.h"
  32. #include "acqprogress.h"
  33. #include <apti18n.h>
  34. /*}}}*/
  35. // DoUpdate - Update the package lists /*{{{*/
  36. // ---------------------------------------------------------------------
  37. /* */
  38. bool DoUpdate(CommandLine &CmdL)
  39. {
  40. if (CmdL.FileSize() != 1)
  41. return _error->Error(_("The update command takes no arguments"));
  42. CacheFile Cache;
  43. // Get the source list
  44. if (Cache.BuildSourceList() == false)
  45. return false;
  46. pkgSourceList *List = Cache.GetSourceList();
  47. // Create the progress
  48. AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0));
  49. // Just print out the uris an exit if the --print-uris flag was used
  50. if (_config->FindB("APT::Get::Print-URIs") == true)
  51. {
  52. // force a hashsum for compatibility reasons
  53. _config->CndSet("Acquire::ForceHash", "md5sum");
  54. // get a fetcher
  55. pkgAcquire Fetcher;
  56. if (Fetcher.Setup(&Stat) == false)
  57. return false;
  58. // Populate it with the source selection and get all Indexes
  59. // (GetAll=true)
  60. if (List->GetIndexes(&Fetcher,true) == false)
  61. return false;
  62. pkgAcquire::UriIterator I = Fetcher.UriBegin();
  63. for (; I != Fetcher.UriEnd(); ++I)
  64. c1out << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' <<
  65. I->Owner->FileSize << ' ' << I->Owner->HashSum() << std::endl;
  66. return true;
  67. }
  68. // do the work
  69. if (_config->FindB("APT::Get::Download",true) == true)
  70. ListUpdate(Stat, *List);
  71. // Rebuild the cache.
  72. if (_config->FindB("pkgCacheFile::Generate", true) == true)
  73. {
  74. pkgCacheFile::RemoveCaches();
  75. if (Cache.BuildCaches() == false)
  76. return false;
  77. }
  78. return true;
  79. }
  80. /*}}}*/