- solutions: keep/lock will be done by APPL_HIGH. So they will not be
[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()
433 {
434     _solv = solver_create( _SATPool );
435     _solv->vendorCheckCb = &vendorCheck;
436     _solv->fixsystem = _fixsystem;
437     _solv->ignorealreadyrecommended = _ignorealreadyrecommended;
438     _solv->updatesystem = _updatesystem;
439     _solv->allowdowngrade = _allowdowngrade;
440     _solv->allowuninstall = _allowuninstall;
441     _solv->allowarchchange = _allowarchchange;
442     _solv->allowvendorchange = _allowvendorchange;
443     _solv->allowvirtualconflicts = _allowvirtualconflicts;
444     _solv->dosplitprovides = _dosplitprovides;
445     _solv->noupdateprovide = _noupdateprovide;
446     _solv->dontinstallrecommended = _onlyRequires;
447     _solv->distupgrade = _distupgrade;
448     _solv->distupgrade_removeunsupported = _distupgrade_removeunsupported;
449
450     sat::Pool::instance().prepare();
451
452     // Solve !
453     MIL << "Starting solving...." << endl;
454     MIL << *this;
455     solver_solve( _solv, &(_jobQueue) );
456     MIL << "....Solver end" << endl;
457
458     // copying solution back to zypp pool
459     //-----------------------------------------
460     _result_items_to_install.clear();
461     _result_items_to_remove.clear();
462
463     /*  solvables to be installed */
464     for (int i = 0; i < _solv->decisionq.count; i++)
465     {
466       Id p;
467       p = _solv->decisionq.elements[i];
468       if (p < 0 || !sat::Solvable(p) || sat::Solvable(p).isSystem())
469         continue;
470
471       PoolItem poolItem((sat::Solvable(p)));
472       if (poolItem) {
473           SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
474           _result_items_to_install.push_back (poolItem);
475       } else {
476           ERR << "id " << p << " not found in ZYPP pool." << endl;
477       }
478     }
479
480     /* solvables to be erased */
481     Repository systemRepo( sat::Pool::instance().findSystemRepo() ); // don't create if it does not exist
482     for_( it, systemRepo.solvablesBegin(), systemRepo.solvablesEnd() )
483     {
484       if (_solv->decisionmap[it->id()] > 0)
485         continue;
486
487       PoolItem poolItem( *it );
488       // Check if this is an update
489       CheckIfUpdate info;
490       invokeOnEach( _pool.byIdentBegin( poolItem ),
491                     _pool.byIdentEnd( poolItem ),
492                     resfilter::ByUninstalled(),                 // ByUninstalled
493                     functor::functorRef<bool,PoolItem> (info) );
494
495       if (info.is_updated) {
496           SATSolutionToPool (poolItem, ResStatus::toBeUninstalledDueToUpgrade , ResStatus::SOLVER);
497       } else {
498           SATSolutionToPool (poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER);
499       }
500       _result_items_to_remove.push_back (poolItem);
501     }
502
503     /*  solvables which are recommended */
504     for (int i = 0; i < _solv->recommendations.count; i++)
505     {
506       Id p;
507       p = _solv->recommendations.elements[i];
508       if (p < 0 || !sat::Solvable(p))
509         continue;
510
511       PoolItem poolItem = _pool.find (sat::Solvable(p));
512       if (poolItem) {
513           poolItem.status().setRecommended(true);
514           _XDEBUG("SATSolutionToPool(" << poolItem << ") recommended !");
515       } else {
516           ERR << "id " << p << " not found in ZYPP pool." << endl;
517       }
518     }
519
520     /*  solvables which are suggested */
521     for (int i = 0; i < _solv->suggestions.count; i++)
522     {
523       Id p;
524       p = _solv->suggestions.elements[i];
525       if (p < 0 || !sat::Solvable(p))
526         continue;
527
528       PoolItem poolItem = _pool.find (sat::Solvable(p));
529       if (poolItem) {
530           poolItem.status().setSuggested(true);
531           _XDEBUG("SATSolutionToPool(" << poolItem << ") suggested !");
532       } else {
533           ERR << "id " << p << " not found in ZYPP pool." << endl;
534       }
535     }
536
537     _problem_items.clear();
538     /*  solvables which are no longer supported */
539     for (int i = 0; i < _solv->orphaned.count; i++)
540     {
541         Id p;
542         p = _solv->orphaned.elements[i];
543         if (p < 0 || !sat::Solvable(p))
544             continue;
545
546         PoolItem poolItem = _pool.find (sat::Solvable(p));
547         if (poolItem) {
548             _problem_items.push_back(poolItem);
549             _XDEBUG( poolItem << " orphaned !");
550         } else {
551             ERR << "id " << p << " not found in ZYPP pool." << endl;
552         }
553     }
554
555     /* Write validation state back to pool */
556     Map installedmap;
557     Queue flags, solvableQueue;
558
559     queue_init(&flags);
560     queue_init(&solvableQueue);
561
562     CollectNonePackages collectNonePackages(&solvableQueue);
563     invokeOnEach( _pool.begin(),
564                   _pool.end(),
565                   functor::not_c(resfilter::byKind<Package>()), // every solvable BUT packages
566                   functor::functorRef<bool,PoolItem> (collectNonePackages) );
567     solver_create_state_maps(_solv, &installedmap, 0);
568     pool_trivial_installable(_solv->pool, &installedmap, &solvableQueue, &flags);
569     for (int i = 0; i < solvableQueue.count; i++) {
570         PoolItem item = _pool.find (sat::Solvable(solvableQueue.elements[i]));
571         item.status().setUndetermined();
572
573         if (flags.elements[i] == -1) {
574             item.status().setNonRelevant();
575             _XDEBUG("SATSolutionToPool(" << item << " ) nonRelevant !");
576         } else if (flags.elements[i] == 1) {
577             item.status().setSatisfied();
578             _XDEBUG("SATSolutionToPool(" << item << " ) satisfied !");
579         } else if (flags.elements[i] == 0) {
580             item.status().setBroken();
581             _XDEBUG("SATSolutionToPool(" << item << " ) broken !");
582         }
583     }
584
585     if (_solv->problems.count > 0 )
586     {
587         ERR << "Solverrun finished with an ERROR" << endl;
588         return false;
589     }
590
591     map_free(&installedmap);
592     queue_free(&(solvableQueue));
593     queue_free(&flags);
594
595     return true;
596 }
597
598
599 void
600 SATResolver::solverInit(const PoolItemList & weakItems)
601 {
602     SATCollectTransact info (*this);
603
604     MIL << "SATResolver::solverInit()" << endl;
605
606     if (_solv) {
607         // remove old stuff
608         solver_free(_solv);
609         _solv = NULL;
610         queue_free( &(_jobQueue) );
611     }
612
613     queue_init( &_jobQueue );
614     _items_to_install.clear();
615     _items_to_remove.clear();
616     _items_to_lock.clear();
617     _items_to_keep.clear();
618
619     invokeOnEach ( _pool.begin(), _pool.end(),
620                    functor::functorRef<bool,PoolItem>(info) );
621
622     for (PoolItemList::const_iterator iter = weakItems.begin(); iter != weakItems.end(); iter++) {
623         Id id = (*iter)->satSolvable().id();
624         if (id == ID_NULL) {
625             ERR << "Weaken: " << *iter << " not found" << endl;
626         }
627         MIL << "Weaken dependencies of " << *iter << endl;
628         queue_push( &(_jobQueue), SOLVER_WEAKEN_SOLVABLE_DEPS );
629         queue_push( &(_jobQueue), id );
630     }
631
632     // Add rules for parallel installable resolvables with different versions
633     std::set<IdString> parallel = ZConfig::instance().multiversion();
634     for (std::set<IdString>::const_iterator it = parallel.begin(); it != parallel.end(); ++it) {
635         queue_push( &(_jobQueue), SOLVER_NOOBSOLETES_SOLVABLE_NAME );
636         queue_push( &(_jobQueue), it->id() );
637     }
638 }
639
640 void
641 SATResolver::solverEnd()
642 {
643     // cleanup
644     solver_free(_solv);
645     _solv = NULL;
646     queue_free( &(_jobQueue) );
647 }
648
649
650 bool
651 SATResolver::resolvePool(const CapabilitySet & requires_caps,
652                          const CapabilitySet & conflict_caps,
653                          const PoolItemList & weakItems)
654 {
655     MIL << "SATResolver::resolvePool()" << endl;
656
657     // initialize
658     solverInit(weakItems);
659
660     for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
661         Id id = (*iter)->satSolvable().id();
662         if (id == ID_NULL) {
663             ERR << "Install: " << *iter << " not found" << endl;
664         } else {
665             MIL << "Install " << *iter << endl;
666             queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE );
667             queue_push( &(_jobQueue), id );
668         }
669     }
670
671     for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
672         Id id = (*iter)->satSolvable().id();
673         if (id == ID_NULL) {
674             ERR << "Delete: " << *iter << " not found" << endl;
675         } else {
676             MIL << "Delete " << *iter << endl;
677             queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE );
678             queue_push( &(_jobQueue), id);
679         }
680     }
681
682     for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
683         queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE_PROVIDES );
684         queue_push( &(_jobQueue), iter->id() );
685         MIL << "Requires " << *iter << endl;
686     }
687
688     for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
689         queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_PROVIDES);
690         queue_push( &(_jobQueue), iter->id() );
691         MIL << "Conflicts " << *iter << endl;
692     }
693
694     // set requirements for a running system
695     setSystemRequirements();
696
697     // set locks for the solver
698     setLocks();
699
700     // solving
701     bool ret = solving();
702     // cleanup
703     if (ret)
704         solverEnd(); // remove solver only if no errors happend. Need it for solving problems
705
706     MIL << "SATResolver::resolvePool() done. Ret:" << ret <<  endl;
707     return ret;
708 }
709
710
711 bool
712 SATResolver::resolveQueue(const SolverQueueItemList &requestQueue,
713                           const PoolItemList & weakItems)
714 {
715     MIL << "SATResolver::resolvQueue()" << endl;
716
717     // initialize
718     solverInit(weakItems);
719
720     // generate solver queue
721     for (SolverQueueItemList::const_iterator iter = requestQueue.begin(); iter != requestQueue.end(); iter++) {
722         (*iter)->addRule(_jobQueue);
723     }
724
725     // Add addition item status to the resolve-queue cause these can be set by problem resolutions
726     for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
727         Id id = (*iter)->satSolvable().id();
728         if (id == ID_NULL) {
729             ERR << "Install: " << *iter << " not found" << endl;
730         } else {
731             MIL << "Install " << *iter << endl;
732             queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE );
733             queue_push( &(_jobQueue), id );
734         }
735     }
736     for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
737         sat::detail::IdType ident( (*iter)->satSolvable().ident().id() );
738         MIL << "Delete " << *iter << ident << endl;
739         queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_NAME );
740         queue_push( &(_jobQueue), ident);
741     }
742
743     // set requirements for a running system
744     setSystemRequirements();
745
746     // set locks for the solver
747     setLocks();
748
749     // solving
750     bool ret = solving();
751
752     // cleanup
753     if (ret)
754         solverEnd(); // remove solver only if no errors happend. Need it for solving problems
755
756     MIL << "SATResolver::resolveQueue() done. Ret:" << ret <<  endl;
757     return ret;
758 }
759
760
761 void SATResolver::doUpdate()
762 {
763     MIL << "SATResolver::doUpdate()" << endl;
764
765     // initialize
766     solverInit(PoolItemList());
767
768     // set requirements for a running system
769     setSystemRequirements();
770
771     // set locks for the solver
772     void setLocks();
773
774     _solv = solver_create( _SATPool );
775     _solv->vendorCheckCb = &vendorCheck;
776
777     _solv->updatesystem = true;
778     _solv->dontinstallrecommended = true; // #FIXME dontinstallrecommended maybe set to false if it works correctly
779
780     sat::Pool::instance().prepare();
781
782     // Solve !
783     MIL << "Starting solving for update...." << endl;
784     MIL << *this;
785     solver_solve( _solv, &(_jobQueue) );
786     MIL << "....Solver end" << endl;
787
788     // copying solution back to zypp pool
789     //-----------------------------------------
790
791     /*  solvables to be installed */
792     for (int i = 0; i < _solv->decisionq.count; i++)
793     {
794       Id p;
795       p = _solv->decisionq.elements[i];
796       if (p < 0 || !sat::Solvable(p))
797         continue;
798       if (sat::Solvable(p).repository().get() == _solv->installed)
799         continue;
800
801       PoolItem poolItem = _pool.find (sat::Solvable(p));
802       if (poolItem) {
803           SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
804       } else {
805           ERR << "id " << p << " not found in ZYPP pool." << endl;
806       }
807     }
808
809     /* solvables to be erased */
810     for (int i = _solv->installed->start; i < _solv->installed->start + _solv->installed->nsolvables; i++)
811     {
812       if (_solv->decisionmap[i] > 0)
813         continue;
814
815       PoolItem poolItem = _pool.find (sat::Solvable(i));
816       if (poolItem) {
817           // Check if this is an update
818           CheckIfUpdate info;
819           invokeOnEach( _pool.byIdentBegin( poolItem ),
820                         _pool.byIdentEnd( poolItem ),
821                         resfilter::ByUninstalled(),                     // ByUninstalled
822                         functor::functorRef<bool,PoolItem> (info) );
823
824           if (info.is_updated) {
825               SATSolutionToPool (poolItem, ResStatus::toBeUninstalledDueToUpgrade , ResStatus::SOLVER);
826           } else {
827               SATSolutionToPool (poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER);
828           }
829       } else {
830           ERR << "id " << i << " not found in ZYPP pool." << endl;
831       }
832     }
833
834     // cleanup
835     solverEnd();
836
837     MIL << "SATResolver::doUpdate() done" << endl;
838 }
839
840
841
842 //----------------------------------------------------------------------------
843 //----------------------------------------------------------------------------
844 // error handling
845 //----------------------------------------------------------------------------
846 //----------------------------------------------------------------------------
847
848 //----------------------------------------------------------------------------
849 // helper function
850 //----------------------------------------------------------------------------
851
852 struct FindPackage : public resfilter::ResObjectFilterFunctor
853 {
854     ProblemSolutionCombi *problemSolution;
855     TransactionKind action;
856     FindPackage (ProblemSolutionCombi *p, const TransactionKind act)
857        : problemSolution (p)
858        , action (act)
859         {
860         }
861
862     bool operator()( PoolItem p)
863    {
864        problemSolution->addSingleAction (p, action);
865        return true;
866    }
867 };
868
869
870 //----------------------------------------------------------------------------
871 // Checking if this solvable/item has a buddy which reflect the real
872 // user visible description of an item
873 // e.g. The release package has a buddy to the concerning product item.
874 // This user want's the message "Product foo conflicts with product bar" and
875 // NOT "package release-foo conflicts with package release-bar"
876 //----------------------------------------------------------------------------
877
878
879 PoolItem SATResolver::mapItem (const PoolItem &item)
880 {
881     sat::Solvable buddy = item.buddy();
882     if (buddy != sat::Solvable())
883     {
884         return _pool.find (buddy);
885     }
886     else
887     {
888         return item;
889     }
890 }
891
892 sat::Solvable SATResolver::mapSolvable (const Id &id)
893 {
894     PoolItem item = _pool.find (sat::Solvable(id));
895     return mapItem(item).satSolvable();
896 }
897
898 string SATResolver::SATprobleminfoString(Id problem, string &detail, Id &ignoreId)
899 {
900   string ret;
901   Pool *pool = _solv->pool;
902   Id probr;
903   Id dep, source, target;
904   sat::Solvable s, s2;
905
906   ignoreId = 0;
907   probr = solver_findproblemrule(_solv, problem);
908   switch (solver_problemruleinfo(_solv, &(_jobQueue), probr, &dep, &source, &target))
909   {
910       case SOLVER_PROBLEM_UPDATE_RULE:
911           s = mapSolvable (source);
912           ret = str::form (_("problem with installed package %s"), solvable2str(pool, s.get()));
913           break;
914       case SOLVER_PROBLEM_JOB_RULE:
915           ret = str::form (_("conflicting requests"));
916           break;
917       case SOLVER_PROBLEM_RPM_RULE:
918           ret = str::form (_("some dependency problem"));
919           break;
920       case SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP:
921           ret = str::form (_("nothing provides requested %s"), dep2str(pool, dep));
922           detail += _("Have you enabled all requested repositories?");
923           break;
924       case SOLVER_PROBLEM_NOT_INSTALLABLE:
925           s = mapSolvable (source);
926           ret = str::form (_("%s is not installable"), solvable2str(pool, s.get()));
927           break;
928       case SOLVER_PROBLEM_NOTHING_PROVIDES_DEP:
929           s = mapSolvable (source);
930           ret = str::form (_("nothing provides %s needed by %s"), dep2str(pool, dep), solvable2str(pool, s.get()));
931           break;
932       case SOLVER_PROBLEM_SAME_NAME:
933           s = mapSolvable (source);
934           s2 = mapSolvable (target);
935           ret = str::form (_("cannot install both %s and %s"), solvable2str(pool, s.get()), solvable2str(pool, s2.get()));
936           break;
937       case SOLVER_PROBLEM_PACKAGE_CONFLICT:
938           s = mapSolvable (source);
939           s2 = mapSolvable (target);
940           ret = str::form (_("%s conflicts with %s provided by %s"), solvable2str(pool, s.get()), dep2str(pool, dep), solvable2str(pool, s2.get()));
941           break;
942       case SOLVER_PROBLEM_PACKAGE_OBSOLETES:
943           s = mapSolvable (source);
944           s2 = mapSolvable (target);
945           ret = str::form (_("%s obsoletes %s provided by %s"), solvable2str(pool, s.get()), dep2str(pool, dep), solvable2str(pool, s2.get()));
946           break;
947       case SOLVER_PROBLEM_SELF_CONFLICT:
948           s = mapSolvable (source);
949           ret = str::form (_("Solvable %s conflicts with %s provided by itself"), solvable2str(pool, s.get()), dep2str(pool, dep));
950           break;
951       case SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE:
952           ignoreId = source; // for setting weak dependencies
953           s = mapSolvable (source);
954           Capability cap(dep);
955           sat::WhatProvides possibleProviders(cap);
956
957           // check, if a provider will be deleted
958           typedef list<PoolItem> ProviderList;
959           ProviderList providerlistInstalled, providerlistUninstalled;
960           for_( iter1, possibleProviders.begin(), possibleProviders.end() ) {
961               PoolItem provider1 = ResPool::instance().find( *iter1 );
962               // find pair of an installed/uninstalled item with the same NVR
963               bool found = false;
964               for_( iter2, possibleProviders.begin(), possibleProviders.end() ) {
965                   PoolItem provider2 = ResPool::instance().find( *iter2 );
966                   if (compareByNVR (provider1.resolvable(),provider2.resolvable()) == 0
967                       && ( (provider1.status().isInstalled() && provider2.status().isUninstalled())
968                           || (provider2.status().isInstalled() && provider1.status().isUninstalled()) ))  {
969                       found = true;
970                       break;
971                   }
972               }
973               if (!found) {
974                   if (provider1.status().isInstalled())
975                       providerlistInstalled.push_back(provider1);
976                   else
977                       providerlistUninstalled.push_back(provider1);
978               }
979           }
980
981           ret = str::form (_("%s requires %s, but this requirement cannot be provided"), solvable2str(pool, s.get()), dep2str(pool, dep));
982           if (providerlistInstalled.size() > 0) {
983               detail += _("deleted providers: ");
984               for (ProviderList::const_iterator iter = providerlistInstalled.begin(); iter != providerlistInstalled.end(); iter++) {
985                   if (iter == providerlistInstalled.begin())
986                       detail += itemToString (*iter, false);
987                   else
988                       detail += "\n                   " + itemToString (mapItem(*iter), false);
989               }
990           }
991           if (providerlistUninstalled.size() > 0) {
992               if (detail.size() > 0)
993                   detail += _("\nuninstallable providers: ");
994               else
995                   detail = _("uninstallable providers: ");
996               for (ProviderList::const_iterator iter = providerlistUninstalled.begin(); iter != providerlistUninstalled.end(); iter++) {
997                   if (iter == providerlistUninstalled.begin())
998                       detail += itemToString (*iter, false);
999                   else
1000                       detail += "\n                   " + itemToString (mapItem(*iter), false);
1001               }
1002           }
1003           break;
1004   }
1005
1006   return ret;
1007 }
1008
1009 ResolverProblemList
1010 SATResolver::problems ()
1011 {
1012     ResolverProblemList resolverProblems;
1013     if (_solv && _solv->problems.count) {
1014         Pool *pool = _solv->pool;
1015         int pcnt;
1016         Id p, rp, what;
1017         Id problem, solution, element;
1018         sat::Solvable s, sd;
1019
1020         CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1021         CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1022
1023         MIL << "Encountered problems! Here are the solutions:\n" << endl;
1024         pcnt = 1;
1025         problem = 0;
1026         while ((problem = solver_next_problem(_solv, problem)) != 0) {
1027             MIL << "Problem " <<  pcnt++ << ":" << endl;
1028             MIL << "====================================" << endl;
1029             string detail;
1030             Id ignoreId;
1031             string whatString = SATprobleminfoString (problem,detail,ignoreId);
1032             MIL << whatString << endl;
1033             MIL << "------------------------------------" << endl;
1034             ResolverProblem_Ptr resolverProblem = new ResolverProblem (whatString, detail);
1035
1036             solution = 0;
1037             while ((solution = solver_next_solution(_solv, problem, solution)) != 0) {
1038                 element = 0;
1039                 ProblemSolutionCombi *problemSolution = new ProblemSolutionCombi(resolverProblem);
1040                 while ((element = solver_next_solutionelement(_solv, problem, solution, element, &p, &rp)) != 0) {
1041                     if (p == 0) {
1042                         /* job, rp is index into job queue */
1043                         what = _jobQueue.elements[rp];
1044                         switch (_jobQueue.elements[rp-1])
1045                         {
1046                             case SOLVER_INSTALL_SOLVABLE: {
1047                                 s = mapSolvable (what);
1048                                 PoolItem poolItem = _pool.find (s);
1049                                 if (poolItem) {
1050                                     if (_solv->installed && s.get()->repo == _solv->installed) {
1051                                         problemSolution->addSingleAction (poolItem, REMOVE);
1052                                         string description = str::form (_("do not keep %s installed"),  solvable2str(pool, s.get()) );
1053                                         MIL << description << endl;
1054                                         problemSolution->addDescription (description);
1055                                     } else {
1056                                         problemSolution->addSingleAction (poolItem, KEEP);
1057                                         string description = str::form (_("do not install %s"), solvable2str(pool, s.get()));
1058                                         MIL << description << endl;
1059                                         problemSolution->addDescription (description);
1060                                     }
1061                                 } else {
1062                                     ERR << "SOLVER_INSTALL_SOLVABLE: No item found for " << id2str(pool, s.get()->name) << "-"
1063                                         <<  id2str(pool, s.get()->evr) << "." <<  id2str(pool, s.get()->arch) << endl;
1064                                 }
1065                             }
1066                                 break;
1067                             case SOLVER_ERASE_SOLVABLE: {
1068                                 s = mapSolvable (what);
1069                                 PoolItem poolItem = _pool.find (s);
1070                                 if (poolItem) {
1071                                     if (_solv->installed && s.get()->repo == _solv->installed) {
1072                                         problemSolution->addSingleAction (poolItem, KEEP);
1073                                         string description = str::form (_("keep %s"), solvable2str(pool, s.get()));
1074                                         MIL << description << endl;
1075                                         problemSolution->addDescription (description);
1076                                     } else {
1077                                         problemSolution->addSingleAction (poolItem, UNLOCK);
1078                                         string description = str::form (_("do not forbid installation of %s"), itemToString(poolItem, false).c_str());
1079                                         MIL << description << endl;
1080                                         problemSolution->addDescription (description);
1081                                     }
1082                                 } else {
1083                                     ERR << "SOLVER_ERASE_SOLVABLE: No item found for " << id2str(pool, s.get()->name) << "-" <<  id2str(pool, s.get()->evr) << "." <<
1084                                         id2str(pool, s.get()->arch) << endl;
1085                                 }
1086                             }
1087                                 break;
1088                             case SOLVER_INSTALL_SOLVABLE_NAME:
1089                                 {
1090                                 IdString ident( what );
1091                                 SolverQueueItemInstall_Ptr install =
1092                                     new SolverQueueItemInstall(_pool, ident.asString(), false );
1093                                 problemSolution->addSingleAction (install, REMOVE_SOLVE_QUEUE_ITEM);
1094
1095                                 string description = str::form (_("do not install %s"), ident.c_str() );
1096                                 MIL << description << endl;
1097                                 problemSolution->addDescription (description);
1098                                 }
1099                                 break;
1100                             case SOLVER_ERASE_SOLVABLE_NAME:
1101                                 {
1102                                 // As we do not know, if this request has come from resolvePool or
1103                                 // resolveQueue we will have to take care for both cases.
1104                                 IdString ident( what );
1105                                 FindPackage info (problemSolution, KEEP);
1106                                 invokeOnEach( _pool.byIdentBegin( ident ),
1107                                               _pool.byIdentEnd( ident ),
1108                                               functor::chain (resfilter::ByInstalled (),                        // ByInstalled
1109                                                               resfilter::ByTransact ()),                        // will be deinstalled
1110                                               functor::functorRef<bool,PoolItem> (info) );
1111
1112                                 SolverQueueItemDelete_Ptr del =
1113                                     new SolverQueueItemDelete(_pool, ident.asString(), false );
1114                                 problemSolution->addSingleAction (del, REMOVE_SOLVE_QUEUE_ITEM);
1115
1116                                 string description = str::form (_("keep %s"), ident.c_str());
1117                                 MIL << description << endl;
1118                                 problemSolution->addDescription (description);
1119                                 }
1120                                 break;
1121                             case SOLVER_INSTALL_SOLVABLE_PROVIDES:
1122                                 {
1123                                 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_REQUIRE);
1124                                 string description = "";
1125
1126                                 // Checking if this problem solution would break your system
1127                                 if (system_requires.find(Capability(what)) != system_requires.end()) {
1128                                     // Show a better warning
1129                                     resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1130                                     resolverProblem->setDescription(_("This request will break your system!"));
1131                                     description = _("ignore the warning of a broken system");
1132                                 } else {
1133                                     description = str::form (_("do not ask to install a solvable providing %s"), dep2str(pool, what));
1134                                 }
1135                                 MIL << description << endl;
1136                                 problemSolution->addDescription (description);
1137                                 }
1138                                 break;
1139                             case SOLVER_ERASE_SOLVABLE_PROVIDES:
1140                                 {
1141                                 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_CONFLICT);
1142                                 string description = "";
1143
1144                                 // Checking if this problem solution would break your system
1145                                 if (system_conflicts.find(Capability(what)) != system_conflicts.end()) {
1146                                     // Show a better warning
1147                                     resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1148                                     resolverProblem->setDescription(_("This request will break your system!"));
1149                                     description = _("ignore the warning of a broken system");
1150                                 } else {
1151                                     description = str::form (_("do not ask to delete all solvables providing %s"), dep2str(pool, what));
1152                                 }
1153                                 MIL << description << endl;
1154                                 problemSolution->addDescription (description);
1155                                 }
1156                                 break;
1157                             case SOLVER_INSTALL_SOLVABLE_UPDATE:
1158                                 {
1159                                 s = mapSolvable (what);
1160                                 PoolItem poolItem = _pool.find (s);
1161                                 if (poolItem) {
1162                                     if (_solv->installed && s.get()->repo == _solv->installed) {
1163                                         problemSolution->addSingleAction (poolItem, KEEP);
1164                                         string description = str::form (_("do not install most recent version of %s"), solvable2str(pool, s.get()));
1165                                         MIL << description << endl;
1166                                         problemSolution->addDescription (description);
1167                                     } else {
1168                                         ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE " << poolItem << " is not selected for installation" << endl;
1169                                     }
1170                                 } else {
1171                                     ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE: No item found for " << id2str(pool, s.get()->name) << "-" <<  id2str(pool, s.get()->evr) << "." <<
1172                                         id2str(pool, s.get()->arch) << endl;
1173                                 }
1174                                 }
1175                                 break;
1176                             default:
1177                                 MIL << "- do something different" << endl;
1178                                 ERR << "No valid solution available" << endl;
1179                                 break;
1180                         }
1181                     } else {
1182                         /* policy, replace p with rp */
1183                         s = mapSolvable (p);
1184                         if (rp)
1185                             sd = mapSolvable (rp);
1186
1187                         PoolItem itemFrom = _pool.find (s);
1188                         if (s == sd && _solv->distupgrade)
1189                         {
1190                             PoolItem poolItem = _pool.find (s);
1191                             if (poolItem) {
1192                                 problemSolution->addSingleAction (poolItem, LOCK); // for solver reason: NOT weak lock.
1193                                 string description = str::form (_("keep %s"), solvable2str(pool, s.get()));
1194                                 MIL << description << endl;
1195                                 problemSolution->addDescription (description);
1196                             } else {
1197                                 ERR << "SOLVER_INSTALL_SOLVABLE: No item found for " << id2str(pool, s.get()->name) << "-"
1198                                     <<  id2str(pool, s.get()->evr) << "." <<  id2str(pool, s.get()->arch) << endl;
1199                             }
1200                         }
1201                         else if (rp)
1202                         {
1203                             int gotone = 0;
1204
1205                             PoolItem itemTo = _pool.find (sd);
1206                             if (itemFrom && itemTo) {
1207                                 problemSolution->addSingleAction (itemTo, INSTALL);
1208
1209                                 if (evrcmp(pool, s.get()->evr, sd.get()->evr, EVRCMP_COMPARE ) > 0)
1210                                 {
1211                                     string description = str::form (_("downgrade of %s to %s"), solvable2str(pool, s.get()), solvable2str(pool, sd.get()));
1212                                     MIL << description << endl;
1213                                     problemSolution->addDescription (description);
1214                                     gotone = 1;
1215                                 }
1216                                 if (!_solv->allowarchchange && s.get()->name == sd.get()->name && s.get()->arch != sd.get()->arch
1217                                     && policy_illegal_archchange(_solv, s.get(), sd.get()))
1218                                 {
1219                                     string description = str::form (_("architecture change of %s to %s"), solvable2str(pool, s.get()), solvable2str(pool, sd.get()));
1220                                     MIL << description << endl;
1221                                     problemSolution->addDescription (description);
1222                                     gotone = 1;
1223                                 }
1224                                 if (!_solv->allowvendorchange && s.get()->name == sd.get()->name && s.get()->vendor != sd.get()->vendor
1225                                     && policy_illegal_vendorchange(_solv, s.get(), sd.get()))
1226                                 {
1227                                     string description = str::form (_("install %s (with vendor change)\n  %s\n-->\n  %s") ,
1228                                                                     solvable2str(pool, sd.get()) , id2str(pool, s.get()->vendor),
1229                                                                     string(sd.get()->vendor ?  id2str(pool, sd.get()->vendor) : " (no vendor) ").c_str() );
1230                                     MIL << description << endl;
1231                                     problemSolution->addDescription (description);
1232                                     gotone = 1;
1233                                 }
1234                                 if (!gotone) {
1235                                     string description = str::form (_("replacement of %s with %s"), solvable2str(pool, s.get()), solvable2str(pool, sd.get()));
1236                                     MIL << description << endl;
1237                                     problemSolution->addDescription (description);
1238                                 }
1239                             } else {
1240                                 ERR << id2str(pool, s.get()->name) << "-" <<  id2str(pool, s.get()->evr) << "." <<  id2str(pool, s.get()->arch)
1241                                     << " or "  << id2str(pool, sd.get()->name) << "-" <<  id2str(pool, sd.get()->evr) << "." <<  id2str(pool, sd.get()->arch) << " not found" << endl;
1242                             }
1243                         }
1244                         else
1245                         {
1246                             if (itemFrom) {
1247                                 string description = str::form (_("deinstallation of %s"), solvable2str(pool, s.get()));
1248                                 MIL << description << endl;
1249                                 problemSolution->addDescription (description);
1250                                 problemSolution->addSingleAction (itemFrom, REMOVE);
1251                             }
1252                         }
1253                     }
1254                 }
1255                 resolverProblem->addSolution (problemSolution,
1256                                               problemSolution->actionCount() > 1 ? true : false); // Solutions with more than 1 action will be shown first.
1257                 MIL << "------------------------------------" << endl;
1258             }
1259
1260             if (ignoreId > 0) {
1261                 // There is a possibility to ignore this error by setting weak dependencies
1262                 PoolItem item = _pool.find (sat::Solvable(ignoreId));
1263                 ProblemSolutionIgnore *problemSolution = new ProblemSolutionIgnore(resolverProblem, item);
1264                 resolverProblem->addSolution (problemSolution,
1265                                               false); // Solutions will be shown at the end
1266                 MIL << "Ignore some dependencies of " << item << endl;
1267                 MIL << "------------------------------------" << endl;
1268             }
1269
1270             // save problem
1271             resolverProblems.push_back (resolverProblem);
1272         }
1273     }
1274     return resolverProblems;
1275 }
1276
1277 void
1278 SATResolver::applySolutions (const ProblemSolutionList & solutions)
1279 {
1280     for (ProblemSolutionList::const_iterator iter = solutions.begin();
1281          iter != solutions.end(); ++iter) {
1282         ProblemSolution_Ptr solution = *iter;
1283         Resolver dummyResolver(_pool);
1284         if (!solution->apply (dummyResolver))
1285             break;
1286     }
1287 }
1288
1289 void SATResolver::setLocks()
1290 {
1291     for (PoolItemList::const_iterator iter = _items_to_lock.begin(); iter != _items_to_lock.end(); iter++) {
1292         sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
1293         if (iter->status().isInstalled()) {
1294             MIL << "Lock installed item " << *iter << endl;
1295             queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE );
1296             queue_push( &(_jobQueue), ident );
1297         } else {
1298             MIL << "Lock NOT installed item " << *iter << endl;
1299             queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE );
1300             queue_push( &(_jobQueue), ident );
1301         }
1302     }
1303
1304     for (PoolItemList::const_iterator iter = _items_to_keep.begin(); iter != _items_to_keep.end(); iter++) {
1305         sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
1306         if (iter->status().isInstalled()) {
1307             MIL << "Keep installed item " << *iter << endl;
1308             queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE | SOLVER_WEAK);
1309             queue_push( &(_jobQueue), ident );
1310         } else {
1311             MIL << "Keep NOT installed item " << *iter << ident << endl;
1312             queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE | SOLVER_WEAK);
1313             queue_push( &(_jobQueue), ident );
1314         }
1315     }
1316 }
1317
1318 void SATResolver::setSystemRequirements()
1319 {
1320     CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1321     CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1322
1323     for (CapabilitySet::const_iterator iter = system_requires.begin(); iter != system_requires.end(); iter++) {
1324         queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE_PROVIDES );
1325         queue_push( &(_jobQueue), iter->id() );
1326         MIL << "SYSTEM Requires " << *iter << endl;
1327     }
1328
1329     for (CapabilitySet::const_iterator iter = system_conflicts.begin(); iter != system_conflicts.end(); iter++) {
1330         queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_PROVIDES);
1331         queue_push( &(_jobQueue), iter->id() );
1332         MIL << "SYSTEM Conflicts " << *iter << endl;
1333     }
1334 }
1335
1336
1337 ///////////////////////////////////////////////////////////////////
1338 };// namespace detail
1339     /////////////////////////////////////////////////////////////////////
1340     /////////////////////////////////////////////////////////////////////
1341   };// namespace solver
1342   ///////////////////////////////////////////////////////////////////////
1343   ///////////////////////////////////////////////////////////////////////
1344 };// namespace zypp
1345 /////////////////////////////////////////////////////////////////////////
1346