Selectable: Consider allowed arch/noarch changes when comuting candiadates.
authorMichael Andres <ma@suse.de>
Fri, 6 Nov 2009 21:15:27 +0000 (22:15 +0100)
committerMichael Andres <ma@suse.de>
Fri, 6 Nov 2009 21:15:27 +0000 (22:15 +0100)
tests/data/TCSelectable/RepoHIGH.xml
tests/data/TCSelectable/RepoMID.xml
tests/data/TCSelectable/solver-system.xml
tests/zypp/Selectable_test.cc
zypp/ui/SelectableImpl.h
zypp/ui/SelectableTraits.h

index 6cfccd6..924fff9 100644 (file)
 </package>
 <package>
        <name>candidate</name>
-       <vendor>unkown</vendor>
+       <vendor>unknown</vendor>
+       <history><update>
+               <arch>i586</arch>
+               <version>4</version>
+               <release>1</release>
+       </update></history>
+</package>
+
+<package>
+       <name>candidatenoarch</name>
+       <vendor>unknown</vendor>
+       <history><update>
+               <arch>noarch</arch>
+               <version>5</version>
+               <release>1</release>
+       </update></history>
+</package>
+<package>
+       <name>candidatenoarch</name>
+       <vendor>unknown</vendor>
+       <history><update>
+               <arch>x86_64</arch>
+               <version>4</version>
+               <release>1</release>
+       </update></history>
+</package>
+<package>
+       <name>candidatenoarch</name>
+       <vendor>unknown</vendor>
        <history><update>
                <arch>i586</arch>
                <version>4</version>
                <release>1</release>
        </update></history>
 </package>
+<package>
+       <name>candidatenoarch</name>
+       <vendor>unknown</vendor>
+       <history><update>
+               <arch>noarch</arch>
+               <version>4</version>
+               <release>1</release>
+       </update></history>
+</package>
 </subchannel></channel>
index f1b6d1d..3537414 100644 (file)
                <release>1</release>
        </update></history>
 </package>
+
+<package>
+       <name>candidatenoarch</name>
+       <vendor>openSUSE</vendor>
+       <history><update>
+               <arch>noarch</arch>
+               <version>0</version>
+               <release>2</release>
+       </update></history>
+</package>
+<package>
+       <name>candidatenoarch</name>
+       <vendor>openSUSE</vendor>
+       <history><update>
+               <arch>x86_64</arch>
+               <version>0</version>
+               <release>1</release>
+       </update></history>
+</package>
+<package>
+       <name>candidatenoarch</name>
+       <vendor>openSUSE</vendor>
+       <history><update>
+               <arch>i586</arch>
+               <version>0</version>
+               <release>1</release>
+       </update></history>
+</package>
+<package>
+       <name>candidatenoarch</name>
+       <vendor>openSUSE</vendor>
+       <history><update>
+               <arch>noarch</arch>
+               <version>0</version>
+               <release>1</release>
+       </update></history>
+</package>
 </subchannel></channel>
index 4fe7341..7e1a908 100644 (file)
@@ -8,4 +8,13 @@
                <release>1</release>
        </update></history>
 </package>
+<package>
+       <name>candidatenoarch</name>
+       <vendor>unknown</vendor>
+       <history><update>
+               <arch>i586</arch>
+               <version>1</version>
+               <release>1</release>
+       </update></history>
+</package>
 </subchannel></channel>
index a878f42..8d49f80 100644 (file)
@@ -29,7 +29,7 @@ BOOST_AUTO_TEST_CASE(candiadate)
   //   U__s_(2)candidate-4-1.x86_64(RepoHIGH)(unkown)
   //   U__s_(3)candidate-4-1.i586(RepoHIGH)(unkown)
   //   U__s_(6)candidate-0-1.x86_64(RepoMID)(SUSE)
