private-upgrade.cc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. // DoUpgradeNoNewPackages - Upgrade all packages /*{{{*/
  38. // ---------------------------------------------------------------------
  39. /* Upgrade all packages without installing new packages or erasing old
  40. packages */
  41. bool DoUpgradeNoNewPackages(CommandLine &CmdL)
  42. {
  43. // Do the upgrade
  44. return UpgradeHelper(CmdL,
  45. APT::Upgrade::FORBID_REMOVE_PACKAGES|
  46. APT::Upgrade::FORBID_INSTALL_NEW_PACKAGES);
  47. }
  48. /*}}}*/
  49. // DoSafeUpgrade - Upgrade all packages with install but not remove /*{{{*/
  50. bool DoUpgradeWithAllowNewPackages(CommandLine &CmdL)
  51. {
  52. return UpgradeHelper(CmdL, APT::Upgrade::FORBID_REMOVE_PACKAGES);
  53. }
  54. /*}}}*/