private-upgrade.cc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. c0out << _("Calculating upgrade... ") << std::flush;
  20. if (APT::Upgrade::Upgrade(Cache, UpgradeFlags) == false)
  21. {
  22. c0out << _("Failed") << std::endl;
  23. ShowBroken(c1out,Cache,false);
  24. return _error->Error(_("Internal error, Upgrade broke stuff"));
  25. }
  26. c0out << _("Done") << std::endl;
  27. // parse additional cmdline pkg manipulation switches
  28. if(!DoCacheManipulationFromCommandLine(CmdL, Cache))
  29. return false;
  30. return InstallPackages(Cache,true);
  31. }
  32. // DoDistUpgrade - Automatic smart upgrader /*{{{*/
  33. // ---------------------------------------------------------------------
  34. /* Intelligent upgrader that will install and remove packages at will */
  35. bool DoDistUpgrade(CommandLine &CmdL)
  36. {
  37. return UpgradeHelper(CmdL, 0);
  38. }
  39. /*}}}*/
  40. bool DoUpgrade(CommandLine &CmdL) /*{{{*/
  41. {
  42. if (_config->FindB("APT::Get::Upgrade-Allow-New", false) == true)
  43. return DoUpgradeWithAllowNewPackages(CmdL);
  44. else
  45. return DoUpgradeNoNewPackages(CmdL);
  46. }
  47. /*}}}*/
  48. // DoUpgradeNoNewPackages - Upgrade all packages /*{{{*/
  49. // ---------------------------------------------------------------------
  50. /* Upgrade all packages without installing new packages or erasing old
  51. packages */
  52. bool DoUpgradeNoNewPackages(CommandLine &CmdL)
  53. {
  54. // Do the upgrade
  55. return UpgradeHelper(CmdL,
  56. APT::Upgrade::FORBID_REMOVE_PACKAGES|
  57. APT::Upgrade::FORBID_INSTALL_NEW_PACKAGES);
  58. }
  59. /*}}}*/
  60. // DoSafeUpgrade - Upgrade all packages with install but not remove /*{{{*/
  61. bool DoUpgradeWithAllowNewPackages(CommandLine &CmdL)
  62. {
  63. return UpgradeHelper(CmdL, APT::Upgrade::FORBID_REMOVE_PACKAGES);
  64. }
  65. /*}}}*/