]> git.saurik.com Git - apt.git/commitdiff
improve the API for Upgrade()
authorMichael Vogt <mvo@debian.org>
Wed, 18 Sep 2013 15:55:44 +0000 (17:55 +0200)
committerMichael Vogt <mvo@debian.org>
Wed, 18 Sep 2013 15:55:44 +0000 (17:55 +0200)
apt-pkg/algorithms.cc
apt-pkg/algorithms.h
apt-private/private-upgrade.cc

index 69d4acd83d621a8776d4124940f8fb8b1d697d56..68531f3cac8fdff770ab79eed59e76bae61e128f 100644 (file)
@@ -422,12 +422,8 @@ bool pkgDistUpgrade(pkgDepCache &Cache)
    return Fix.Resolve();
 }
                                                                        /*}}}*/
-// AllUpgrade - Upgrade as many packages as possible                   /*{{{*/
-// ---------------------------------------------------------------------
-/* Right now the system must be consistent before this can be called.
-   It also will not change packages marked for install, it only tries
-   to install packages not marked for install */
-bool pkgAllUpgrade(pkgDepCache &Cache)
+// AllUpgradeNoNewPackages - Upgrade but no removals or new pkgs        /*{{{*/
+bool pkgAllUpgradeNoNewPackages(pkgDepCache &Cache)
 {
    std::string const solver = _config->Find("APT::Solver", "internal");
    if (solver != "internal") {
@@ -459,13 +455,13 @@ bool pkgAllUpgrade(pkgDepCache &Cache)
    return Fix.ResolveByKeep();
 }
                                                                        /*}}}*/
-// AllUpgradeNoDelete - Upgrade without removing packages              /*{{{*/
+// AllUpgradeWithNewInstalls - Upgrade + install new packages as needed /*{{{*/
 // ---------------------------------------------------------------------
 /* Right now the system must be consistent before this can be called.
  * Upgrade as much as possible without deleting anything (useful for
  * stable systems)
  */
-bool pkgAllUpgradeNoDelete(pkgDepCache &Cache)
+bool pkgAllUpgradeWithNewPackages(pkgDepCache &Cache)
 {
    pkgDepCache::ActionGroup group(Cache);
 
@@ -502,6 +498,16 @@ bool pkgAllUpgradeNoDelete(pkgDepCache &Cache)
    return Fix.ResolveByKeep();
 }
                                                                        /*}}}*/
+// AllUpgrade - Upgrade as many packages as possible                   /*{{{*/
+// ---------------------------------------------------------------------
+/* Right now the system must be consistent before this can be called.
+   It also will not change packages marked for install, it only tries
+   to install packages not marked for install */
+bool pkgAllUpgrade(pkgDepCache &Cache)
+{
+   return pkgAllUpgradeNoNewPackages(Cache);
+}
+                                                                       /*}}}*/
 // MinimizeUpgrade - Minimizes the set of packages to be upgraded      /*{{{*/
 // ---------------------------------------------------------------------
 /* This simply goes over the entire set of packages and tries to keep 
@@ -547,6 +553,22 @@ bool pkgMinimizeUpgrade(pkgDepCache &Cache)
    return true;
 }
                                                                        /*}}}*/
+// APT::Upgrade::Upgrade - Upgrade using a specific strategy           /*{{{*/
+bool APT::Upgrade::Upgrade(pkgDepCache &Cache, APT::Upgrade::UpgradeMode mode)
+{
+   switch(mode) {
+      case APT::Upgrade::NO_INSTALL_OR_REMOVE:
+         return pkgAllUpgradeNoNewPackages(Cache);
+      case APT::Upgrade::ALLOW_NEW_INSTALLS:
+         return pkgAllUpgradeWithNewPackages(Cache);
+      case APT::Upgrade::ALLOW_REMOVAL_AND_NEW_INSTALLS:
+         return pkgDistUpgrade(Cache);
+      default:
+         _error->Error("pkgAllUpgrade called with unknwon mode %i", mode);
+   }
+   return false;
+}
+                                                                       /*}}}*/
 // ProblemResolver::pkgProblemResolver - Constructor                   /*{{{*/
 // ---------------------------------------------------------------------
 /* */
index a499db8ba3fad782109890ae7be3030f73b0bb05..9ff84e3ffd4781031e0c958085431eef122344e0 100644 (file)
@@ -45,6 +45,15 @@ using std::ostream;
 
 class pkgAcquireStatus;
 
+namespace APT {
+   namespace Upgrade {
+      enum UpgradeMode {NO_INSTALL_OR_REMOVE,
+                        ALLOW_NEW_INSTALLS,
+                        ALLOW_REMOVAL_AND_NEW_INSTALLS};
+      bool Upgrade(pkgDepCache &Cache, UpgradeMode mode);
+   }
+}
+
 class pkgSimulate : public pkgPackageManager                           /*{{{*/
 {
    protected:
@@ -85,6 +94,7 @@ private:
                                                                        /*}}}*/
 class pkgProblemResolver                                               /*{{{*/
 {
+ private:
    /** \brief dpointer placeholder (for later in case we need it) */
    void *d;
 
@@ -146,8 +156,6 @@ bool pkgFixBroken(pkgDepCache &Cache);
 
 bool pkgAllUpgrade(pkgDepCache &Cache);
 
-bool pkgAllUpgradeNoDelete(pkgDepCache &Cache);
-
 bool pkgMinimizeUpgrade(pkgDepCache &Cache);
 
 void pkgPrioSortList(pkgCache &Cache,pkgCache::Version **List);
index 9a5286b57fc26e2b88678ed4a3492a7ae09ecbde..6ea7c19d6ba29f33b1106b92f9af2235059baadb 100644 (file)
@@ -39,7 +39,7 @@ bool DoUpgradeWithAllowNewPackages(CommandLine &CmdL)
       return false;
 
    // Do the upgrade
-   if (pkgAllUpgradeNoDelete(Cache) == false)
+   if (APT::Upgrade::Upgrade(Cache, APT::Upgrade::ALLOW_NEW_INSTALLS) == false)
    {
       ShowBroken(c1out,Cache,false);
       return _error->Error(_("Internal error, AllUpgrade broke stuff"));