added solutions for ResolveQueue
authorStefan Schubert <schubi@suse.de>
Thu, 15 May 2008 12:15:53 +0000 (12:15 +0000)
committerStefan Schubert <schubi@suse.de>
Thu, 15 May 2008 12:15:53 +0000 (12:15 +0000)
zypp/solver/detail/ProblemSolutionCombi.cc
zypp/solver/detail/ProblemSolutionCombi.h
zypp/solver/detail/Resolver.cc
zypp/solver/detail/Resolver.h
zypp/solver/detail/SATResolver.cc
zypp/solver/detail/SolutionAction.cc
zypp/solver/detail/SolutionAction.h
zypp/solver/detail/SolverQueueItem.h
zypp/solver/detail/SolverQueueItemDelete.cc
zypp/solver/detail/SolverQueueItemInstall.cc

index 3273fcb..11b5ce8 100644 (file)
@@ -65,6 +65,12 @@ void ProblemSolutionCombi::addSingleAction( PoolItem item, const TransactionKind
     actNumber++;
 }
 
+void ProblemSolutionCombi::addSingleAction( SolverQueueItem_Ptr item, const TransactionKind action)
+{
+    addAction (new TransactionSolutionAction(item, action));
+    actNumber++;
+}
+
 void ProblemSolutionCombi::addDescription( const std::string description)
 {
     if ( _description.size() == 0
index a996411..96be552 100644 (file)
@@ -25,6 +25,7 @@
 #include <string>
 #include "zypp/ProblemSolution.h"
 #include "zypp/solver/detail/Types.h"
+#include "zypp/solver/detail/SolverQueueItem.h"
 
 /////////////////////////////////////////////////////////////////////////
 namespace zypp
@@ -58,9 +59,14 @@ namespace zypp
            void addSingleAction( PoolItem item, const TransactionKind action);
 
            /**
-            * Add a single action of an capability
+            * Add a single action of a capability
             */
-           void addSingleAction( Capability capability, const TransactionKind action);     
+           void addSingleAction( Capability capability, const TransactionKind action);
+
+           /**
+            * Add a single action of a SolverQueueItem
+            */
+           void addSingleAction( SolverQueueItem_Ptr item, const TransactionKind action);          
 
            /**
             * returns the number of actions
index caa3fc5..5da3907 100644 (file)
@@ -69,6 +69,7 @@ Resolver::Resolver (const ResPool & pool)
     : _pool(pool)
     , _satResolver(NULL)
     , _poolchanged(_pool.serial() )
+    , _testing(false)
     , _forceResolve(false)
     , _upgradeMode(false)
     , _verifying(false)
@@ -133,6 +134,40 @@ Resolver::removeExtraConflict (const Capability & capability)
     _extra_conflicts.erase (capability);
 }
 
+
+void Resolver::removeQueueItem (const SolverQueueItem_Ptr item)
+{
+    bool found = false;
+    for (SolverQueueItemList::const_iterator iter = _added_queue_items.begin();
+        iter != _added_queue_items.end(); iter++) {
+       if (*iter == item) {
+           _added_queue_items.remove(*iter);
+           found = true;
+           break;
+       }
+    }
+    if (!found) {
+       _removed_queue_items.push_back (item);
+       _removed_queue_items.unique ();
+    }
+}
+void Resolver::addQueueItem (const SolverQueueItem_Ptr item)
+{
+    bool found = false;
+    for (SolverQueueItemList::const_iterator iter = _removed_queue_items.begin();
+        iter != _removed_queue_items.end(); iter++) {
+       if (*iter == item) {
+           _removed_queue_items.remove(*iter);
+           found = true;
+           break;
+       }
+    }
+    if (!found) {
+       _added_queue_items.push_back (item);
+       _added_queue_items.unique ();
+    }    
+}
+
 void
 Resolver::addWeak (const PoolItem item)
 {
@@ -202,6 +237,10 @@ Resolver::undo(void)
     //  Regard dependencies of the item weak onl
     _addWeak.clear();
 
+    // Additional QueueItems which has to be regarded by the solver
+    _removed_queue_items.clear();
+    _added_queue_items.clear();    
+
     return;
 }
 
@@ -262,6 +301,34 @@ bool
 Resolver::resolveQueue(solver::detail::SolverQueueItemList & queue)
 {
     solverInit();
+    
+    // add/remove additional SolverQueueItems
+    for (SolverQueueItemList::const_iterator iter = _removed_queue_items.begin();
+        iter != _removed_queue_items.end(); iter++) {
+       for (SolverQueueItemList::const_iterator iterQueue = queue.begin(); iterQueue != queue.end(); iterQueue++) {
+           if ( (*iterQueue)->cmp(*iter) == 0) {           
+               MIL << "remove from queue" << *iter;
+               queue.remove(*iterQueue);
+               break;
+           }       
+       }
+    }
+
+    for (SolverQueueItemList::const_iterator iter = _added_queue_items.begin();
+        iter != _added_queue_items.end(); iter++) {
+       bool found = false;
+       for (SolverQueueItemList::const_iterator iterQueue = queue.begin(); iterQueue != queue.end(); iterQueue++) {
+           if ( (*iterQueue)->cmp(*iter) == 0) {
+               found = true;
+               break;
+           }       
+       }
+       if (!found) {
+           MIL << "add to queue" << *iter;         
+           queue.push_back(*iter);
+       }
+    }
+    
     return _satResolver->resolveQueue(queue, _addWeak);
 }
 
index b9b6b3a..a965b82 100644 (file)
@@ -91,6 +91,11 @@ class Resolver : public base::ReferenceCounted, private base::NonCopyable {
                                   // no recommended resolvables, language
                                   // packages, hardware packages (modalias)  
 
+    // Additional QueueItems which has to be regarded by the solver
+    // This will be used e.g. by solution actions
+    solver::detail::SolverQueueItemList _removed_queue_items;
+    solver::detail::SolverQueueItemList _added_queue_items;    
+    
     // helpers
     bool doesObsoleteCapability (PoolItem candidate, const Capability & cap);
     bool doesObsoleteItem (PoolItem candidate, PoolItem installed);
@@ -121,7 +126,10 @@ class Resolver : public base::ReferenceCounted, private base::NonCopyable {
     void addExtraRequire (const Capability & capability);
     void removeExtraRequire (const Capability & capability);
     void addExtraConflict (const Capability & capability);
-    void removeExtraConflict (const Capability & capability);    
+    void removeExtraConflict (const Capability & capability);
+
+    void removeQueueItem (const SolverQueueItem_Ptr item);
+    void addQueueItem (const SolverQueueItem_Ptr item);    
 
     const CapabilitySet extraRequires () { return _extra_requires; }
     const CapabilitySet extraConflicts () { return _extra_conflicts; }
@@ -153,7 +161,7 @@ class Resolver : public base::ReferenceCounted, private base::NonCopyable {
 
     bool testing(void) const { return _testing; }
     void setTesting( bool testing ) { _testing = testing; }    
-
+    
 };
 
 ///////////////////////////////////////////////////////////////////
index d98731f..cddfbe2 100644 (file)
@@ -36,6 +36,8 @@
 #include "zypp/solver/detail/SATResolver.h"
 #include "zypp/solver/detail/ProblemSolutionCombi.h"
 #include "zypp/solver/detail/ProblemSolutionIgnore.h"
+#include "zypp/solver/detail/SolverQueueItemInstall.h"
+#include "zypp/solver/detail/SolverQueueItemDelete.h"
 
 extern "C" {
 #include "satsolver/repo_solv.h"
@@ -836,23 +838,6 @@ void SATResolver::doUpdate()
 // helper function
 //----------------------------------------------------------------------------
 
-struct FindPackage : public resfilter::ResObjectFilterFunctor
-{
-    ProblemSolutionCombi *problemSolution;
-    TransactionKind action;
-    FindPackage (ProblemSolutionCombi *p, const TransactionKind act)
-       : problemSolution (p)
-        , action (act)
-    {
-    }
-
-    bool operator()( PoolItem p)
-    {
-       problemSolution->addSingleAction (p, action);
-       return true;
-    }
-};
-
 
 string SATResolver::SATprobleminfoString(Id problem, string &detail, Id &ignoreId)
 {
@@ -1040,12 +1025,11 @@ SATResolver::problems ()
                                break;
                            case SOLVER_INSTALL_SOLVABLE_NAME:
                                {
-                               FindPackage info (problemSolution, KEEP);
-                                IdString ident( what );
-                               invokeOnEach( _pool.byIdentBegin( ident ),
-                                             _pool.byIdentEnd( ident ),
-                                             resfilter::ByUninstalled (),
-                                             functor::functorRef<bool,PoolItem> (info) );
+                               IdString ident( what );                             
+                               SolverQueueItemInstall_Ptr install =
+                                   new SolverQueueItemInstall(_pool, ident.asString(), false );
+                               problemSolution->addSingleAction (install, REMOVE_SOLVE_QUEUE_ITEM);                            
+                               
                                string description = str::form (_("do not install %s"), ident.c_str() );
                                MIL << description << endl;
                                problemSolution->addDescription (description);
@@ -1053,13 +1037,11 @@ SATResolver::problems ()
                                break;
                            case SOLVER_ERASE_SOLVABLE_NAME:
                                {
-                               FindPackage info (problemSolution, KEEP);
                                 IdString ident( what );
-                               invokeOnEach( _pool.byIdentBegin( ident ),
-                                             _pool.byIdentEnd( ident ),
-                                             functor::chain (resfilter::ByInstalled (),                        // ByInstalled
-                                                             resfilter::ByTransact ()),                        // will be deinstalled
-                                             functor::functorRef<bool,PoolItem> (info) );
+                               SolverQueueItemDelete_Ptr del =
+                                   new SolverQueueItemDelete(_pool, ident.asString(), false );
+                               problemSolution->addSingleAction (del, REMOVE_SOLVE_QUEUE_ITEM);                                
+                               
                                string description = str::form (_("keep %s"), ident.c_str());
                                MIL << description << endl;
                                problemSolution->addDescription (description);
@@ -1067,7 +1049,7 @@ SATResolver::problems ()
                                break;
                            case SOLVER_INSTALL_SOLVABLE_PROVIDES:
                                {
-                               problemSolution->addSingleAction (Capability(what), REMOVE_REQUIRE);
+                               problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_REQUIRE);
                                string description = str::form (_("do not ask to install a solvable providing %s"), dep2str(pool, what));
                                MIL << description << endl;
                                problemSolution->addDescription (description);
@@ -1075,7 +1057,7 @@ SATResolver::problems ()
                                break;
                            case SOLVER_ERASE_SOLVABLE_PROVIDES:
                                {
-                               problemSolution->addSingleAction (Capability(what), REMOVE_CONFLICT);                               
+                               problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_CONFLICT);                                 
                                string description = str::form (_("do not ask to delete all solvables providing %s"), dep2str(pool, what));
                                MIL << description << endl;
                                problemSolution->addDescription (description);
index 1c4d48e..93a75e5 100644 (file)
@@ -63,12 +63,14 @@ TransactionSolutionAction::dumpOn( ostream& os) const
 {
     os << "TransactionSolutionAction: ";
     switch (_action) {
-       case KEEP:              os << "Keep " << _item; break;
-       case INSTALL:           os << "Install " << _item; break;
-       case REMOVE:            os << "Remove " << _item; break;
-       case UNLOCK:            os << "Unlock " << _item; break;
-       case REMOVE_REQUIRE:    os << "Remove require " << _capability; break;
-       case REMOVE_CONFLICT:   os << "Remove conflict " << _capability; break;     
+       case KEEP:                      os << "Keep " << _item; break;
+       case INSTALL:                   os << "Install " << _item; break;
+       case REMOVE:                    os << "Remove " << _item; break;
+       case UNLOCK:                    os << "Unlock " << _item; break;
+       case REMOVE_EXTRA_REQUIRE:      os << "Remove require " << _capability; break;
+       case REMOVE_EXTRA_CONFLICT:     os << "Remove conflict " << _capability; break;
+       case ADD_SOLVE_QUEUE_ITEM:      os << "Add SolveQueueItem " <<  _solverQueueItem; break;
+       case REMOVE_SOLVE_QUEUE_ITEM:   os << "Remove SolveQueueItem " <<  _solverQueueItem; break;         
     }
 
     os << endl;
@@ -152,12 +154,18 @@ TransactionSolutionAction::execute(Resolver & resolver) const
            ret = _item.status().setLock (false, ResStatus::USER);
            if (!ret) ERR << "Cannot unlock " << _item << endl;
            break;
-       case REMOVE_REQUIRE:
+       case REMOVE_EXTRA_REQUIRE:
            resolver.removeExtraRequire (_capability);
            break;          
-       case REMOVE_CONFLICT:
+       case REMOVE_EXTRA_CONFLICT:
            resolver.removeExtraConflict (_capability);
-           break;          
+           break;
+       case ADD_SOLVE_QUEUE_ITEM:
+           resolver.addQueueItem(_solverQueueItem);
+           break;
+       case REMOVE_SOLVE_QUEUE_ITEM:
+           resolver.removeQueueItem(_solverQueueItem);
+           break;
        default:
            ERR << "Wrong TransactionKind" << endl;
            ret = false;
index e38d309..9da7262 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "zypp/solver/detail/Types.h"
 #include "zypp/solver/detail/Resolver.h"
+#include "zypp/solver/detail/SolverQueueItem.h"
 
 /////////////////////////////////////////////////////////////////////////
 namespace zypp
@@ -68,8 +69,10 @@ namespace zypp
            INSTALL,
            REMOVE,
            UNLOCK,
-           REMOVE_REQUIRE,
-           REMOVE_CONFLICT,
+           REMOVE_EXTRA_REQUIRE,
+           REMOVE_EXTRA_CONFLICT,
+           ADD_SOLVE_QUEUE_ITEM,
+           REMOVE_SOLVE_QUEUE_ITEM,
        } TransactionKind;
 
 
@@ -86,6 +89,12 @@ namespace zypp
                : SolutionAction(),
                  _capability( capability ), _action( action ) {}
 
+
+           TransactionSolutionAction( SolverQueueItem_Ptr item,
+                                      TransactionKind action )
+               : SolutionAction(),
+                 _solverQueueItem( item ), _action( action ) {}
+
            TransactionSolutionAction( TransactionKind action )
                : SolutionAction(),
                  _item(), _action( action ) {}
@@ -98,6 +107,7 @@ namespace zypp
          // ---------------------------------- accessors
 
          const PoolItem item() const { return _item; }
+         const Capability capability() const { return _capability; }       
          TransactionKind action() const { return _action; }
 
          // ---------------------------------- methods
@@ -107,6 +117,8 @@ namespace zypp
 
            PoolItem _item;
            Capability _capability;
+           SolverQueueItem_Ptr _solverQueueItem;
+           
            const TransactionKind _action;
        };
 
index 05db856..296d47a 100644 (file)
@@ -107,7 +107,6 @@ class SolverQueueItem : public base::ReferenceCounted, private base::NonCopyable
     virtual int cmp (SolverQueueItem_constPtr item) const = 0;
     int compare (SolverQueueItem_constPtr item) const { return CMP(_type, item->_type); }
 
-
 };
 
 ///////////////////////////////////////////////////////////////////
index f854564..68dfb3d 100644 (file)
@@ -98,16 +98,8 @@ SolverQueueItemDelete::cmp (SolverQueueItem_constPtr item) const
     SolverQueueItemDelete_constPtr del = dynamic_pointer_cast<const SolverQueueItemDelete>(item);
     if (_name != del->_name) {
        return _name.compare(del->_name);
-    } else {
-       if (_soft == del->_soft) {
-           return 0;
-       } else {
-           if (_soft)
-               return 1;
-           else
-               return -1;
-       }
     }
+    return 0;
 }
 
 //---------------------------------------------------------------------------
index 9536518..71923c1 100644 (file)
@@ -100,16 +100,8 @@ SolverQueueItemInstall::cmp (SolverQueueItem_constPtr item) const
     SolverQueueItemInstall_constPtr ins = dynamic_pointer_cast<const SolverQueueItemInstall>(item);
     if (_name != ins->_name) {
        return _name.compare(ins->_name);
-    } else {
-       if (_soft == ins->_soft) {
-           return 0;
-       } else {
-           if (_soft)
-               return 1;
-           else
-               return -1;
-       }
-    }
+    } 
+    return 0;
 }