private-upgrade.cc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false)
  18. return false;
  19. if(!DoCacheManipulationFromCommandLine(CmdL, Cache, UpgradeFlags))
  20. return false;
  21. return InstallPackages(Cache,true);
  22. }
  23. // DoDistUpgrade - Automatic smart upgrader /*{{{*/
  24. // ---------------------------------------------------------------------
  25. /* Intelligent upgrader that will install and remove packages at will */
  26. bool DoDistUpgrade(CommandLine &CmdL)
  27. {
  28. return UpgradeHelper(CmdL, APT::Upgrade::ALLOW_EVERYTHING);
  29. }
  30. /*}}}*/
  31. bool DoUpgrade(CommandLine &CmdL) /*{{{*/
  32. {
  33. if (_config->FindB("APT::Get::Upgrade-Allow-New", false) == true)
  34. return DoUpgradeWithAllowNewPackages(CmdL);
  35. else
  36. return DoUpgradeNoNewPackages(CmdL);
  37. }
  38. /*}}}*/
  39. // DoUpgradeNoNewPackages - Upgrade all packages /*{{{*/
  40. // ---------------------------------------------------------------------
  41. /* Upgrade all packages without installing new packages or erasing old
  42. packages */
  43. bool DoUpgradeNoNewPackages(CommandLine &CmdL)
  44. {
  45. // Do the upgrade
  46. return UpgradeHelper(CmdL,
  47. APT::Upgrade::FORBID_REMOVE_PACKAGES|
  48. APT::Upgrade::FORBID_INSTALL_NEW_PACKAGES);
  49. }
  50. /*}}}*/
  51. // DoSafeUpgrade - Upgrade all packages with install but not remove /*{{{*/
  52. bool DoUpgradeWithAllowNewPackages(CommandLine &CmdL)
  53. {
  54. return UpgradeHelper(CmdL, APT::Upgrade::FORBID_REMOVE_PACKAGES);
  55. }
  56. /*}}}*/