- improved error messages
authorStefan Schubert <schubi@suse.de>
Thu, 24 Jan 2008 09:06:37 +0000 (09:06 +0000)
committerStefan Schubert <schubi@suse.de>
Thu, 24 Jan 2008 09:06:37 +0000 (09:06 +0000)
- activated lock/kepp requests

zypp/ResolverProblem.cc
zypp/ResolverProblem.h
zypp/sat/SATResolver.cc
zypp/sat/SATResolver.h
zypp/solver/detail/ProblemSolutionCombi.cc
zypp/solver/detail/ProblemSolutionCombi.h
zypp/solver/detail/Resolver.cc

index af733aa33d8a9be78999dde775b400b04a82997c..41969de7731c1397f95f7157592b3fec18325229 100644 (file)
@@ -101,9 +101,14 @@ ResolverProblem::solutions() const
  **/
 
 void
-ResolverProblem::addSolution( ProblemSolution_Ptr solution )
+ResolverProblem::addSolution( ProblemSolution_Ptr solution,
+                             bool inFront )
 {
-    _solutions.push_back (solution);
+    if (inFront) {
+       _solutions.push_front (solution);
+    } else {
+       _solutions.push_back (solution);
+    }
 }
 
 void
index 6780b967b73e2add3a5d8730099c62baeadc17de..4cd6b0dc601e7746776bc2dbfcc329f34feb5d55 100644 (file)
@@ -97,7 +97,7 @@ namespace zypp
         * Add a solution to this problem. This class takes over ownership of
         * the problem and will delete it when neccessary.
         **/
-       void addSolution( ProblemSolution_Ptr solution );
+       void addSolution( ProblemSolution_Ptr solution, bool inFront = false );
 
     };
     ///////////////////////////////////////////////////////////////////////
index 593ec5cc115622c4627e67c285e88d5c2fc89db7..9ecc5e194351b600760d73fedf8c06e03ee44bb8 100644 (file)
@@ -21,7 +21,7 @@
 
 #include "zypp/solver/detail/Helper.h"
 #include "zypp/base/String.h"
-#include "zypp/Capabilities.h"
+#include "zypp/Capability.h"
 #include "zypp/ResStatus.h"
 #include "zypp/base/Logger.h"
 #include "zypp/base/String.h"
@@ -33,6 +33,7 @@
 #include "zypp/sat/SATResolver.h"
 #include "zypp/sat/Pool.h"
 #include "zypp/solver/detail/ProblemSolutionCombi.h"
+#include "zypp/solver/detail/Testcase.h"
 
 extern "C" {
 #include "satsolver/repo_solv.h"
@@ -94,6 +95,8 @@ SATResolver::SATResolver (const ResPool & pool, Pool *SATPool)
     , _architecture( zypp_detail::defaultArchitecture() )
 
 {
+    Testcase testcase("/var/log/YaST2/autotestcase");
+    testcase.createTestcasePool (pool); // dump pool to testcase
 }
 
 
@@ -166,17 +169,10 @@ SATResolver::addPoolItemsToRemoveFromList (PoolItemList & rl)
 }
 
 void
-SATResolver::addPoolItemToLockUninstalled (PoolItem_Ref item)
+SATResolver::addPoolItemToLock (PoolItem_Ref item)
 {
-    _items_to_lockUninstalled.push_back (item);
-    _items_to_lockUninstalled.unique ();
-}
-
-void
-SATResolver::addPoolItemToKepp (PoolItem_Ref item)
-{
-    _items_to_keep.push_back (item);
-    _items_to_keep.unique ();
+    _items_to_lock.push_back (item);
+    _items_to_lock.unique ();
 }
 
 
@@ -333,17 +329,11 @@ struct SATCollectTransact : public resfilter::PoolItemFilterFunctor
        }
 
         if (status.isLocked()
-            && status.isUninstalled()) {
-            // This item could be selected by solver in a former run. Now it
-            // is locked. So we will have to evaluate a new solver run.
-            resolver.addPoolItemToLockUninstalled (item);
+            || (status.isKept()
+               && !by_solver)) {
+            resolver.addPoolItemToLock (item);
         }
 
-        if (status.isKept()
-            && !by_solver) {
-           // collecting all keep states
-           resolver.addPoolItemToKepp (item);
-       }
 
        return true;
     }