-  //   U__s_(7)candidate-0-1.i586(RepoMID)(SUSE) <- candidate (highrst prio matching arch and vendor)
+  //   U__s_(7)candidate-0-1.i586(RepoMID)(SUSE) <- candidate (highest prio matching arch and vendor)
   //   U__s_(4)candidate-2-1.x86_64(RepoLOW)(openSUSE)
   //   U__s_(5)candidate-2-1.i586(RepoLOW)(openSUSE)
   // }
@@ -39,3 +39,28 @@ BOOST_AUTO_TEST_CASE(candiadate)
   // no updateCandidate due to low version
   BOOST_CHECK_EQUAL( s->updateCandidateObj(), PoolItem() );
 }
+
+BOOST_AUTO_TEST_CASE(candiadatenoarch)
+{
+  ResPoolProxy poolProxy( test.poolProxy() );
+  ui::Selectable::Ptr s( poolProxy.lookup( ResKind::package, "candidatenoarch" ) );
+/*[package]candidatenoarch: S_KeepInstalled
+   (I 1) {
+   I__s_(17)candidatenoarch-1-1.i586(@System)
+}  (A 8) {
+ C U__s_(4)candidatenoarch-5-1.noarch(RepoHIGH) <- candidate (arch/noarch change)
+   U__s_(5)candidatenoarch-4-1.x86_64(RepoHIGH)
+   U__s_(6)candidatenoarch-4-1.i586(RepoHIGH)
+   U__s_(7)candidatenoarch-4-1.noarch(RepoHIGH)
+   U__s_(12)candidatenoarch-0-2.noarch(RepoMID)
+   U__s_(13)candidatenoarch-0-1.x86_64(RepoMID)
+   U__s_(14)candidatenoarch-0-1.i586(RepoMID)
+   U__s_(15)candidatenoarch-0-1.noarch(RepoMID)
+}  */
+  std::cout << dump(s) << endl;
+  BOOST_CHECK_EQUAL( s->candidateObj()->repoInfo().alias(), "RepoHIGH" );
+  BOOST_CHECK_EQUAL( s->candidateObj()->edition(), Edition("5-1") );
+  BOOST_CHECK_EQUAL( s->candidateObj()->arch(), Arch_noarch );
+  // no updateCandidate due to low version
+  BOOST_CHECK_EQUAL( s->updateCandidateObj(), s->candidateObj() );
+}
index 7d211b4..86f1ecc 100644 (file)
@@ -154,8 +154,9 @@ namespace zypp
                  || VendorAttr::instance().equivalent( _defaultCandidate->vendor(), installed->vendor() ) ) )
           return PoolItem();
 
-        // check arch change
-        if ( _defaultCandidate->arch() != installed->arch() )
+        // check arch change (arch noarch changes are allowed)
+        if ( _defaultCandidate->arch() != installed->arch()
+           && ! ( _defaultCandidate->arch() == Arch_noarch || installed->arch() == Arch_noarch ) )
           return PoolItem();
 
         // check greater edition
