private-update.cc 2.5 KB

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