@@ -357,8 +347,32 @@ struct SATCollectTransact : public resfilter::PoolItemFilterFunctor
 //----------------------------------------------------------------------------
 
 
+class CheckIfUpdate : public resfilter::PoolItemFilterFunctor
+{
+  public:
+    bool is_updated;
+
+    CheckIfUpdate()
+       : is_updated( false )
+    {}
+
+    // check this item will be installed
+
+    bool operator()( PoolItem_Ref item )
+    {
+       if (item.status().isToBeInstalled())    
+       {
+           is_updated = true;
+           return false;
+       }
+       return true;
+    }
+};
+
+
 bool
-SATResolver::resolvePool()
+SATResolver::resolvePool(const CapabilitySet & requires_caps,
+                        const CapabilitySet & conflict_caps)
 {
     SATCollectTransact info (*this);
     MIL << "SATResolver::resolvePool()" << endl;
@@ -373,6 +387,7 @@ SATResolver::resolvePool()
     queue_init( &jobQueue );
     _items_to_install.clear();
     _items_to_remove.clear();
+    _items_to_lock.clear();    
 
     invokeOnEach ( _pool.begin(), _pool.end(),
                   resfilter::ByTransact( ),                    // collect transacts from Pool to resolver queue
@@ -404,6 +419,33 @@ SATResolver::resolvePool()
        queue_push( &(jobQueue), SOLVER_ERASE_SOLVABLE_NAME );
        queue_push( &(jobQueue), s->name);
     }
+
+    for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
+       queue_push( &(jobQueue), SOLVER_INSTALL_SOLVABLE_PROVIDES );
+       queue_push( &(jobQueue), str2id( _SATPool, (iter->asString()).c_str(), 1 ) );
+       MIL << "Requires " << iter->asString() << endl;
+    }
+
+    for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
+       queue_push( &(jobQueue), SOLVER_ERASE_SOLVABLE_PROVIDES);
+       queue_push( &(jobQueue), str2id( _SATPool, (iter->asString()).c_str(), 1 ));
+       MIL << "Conflicts " << iter->asString() << endl;        
+    }
+
+    for (PoolItemList::const_iterator iter = _items_to_lock.begin(); iter != _items_to_lock.end(); iter++) {
+       Solvable *s = _SATPool->solvables + iter->satSolvable().id();
+       Id id = iter->satSolvable().id();
+       if (iter->status().isInstalled()) {
+           MIL << "Lock installed item " << *iter << " with the string ID: " << s->name << endl;
+           queue_push( &(jobQueue), SOLVER_INSTALL_SOLVABLE );     
+           queue_push( &(jobQueue), id );
+       } else {
+           MIL << "Lock NOT installed item " << *iter << " with the string ID: " << s->name << endl;
+           queue_push( &(jobQueue), SOLVER_ERASE_SOLVABLE );
+           queue_push( &(jobQueue), id );
+       }
+    }
+    
     solv = solver_create( _SATPool, sat::Pool::instance().systemRepo().get() );
     sat::Pool::instance().setDirty();
     sat::Pool::instance().prepare();
@@ -426,19 +468,6 @@ SATResolver::resolvePool()
        ERR << "Solverrun finished with an ERROR" << endl;
        return false;
     }
-    /* solvables to be erased */
-    for (int i = solv->installed->start; i < solv->installed->start + solv->installed->nsolvables; i++)
-    {
-      if (solv->decisionmap[i] > 0)
-       continue;
-
-      PoolItem_Ref poolItem = _pool.find (sat::Solvable(i));
-      if (poolItem) {
-         SATSolutionToPool (poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER);
-      } else {
-         ERR << "id " << i << " not found in ZYPP pool." << endl;
-      }
-    }
 
     /*  solvables to be installed */
     for (int i = 0; i < solv->decisionq.count; i++)
@@ -458,6 +487,32 @@ SATResolver::resolvePool()
       }
     }
 
