private-upgrade.cc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Includes /*{{{*/
  2. #include <config.h>
  3. #include <apt-pkg/upgrade.h>
  4. #include <apt-pkg/configuration.h>
  5. #include <apt-pkg/error.h>
  6. #include <apt-private/private-install.h>
  7. #include <apt-private/private-cachefile.h>
  8. #include <apt-private/private-upgrade.h>
  9. #include <apt-private/private-output.h>
  10. #include <iostream>
  11. #include <apti18n.h>
  12. /*}}}*/
  13. // this is actually performing the various upgrade operations
  14. static bool UpgradeHelper(CommandLine &CmdL, int UpgradeFlags)
  15. {
  16. CacheFile Cache;
  17. std::vector<std::string> VolatileCmdL;
  18. Cache.GetSourceList()->AddVolatileFiles(CmdL, &VolatileCmdL);
  19. if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false)
  20. return false;
  21. if(!DoCacheManipulationFromCommandLine(CmdL, VolatileCmdL, Cache, UpgradeFlags))
  22. return false;
  23. return InstallPackages(Cache,true);
  24. }
  25. // DoDistUpgrade - Automatic smart upgrader /*{{{*/
  26. // ---------------------------------------------------------------------
  27. /* Intelligent upgrader that will install and remove packages at will */
  28. bool DoDistUpgrade(CommandLine &CmdL)
  29. {
  30. return UpgradeHelper(CmdL, APT::Upgrade::ALLOW_EVERYTHING);
  31. }
  32. /*}}}*/
  33. bool DoUpgrade(CommandLine &CmdL) /*{{{*/
  34. {
  35. if (_config->FindB("APT::Get::Upgrade-Allow-New", false) == true)
  36. return DoUpgradeWithAllowNewPackages(CmdL);
  37. else
  38. return DoUpgradeNoNewPackages(CmdL);
  39. }
  40. /*}}}*/
  41. // DoUpgradeNoNewPackages - Upgrade all packages /*{{{*/
  42. // ---------------------------------------------------------------------
  43. /* Upgrade all packages without installing new packages or erasing old
  44. packages */
  45. bool DoUpgradeNoNewPackages(CommandLine &CmdL)
  46. {
  47. // Do the upgrade
  48. return UpgradeHelper(CmdL,
  49. APT::Upgrade::FORBID_REMOVE_PACKAGES|
  50. APT::Upgrade::FORBID_INSTALL_NEW_PACKAGES);
  51. }
  52. /*}}}*/
  53. // DoSafeUpgrade - Upgrade all packages with install but not remove /*{{{*/
  54. bool DoUpgradeWithAllowNewPackages(CommandLine &CmdL)
  55. {
  56. return UpgradeHelper(CmdL, APT::Upgrade::FORBID_REMOVE_PACKAGES);
  57. }
  58. /*}}}*/