take care about SOLVER_PROBLEM_DISTUPGRADE_RULE/SOLVER_PROBLEM_INFARCH_RULE
[platform/upstream/libzypp.git] / zypp / solver / detail / SATResolver.cc
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* SATResolver.cc
3  *
4  * Copyright (C) 2000-2002 Ximian, Inc.
5  * Copyright (C) 2005 SUSE Linux Products GmbH
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License,
9  * version 2, as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19  * 02111-1307, USA.
20  */
21 #include <sstream>
22 #include "zypp/solver/detail/Helper.h"
23 #include "zypp/base/String.h"
24 #include "zypp/Capability.h"
25 #include "zypp/ResStatus.h"
26 #include "zypp/VendorAttr.h"
27 #include "zypp/base/Logger.h"
28 #include "zypp/base/String.h"
29 #include "zypp/base/Gettext.h"
30 #include "zypp/base/Algorithm.h"
31 #include "zypp/ResPool.h"
32 #include "zypp/ResFilters.h"
33 #include "zypp/ZConfig.h"
34 #include "zypp/sat/Pool.h"
35 #include "zypp/sat/WhatProvides.h"
36 #include "zypp/solver/detail/SATResolver.h"
37 #include "zypp/solver/detail/ProblemSolutionCombi.h"
38 #include "zypp/solver/detail/ProblemSolutionIgnore.h"
39 #include "zypp/solver/detail/SolverQueueItemInstall.h"
40 #include "zypp/solver/detail/SolverQueueItemDelete.h"
41 #include "zypp/solver/detail/SystemCheck.h"
42
43 extern "C" {
44 #include "satsolver/repo_solv.h"
45 #include "satsolver/poolarch.h"
46 #include "satsolver/evr.h"
47 #include "satsolver/poolvendor.h"
48 #include "satsolver/policy.h"
49 #include "satsolver/bitmap.h"
50 #include "satsolver/queue.h"
51 }
52
53 /////////////////////////////////////////////////////////////////////////
54 namespace zypp
55 { ///////////////////////////////////////////////////////////////////////
56   ///////////////////////////////////////////////////////////////////////
57   namespace solver
58   { /////////////////////////////////////////////////////////////////////
59     /////////////////////////////////////////////////////////////////////
60     namespace detail
61     { ///////////////////////////////////////////////////////////////////
62
63 using namespace std;
64
65 IMPL_PTR_TYPE(SATResolver);
66
67 //---------------------------------------------------------------------------
68 // Callbacks for SAT policies
69 //---------------------------------------------------------------------------
70
71 int vendorCheck (Pool *pool, Solvable *solvable1, Solvable *solvable2) {
72 //    DBG << "vendorCheck: " << id2str(pool, solvable1->vendor) << " <--> " << id2str(pool, solvable1->vendor) << endl;
73     return VendorAttr::instance().equivalent(id2str(pool, solvable1->vendor), id2str(pool, solvable2->vendor)) ? 0:1;
74 }
75
76
77 string
78 itemToString (PoolItem item, bool shortVersion)
79 {
80     ostringstream os;
81     if (!item) return "";
82
83     if (item->kind() != ResKind::package)
84         os << item->kind() << ':';
85     os  << item->name();
86     if (!shortVersion) {
87         os << '-' << item->edition();
88         if (item->arch() != "") {
89             os << '.' << item->arch();
90         }
91         Repository s = item->repository();
92         if (s) {
93             string alias = s.info().alias();
94             if (!alias.empty()
95                 && alias != "@system")
96             {
97                 os << '[' << s.info().alias() << ']';
98             }
99         }
100     }
101     return os.str();
102 }
103
104
105 //---------------------------------------------------------------------------
106
107 std::ostream &
108 SATResolver::dumpOn( std::ostream & os ) const
109 {
110     os << "<resolver>" << endl;
111     if (_solv) {
112         os << "  fixsystem = " << _solv->fixsystem << endl;
113         os << "  allowdowngrade = " << _solv->allowdowngrade << endl;
114         os << "  allowarchchange = " << _solv->allowarchchange << endl;
115         os << "  allowvendorchange = " <<  _solv->allowvendorchange << endl;
116         os << "  allowuninstall = " << _solv->allowuninstall << endl;
117         os << "  updatesystem = " << _solv->updatesystem << endl;
118         os << "  allowvirtualconflicts = " <<  _solv->allowvirtualconflicts << endl;
119         os << "  noupdateprovide = " << _solv->noupdateprovide << endl;
120         os << "  dosplitprovides = " << _solv->dosplitprovides << endl;
121         os << "  onlyRequires = " << _solv->dontinstallrecommended << endl;
122         os << "  ignorealreadyrecommended = " << _solv->ignorealreadyrecommended << endl;
123         os << "  distupgrade = " << _distupgrade << endl;
124         os << "  distupgrade_removeunsupported = " << _distupgrade_removeunsupported << endl;
125
126     } else {
127         os << "<NULL>";
128     }
129     return os << "<resolver/>" << endl;
130 }
131
132 //---------------------------------------------------------------------------
133
134 SATResolver::SATResolver (const ResPool & pool, Pool *SATPool)
135     : _pool (pool)
136     , _SATPool (SATPool)
137     , _solv(NULL)
138     , _fixsystem(false)
139     , _allowdowngrade(false)
140     , _allowarchchange(false)
141     , _allowvendorchange(false)
142     , _allowuninstall(false)
143     , _updatesystem(false)
144     , _allowvirtualconflicts(false)
145     , _noupdateprovide(false)
146     , _dosplitprovides(false)
147     , _onlyRequires(ZConfig::instance().solver_onlyRequires())
148     , _ignorealreadyrecommended(false)
149     , _distupgrade(false)
150     , _distupgrade_removeunsupported(false)
151
152 {
153 }
154
155
156 SATResolver::~SATResolver()
157 {
158 }
159
160 //---------------------------------------------------------------------------
161
162
163 ResPool
164 SATResolver::pool (void) const
165 {
166     return _pool;
167 }
168
169
170 void
171 SATResolver::resetItemTransaction (PoolItem item)
172 {
173     bool found = false;
174     for (PoolItemList::const_iterator iter = _items_to_remove.begin();
175          iter != _items_to_remove.end(); iter++) {
176         if (*iter == item) {
177             _items_to_remove.remove(*iter);
178             found = true;
179             break;
180         }
181     }
182     if (!found) {
183         for (PoolItemList::const_iterator iter = _items_to_install.begin();
184              iter != _items_to_install.end(); iter++) {
185             if (*iter == item) {
186                 _items_to_install.remove(*iter);
187                 found = true;
188                 break;
189             }
190         }
191     }
192     if (!found) {
193         for (PoolItemList::const_iterator iter = _items_to_keep.begin();
194              iter != _items_to_keep.end(); iter++) {
195             if (*iter == item) {
196                 _items_to_keep.remove(*iter);
197                 found = true;
198                 break;
199             }
200         }
201     }
202     if (!found) {
203         for (PoolItemList::const_iterator iter = _items_to_lock.begin();
204              iter != _items_to_lock.end(); iter++) {
205             if (*iter == item) {
206                 _items_to_lock.remove(*iter);
207                 found = true;
208                 break;
209             }
210         }
211     }
212 }
213
214
215 void
216 SATResolver::addPoolItemToInstall (PoolItem item)
217 {
218     resetItemTransaction (item);
219     _items_to_install.push_back (item);
220     _items_to_install.unique ();
221 }
222
223
224 void
225 SATResolver::addPoolItemsToInstallFromList (PoolItemList & rl)
226 {
227     for (PoolItemList::const_iterator iter = rl.begin(); iter != rl.end(); iter++) {
228         addPoolItemToInstall (*iter);
229     }
230 }
231
232
233 void
234 SATResolver::addPoolItemToRemove (PoolItem item)
235 {
236     resetItemTransaction (item);
237     _items_to_remove.push_back (item);
238     _items_to_remove.unique ();
239 }
240
241
242 void
243 SATResolver::addPoolItemsToRemoveFromList (PoolItemList & rl)
244 {
245     for (PoolItemList::const_iterator iter = rl.begin(); iter != rl.end(); iter++) {
246         addPoolItemToRemove (*iter);
247     }
248 }
249
250 void
251 SATResolver::addPoolItemToLock (PoolItem item)
252 {
253     resetItemTransaction (item);
254     _items_to_lock.push_back (item);
255     _items_to_lock.unique ();
256 }
257
258 void
259 SATResolver::addPoolItemToKeep (PoolItem item)
260 {
261     resetItemTransaction (item);
262     _items_to_keep.push_back (item);
263     _items_to_keep.unique ();
264 }
265
266 //---------------------------------------------------------------------------
267
268 // copy marked item from solution back to pool
269 // if data != NULL, set as APPL_LOW (from establishPool())
270
271 static void
272 SATSolutionToPool (PoolItem item, const ResStatus & status, const ResStatus::TransactByValue causer)
273 {
274     // resetting
275     item.status().resetTransact (causer);
276     item.status().resetWeak ();
277
278     bool r;
279
280     // installation/deletion
281     if (status.isToBeInstalled()) {
282         r = item.status().setToBeInstalled (causer);
283         _XDEBUG("SATSolutionToPool install returns " << item << ", " << r);
284     }
285     else if (status.isToBeUninstalledDueToUpgrade()) {
286         r = item.status().setToBeUninstalledDueToUpgrade (causer);
287         _XDEBUG("SATSolutionToPool upgrade returns " << item << ", " <<  r);
288     }
289     else if (status.isToBeUninstalled()) {
290         r = item.status().setToBeUninstalled (causer);
291         _XDEBUG("SATSolutionToPool remove returns " << item << ", " <<  r);
292     }
293
294     return;
295 }
296
297
298 //----------------------------------------------------------------------------
299 // helper functions for distupgrade
300 //----------------------------------------------------------------------------
301
302 bool SATResolver::doesObsoleteItem (PoolItem candidate, PoolItem installed) {
303   Solvable *sCandidate = _SATPool->solvables + candidate.satSolvable().id();
304   ::_Repo *installedRepo = sat::Pool::instance().systemRepo().get();
305
306   Id p, pp, obsolete, *obsoleteIt;
307
308   if ((!installedRepo || sCandidate->repo != installedRepo) && sCandidate->obsoletes) {
309       obsoleteIt = sCandidate->repo->idarraydata + sCandidate->obsoletes;
310       while ((obsolete = *obsoleteIt++) != 0)
311       {
312           for (pp = pool_whatprovides(_SATPool, obsolete); (p = _SATPool->whatprovidesdata[pp++]) != 0; ) {
313               if (p > 0 &&  installed.satSolvable().id() == (sat::detail::SolvableIdType)p) {
314                   MIL << candidate << " obsoletes " << installed << endl;
315                   return true;
316               }
317           }
318       }
319   }
320   return false;
321 }
322
323 //----------------------------------------------------------------------------
324 //----------------------------------------------------------------------------
325 // resolvePool
326 //----------------------------------------------------------------------------
327 //----------------------------------------------------------------------------
328
329 //----------------------------------------------------------------------------
330 // Helper functions for the ZYPP-Pool
331 //----------------------------------------------------------------------------
332
333
334 //------------------------------------------------------------------------------------------------------------
335 //  This function loops over the pool and grabs all items
336 //  It clears all previous bySolver() states also
337 //
338 //  Every toBeInstalled is passed to zypp::solver:detail::Resolver.addPoolItemToInstall()
339 //  Every toBeUninstalled is passed to zypp::solver:detail::Resolver.addPoolItemToRemove()
340 //
341 //  Solver results must be written back to the pool.
342 //------------------------------------------------------------------------------------------------------------
343
344
345 struct SATCollectTransact : public resfilter::PoolItemFilterFunctor
346 {
347     SATResolver & resolver;
348
349     SATCollectTransact (SATResolver & r)
350         : resolver (r)
351     { }
352
353     bool operator()( PoolItem item )            // only transacts() items go here
354     {
355         ResStatus status = item.status();
356         bool by_solver = (status.isBySolver() || status.isByApplLow());
357
358         if (by_solver) {
359             item.status().resetTransact( ResStatus::APPL_LOW );// clear any solver/establish transactions
360             return true;                                // back out here, dont re-queue former solver result
361         }
362
363         if (status.isToBeInstalled()) {
364             resolver.addPoolItemToInstall(item);        // -> install!
365         }
366         else if (status.isToBeUninstalled()) {
367             resolver.addPoolItemToRemove(item);         // -> remove !
368         }
369         else if (status.isLocked()
370                  && !by_solver) {
371             resolver.addPoolItemToLock (item);
372         }
373         else if (status.isKept()
374                  && !by_solver) {
375             resolver.addPoolItemToKeep (item);
376         }
377
378         return true;
379     }
380 };
381
382
383 //----------------------------------------------------------------------------
384 //----------------------------------------------------------------------------
385 // solving.....
386 //----------------------------------------------------------------------------
387 //----------------------------------------------------------------------------
388
389
390 class CheckIfUpdate : public resfilter::PoolItemFilterFunctor
391 {
392   public:
393     bool is_updated;
394
395     CheckIfUpdate()
396         : is_updated( false )
397     {}
398
399     // check this item will be installed
400
401     bool operator()( PoolItem item )
402     {
403         if (item.status().isToBeInstalled())
404         {
405             is_updated = true;
406             return false;
407         }
408         return true;
409     }
410 };
411
412
413 class CollectNonePackages : public resfilter::PoolItemFilterFunctor
414 {
415   public:
416     Queue *solvableQueue;
417
418     CollectNonePackages( Queue *queue )
419         :solvableQueue (queue)
420     {}
421
422     // collecting none packges
423
424     bool operator()( PoolItem item )
425     {
426         queue_push(solvableQueue, item.satSolvable().id());
427         return true;
428     }
429 };
430
431 bool
432 SATResolver::solving(const CapabilitySet & requires_caps,
433                      const CapabilitySet & conflict_caps)
434 {
435     _solv = solver_create( _SATPool );
436     _solv->vendorCheckCb = &vendorCheck;
437     _solv->fixsystem = _fixsystem;
438     _solv->ignorealreadyrecommended = _ignorealreadyrecommended;
439     _solv->updatesystem = _updatesystem;
440     _solv->allowdowngrade = _allowdowngrade;
441     _solv->allowuninstall = _allowuninstall;
442     _solv->allowarchchange = _allowarchchange;
443     _solv->allowvendorchange = _allowvendorchange;
444     _solv->allowvirtualconflicts = _allowvirtualconflicts;
445     _solv->dosplitprovides = _dosplitprovides;
446     _solv->noupdateprovide = _noupdateprovide;
447     _solv->dontinstallrecommended = _onlyRequires;
448     _solv->distupgrade = _distupgrade;
449     _solv->distupgrade_removeunsupported = _distupgrade_removeunsupported;
450
451     sat::Pool::instance().prepare();
452
453     // Solve !
454     MIL << "Starting solving...." << endl;
455     MIL << *this;
456     solver_solve( _solv, &(_jobQueue) );
457     MIL << "....Solver end" << endl;
458
459     // copying solution back to zypp pool
460     //-----------------------------------------
461     _result_items_to_install.clear();
462     _result_items_to_remove.clear();
463
464     /*  solvables to be installed */
465     for (int i = 0; i < _solv->decisionq.count; i++)
466     {
467       Id p;
468       p = _solv->decisionq.elements[i];
469       if (p < 0 || !sat::Solvable(p) || sat::Solvable(p).isSystem())
470         continue;
471
472       PoolItem poolItem((sat::Solvable(p)));
473       if (poolItem) {
474           SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
475           _result_items_to_install.push_back (poolItem);
476       } else {
477           ERR << "id " << p << " not found in ZYPP pool." << endl;
478       }
479     }
480
481     /* solvables to be erased */
482     Repository systemRepo( sat::Pool::instance().findSystemRepo() ); // don't create if it does not exist
483     for_( it, systemRepo.solvablesBegin(), systemRepo.solvablesEnd() )
484     {
485       if (_solv->decisionmap[it->id()] > 0)
486         continue;
487
488       PoolItem poolItem( *it );
489       // Check if this is an update
490       CheckIfUpdate info;
491       invokeOnEach( _pool.byIdentBegin( poolItem ),
492                     _pool.byIdentEnd( poolItem ),
493                     resfilter::ByUninstalled(),                 // ByUninstalled
494                     functor::functorRef<bool,PoolItem> (info) );
495
496       if (info.is_updated) {
497           SATSolutionToPool (poolItem, ResStatus::toBeUninstalledDueToUpgrade , ResStatus::SOLVER);
498       } else {
499           SATSolutionToPool (poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER);
500       }
501       _result_items_to_remove.push_back (poolItem);
502     }
503
504     /*  solvables which are recommended */
505     for (int i = 0; i < _solv->recommendations.count; i++)
506     {
507       Id p;
508       p = _solv->recommendations.elements[i];
509       if (p < 0 || !sat::Solvable(p))
510         continue;
511
512       PoolItem poolItem = _pool.find (sat::Solvable(p));
513       if (poolItem) {
514           poolItem.status().setRecommended(true);
515           _XDEBUG("SATSolutionToPool(" << poolItem << ") recommended !");
516       } else {
517           ERR << "id " << p << " not found in ZYPP pool." << endl;
518       }
519     }
520
521     /*  solvables which are suggested */
522     for (int i = 0; i < _solv->suggestions.count; i++)
523     {
524       Id p;
525       p = _solv->suggestions.elements[i];
526       if (p < 0 || !sat::Solvable(p))
527         continue;
528
529       PoolItem poolItem = _pool.find (sat::Solvable(p));
530       if (poolItem) {
531           poolItem.status().setSuggested(true);
532           _XDEBUG("SATSolutionToPool(" << poolItem << ") suggested !");
533       } else {
534           ERR << "id " << p << " not found in ZYPP pool." << endl;
535       }
536     }
537
538     _problem_items.clear();
539     /*  solvables which are no longer supported */
540     for (int i = 0; i < _solv->orphaned.count; i++)
541     {
542         Id p;
543         p = _solv->orphaned.elements[i];
544         if (p < 0 || !sat::Solvable(p))
545             continue;
546
547         PoolItem poolItem = _pool.find (sat::Solvable(p));
548         if (poolItem) {
549             _problem_items.push_back(poolItem);
550             _XDEBUG( poolItem << " orphaned !");
551         } else {
552             ERR << "id " << p << " not found in ZYPP pool." << endl;
553         }
554     }
555
556     /* Write validation state back to pool */
557     Map installedmap;
558     Queue flags, solvableQueue;
559
560     queue_init(&flags);
561     queue_init(&solvableQueue);
562
563     CollectNonePackages collectNonePackages(&solvableQueue);
564     invokeOnEach( _pool.begin(),
565                   _pool.end(),
566                   functor::not_c(resfilter::byKind<Package>()), // every solvable BUT packages
567                   functor::functorRef<bool,PoolItem> (collectNonePackages) );
568     solver_create_state_maps(_solv, &installedmap, 0);
569     pool_trivial_installable(_solv->pool, &installedmap, &solvableQueue, &flags);
570     for (int i = 0; i < solvableQueue.count; i++) {
571         PoolItem item = _pool.find (sat::Solvable(solvableQueue.elements[i]));
572         item.status().setUndetermined();
573
574         if (flags.elements[i] == -1) {
575             item.status().setNonRelevant();
576             _XDEBUG("SATSolutionToPool(" << item << " ) nonRelevant !");
577         } else if (flags.elements[i] == 1) {
578             item.status().setSatisfied();
579             _XDEBUG("SATSolutionToPool(" << item << " ) satisfied !");
580         } else if (flags.elements[i] == 0) {
581             item.status().setBroken();
582             _XDEBUG("SATSolutionToPool(" << item << " ) broken !");
583         }
584     }
585
586     // Solvables which were selected due requirements which have been made by the user will
587     // be selected by APPL_LOW. We can't use any higher level, because this setting must
588     // not serve as a request for the next solver run. APPL_LOW is reset before solving.
589     for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
590         sat::WhatProvides rpmProviders(*iter);
591         for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
592             PoolItem poolItem(*iter2);
593             if (poolItem.status().isToBeInstalled()) {
594                 MIL << "User requirement " << *iter << " sets " << poolItem << endl;
595                 poolItem.status().setTransactByValue (ResStatus::APPL_LOW);
596             }
597         }
598     }
599     for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
600         sat::WhatProvides rpmProviders(*iter);
601         for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
602             PoolItem poolItem(*iter2);
603             if (poolItem.status().isToBeUninstalled()) {
604                 MIL << "User conflict " << *iter << " sets " << poolItem << endl;
605                 poolItem.status().setTransactByValue (ResStatus::APPL_LOW);
606             }
607         }
608     }
609
610     if (_solv->problems.count > 0 )
611     {
612         ERR << "Solverrun finished with an ERROR" << endl;
613         return false;
614     }
615
616     map_free(&installedmap);
617     queue_free(&(solvableQueue));
618     queue_free(&flags);
619
620     return true;
621 }
622
623
624 void
625 SATResolver::solverInit(const PoolItemList & weakItems)
626 {
627     SATCollectTransact info (*this);
628
629     MIL << "SATResolver::solverInit()" << endl;
630
631     if (_solv) {
632         // remove old stuff
633         solver_free(_solv);
634         _solv = NULL;
635         queue_free( &(_jobQueue) );
636     }
637
638     queue_init( &_jobQueue );
639     _items_to_install.clear();
640     _items_to_remove.clear();
641     _items_to_lock.clear();
642     _items_to_keep.clear();
643
644     invokeOnEach ( _pool.begin(), _pool.end(),
645                    functor::functorRef<bool,PoolItem>(info) );
646
647     for (PoolItemList::const_iterator iter = weakItems.begin(); iter != weakItems.end(); iter++) {
648         Id id = (*iter)->satSolvable().id();
649         if (id == ID_NULL) {
650             ERR << "Weaken: " << *iter << " not found" << endl;
651         }
652         MIL << "Weaken dependencies of " << *iter << endl;
653         queue_push( &(_jobQueue), SOLVER_WEAKEN_SOLVABLE_DEPS );
654         queue_push( &(_jobQueue), id );
655     }
656
657     // Add rules for parallel installable resolvables with different versions
658     std::set<IdString> parallel = ZConfig::instance().multiversion();
659     for (std::set<IdString>::const_iterator it = parallel.begin(); it != parallel.end(); ++it) {
660         queue_push( &(_jobQueue), SOLVER_NOOBSOLETES_SOLVABLE_NAME );
661         queue_push( &(_jobQueue), it->id() );
662     }
663 }
664
665 void
666 SATResolver::solverEnd()
667 {
668     // cleanup
669     solver_free(_solv);
670     _solv = NULL;
671     queue_free( &(_jobQueue) );
672 }
673
674
675 bool
676 SATResolver::resolvePool(const CapabilitySet & requires_caps,
677                          const CapabilitySet & conflict_caps,
678                          const PoolItemList & weakItems)
679 {
680     MIL << "SATResolver::resolvePool()" << endl;
681
682     // initialize
683     solverInit(weakItems);
684
685     for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
686         Id id = (*iter)->satSolvable().id();
687         if (id == ID_NULL) {
688             ERR << "Install: " << *iter << " not found" << endl;
689         } else {
690             MIL << "Install " << *iter << endl;
691             queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE );
692             queue_push( &(_jobQueue), id );
693         }
694     }
695
696     for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
697         Id id = (*iter)->satSolvable().id();
698         if (id == ID_NULL) {
699             ERR << "Delete: " << *iter << " not found" << endl;
700         } else {
701             MIL << "Delete " << *iter << endl;
702             queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE );
703             queue_push( &(_jobQueue), id);
704         }
705     }
706
707     for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
708         queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE_PROVIDES );
709         queue_push( &(_jobQueue), iter->id() );
710         MIL << "Requires " << *iter << endl;
711     }
712
713     for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
714         queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_PROVIDES);
715         queue_push( &(_jobQueue), iter->id() );
716         MIL << "Conflicts " << *iter << endl;
717     }
718
719     // set requirements for a running system
720     setSystemRequirements();
721
722     // set locks for the solver
723     setLocks();
724
725     // solving
726     bool ret = solving(requires_caps, conflict_caps);
727     // cleanup
728     if (ret)
729         solverEnd(); // remove solver only if no errors happend. Need it for solving problems
730
731     MIL << "SATResolver::resolvePool() done. Ret:" << ret <<  endl;
732     return ret;
733 }
734
735
736 bool
737 SATResolver::resolveQueue(const SolverQueueItemList &requestQueue,
738                           const PoolItemList & weakItems)
739 {
740     MIL << "SATResolver::resolvQueue()" << endl;
741
742     // initialize
743     solverInit(weakItems);
744
745     // generate solver queue
746     for (SolverQueueItemList::const_iterator iter = requestQueue.begin(); iter != requestQueue.end(); iter++) {
747         (*iter)->addRule(_jobQueue);
748     }
749
750     // Add addition item status to the resolve-queue cause these can be set by problem resolutions
751     for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
752         Id id = (*iter)->satSolvable().id();
753         if (id == ID_NULL) {
754             ERR << "Install: " << *iter << " not found" << endl;
755         } else {
756             MIL << "Install " << *iter << endl;
757             queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE );
758             queue_push( &(_jobQueue), id );
759         }
760     }
761     for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
762         sat::detail::IdType ident( (*iter)->satSolvable().ident().id() );
763         MIL << "Delete " << *iter << ident << endl;
764         queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_NAME );
765         queue_push( &(_jobQueue), ident);
766     }
767
768     // set requirements for a running system
769     setSystemRequirements();
770
771     // set locks for the solver
772     setLocks();
773
774     // solving
775     bool ret = solving();
776
777     // cleanup
778     if (ret)
779         solverEnd(); // remove solver only if no errors happend. Need it for solving problems
780
781     MIL << "SATResolver::resolveQueue() done. Ret:" << ret <<  endl;
782     return ret;
783 }
784
785
786 void SATResolver::doUpdate()
787 {
788     MIL << "SATResolver::doUpdate()" << endl;
789
790     // initialize
791     solverInit(PoolItemList());
792
793     // set requirements for a running system
794     setSystemRequirements();
795
796     // set locks for the solver
797     setLocks();
798
799     _solv = solver_create( _SATPool );
800     _solv->vendorCheckCb = &vendorCheck;
801
802     _solv->updatesystem = true;
803     _solv->dontinstallrecommended = true; // #FIXME dontinstallrecommended maybe set to false if it works correctly
804
805     sat::Pool::instance().prepare();
806
807     // Solve !
808     MIL << "Starting solving for update...." << endl;
809     MIL << *this;
810     solver_solve( _solv, &(_jobQueue) );
811     MIL << "....Solver end" << endl;
812
813     // copying solution back to zypp pool
814     //-----------------------------------------
815
816     /*  solvables to be installed */
817     for (int i = 0; i < _solv->decisionq.count; i++)
818     {
819       Id p;
820       p = _solv->decisionq.elements[i];
821       if (p < 0 || !sat::Solvable(p))
822         continue;
823       if (sat::Solvable(p).repository().get() == _solv->installed)
824         continue;
825
826       PoolItem poolItem = _pool.find (sat::Solvable(p));
827       if (poolItem) {
828           SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
829       } else {
830           ERR << "id " << p << " not found in ZYPP pool." << endl;
831       }
832     }
833
834     /* solvables to be erased */
835     for (int i = _solv->installed->start; i < _solv->installed->start + _solv->installed->nsolvables; i++)
836     {
837       if (_solv->decisionmap[i] > 0)
838         continue;
839
840       PoolItem poolItem = _pool.find (sat::Solvable(i));
841       if (poolItem) {
842           // Check if this is an update
843           CheckIfUpdate info;
844           invokeOnEach( _pool.byIdentBegin( poolItem ),
845                         _pool.byIdentEnd( poolItem ),
846                         resfilter::ByUninstalled(),                     // ByUninstalled
847                         functor::functorRef<bool,PoolItem> (info) );
848
849           if (info.is_updated) {
850               SATSolutionToPool (poolItem, ResStatus::toBeUninstalledDueToUpgrade , ResStatus::SOLVER);
851           } else {
852               SATSolutionToPool (poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER);
853           }
854       } else {
855           ERR << "id " << i << " not found in ZYPP pool." << endl;
856       }
857     }
858
859     // cleanup
860     solverEnd();
861
862     MIL << "SATResolver::doUpdate() done" << endl;
863 }
864
865
866
867 //----------------------------------------------------------------------------
868 //----------------------------------------------------------------------------
869 // error handling
870 //----------------------------------------------------------------------------
871 //----------------------------------------------------------------------------
872
873 //----------------------------------------------------------------------------
874 // helper function
875 //----------------------------------------------------------------------------
876
877 struct FindPackage : public resfilter::ResObjectFilterFunctor
878 {
879     ProblemSolutionCombi *problemSolution;
880     TransactionKind action;
881     FindPackage (ProblemSolutionCombi *p, const TransactionKind act)
882        : problemSolution (p)
883        , action (act)
884         {
885         }
886
887     bool operator()( PoolItem p)
888    {
889        problemSolution->addSingleAction (p, action);
890        return true;
891    }
892 };
893
894
895 //----------------------------------------------------------------------------
896 // Checking if this solvable/item has a buddy which reflect the real
897 // user visible description of an item
898 // e.g. The release package has a buddy to the concerning product item.
899 // This user want's the message "Product foo conflicts with product bar" and
900 // NOT "package release-foo conflicts with package release-bar"
901 //----------------------------------------------------------------------------
902
903
904 PoolItem SATResolver::mapItem (const PoolItem &item)
905 {
906     sat::Solvable buddy = item.buddy();
907     if (buddy != sat::Solvable())
908     {
909         return _pool.find (buddy);
910     }
911     else
912     {
913         return item;
914     }
915 }
916
917 sat::Solvable SATResolver::mapSolvable (const Id &id)
918 {
919     PoolItem item = _pool.find (sat::Solvable(id));
920     return mapItem(item).satSolvable();
921 }
922
923 string SATResolver::SATprobleminfoString(Id problem, string &detail, Id &ignoreId)
924 {
925   string ret;
926   Pool *pool = _solv->pool;
927   Id probr;
928   Id dep, source, target;
929   sat::Solvable s, s2;
930
931   ignoreId = 0;
932   probr = solver_findproblemrule(_solv, problem);
933   switch (solver_problemruleinfo(_solv, &(_jobQueue), probr, &dep, &source, &target))
934   {
935       case SOLVER_PROBLEM_DISTUPGRADE_RULE:
936           s = mapSolvable (source);
937           ret = str::form (_("%s does not belong to a distupgrade repository"), solvable2str(pool, s.get()));
938           break;
939       case SOLVER_PROBLEM_INFARCH_RULE:
940           s = mapSolvable (source);
941           ret = str::form (_("%s has inferior architecture"), solvable2str(pool, s.get()));
942           break;
943       case SOLVER_PROBLEM_UPDATE_RULE:
944           s = mapSolvable (source);
945           ret = str::form (_("problem with installed package %s"), solvable2str(pool, s.get()));
946           break;
947       case SOLVER_PROBLEM_JOB_RULE:
948           ret = str::form (_("conflicting requests"));
949           break;
950       case SOLVER_PROBLEM_RPM_RULE:
951           ret = str::form (_("some dependency problem"));
952           break;
953       case SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP:
954           ret = str::form (_("nothing provides requested %s"), dep2str(pool, dep));
955           detail += _("Have you enabled all requested repositories?");
956           break;
957       case SOLVER_PROBLEM_NOT_INSTALLABLE:
958           s = mapSolvable (source);
959           ret = str::form (_("%s is not installable"), solvable2str(pool, s.get()));
960           break;
961       case SOLVER_PROBLEM_NOTHING_PROVIDES_DEP:
962           s = mapSolvable (source);
963           ret = str::form (_("nothing provides %s needed by %s"), dep2str(pool, dep), solvable2str(pool, s.get()));
964           break;
965       case SOLVER_PROBLEM_SAME_NAME:
966           s = mapSolvable (source);
967           s2 = mapSolvable (target);
968           ret = str::form (_("cannot install both %s and %s"), solvable2str(pool, s.get()), solvable2str(pool, s2.get()));
969           break;
970       case SOLVER_PROBLEM_PACKAGE_CONFLICT:
971           s = mapSolvable (source);
972           s2 = mapSolvable (target);
973           ret = str::form (_("%s conflicts with %s provided by %s"), solvable2str(pool, s.get()), dep2str(pool, dep), solvable2str(pool, s2.get()));
974           break;
975       case SOLVER_PROBLEM_PACKAGE_OBSOLETES:
976           s = mapSolvable (source);
977           s2 = mapSolvable (target);
978           ret = str::form (_("%s obsoletes %s provided by %s"), solvable2str(pool, s.get()), dep2str(pool, dep), solvable2str(pool, s2.get()));
979           break;
980       case SOLVER_PROBLEM_SELF_CONFLICT:
981           s = mapSolvable (source);
982           ret = str::form (_("solvable %s conflicts with %s provided by itself"), solvable2str(pool, s.get()), dep2str(pool, dep));
983           break;
984       case SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE:
985           ignoreId = source; // for setting weak dependencies
986           s = mapSolvable (source);
987           Capability cap(dep);
988           sat::WhatProvides possibleProviders(cap);
989
990           // check, if a provider will be deleted
991           typedef list<PoolItem> ProviderList;
992           ProviderList providerlistInstalled, providerlistUninstalled;
993           for_( iter1, possibleProviders.begin(), possibleProviders.end() ) {
994               PoolItem provider1 = ResPool::instance().find( *iter1 );
995               // find pair of an installed/uninstalled item with the same NVR
996               bool found = false;
997               for_( iter2, possibleProviders.begin(), possibleProviders.end() ) {
998                   PoolItem provider2 = ResPool::instance().find( *iter2 );
999                   if (compareByNVR (provider1.resolvable(),provider2.resolvable()) == 0
1000                       && ( (provider1.status().isInstalled() && provider2.status().isUninstalled())
1001                           || (provider2.status().isInstalled() && provider1.status().isUninstalled()) ))  {
1002                       found = true;
1003                       break;
1004                   }
1005               }
1006               if (!found) {
1007                   if (provider1.status().isInstalled())
1008                       providerlistInstalled.push_back(provider1);
1009                   else
1010                       providerlistUninstalled.push_back(provider1);
1011               }
1012           }
1013
1014           ret = str::form (_("%s requires %s, but this requirement cannot be provided"), solvable2str(pool, s.get()), dep2str(pool, dep));
1015           if (providerlistInstalled.size() > 0) {
1016               detail += _("deleted providers: ");
1017               for (ProviderList::const_iterator iter = providerlistInstalled.begin(); iter != providerlistInstalled.end(); iter++) {
1018                   if (iter == providerlistInstalled.begin())
1019                       detail += itemToString (*iter, false);
1020                   else
1021                       detail += "\n                   " + itemToString (mapItem(*iter), false);
1022               }
1023           }
1024           if (providerlistUninstalled.size() > 0) {
1025               if (detail.size() > 0)
1026                   detail += _("\nuninstallable providers: ");
1027               else
1028                   detail = _("uninstallable providers: ");
1029               for (ProviderList::const_iterator iter = providerlistUninstalled.begin(); iter != providerlistUninstalled.end(); iter++) {
1030                   if (iter == providerlistUninstalled.begin())
1031                       detail += itemToString (*iter, false);
1032                   else
1033                       detail += "\n                   " + itemToString (mapItem(*iter), false);
1034               }
1035           }
1036           break;
1037   }
1038
1039   return ret;
1040 }
1041
1042 ResolverProblemList
1043 SATResolver::problems ()
1044 {
1045     ResolverProblemList resolverProblems;
1046     if (_solv && _solv->problems.count) {
1047         Pool *pool = _solv->pool;
1048         int pcnt;
1049         Id p, rp, what;
1050         Id problem, solution, element;
1051         sat::Solvable s, sd;
1052
1053         CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1054         CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1055
1056         MIL << "Encountered problems! Here are the solutions:\n" << endl;
1057         pcnt = 1;
1058         problem = 0;
1059         while ((problem = solver_next_problem(_solv, problem)) != 0) {
1060             MIL << "Problem " <<  pcnt++ << ":" << endl;
1061             MIL << "====================================" << endl;
1062             string detail;
1063             Id ignoreId;
1064             string whatString = SATprobleminfoString (problem,detail,ignoreId);
1065             MIL << whatString << endl;
1066             MIL << "------------------------------------" << endl;
1067             ResolverProblem_Ptr resolverProblem = new ResolverProblem (whatString, detail);
1068
1069             solution = 0;
1070             while ((solution = solver_next_solution(_solv, problem, solution)) != 0) {
1071                 element = 0;
1072                 ProblemSolutionCombi *problemSolution = new ProblemSolutionCombi(resolverProblem);
1073                 while ((element = solver_next_solutionelement(_solv, problem, solution, element, &p, &rp)) != 0) {
1074                     if (p == SOLVER_SOLUTION_JOB) {
1075                         /* job, rp is index into job queue */
1076                         what = _jobQueue.elements[rp];
1077                         switch (_jobQueue.elements[rp-1])
1078                         {
1079                             case SOLVER_INSTALL_SOLVABLE: {
1080                                 s = mapSolvable (what);
1081                                 PoolItem poolItem = _pool.find (s);
1082                                 if (poolItem) {
1083                                     if (_solv->installed && s.get()->repo == _solv->installed) {
1084                                         problemSolution->addSingleAction (poolItem, REMOVE);
1085                                         string description = str::form (_("do not keep %s installed"),  solvable2str(pool, s.get()) );
1086                                         MIL << description << endl;
1087                                         problemSolution->addDescription (description);
1088                                     } else {
1089                                         problemSolution->addSingleAction (poolItem, KEEP);
1090                                         string description = str::form (_("do not install %s"), solvable2str(pool, s.get()));
1091                                         MIL << description << endl;
1092                                         problemSolution->addDescription (description);
1093                                     }
1094                                 } else {
1095                                     ERR << "SOLVER_INSTALL_SOLVABLE: No item found for " << id2str(pool, s.get()->name) << "-"
1096                                         <<  id2str(pool, s.get()->evr) << "." <<  id2str(pool, s.get()->arch) << endl;
1097                                 }
1098                             }
1099                                 break;
1100                             case SOLVER_ERASE_SOLVABLE: {
1101                                 s = mapSolvable (what);
1102                                 PoolItem poolItem = _pool.find (s);
1103                                 if (poolItem) {
1104                                     if (_solv->installed && s.get()->repo == _solv->installed) {
1105                                         problemSolution->addSingleAction (poolItem, KEEP);
1106                                         string description = str::form (_("keep %s"), solvable2str(pool, s.get()));
1107                                         MIL << description << endl;
1108                                         problemSolution->addDescription (description);
1109                                     } else {
1110                                         problemSolution->addSingleAction (poolItem, UNLOCK);
1111                                         string description = str::form (_("do not forbid installation of %s"), itemToString(poolItem, false).c_str());
1112                                         MIL << description << endl;
1113                                         problemSolution->addDescription (description);
1114                                     }
1115                                 } else {
1116                                     ERR << "SOLVER_ERASE_SOLVABLE: No item found for " << id2str(pool, s.get()->name) << "-" <<  id2str(pool, s.get()->evr) << "." <<
1117                                         id2str(pool, s.get()->arch) << endl;
1118                                 }
1119                             }
1120                                 break;
1121                             case SOLVER_INSTALL_SOLVABLE_NAME:
1122                                 {
1123                                 IdString ident( what );
1124                                 SolverQueueItemInstall_Ptr install =
1125                                     new SolverQueueItemInstall(_pool, ident.asString(), false );
1126                                 problemSolution->addSingleAction (install, REMOVE_SOLVE_QUEUE_ITEM);
1127
1128                                 string description = str::form (_("do not install %s"), ident.c_str() );
1129                                 MIL << description << endl;
1130                                 problemSolution->addDescription (description);
1131                                 }
1132                                 break;
1133                             case SOLVER_ERASE_SOLVABLE_NAME:
1134                                 {
1135                                 // As we do not know, if this request has come from resolvePool or
1136                                 // resolveQueue we will have to take care for both cases.
1137                                 IdString ident( what );
1138                                 FindPackage info (problemSolution, KEEP);
1139                                 invokeOnEach( _pool.byIdentBegin( ident ),
1140                                               _pool.byIdentEnd( ident ),
1141                                               functor::chain (resfilter::ByInstalled (),                        // ByInstalled
1142                                                               resfilter::ByTransact ()),                        // will be deinstalled
1143                                               functor::functorRef<bool,PoolItem> (info) );
1144
1145                                 SolverQueueItemDelete_Ptr del =
1146                                     new SolverQueueItemDelete(_pool, ident.asString(), false );
1147                                 problemSolution->addSingleAction (del, REMOVE_SOLVE_QUEUE_ITEM);
1148
1149                                 string description = str::form (_("keep %s"), ident.c_str());
1150                                 MIL << description << endl;
1151                                 problemSolution->addDescription (description);
1152                                 }
1153                                 break;
1154                             case SOLVER_INSTALL_SOLVABLE_PROVIDES:
1155                                 {
1156                                 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_REQUIRE);
1157                                 string description = "";
1158
1159                                 // Checking if this problem solution would break your system
1160                                 if (system_requires.find(Capability(what)) != system_requires.end()) {
1161                                     // Show a better warning
1162                                     resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1163                                     resolverProblem->setDescription(_("This request will break your system!"));
1164                                     description = _("ignore the warning of a broken system");
1165                                 } else {
1166                                     description = str::form (_("do not ask to install a solvable providing %s"), dep2str(pool, what));
1167                                 }
1168                                 MIL << description << endl;
1169                                 problemSolution->addDescription (description);
1170                                 }
1171                                 break;
1172                             case SOLVER_ERASE_SOLVABLE_PROVIDES:
1173                                 {
1174                                 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_CONFLICT);
1175                                 string description = "";
1176
1177                                 // Checking if this problem solution would break your system
1178                                 if (system_conflicts.find(Capability(what)) != system_conflicts.end()) {
1179                                     // Show a better warning
1180                                     resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1181                                     resolverProblem->setDescription(_("This request will break your system!"));
1182                                     description = _("ignore the warning of a broken system");
1183                                 } else {
1184                                     description = str::form (_("do not ask to delete all solvables providing %s"), dep2str(pool, what));
1185                                 }
1186                                 MIL << description << endl;
1187                                 problemSolution->addDescription (description);
1188                                 }
1189                                 break;
1190                             case SOLVER_INSTALL_SOLVABLE_UPDATE:
1191                                 {
1192                                 s = mapSolvable (what);
1193                                 PoolItem poolItem = _pool.find (s);
1194                                 if (poolItem) {
1195                                     if (_solv->installed && s.get()->repo == _solv->installed) {
1196                                         problemSolution->addSingleAction (poolItem, KEEP);
1197                                         string description = str::form (_("do not install most recent version of %s"), solvable2str(pool, s.get()));
1198                                         MIL << description << endl;
1199                                         problemSolution->addDescription (description);
1200                                     } else {
1201                                         ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE " << poolItem << " is not selected for installation" << endl;
1202                                     }
1203                                 } else {
1204                                     ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE: No item found for " << id2str(pool, s.get()->name) << "-" <<  id2str(pool, s.get()->evr) << "." <<
1205                                         id2str(pool, s.get()->arch) << endl;
1206                                 }
1207                                 }
1208                                 break;
1209                             default:
1210                                 MIL << "- do something different" << endl;
1211                                 ERR << "No valid solution available" << endl;
1212                                 break;
1213                         }
1214                     } else if (p == SOLVER_SOLUTION_INFARCH) {
1215                         s = mapSolvable (rp);
1216                         PoolItem poolItem = _pool.find (s);
1217                         if (_solv->installed && s.get()->repo == _solv->installed) {
1218                             problemSolution->addSingleAction (poolItem, KEEP);
1219                             string description = str::form (_("keep %s despite the inferior architecture"), solvable2str(pool, s.get()));
1220                             MIL << description << endl;
1221                             problemSolution->addDescription (description);                          
1222                         } else {
1223                             problemSolution->addSingleAction (poolItem, INSTALL);
1224                             string description = str::form (_("install %s despite the inferior architecture"), solvable2str(pool, s.get()));
1225                             MIL << description << endl;
1226                             problemSolution->addDescription (description);                                                  
1227                         }
1228                     } else if (p == SOLVER_SOLUTION_DISTUPGRADE) {
1229                         s = mapSolvable (rp);
1230                         PoolItem poolItem = _pool.find (s);
1231                         if (_solv->installed && s.get()->repo == _solv->installed) {
1232                             problemSolution->addSingleAction (poolItem, KEEP);
1233                             string description = str::form (_("keep obsolete %s"), solvable2str(pool, s.get()));
1234                             MIL << description << endl;
1235                             problemSolution->addDescription (description);                          
1236                         } else {
1237                             problemSolution->addSingleAction (poolItem, INSTALL);
1238                             string description = str::form (_("install %s from excluded repository"), solvable2str(pool, s.get()));
1239                             MIL << description << endl;
1240                             problemSolution->addDescription (description);                                                                          
1241                         }
1242                     } else {
1243                         /* policy, replace p with rp */
1244                         s = mapSolvable (p);
1245                         if (rp)
1246                             sd = mapSolvable (rp);
1247
1248                         PoolItem itemFrom = _pool.find (s);
1249                         if (s == sd && _solv->distupgrade)
1250                         {
1251                             PoolItem poolItem = _pool.find (s);
1252                             if (poolItem) {
1253                                 problemSolution->addSingleAction (poolItem, LOCK); // for solver reason: NOT weak lock.
1254                                 string description = str::form (_("keep %s"), solvable2str(pool, s.get()));
1255                                 MIL << description << endl;
1256                                 problemSolution->addDescription (description);
1257                             } else {
1258                                 ERR << "SOLVER_INSTALL_SOLVABLE: No item found for " << id2str(pool, s.get()->name) << "-"
1259                                     <<  id2str(pool, s.get()->evr) << "." <<  id2str(pool, s.get()->arch) << endl;
1260                             }
1261                         }
1262                         else if (rp)
1263                         {
1264                             int gotone = 0;
1265
1266                             PoolItem itemTo = _pool.find (sd);
1267                             if (itemFrom && itemTo) {
1268                                 problemSolution->addSingleAction (itemTo, INSTALL);
1269
1270                                 if (evrcmp(pool, s.get()->evr, sd.get()->evr, EVRCMP_COMPARE ) > 0)
1271                                 {
1272                                     string description = str::form (_("downgrade of %s to %s"), solvable2str(pool, s.get()), solvable2str(pool, sd.get()));
1273                                     MIL << description << endl;
1274                                     problemSolution->addDescription (description);
1275                                     gotone = 1;
1276                                 }
1277                                 if (!_solv->allowarchchange && s.get()->name == sd.get()->name && s.get()->arch != sd.get()->arch
1278                                     && policy_illegal_archchange(_solv, s.get(), sd.get()))
1279                                 {
1280                                     string description = str::form (_("architecture change of %s to %s"), solvable2str(pool, s.get()), solvable2str(pool, sd.get()));
1281                                     MIL << description << endl;
1282                                     problemSolution->addDescription (description);
1283                                     gotone = 1;
1284                                 }
1285                                 if (!_solv->allowvendorchange && s.get()->name == sd.get()->name && s.get()->vendor != sd.get()->vendor
1286                                     && policy_illegal_vendorchange(_solv, s.get(), sd.get()))
1287                                 {
1288                                     string description = str::form (_("install %s (with vendor change)\n  %s\n-->\n  %s") ,
1289                                                                     solvable2str(pool, sd.get()) , id2str(pool, s.get()->vendor),
1290                                                                     string(sd.get()->vendor ?  id2str(pool, sd.get()->vendor) : " (no vendor) ").c_str() );
1291                                     MIL << description << endl;
1292                                     problemSolution->addDescription (description);
1293                                     gotone = 1;
1294                                 }
1295                                 if (!gotone) {
1296                                     string description = str::form (_("replacement of %s with %s"), solvable2str(pool, s.get()), solvable2str(pool, sd.get()));
1297                                     MIL << description << endl;
1298                                     problemSolution->addDescription (description);
1299                                 }
1300                             } else {
1301                                 ERR << id2str(pool, s.get()->name) << "-" <<  id2str(pool, s.get()->evr) << "." <<  id2str(pool, s.get()->arch)
1302                                     << " or "  << id2str(pool, sd.get()->name) << "-" <<  id2str(pool, sd.get()->evr) << "." <<  id2str(pool, sd.get()->arch) << " not found" << endl;
1303                             }
1304                         }
1305                         else
1306                         {
1307                             if (itemFrom) {
1308                                 string description = str::form (_("deinstallation of %s"), solvable2str(pool, s.get()));
1309                                 MIL << description << endl;
1310                                 problemSolution->addDescription (description);
1311                                 problemSolution->addSingleAction (itemFrom, REMOVE);
1312                             }
1313                         }
1314                     }
1315                 }
1316                 resolverProblem->addSolution (problemSolution,
1317                                               problemSolution->actionCount() > 1 ? true : false); // Solutions with more than 1 action will be shown first.
1318                 MIL << "------------------------------------" << endl;
1319             }
1320
1321             if (ignoreId > 0) {
1322                 // There is a possibility to ignore this error by setting weak dependencies
1323                 PoolItem item = _pool.find (sat::Solvable(ignoreId));
1324                 ProblemSolutionIgnore *problemSolution = new ProblemSolutionIgnore(resolverProblem, item);
1325                 resolverProblem->addSolution (problemSolution,
1326                                               false); // Solutions will be shown at the end
1327                 MIL << "ignore some dependencies of " << item << endl;
1328                 MIL << "------------------------------------" << endl;
1329             }
1330
1331             // save problem
1332             resolverProblems.push_back (resolverProblem);
1333         }
1334     }
1335     return resolverProblems;
1336 }
1337
1338 void
1339 SATResolver::applySolutions (const ProblemSolutionList & solutions)
1340 {
1341     for (ProblemSolutionList::const_iterator iter = solutions.begin();
1342          iter != solutions.end(); ++iter) {
1343         ProblemSolution_Ptr solution = *iter;
1344         Resolver dummyResolver(_pool);
1345         if (!solution->apply (dummyResolver))
1346             break;
1347     }
1348 }
1349
1350 void SATResolver::setLocks()
1351 {
1352     for (PoolItemList::const_iterator iter = _items_to_lock.begin(); iter != _items_to_lock.end(); iter++) {
1353         sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
1354         if (iter->status().isInstalled()) {
1355             MIL << "Lock installed item " << *iter << endl;
1356             queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE );
1357             queue_push( &(_jobQueue), ident );
1358         } else {
1359             MIL << "Lock NOT installed item " << *iter << endl;
1360             queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE );
1361             queue_push( &(_jobQueue), ident );
1362         }
1363     }
1364
1365     for (PoolItemList::const_iterator iter = _items_to_keep.begin(); iter != _items_to_keep.end(); iter++) {
1366         sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
1367         if (iter->status().isInstalled()) {
1368             MIL << "Keep installed item " << *iter << endl;
1369             queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE | SOLVER_WEAK);
1370             queue_push( &(_jobQueue), ident );
1371         } else {
1372             MIL << "Keep NOT installed item " << *iter << ident << endl;
1373             queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE | SOLVER_WEAK);
1374             queue_push( &(_jobQueue), ident );
1375         }
1376     }
1377 }
1378
1379 void SATResolver::setSystemRequirements()
1380 {
1381     CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1382     CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1383
1384     for (CapabilitySet::const_iterator iter = system_requires.begin(); iter != system_requires.end(); iter++) {
1385         queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE_PROVIDES);
1386         queue_push( &(_jobQueue), iter->id() );
1387         MIL << "SYSTEM Requires " << *iter << endl;
1388     }
1389
1390     for (CapabilitySet::const_iterator iter = system_conflicts.begin(); iter != system_conflicts.end(); iter++) {
1391         queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_PROVIDES);
1392         queue_push( &(_jobQueue), iter->id() );
1393         MIL << "SYSTEM Conflicts " << *iter << endl;
1394     }
1395
1396     // try to prefer none architecture change if possible
1397     // So the architecture of the "rpm" package should be prefered
1398
1399     Capability cap("rpm");
1400     sat::WhatProvides rpmProviders(cap);
1401     for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
1402         if (iter2->isSystem()) {
1403             sat::detail::IdType nid = iter2->ident().id();
1404             nid = rel2id(_SATPool,
1405                          nid,
1406                          iter2->arch().id(), REL_ARCH, true);
1407             if (_distupgrade)
1408             {
1409                 bool addRule = false;
1410                 Capability cap(nid);
1411                 sat::WhatProvides rpmProviders(cap);
1412                 for_( iter3, rpmProviders.begin(), rpmProviders.end() ) {
1413                     if ( !(iter3->isSystem())) {
1414                         addRule = true;
1415                         break;
1416                     }
1417                 }
1418                 if (!addRule)
1419                     break;
1420             }
1421
1422             queue_push(&(_jobQueue), SOLVER_INSTALL|SOLVABLE_NAME|SOLVER_ESSENTIAL);
1423             queue_push(&(_jobQueue), nid);
1424             break;
1425         }
1426     }
1427 }
1428
1429
1430 ///////////////////////////////////////////////////////////////////
1431 };// namespace detail
1432     /////////////////////////////////////////////////////////////////////
1433     /////////////////////////////////////////////////////////////////////
1434   };// namespace solver
1435   ///////////////////////////////////////////////////////////////////////
1436   ///////////////////////////////////////////////////////////////////////
1437 };// namespace zypp
1438 /////////////////////////////////////////////////////////////////////////
1439