+    /* solvables to be erased */
+    for (int i = solv->installed->start; i < solv->installed->start + solv->installed->nsolvables; i++)
+    {
+      if (solv->decisionmap[i] > 0)
+       continue;
+
+      PoolItem_Ref poolItem = _pool.find (sat::Solvable(i));
+      if (poolItem) {
+         // Check if this is an update
+         CheckIfUpdate info;     
+         invokeOnEach( _pool.byNameBegin( poolItem->name() ),
+                       _pool.byNameEnd( poolItem->name() ),
+                       functor::chain (resfilter::ByUninstalled (),                    // ByUninstalled
+                                       resfilter::ByKind( poolItem->kind() ) ),        // equal kind
+                       functor::functorRef<bool,PoolItem> (info) );
+         
+         if (info.is_updated) {
+             SATSolutionToPool (poolItem, ResStatus::toBeUninstalledDueToUpgrade , ResStatus::SOLVER);
+         } else {
+             SATSolutionToPool (poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER);
+         }
+      } else {
+         ERR << "id " << i << " not found in ZYPP pool." << endl;
+      }
+    }
+
     // clean up
     solver_free(solv);
     solv = NULL;
@@ -518,7 +573,7 @@ std::string SATResolver::SATprobleminfoString(Id problem)
          break;
       case SOLVER_PROBLEM_NOT_INSTALLABLE:
          s = pool_id2solvable(pool, source);
-         ret = str::form (_("package %s is not installable"), solvable2str(pool, s));
+         ret = str::form (_("%s is not installable"), solvable2str(pool, s));
          break;
       case SOLVER_PROBLEM_NOTHING_PROVIDES_DEP:
          s = pool_id2solvable(pool, source);
@@ -532,16 +587,16 @@ std::string SATResolver::SATprobleminfoString(Id problem)
       case SOLVER_PROBLEM_PACKAGE_CONFLICT:
          s = pool_id2solvable(pool, source);
          s2 = pool_id2solvable(pool, target);
-         ret = str::form (_("package %s conflicts with %s provided by %s"), solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
+         ret = str::form (_("%s conflicts with %s provided by %s"), solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
          break;
       case SOLVER_PROBLEM_PACKAGE_OBSOLETES:
          s = pool_id2solvable(pool, source);
          s2 = pool_id2solvable(pool, target);
-         ret = str::form (_("package %s obsoletes %s provided by %s"), solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
+         ret = str::form (_("%s obsoletes %s provided by %s"), solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
          break;
       case SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE:
          s = pool_id2solvable(pool, source);
-         ret = str::form (_("package %s requires %s, but none of the providers can be installed"), solvable2str(pool, s), dep2str(pool, dep));
+         ret = str::form (_("%s requires %s, but none of the providers can be installed"), solvable2str(pool, s), dep2str(pool, dep));
          break;
   }
 
@@ -589,7 +644,7 @@ SATResolver::problems ()
                                        MIL << description << endl;
                                        problemSolution->addDescription (description);
                                    } else {
-                                       problemSolution->addSingleAction (poolItem, KEEP);
+                                       problemSolution->addSingleAction (poolItem, REMOVE);
                                        string description = str::form (_("do not install %s"), solvable2str(pool, s));
                                        MIL << description << endl;
                                        problemSolution->addDescription (description);
@@ -606,7 +661,7 @@ SATResolver::problems ()
                                if (poolItem) {
                                    if (solv->installed && s->repo == solv->installed) {
                                        problemSolution->addSingleAction (poolItem, KEEP);
-                                       string description = str::form (_("do not deinstall %s"), solvable2str(pool, s));
+                                       string description = str::form (_("keep %s"), solvable2str(pool, s));
                                        MIL << description << endl;
                                        problemSolution->addDescription (description);
                                    } else {
@@ -643,7 +698,7 @@ SATResolver::problems ()
                                              functor::chain (resfilter::ByInstalled (),                        // ByInstalled
                                                              resfilter::ByTransact ()),                        // will be deinstalled
                                              functor::functorRef<bool,PoolItem> (info) );
-                               string description = str::form (_("do not deinstall %s"), id2str(pool, what));
+                               string description = str::form (_("keep %s"), id2str(pool, what));
                                MIL << description << endl;
                                problemSolution->addDescription (description);
                                }
@@ -673,7 +728,7 @@ SATResolver::problems ()
                                        || poolItem.status().staysInstalled())
                                        problemSolution->addSingleAction (poolItem, KEEP);
                                }
-                               string description = str::form (_("do not deinstall all solvables providing %s"), dep2str(pool, what));
+                               string description = str::form (_("keep all solvables providing %s"), dep2str(pool, what));
                                MIL << description << endl;
                                problemSolution->addDescription (description);
                                }
@@ -760,7 +815,8 @@ SATResolver::problems ()
                        }
                    }
                }