@@ -280,11 +281,12 @@ namespace zypp
           for ( installed_const_iterator iit = installedBegin();
                 iit != installedEnd(); ++iit )
           {
-            PoolItem sameArch; // in case there's no same vendor at least stay with same arch
+            PoolItem sameArch; // in case there's no same vendor at least stay with same arch.
             for ( available_const_iterator it = availableBegin();
                   it != availableEnd(); ++it )
             {
-              if ( (*iit)->arch() == (*it)->arch() )
+              // 'same arch' includes allowed changes to/from noarch.
+              if ( (*iit)->arch() == (*it)->arch() || (*iit)->arch() == Arch_noarch || (*it)->arch() == Arch_noarch )
               {
                 if ( ! solver_allowVendorChange )
                 {
@@ -345,14 +347,43 @@ namespace zypp
     inline std::ostream & dumpOn( std::ostream & str, const Selectable::Impl & obj )
     {
       str << '[' << obj.kind() << ']' << obj.name() << ": " << obj.status() << endl;
-      if ( obj.candidateObj() )
-        str << "(C " << obj.candidateObj() << ")" << endl;
-      else
-        str << "(C NONE )" << endl;
-      dumpRange( str << "  (I " << obj.installedSize() << ") ", obj.installedBegin(), obj.installedEnd() );
+
       if ( obj.installedEmpty() )
-        str << endl << " ";
-      dumpRange( str << " (A " << obj.availableSize() << ") ", obj.availableBegin(), obj.availableEnd() ) << endl;
+        str << "   (I 0) {}" << endl << "   ";
+      else
+      {
+        str << "   (I " << obj.installedSize() << ") {" << endl;
+        for_( it, obj.installedBegin(), obj.installedEnd() )
+        {
+          str << "   " << *it << endl;
+        }
+        str << "}  ";
+      }
+
+      if ( obj.availableEmpty() )
+      {
+        str << "(A 0) {}";
+      }
+      else
+      {
+        PoolItem cand( obj.candidateObj() );
+        PoolItem up( obj.updateCandidateObj() );
+        str << "(A " << obj.availableSize() << ") {" << endl;
+        for_( it, obj.availableBegin(), obj.availableEnd() )
+        {
+          char t = ' ';
+          if ( *it == cand )
+          {
+            t = *it == up ? 'C' : 'c';
+          }
+          else if ( *it == up )
+          {
+            t = 'u';
+          }
+          str << " " << t << " " << *it << endl;
+        }
+        str << "}  ";
+      }
 
       return str;
     }
index b994bf7..298994f 100644 (file)
@@ -34,7 +34,7 @@ namespace zypp
     {
       /** Oder on AvailableItemSet.
        * \li repository priority
-       * \li best Arch
+       * \li best Arch (arch/noarch changes are ok)
        * \li best Edition
        * \li ResObject::constPtr as fallback.
       */
@@ -47,21 +47,30 @@ namespace zypp
         //
         bool operator()( const PoolItem & lhs, const PoolItem & rhs ) const
         {
-          unsigned lprio = lhs->satSolvable().repository().info().priority();
-          unsigned rprio = rhs->satSolvable().repository().info().priority();
+          int lprio = lhs->satSolvable().repository().satInternalPriority();
+          int rprio = rhs->satSolvable().repository().satInternalPriority();
           if ( lprio != rprio )
-            return( lprio < rprio ); // lower value meands higher priority :(
-          int res = lhs->arch().compare( rhs->arch() );
-          if ( res )
-            return res > 0;
-          res = lhs->edition().compare( rhs->edition() );
+            return( lprio > rprio );
+
+          // arch/noarch changes are ok.
+          if ( lhs->arch() != Arch_noarch && rhs->arch() != Arch_noarch )
+          {
+            int res = lhs->arch().compare( rhs->arch() );
+            if ( res )
+              return res > 0;
+          }
+
+          int res = lhs->edition().compare( rhs->edition() );
           if ( res )
             return res > 0;
 
-          // no more criteria, still equal:
-          // use the ResObject::constPtr (the poiner value)
-          // (here it's arbitrary whether < or > )
-          return lhs.resolvable() < rhs.resolvable();
+          lprio = lhs->satSolvable().repository().satInternalSubPriority();
+          rprio = rhs->satSolvable().repository().satInternalSubPriority();
+          if ( lprio != rprio )
+            return( lprio > rprio );
+
+          // no more criteria, still equal: sort by id
+          return lhs.satSolvable().id() < rhs.satSolvable().id();
         }
       };
 
@@ -90,10 +99,8 @@ namespace zypp
           if ( ldate != rdate )
             return( ldate > rdate );
 
-          // no more criteria, still equal:
-          // use the ResObject::constPtr (the poiner value)
-          // (here it's arbitrary whether < or > )
-          return lhs.resolvable() < rhs.resolvable();
+          // no more criteria, still equal: sort by id
+          return lhs.satSolvable().id() < rhs.satSolvable().id();
         }
       };