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