private-update.cc 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 <sys/types.h>
  26. #include <sys/stat.h>
  27. #include <unistd.h>
  28. #include "private-cachefile.h"
  29. #include "private-output.h"
  30. #include "acqprogress.h"
  31. #include <apti18n.h>
  32. /*}}}*/
  33. // DoUpdate - Update the package lists /*{{{*/
  34. // ---------------------------------------------------------------------
  35. /* */
  36. bool DoUpdate(CommandLine &CmdL)
  37. {
  38. if (CmdL.FileSize() != 1)
  39. return _error->Error(_("The update command takes no arguments"));
  40. CacheFile Cache;
  41. // Get the source list
  42. if (Cache.BuildSourceList() == false)
  43. return false;
  44. pkgSourceList *List = Cache.GetSourceList();
  45. // Create the progress
  46. AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0));
  47. // Just print out the uris an exit if the --print-uris flag was used
  48. if (_config->FindB("APT::Get::Print-URIs") == true)
  49. {
  50. // force a hashsum for compatibility reasons
  51. _config->CndSet("Acquire::ForceHash", "md5sum");
  52. // get a fetcher
  53. pkgAcquire Fetcher;
  54. if (Fetcher.Setup(&Stat) == false)
  55. return false;
  56. // Populate it with the source selection and get all Indexes
  57. // (GetAll=true)
  58. if (List->GetIndexes(&Fetcher,true) == false)
  59. return false;
  60. pkgAcquire::UriIterator I = Fetcher.UriBegin();
  61. for (; I != Fetcher.UriEnd(); ++I)
  62. c1out << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' <<
  63. I->Owner->FileSize << ' ' << I->Owner->HashSum() << std::endl;
  64. return true;
  65. }
  66. // do the work
  67. if (_config->FindB("APT::Get::Download",true) == true)
  68. ListUpdate(Stat, *List);
  69. // Rebuild the cache.
  70. if (_config->FindB("pkgCacheFile::Generate", true) == true)
  71. {
  72. pkgCacheFile::RemoveCaches();
  73. if (Cache.BuildCaches() == false)
  74. return false;
  75. }
  76. return true;
  77. }
  78. /*}}}*/