-               resolverProblem->addSolution (problemSolution);
+               resolverProblem->addSolution (problemSolution,
+                                             problemSolution->actionCount() > 1 ? true : false); // Solutions with more than 1 action will be shown first.
                MIL << "------------------------------------" << endl;
            }
            // save problem
index be0e814a4407da018c2f1b033e66b9288450d179..fe855418f09df53ac591f440e16441b5c1553c86 100644 (file)
@@ -34,6 +34,7 @@
 #include "zypp/ProblemTypes.h"
 #include "zypp/ResolverProblem.h"
 #include "zypp/ProblemSolution.h"
+#include "zypp/Capability.h"
 extern "C" {
 #include "satsolver/solver.h"
 #include "satsolver/pool.h"
@@ -73,8 +74,7 @@ class SATResolver : public base::ReferenceCounted, private base::NonCopyable {
     // list populated by calls to addPoolItemTo*()
     PoolItemList _items_to_install;
     PoolItemList _items_to_remove;
-    PoolItemList _items_to_lockUninstalled;
-    PoolItemList _items_to_keep;
+    PoolItemList _items_to_lock;
     
     // ---------------------------------- methods
     std::string SATprobleminfoString (Id problem);
@@ -98,7 +98,8 @@ class SATResolver : public base::ReferenceCounted, private base::NonCopyable {
     ResPool pool (void) const;
     void setPool (const ResPool & pool) { _pool = pool; }
 
-    bool resolvePool();
+    bool resolvePool(const CapabilitySet & requires_caps,
+                    const CapabilitySet & conflict_caps);
 
     ResolverProblemList problems ();
     void applySolutions (const ProblemSolutionList &solutions);
@@ -112,8 +113,7 @@ class SATResolver : public base::ReferenceCounted, private base::NonCopyable {
     void addPoolItemToInstall (PoolItem_Ref item);
     void addPoolItemsToInstallFromList (PoolItemList & rl);
 
-    void addPoolItemToLockUninstalled (PoolItem_Ref item);
-    void addPoolItemToKepp (PoolItem_Ref item);
+    void addPoolItemToLock (PoolItem_Ref item);
 
     void addPoolItemToRemove (PoolItem_Ref item);
     void addPoolItemsToRemoveFromList (PoolItemList & rl);
index 82f30cd19f579665b85153d175d64d144bf69bb7..b3f96dccff6b678d49027366a5803aaa4299ad38 100644 (file)
@@ -47,6 +47,7 @@ IMPL_PTR_TYPE(ProblemSolutionCombi);
 
 ProblemSolutionCombi::ProblemSolutionCombi( ResolverProblem_Ptr parent)
     : ProblemSolution (parent, "", "")
+      , actNumber(0)
 {
     _description = "";
     _details = "";
@@ -55,6 +56,7 @@ ProblemSolutionCombi::ProblemSolutionCombi( ResolverProblem_Ptr parent)
 void ProblemSolutionCombi::addSingleAction( PoolItem_Ref item, const TransactionKind action)
 {
     addAction (new TransactionSolutionAction(item, action));
+    actNumber++;
 }
 
 void ProblemSolutionCombi::addDescription( const std::string description)
index ba71bed5a5d218ccb41399640bc96b9601d212b7..39587783f02c5c9f429625143d8b5e4a5b1a09ce 100644 (file)
@@ -44,6 +44,8 @@ namespace zypp
         **/
        class ProblemSolutionCombi : public ProblemSolution
        {
+        protected:
+           int actNumber; // number of actions
        public:
 
            /**
@@ -54,10 +56,17 @@ namespace zypp
             * Add a single action
             */
            void addSingleAction( PoolItem_Ref item, const TransactionKind action);
+
+           /**
+            * returns the number of actions
+            */
+           int actionCount() { return actNumber;}
+           
            /**
             * Set description text
             */
-           void addDescription( const std::string description);            
+           void addDescription( const std::string description);
+
        };
 
       ///////////////////////////////////////////////////////////////////
index 84f85aa6c086eb1d4e97b0b1fb489f16314aea2b..5ecb39a6ce5ccddb497d9846c49ebfaec639d660 100644 (file)
@@ -301,7 +301,7 @@ Resolver::resolvePool()
        }
        MIL << "------SAT-Pool end------" << endl;
 #endif
-       return _satResolver->resolvePool();
+       return _satResolver->resolvePool(_extra_requires, _extra_conflicts);
 }