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