private-upgrade.cc 2.1 KB

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