- Fixes to Selectable doing staus manipulation on non-USER level.
authorMichael Andres <ma@suse.de>
Fri, 15 Aug 2008 13:39:10 +0000 (13:39 +0000)
committerMichael Andres <ma@suse.de>
Fri, 15 Aug 2008 13:39:10 +0000 (13:39 +0000)
package/libzypp.changes
zypp/ui/Selectable.cc
zypp/ui/Selectable.h
zypp/ui/SelectableImpl.cc
zypp/ui/SelectableImpl.h

index 7f8db7a05c00f692fabdd54ae43d9a12952ac783..f478b7ef9acbbf1eebde6eda6d85588b05aebc6e 100644 (file)
@@ -1,3 +1,9 @@
+-------------------------------------------------------------------
+Fri Aug 15 15:30:32 CEST 2008 - ma@suse.de
+
+- Fixes to Selectable doing staus manipulation on non-USER level.
+- revision 10873
+
 -------------------------------------------------------------------
 Fri Aug 15 14:23:02 CEST 2008 - ma@suse.de
 
index a244ad62026eb43b80902870421cebc9fe99ad4d..2588faae744a20d312e5ece563a071808ea6be2a 100644 (file)
@@ -73,8 +73,11 @@ namespace zypp
     PoolItem Selectable::candidateObj() const
     { return _pimpl->candidateObj(); }
 
-    PoolItem Selectable::setCandidate( ResObject::constPtr byUser_r )
-    { return _pimpl->setCandidate( byUser_r ); }
+    PoolItem Selectable::setCandidate( const PoolItem & newCandidate_r, ResStatus::TransactByValue causer_r )
+    { return _pimpl->setCandidate( newCandidate_r, causer_r ); }
+
+    PoolItem Selectable::setCandidate( ResObject::constPtr newCandidate_r, ResStatus::TransactByValue causer_r )
+    { return _pimpl->setCandidate( PoolItem( newCandidate_r ), causer_r ); }
 
     PoolItem Selectable::theObj() const
     { return _pimpl->theObj(); }
index d4e3befada729a0866aa37ac0f7b4c0e003029fe..7cf215b9df3110b596346360470696b20f8e7d1d 100644 (file)
@@ -128,8 +128,13 @@ namespace zypp
        * \return The new candidate, or NULL if choice was invalid
        * (NULL or not among availableObjs). An invalid choice
        * selects the default candidate.
+       * In case the causer is not \c ResStatus::USER the operation
+       * may also fail if there are insufficient permissions to change
+       * a transacting candidate.
        */
-      PoolItem setCandidate( ResObject::constPtr byUser_r );
+      PoolItem setCandidate( const PoolItem & newCandidate_r, ResStatus::TransactByValue causer_r = ResStatus::USER );
+      /** \overload */
+      PoolItem setCandidate( ResObject::constPtr newCandidate_r, ResStatus::TransactByValue causer_r = ResStatus::USER );
 
       /** Best among all objects. */
       PoolItem theObj() const;
index 78e2ba47152f3a2d4d0b23d3270eda3b76529a75..58377ad5829e4cef4ecba9b3cab7007c10e9d701 100644 (file)
@@ -283,35 +283,44 @@ namespace zypp
       return false;
     }
 
-    PoolItem Selectable::Impl::setCandidate( ResObject::constPtr byUser_r )
+    PoolItem Selectable::Impl::setCandidate( const PoolItem & newCandidate_r, ResStatus::TransactByValue causer_r )
     {
-      _candidate = PoolItem();
+      PoolItem newCandidate;
 
-      if ( byUser_r ) // must be in available list
+      if ( newCandidate_r ) // must be in available list
+      {
+        for_( it, availableBegin(), availableEnd() )
         {
-          for ( available_const_iterator it = availableBegin();
-                it != availableEnd(); ++it )
-            {
-              if ( it->resolvable() == byUser_r )
-                {
-                  _candidate = *it;
-                  break;
-                }
-            }
+          if ( *it == newCandidate_r )
+          {
+            newCandidate = *it;
+            break;
+          }
         }
+      }
 
-      if ( _candidate )
+      if ( newCandidate )
+      {
+        PoolItem trans( transactingCandidate() );
+        if ( trans && trans != newCandidate )
         {
-          PoolItem trans( transactingCandidate() );
-          if ( trans && trans != _candidate )
-            {
-              // adjust transact to the new cancidate
-              trans.status().setTransact( false, ResStatus::USER );
-              _candidate.status().setTransact( true, ResStatus::USER );
-            }
+          // adjust transact to the new cancidate
+          if (    trans.status().maySetTransact( false, causer_r )
+               && newCandidate.status().maySetTransact( true, causer_r ) )
+          {
+            trans.status().setTransact( false, causer_r );
+            newCandidate.status().setTransact( true, causer_r );
+          }
+          else
+          {
+            // No permission to change a transacting candidate.
+            // Leave _candidate untouched and return NULL.
+            return PoolItem();
+          }
         }
+      }
 
-      return _candidate;
+      return _candidate = newCandidate;
     }
 
     ResStatus::TransactByValue Selectable::Impl::modifiedBy() const
index 507c242626d1bc0888cc0dec30cd7ece3f83b196..9620b107eeee3cf59794a0d48597a3c5055f06c7 100644 (file)
@@ -68,7 +68,6 @@ namespace zypp
           else
             _availableItems.insert( *it );
         }
-        setCandidate( NULL );
       }
 
     public:
@@ -117,7 +116,7 @@ namespace zypp
        * \return The new userCandidate or NULL if choice was invalid
        * (not among availableObjs).
       */
-      PoolItem setCandidate( ResObject::constPtr byUser_r );
+      PoolItem setCandidate( const PoolItem & newCandidate_r, ResStatus::TransactByValue causer_r );
 
       /** Best among all objects. */
       PoolItem theObj() const