Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / zypp / solver / detail / SolutionAction.cc
index f497212..4ff9100 100644 (file)
  * 02111-1307, USA.
  */
 
+#define ZYPP_USE_RESOLVER_INTERNALS
+
 #include "zypp/solver/detail/Resolver.h"
 #include "zypp/solver/detail/SolutionAction.h"
-#include "zypp/CapSet.h"
+#include "zypp/solver/detail/SolverQueueItem.h"
+#include "zypp/Capabilities.h"
 #include "zypp/base/Logger.h"
-#include "zypp/Dependencies.h"
-
 
 /////////////////////////////////////////////////////////////////////////
 namespace zypp
@@ -41,8 +42,6 @@ namespace zypp
 using namespace std;
 
 IMPL_PTR_TYPE(SolutionAction);
-IMPL_PTR_TYPE(TransactionSolutionAction);
-IMPL_PTR_TYPE(InjectSolutionAction);
 
 //---------------------------------------------------------------------------
 
@@ -58,20 +57,21 @@ SolutionAction::~SolutionAction()
 
 //---------------------------------------------------------------------------
 
-ostream&
-operator<<( ostream& os, const TransactionSolutionAction & action)
+ostream &
+TransactionSolutionAction::dumpOn( ostream& os) const
 {
     os << "TransactionSolutionAction: ";
-    switch (action._action) {
-       case KEEP:      os << "Keep"; break;
-       case INSTALL:   os << "Install"; break;
-       case UPDATE:    os << "Update"; break;
-       case REMOVE:    os << "Remove"; break;
-       case UNLOCK:    os << "Unlock"; break;      
+    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 LOCK:                      os << "Lock " << _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 << " ";
-    os << action._item;
-    os << endl;
     return os;
 }
 
@@ -80,56 +80,84 @@ ostream&
 operator<<( ostream& os, const SolutionActionList & actionlist)
 {
     for (SolutionActionList::const_iterator iter = actionlist.begin(); iter != actionlist.end(); ++iter) {
-       os << (*iter);
+       os << *(*iter);
        os << endl;
     }
     return os;
 }
 
+//---------------------------------------------------------------------------
 
-ostream&
-operator<<( ostream& os, const CSolutionActionList & actionlist)
+ostream &
+InjectSolutionAction::dumpOn( ostream& os ) const
 {
-    for (CSolutionActionList::const_iterator iter = actionlist.begin(); iter != actionlist.end(); ++iter) {
-       os << (*iter);
-       os << endl;
+    os << "InjectSolutionAction: ";
+    switch (_kind) {
+       case WEAK:      os << "Weak"; break;
+       default: os << "Wrong kind"; break;
     }
+    os << " ";
+    os << _item;
     return os;
 }
 
 //---------------------------------------------------------------------------
 
-ostream&
-operator<<( ostream& os, const InjectSolutionAction & action)
+
+ostream &
+SolutionAction::dumpOn( std::ostream & os ) const
 {
-    os << "InjectSolutionAction: ";
-    os << action._capability;
-    os << ", ";
-    os << action._kind;
-    os << endl;
+    os << "SolutionAction<";
+    os << "not specified";
+    os << "> ";
     return os;
 }
 
-//---------------------------------------------------------------------------
-
 
-bool 
-TransactionSolutionAction::execute(Resolver & resolver) const
+bool
+TransactionSolutionAction::execute(ResolverInternal & resolver) const
 {
     bool ret = true;
     switch (action()) {
        case KEEP:
+           _item.status().resetTransact (ResStatus::USER);
+           ret = _item.status().setTransact (false, ResStatus::APPL_HIGH); // APPL_HIGH: Locking should not be saved permanently
+           break;
        case INSTALL:
-       case UPDATE:
-           resolver.addPoolItemToInstall (_item);
+           if (_item.status().isToBeUninstalled())
+               ret = _item.status().setTransact (false, ResStatus::USER);
+           else
+               _item.status().setToBeInstalled (ResStatus::USER);
            break;
        case REMOVE:
-           resolver.addPoolItemToRemove (_item);           
+           if (_item.status().isToBeInstalled()) {
+               _item.status().setTransact (false,ResStatus::USER);
+               _item.status().setLock (true,ResStatus::USER); // no other dependency can set it again
+           } else if (_item.status().isInstalled())
+               _item.status().setToBeUninstalled (ResStatus::USER);
+           else
+               _item.status().setLock (true,ResStatus::USER); // no other dependency can set it again
            break;
        case UNLOCK:
-           ERR << "Not implemented yet" << endl;
-           ret = false;
-#warning Unlocking items not implemented
+           ret = _item.status().setLock (false, ResStatus::USER);
+           if (!ret) ERR << "Cannot unlock " << _item << endl;
+           break;
+       case LOCK:
+           _item.status().resetTransact (ResStatus::USER);
+           ret = _item.status().setLock (true, ResStatus::APPL_HIGH); // APPL_HIGH: Locking should not be saved permanently
+           if (!ret) ERR << "Cannot lock " << _item << endl;
+           break;
+       case REMOVE_EXTRA_REQUIRE:
+           resolver.removeExtraRequire (_capability);
+           break;
+       case REMOVE_EXTRA_CONFLICT:
+           resolver.removeExtraConflict (_capability);
+           break;
+       case ADD_SOLVE_QUEUE_ITEM:
+           resolver.addQueueItem(_solverQueueItem);
+           break;
+       case REMOVE_SOLVE_QUEUE_ITEM:
+           resolver.removeQueueItem(_solverQueueItem);
            break;
        default:
            ERR << "Wrong TransactionKind" << endl;
@@ -139,28 +167,18 @@ TransactionSolutionAction::execute(Resolver & resolver) const
 }
 
 bool
-InjectSolutionAction::execute(Resolver & resolver) const
+InjectSolutionAction::execute(ResolverInternal & resolver) const
 {
-    ResObject::constPtr resolvable = _item.resolvable();
-    CapSet dep;
-    
-    dep.insert(_capability);
-    Dependencies dependencies;
-
-    if (_kind == Dep::CONFLICTS) {
-       // removing provide, it the other resolvable has the conflict
-       dependencies[Dep::PROVIDES] = dep;
-       // removing conflict
-       dependencies[Dep::CONFLICTS] = dep;             
-    } else if (_kind  == Dep::PROVIDES) {
-       // removing the requires dependency from the item
-       dependencies[Dep::REQUIRES] = dep;
-    } else {
-       ERR << "No valid InjectSolutionAction kind found" << endl;
-       return false;
+    switch (_kind) {
+        case WEAK:
+           // set item dependencies to weak
+           resolver.addWeak (_item);
+            break;
+        default:
+           ERR << "No valid InjectSolutionAction kind found" << endl;
+           return false;
     }
-#warning Disabling capabilities currently not possible;
-//    resolvable->deprecatedSetDeps(dependencies);
+
     return true;
 }