Просмотр исходного кода

make ResolveByKeep() more clever and hold back packages that would go into a broken policy state by the upgrade

Michael Vogt лет назад: 15
Родитель
Сommit
953b348cb0
4 измененных файлов с 570 добавлено и 410 удалено
  1. 34 6
      apt-pkg/algorithms.cc
  2. 3 0
      apt-pkg/algorithms.h
  3. 513 404
      po/apt-all.pot
  4. 20 0
      test/integration/test-resolve-by-keep-new-recommends

+ 34 - 6
apt-pkg/algorithms.cc

@@ -1176,6 +1176,31 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
    return true;
    return true;
 }
 }
 									/*}}}*/
 									/*}}}*/
+
+// ProblemResolver::BreaksInstOrPolicy - Check if the given pkg is broken/*{{{*/
+// ---------------------------------------------------------------------
+/* This checks if the given package is broken either by a hard dependency
+   (InstBroken()) or by introducing a new policy breakage e.g. new
+   unsatisfied recommends for a package that was in "policy-good" state
+
+   Note that this is not perfect as it will ignore further breakage
+   for already broken policy (recommends)
+*/
+bool pkgProblemResolver::InstOrNewPolicyBroken(pkgCache::PkgIterator I)
+{
+   
+   // a broken install is always a problem
+   if (Cache[I].InstBroken() == true)
+      return true;
+
+   // a newly broken policy (recommends/suggests) is a problem
+   if (Cache[I].NowPolicyBroken() == false &&
+       Cache[I].InstPolicyBroken() == true)
+      return true;
+       
+   return false;
+}
+
 // ProblemResolver::ResolveByKeep - Resolve problems using keep		/*{{{*/
 // ProblemResolver::ResolveByKeep - Resolve problems using keep		/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* This is the work horse of the soft upgrade routine. It is very gental 
 /* This is the work horse of the soft upgrade routine. It is very gental 
@@ -1220,9 +1245,12 @@ bool pkgProblemResolver::ResolveByKeep()
    {
    {
       pkgCache::PkgIterator I(Cache,*K);
       pkgCache::PkgIterator I(Cache,*K);
 
 
-      if (Cache[I].InstallVer == 0 || Cache[I].InstBroken() == false)
+      if (Cache[I].InstallVer == 0)
 	 continue;
 	 continue;
 
 
+      if (InstOrNewPolicyBroken(I) == false)
+         continue;
+
       /* Keep the package. If this works then great, otherwise we have
       /* Keep the package. If this works then great, otherwise we have
        	 to be significantly more agressive and manipulate its dependencies */
        	 to be significantly more agressive and manipulate its dependencies */
       if ((Flags[I->ID] & Protected) == 0)
       if ((Flags[I->ID] & Protected) == 0)
@@ -1230,7 +1258,7 @@ bool pkgProblemResolver::ResolveByKeep()
 	 if (Debug == true)
 	 if (Debug == true)
 	    clog << "Keeping package " << I.FullName(false) << endl;
 	    clog << "Keeping package " << I.FullName(false) << endl;
 	 Cache.MarkKeep(I, false, false);
 	 Cache.MarkKeep(I, false, false);
-	 if (Cache[I].InstBroken() == false)
+	 if (InstOrNewPolicyBroken(I) == false)
 	 {
 	 {
 	    K = PList - 1;
 	    K = PList - 1;
 	    continue;
 	    continue;
@@ -1280,11 +1308,11 @@ bool pkgProblemResolver::ResolveByKeep()
 		  Cache.MarkKeep(Pkg, false, false);
 		  Cache.MarkKeep(Pkg, false, false);
 	       }
 	       }
 	       
 	       
-	       if (Cache[I].InstBroken() == false)
+	       if (InstOrNewPolicyBroken(I) == false)
 		  break;
 		  break;
 	    }
 	    }
 	    
 	    
-	    if (Cache[I].InstBroken() == false)
+	    if (InstOrNewPolicyBroken(I) == false)
 	       break;
 	       break;
 
 
 	    if (Start == End)
 	    if (Start == End)
@@ -1292,11 +1320,11 @@ bool pkgProblemResolver::ResolveByKeep()
 	    Start++;
 	    Start++;
 	 }
 	 }
 	      
 	      
-	 if (Cache[I].InstBroken() == false)
+	 if (InstOrNewPolicyBroken(I) == false)
 	    break;
 	    break;
       }
       }
 
 
-      if (Cache[I].InstBroken() == true)
+      if (InstOrNewPolicyBroken(I) == true)
 	 continue;
 	 continue;
       
       
       // Restart again.
       // Restart again.

+ 3 - 0
apt-pkg/algorithms.h

@@ -106,6 +106,9 @@ class pkgProblemResolver						/*{{{*/
    void MakeScores();
    void MakeScores();
    bool DoUpgrade(pkgCache::PkgIterator Pkg);
    bool DoUpgrade(pkgCache::PkgIterator Pkg);
    
    
+   protected:
+   bool InstOrNewPolicyBroken(pkgCache::PkgIterator Pkg);
+
    public:
    public:
    
    
    inline void Protect(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= Protected; Cache.MarkProtected(Pkg);};
    inline void Protect(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= Protected; Cache.MarkProtected(Pkg);};

Разница между файлами не показана из-за своего большого размера
+ 513 - 404
po/apt-all.pot


+ 20 - 0
test/integration/test-resolve-by-keep-new-recommends

@@ -0,0 +1,20 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+setupenvironment
+configarchitecture "i386"
+
+insertinstalledpackage 'foo' 'i386' '1.0'
+insertpackage 'unstable' 'foo' 'i386' '2.0' 'Recommends: bar'
+
+setupaptarchive
+
+UPGRADE_KEEP="Reading package lists...
+Building dependency tree...
+The following packages have been kept back:
+  foo
+0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded."
+testequal "$UPGRADE_KEEP" aptget upgrade -s
+