You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

67 lines
2.1 KiB

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