1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
4 * Copyright (C) 2000-2002 Ximian, Inc.
5 * Copyright (C) 2005 SUSE Linux Products GmbH
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.
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.
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
22 #include "zypp/solver/detail/Helper.h"
23 #include "zypp/base/String.h"
24 #include "zypp/Capability.h"
25 #include "zypp/ResStatus.h"
26 #include "zypp/VendorAttr.h"
27 #include "zypp/base/Logger.h"
28 #include "zypp/base/String.h"
29 #include "zypp/base/Gettext.h"
30 #include "zypp/base/Algorithm.h"
31 #include "zypp/ResPool.h"
32 #include "zypp/ResFilters.h"
33 #include "zypp/ZConfig.h"
34 #include "zypp/sat/SATResolver.h"
35 #include "zypp/sat/Pool.h"
36 #include "zypp/sat/WhatProvides.h"
37 #include "zypp/solver/detail/ProblemSolutionCombi.h"
40 #include "satsolver/repo_solv.h"
41 #include "satsolver/poolarch.h"
42 #include "satsolver/evr.h"
43 #include "satsolver/poolvendor.h"
44 #include "satsolver/policy.h"
47 /////////////////////////////////////////////////////////////////////////
49 { ///////////////////////////////////////////////////////////////////////
50 ///////////////////////////////////////////////////////////////////////
52 { /////////////////////////////////////////////////////////////////////
53 /////////////////////////////////////////////////////////////////////
55 { ///////////////////////////////////////////////////////////////////
59 IMPL_PTR_TYPE(SATResolver);
61 static PoolItemSet triggeredSolution; // only the latest state of an item is interesting
62 // for the pool. Documents already inserted items.
64 //---------------------------------------------------------------------------
65 // Callbacks for SAT policies
66 //---------------------------------------------------------------------------
68 int vendorCheck (Pool *pool, Solvable *solvable1, Solvable *solvable2) {
69 // DBG << "vendorCheck: " << id2str(pool, solvable1->vendor) << " <--> " << id2str(pool, solvable1->vendor) << endl;
70 return VendorAttr::instance().equivalent(id2str(pool, solvable1->vendor), id2str(pool, solvable2->vendor)) ? 0:1;
75 itemToString (PoolItem item, bool shortVersion)
80 if (item->kind() != ResTraits<zypp::Package>::kind)
81 os << item->kind() << ':';
84 os << '-' << item->edition();
85 if (item->arch() != "") {
86 os << '.' << item->arch();
88 Repository s = item->repository();
90 string alias = s.info().alias();
92 && alias != "@system")
94 os << '[' << s.info().alias() << ']';
102 //---------------------------------------------------------------------------
105 SATResolver::dumpOn( std::ostream & os ) const
107 return os << "<resolver/>";
110 //---------------------------------------------------------------------------
112 SATResolver::SATResolver (const ResPool & pool, Pool *SATPool)
117 , _allowdowngrade(false)
118 , _allowarchchange(false)
119 , _allowvendorchange(false)
120 , _allowuninstall(false)
121 , _updatesystem(false)
122 , _allowvirtualconflicts(false)
123 , _noupdateprovide(false)
124 , _dosplitprovides(false)
125 , _onlyRequires(ZConfig::instance().solver_onlyRequires())
131 SATResolver::~SATResolver()
135 //---------------------------------------------------------------------------
139 SATResolver::pool (void) const
146 SATResolver::addPoolItemToInstall (PoolItem item)
149 for (PoolItemList::const_iterator iter = _items_to_remove.begin();
150 iter != _items_to_remove.end(); iter++) {
152 _items_to_remove.remove(*iter);
158 _items_to_install.push_back (item);
159 _items_to_install.unique ();
165 SATResolver::addPoolItemsToInstallFromList (PoolItemList & rl)
167 for (PoolItemList::const_iterator iter = rl.begin(); iter != rl.end(); iter++) {
168 addPoolItemToInstall (*iter);
174 SATResolver::addPoolItemToRemove (PoolItem item)
177 for (PoolItemList::const_iterator iter = _items_to_install.begin();
178 iter != _items_to_install.end(); iter++) {
180 _items_to_install.remove(*iter);
186 _items_to_remove.push_back (item);
187 _items_to_remove.unique ();
193 SATResolver::addPoolItemsToRemoveFromList (PoolItemList & rl)
195 for (PoolItemList::const_iterator iter = rl.begin(); iter != rl.end(); iter++) {
196 addPoolItemToRemove (*iter);
201 SATResolver::addPoolItemToLock (PoolItem item)
203 _items_to_lock.push_back (item);
204 _items_to_lock.unique ();
208 //---------------------------------------------------------------------------
210 // copy marked item from solution back to pool
211 // if data != NULL, set as APPL_LOW (from establishPool())
214 SATSolutionToPool (PoolItem item, const ResStatus & status, const ResStatus::TransactByValue causer)
217 if (triggeredSolution.find(item) != triggeredSolution.end()) {
218 _XDEBUG("SATSolutionToPool(" << item << ") is already in the pool --> skip");
223 triggeredSolution.insert(item);
225 // resetting transaction only
226 item.status().resetTransact (causer);
230 if (status.isToBeInstalled()) {
231 r = item.status().setToBeInstalled (causer);
232 _XDEBUG("SATSolutionToPool(" << item << ", " << status << ") install !" << r);
234 else if (status.isToBeUninstalledDueToUpgrade()) {
235 r = item.status().setToBeUninstalledDueToUpgrade (causer);
236 _XDEBUG("SATSolutionToPool(" << item << ", " << status << ") upgrade !" << r);
238 else if (status.isToBeUninstalled()) {
239 r = item.status().setToBeUninstalled (causer);
240 _XDEBUG("SATSolutionToPool(" << item << ", " << status << ") remove !" << r);
242 else if (status.isIncomplete()
243 || status.isNeeded()) {
244 r = item.status().setIncomplete();
245 _XDEBUG("SATSolutionToPool(" << item << ", " << status << ") incomplete !" << r);
247 else if (status.isUnneeded()) {
248 r = item.status().setUnneeded();
249 _XDEBUG("SATSolutionToPool(" << item << ", " << status << ") unneeded !" << r);
251 else if (status.isSatisfied()) {
252 r = item.status().setSatisfied();
253 _XDEBUG("SATSolutionToPool(" << item << ", " << status << ") satisfied !" << r);
255 else if (status.isRecommended()) {
256 item.status().setRecommended(true);
257 _XDEBUG("SATSolutionToPool(" << item << ", " << status << ") recommended !" << r);
259 else if (status.isSuggested()) {
260 item.status().setSuggested(true);
261 _XDEBUG("SATSolutionToPool(" << item << ", " << status << ") suggested !" << r);
263 _XDEBUG("SATSolutionToPool(" << item << ", " << status << ") unchanged !");
269 //----------------------------------------------------------------------------
270 // helper functions for distupgrade
271 //----------------------------------------------------------------------------
273 bool SATResolver::doesObsoleteItem (PoolItem candidate, PoolItem installed) {
274 Solvable *sCandidate = _SATPool->solvables + candidate.satSolvable().id();
275 ::_Repo *installedRepo = sat::Pool::instance().systemRepo().get();
277 Id p, *pp, obsolete, *obsoleteIt;
279 if ((!installedRepo || sCandidate->repo != installedRepo) && sCandidate->obsoletes) {
280 obsoleteIt = sCandidate->repo->idarraydata + sCandidate->obsoletes;
281 while ((obsolete = *obsoleteIt++) != 0)
283 for (pp = pool_whatprovides(_SATPool, obsolete) ; (p = *pp++) != 0; ) {
284 if (p > 0 && installed.satSolvable().id() == (sat::detail::SolvableIdType)p) {
285 MIL << candidate << " obsoletes " << installed << endl;
294 //----------------------------------------------------------------------------
295 //----------------------------------------------------------------------------
297 //----------------------------------------------------------------------------
298 //----------------------------------------------------------------------------
300 //----------------------------------------------------------------------------
301 // Helper functions for the ZYPP-Pool
302 //----------------------------------------------------------------------------
305 //------------------------------------------------------------------------------------------------------------
306 // This function loops over the pool and grabs all items
307 // It clears all previous bySolver() states also
309 // Every toBeInstalled is passed to zypp::solver:detail::Resolver.addPoolItemToInstall()
310 // Every toBeUninstalled is passed to zypp::solver:detail::Resolver.addPoolItemToRemove()
312 // Solver results must be written back to the pool.
313 //------------------------------------------------------------------------------------------------------------
316 struct SATCollectTransact : public resfilter::PoolItemFilterFunctor
318 SATResolver & resolver;
320 SATCollectTransact (SATResolver & r)
324 bool operator()( PoolItem item ) // only transacts() items go here
326 ResStatus status = item.status();
327 bool by_solver = (status.isBySolver() || status.isByApplLow());
330 _XDEBUG("Resetting " << item );
331 item.status().resetTransact( ResStatus::APPL_LOW );// clear any solver/establish transactions
332 return true; // back out here, dont re-queue former solver result
335 if (status.isToBeInstalled()) {
336 resolver.addPoolItemToInstall(item); // -> install!
338 else if (status.isToBeUninstalled()) {
339 resolver.addPoolItemToRemove(item); // -> remove !
341 else if (status.isLocked()
344 resolver.addPoolItemToLock (item);
352 //----------------------------------------------------------------------------
353 //----------------------------------------------------------------------------
355 //----------------------------------------------------------------------------
356 //----------------------------------------------------------------------------
359 class CheckIfUpdate : public resfilter::PoolItemFilterFunctor
365 : is_updated( false )
368 // check this item will be installed
370 bool operator()( PoolItem item )
372 if (item.status().isToBeInstalled())
383 SATResolver::resolvePool(const CapabilitySet & requires_caps,
384 const CapabilitySet & conflict_caps)
386 SATCollectTransact info (*this);
388 MIL << "SATResolver::resolvePool()" << endl;
394 queue_free( &(_jobQueue) );
397 queue_init( &_jobQueue );
398 _items_to_install.clear();
399 _items_to_remove.clear();
400 _items_to_lock.clear();
402 invokeOnEach ( _pool.begin(), _pool.end(),
403 functor::functorRef<bool,PoolItem>(info) );
405 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
408 Id id = (*iter)->satSolvable().id();
410 ERR << "Install: " << *iter << " not found" << endl;
412 MIL << "Install " << *iter << " with the SAT-Pool ID: " << id << endl;
413 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE );
414 queue_push( &(_jobQueue), id );
417 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
418 sat::detail::IdType ident( (*iter)->satSolvable().ident().id() );
419 MIL << "Delete " << *iter << " with the string ID: " << ident << endl;
420 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_NAME );
421 queue_push( &(_jobQueue), ident);
424 for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
425 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE_PROVIDES );
426 queue_push( &(_jobQueue), iter->id() );
427 MIL << "Requires " << *iter << endl;
430 for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
431 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_PROVIDES);
432 queue_push( &(_jobQueue), iter->id() );
433 MIL << "Conflicts " << *iter << endl;
436 for (PoolItemList::const_iterator iter = _items_to_lock.begin(); iter != _items_to_lock.end(); iter++) {
437 sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
438 if (iter->status().isInstalled()) {
439 MIL << "Lock installed item " << *iter << " with the string ID: " << ident << endl;
440 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE );
441 queue_push( &(_jobQueue), ident );
443 MIL << "Lock NOT installed item " << *iter << " with the string ID: " << ident << endl;
444 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE );
445 queue_push( &(_jobQueue), ident );
449 _solv = solver_create( _SATPool, sat::Pool::instance().systemRepo().get() );
450 _solv->vendorCheckCb = &vendorCheck;
451 _solv->fixsystem = _fixsystem;
452 _solv->updatesystem = _updatesystem;
453 _solv->allowdowngrade = _allowdowngrade;
454 _solv->allowuninstall = _allowuninstall;
455 _solv->allowarchchange = _allowarchchange;
456 _solv->dosplitprovides = _dosplitprovides;
457 _solv->noupdateprovide = _noupdateprovide;
458 _solv->dontinstallrecommended = _onlyRequires;
460 sat::Pool::instance().prepare();
463 MIL << "Starting solving...." << endl;
464 solver_solve( _solv, &(_jobQueue) );
465 MIL << "....Solver end" << endl;
467 // copying solution back to zypp pool
468 //-----------------------------------------
470 if (_solv->problems.count > 0 )
472 ERR << "Solverrun finished with an ERROR" << endl;
476 /* solvables to be installed */
477 for (int i = 0; i < _solv->decisionq.count; i++)
480 p = _solv->decisionq.elements[i];
481 if (p < 0 || !sat::Solvable(p))
483 if (sat::Solvable(p).repository().get() == _solv->installed)
486 PoolItem poolItem = _pool.find (sat::Solvable(p));
488 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
490 ERR << "id " << p << " not found in ZYPP pool." << endl;
494 /* solvables to be erased */
495 for (int i = _solv->installed->start; i < _solv->installed->start + _solv->installed->nsolvables; i++)
497 if (_solv->decisionmap[i] > 0)
500 PoolItem poolItem = _pool.find (sat::Solvable(i));
502 // Check if this is an update
504 invokeOnEach( _pool.byIdentBegin( poolItem ),
505 _pool.byIdentEnd( poolItem ),
506 resfilter::ByUninstalled(), // ByUninstalled
507 functor::functorRef<bool,PoolItem> (info) );
509 if (info.is_updated) {
510 SATSolutionToPool (poolItem, ResStatus::toBeUninstalledDueToUpgrade , ResStatus::SOLVER);
512 SATSolutionToPool (poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER);
515 ERR << "id " << i << " not found in ZYPP pool." << endl;
519 /* solvables which are recommended */
520 for (int i = 0; i < _solv->recommendations.count; i++)
523 p = _solv->recommendations.elements[i];
524 if (p < 0 || !sat::Solvable(p))
527 PoolItem poolItem = _pool.find (sat::Solvable(p));
529 SATSolutionToPool (poolItem, ResStatus::recommended, ResStatus::SOLVER);
531 ERR << "id " << p << " not found in ZYPP pool." << endl;
535 /* solvables which are suggested */
536 for (int i = 0; i < _solv->suggestions.count; i++)
539 p = _solv->suggestions.elements[i];
540 if (p < 0 || !sat::Solvable(p))
543 PoolItem poolItem = _pool.find (sat::Solvable(p));
545 SATSolutionToPool (poolItem, ResStatus::suggested, ResStatus::SOLVER);
547 ERR << "id " << p << " not found in ZYPP pool." << endl;
554 queue_free( &(_jobQueue) );
556 MIL << "SATResolver::resolvePool() done" << endl;
561 bool SATResolver::doUpdate()
563 MIL << "SATResolver::doUpdate()" << endl;
569 queue_free( &(_jobQueue) );
572 queue_init( &_jobQueue );
574 _solv = solver_create( _SATPool, sat::Pool::instance().systemRepo().get() );
575 _solv->vendorCheckCb = &vendorCheck;
577 _solv->updatesystem = true;
578 _solv->dontinstallrecommended = true; // #FIXME dontinstallrecommended maybe set to false if it works correctly
580 sat::Pool::instance().prepare();
583 MIL << "Starting solving...." << endl;
584 solver_solve( _solv, &(_jobQueue) );
585 MIL << "....Solver end" << endl;
587 // copying solution back to zypp pool
588 //-----------------------------------------
590 /* solvables to be installed */
591 for (int i = 0; i < _solv->decisionq.count; i++)
594 p = _solv->decisionq.elements[i];
595 if (p < 0 || !sat::Solvable(p))
597 if (sat::Solvable(p).repository().get() == _solv->installed)
600 PoolItem poolItem = _pool.find (sat::Solvable(p));
602 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
604 ERR << "id " << p << " not found in ZYPP pool." << endl;
608 /* solvables to be erased */
609 for (int i = _solv->installed->start; i < _solv->installed->start + _solv->installed->nsolvables; i++)
611 if (_solv->decisionmap[i] > 0)
614 PoolItem poolItem = _pool.find (sat::Solvable(i));
616 // Check if this is an update
618 invokeOnEach( _pool.byIdentBegin( poolItem ),
619 _pool.byIdentEnd( poolItem ),
620 resfilter::ByUninstalled(), // ByUninstalled
621 functor::functorRef<bool,PoolItem> (info) );
623 if (info.is_updated) {
624 SATSolutionToPool (poolItem, ResStatus::toBeUninstalledDueToUpgrade , ResStatus::SOLVER);
626 SATSolutionToPool (poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER);
629 ERR << "id " << i << " not found in ZYPP pool." << endl;
636 queue_free( &(_jobQueue) );
638 MIL << "SATResolver::doUpdate() done" << endl;
644 //----------------------------------------------------------------------------
645 //----------------------------------------------------------------------------
647 //----------------------------------------------------------------------------
648 //----------------------------------------------------------------------------
650 //----------------------------------------------------------------------------
652 //----------------------------------------------------------------------------
654 struct FindPackage : public resfilter::ResObjectFilterFunctor
656 ProblemSolutionCombi *problemSolution;
657 TransactionKind action;
658 FindPackage (ProblemSolutionCombi *p, const TransactionKind act)
659 : problemSolution (p)
664 bool operator()( PoolItem p)
666 problemSolution->addSingleAction (p, action);
672 string SATResolver::SATprobleminfoString(Id problem, string &detail)
675 Pool *pool = _solv->pool;
677 Id dep, source, target;
680 probr = solver_findproblemrule(_solv, problem);
681 switch (solver_problemruleinfo(_solv, &(_jobQueue), probr, &dep, &source, &target))
683 case SOLVER_PROBLEM_UPDATE_RULE:
684 s = pool_id2solvable(pool, source);
685 ret = str::form (_("problem with installed package %s"), solvable2str(pool, s));
687 case SOLVER_PROBLEM_JOB_RULE:
688 ret = str::form (_("conflicting requests"));
690 case SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP:
691 ret = str::form (_("nothing provides requested %s"), dep2str(pool, dep));
693 case SOLVER_PROBLEM_NOT_INSTALLABLE:
694 s = pool_id2solvable(pool, source);
695 ret = str::form (_("%s is not installable"), solvable2str(pool, s));
697 case SOLVER_PROBLEM_NOTHING_PROVIDES_DEP:
698 s = pool_id2solvable(pool, source);
699 ret = str::form (_("nothing provides %s needed by %s"), dep2str(pool, dep), solvable2str(pool, s));
701 case SOLVER_PROBLEM_SAME_NAME:
702 s = pool_id2solvable(pool, source);
703 s2 = pool_id2solvable(pool, target);
704 ret = str::form (_("cannot install both %s and %s"), solvable2str(pool, s), solvable2str(pool, s2));
706 case SOLVER_PROBLEM_PACKAGE_CONFLICT:
707 s = pool_id2solvable(pool, source);
708 s2 = pool_id2solvable(pool, target);
709 ret = str::form (_("%s conflicts with %s provided by %s"), solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
711 case SOLVER_PROBLEM_PACKAGE_OBSOLETES:
712 s = pool_id2solvable(pool, source);
713 s2 = pool_id2solvable(pool, target);
714 ret = str::form (_("%s obsoletes %s provided by %s"), solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
716 case SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE:
717 s = pool_id2solvable(pool, source);
719 sat::WhatProvides possibleProviders(cap);
721 // check, if a provider will be deleted
722 typedef list<PoolItem> ProviderList;
723 ProviderList providerlistInstalled, providerlistUninstalled;
724 for_( iter1, possibleProviders.begin(), possibleProviders.end() ) {
725 PoolItem provider1 = ResPool::instance().find( *iter1 );
726 // find pair of an installed/uninstalled item with the same NVR
728 for_( iter2, possibleProviders.begin(), possibleProviders.end() ) {
729 PoolItem provider2 = ResPool::instance().find( *iter2 );
730 if (compareByNVR (provider1.resolvable(),provider2.resolvable()) == 0
731 && (provider1.status().isInstalled() && provider2.status().isUninstalled()
732 || provider2.status().isInstalled() && provider1.status().isUninstalled())) {
738 if (provider1.status().isInstalled())
739 providerlistInstalled.push_back(provider1);
741 providerlistUninstalled.push_back(provider1);
745 ret = str::form (_("%s requires %s, but this requirement cannot be provided"), solvable2str(pool, s), dep2str(pool, dep));
746 if (providerlistInstalled.size() > 0) {
747 detail += _("deleted providers: ");
748 for (ProviderList::const_iterator iter = providerlistInstalled.begin(); iter != providerlistInstalled.end(); iter++) {
749 if (iter == providerlistInstalled.begin())
750 detail += itemToString (*iter, false);
752 detail += "\n " + itemToString (*iter, false);
755 if (providerlistUninstalled.size() > 0) {
756 if (detail.size() > 0)
757 detail += _("\nuninstallable providers: ");
759 detail = _("uninstallable providers: ");
760 for (ProviderList::const_iterator iter = providerlistUninstalled.begin(); iter != providerlistUninstalled.end(); iter++) {
761 if (iter == providerlistUninstalled.begin())
762 detail += itemToString (*iter, false);
764 detail += "\n " + itemToString (*iter, false);
774 SATResolver::problems ()
776 ResolverProblemList resolverProblems;
777 if (_solv && _solv->problems.count) {
778 Pool *pool = _solv->pool;
781 Id problem, solution, element;
784 MIL << "Encountered problems! Here are the solutions:\n" << endl;
787 while ((problem = solver_next_problem(_solv, problem)) != 0) {
788 MIL << "Problem " << pcnt++ << ":" << endl;
789 MIL << "====================================" << endl;
791 string whatString = SATprobleminfoString (problem,detail);
792 MIL << whatString << endl;
793 MIL << "------------------------------------" << endl;
794 ResolverProblem_Ptr resolverProblem = new ResolverProblem (whatString, detail);
796 while ((solution = solver_next_solution(_solv, problem, solution)) != 0) {
798 ProblemSolutionCombi *problemSolution = new ProblemSolutionCombi(resolverProblem);
799 while ((element = solver_next_solutionelement(_solv, problem, solution, element, &p, &rp)) != 0) {
801 /* job, rp is index into job queue */
802 what = _jobQueue.elements[rp];
803 switch (_jobQueue.elements[rp-1])
805 case SOLVER_INSTALL_SOLVABLE: {
806 s = pool->solvables + what;
807 PoolItem poolItem = _pool.find (sat::Solvable(what));
809 if (_solv->installed && s->repo == _solv->installed) {
810 problemSolution->addSingleAction (poolItem, REMOVE);
811 string description = str::form (_("do not keep %s installed"), solvable2str(pool, s) );
812 MIL << description << endl;
813 problemSolution->addDescription (description);
815 problemSolution->addSingleAction (poolItem, REMOVE);
816 string description = str::form (_("do not install %s"), solvable2str(pool, s));
817 MIL << description << endl;
818 problemSolution->addDescription (description);
821 ERR << "SOLVER_INSTALL_SOLVABLE: No item found for " << id2str(pool, s->name) << "-"
822 << id2str(pool, s->evr) << "." << id2str(pool, s->arch) << endl;
826 case SOLVER_ERASE_SOLVABLE: {
827 s = pool->solvables + what;
828 PoolItem poolItem = _pool.find (sat::Solvable(what));
830 if (_solv->installed && s->repo == _solv->installed) {
831 problemSolution->addSingleAction (poolItem, KEEP);
832 string description = str::form (_("keep %s"), solvable2str(pool, s));
833 MIL << description << endl;
834 problemSolution->addDescription (description);
836 problemSolution->addSingleAction (poolItem, INSTALL);
837 string description = str::form (_("do not forbid installation of %s"), solvable2str(pool, s));
838 MIL << description << endl;
839 problemSolution->addDescription (description);
842 ERR << "SOLVER_ERASE_SOLVABLE: No item found for " << id2str(pool, s->name) << "-" << id2str(pool, s->evr) << "." <<
843 id2str(pool, s->arch) << endl;
847 case SOLVER_INSTALL_SOLVABLE_NAME:
849 FindPackage info (problemSolution, KEEP);
850 IdString ident( what );
851 invokeOnEach( _pool.byIdentBegin( ident ),
852 _pool.byIdentEnd( ident ),
853 resfilter::ByUninstalled (),
854 functor::functorRef<bool,PoolItem> (info) );
855 string description = str::form (_("do not install %s"), ident.c_str() );
856 MIL << description << endl;
857 problemSolution->addDescription (description);
860 case SOLVER_ERASE_SOLVABLE_NAME:
862 FindPackage info (problemSolution, KEEP);
863 IdString ident( what );
864 invokeOnEach( _pool.byIdentBegin( ident ),
865 _pool.byIdentEnd( ident ),
866 functor::chain (resfilter::ByInstalled (), // ByInstalled
867 resfilter::ByTransact ()), // will be deinstalled
868 functor::functorRef<bool,PoolItem> (info) );
869 string description = str::form (_("keep %s"), ident.c_str());
870 MIL << description << endl;
871 problemSolution->addDescription (description);
874 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
877 FOR_PROVIDES(p, pp, what);
879 PoolItem poolItem = _pool.find (sat::Solvable(p));
880 if (poolItem.status().isToBeInstalled()
881 || poolItem.status().staysUninstalled())
882 problemSolution->addSingleAction (poolItem, KEEP);
884 string description = str::form (_("do not ask to install a solvable providing %s"), dep2str(pool, what));
885 MIL << description << endl;
886 problemSolution->addDescription (description);
889 case SOLVER_ERASE_SOLVABLE_PROVIDES:
892 FOR_PROVIDES(p, pp, what);
894 PoolItem poolItem = _pool.find (sat::Solvable(p));
895 if (poolItem.status().isToBeUninstalled()
896 || poolItem.status().staysInstalled())
897 problemSolution->addSingleAction (poolItem, KEEP);
899 string description = str::form (_("do not ask to delete all solvables providing %s"), dep2str(pool, what));
900 MIL << description << endl;
901 problemSolution->addDescription (description);
904 case SOLVER_INSTALL_SOLVABLE_UPDATE:
906 PoolItem poolItem = _pool.find (sat::Solvable(what));
907 s = pool->solvables + what;
909 if (_solv->installed && s->repo == _solv->installed) {
910 problemSolution->addSingleAction (poolItem, KEEP);
911 string description = str::form (_("do not install most recent version of %s"), solvable2str(pool, s));
912 MIL << description << endl;
913 problemSolution->addDescription (description);
915 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE " << poolItem << " is not selected for installation" << endl;
918 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE: No item found for " << id2str(pool, s->name) << "-" << id2str(pool, s->evr) << "." <<
919 id2str(pool, s->arch) << endl;
924 MIL << "- do something different" << endl;
925 ERR << "No valid solution available" << endl;
929 /* policy, replace p with rp */
930 s = pool->solvables + p;
931 sd = rp ? pool->solvables + rp : 0;
933 PoolItem itemFrom = _pool.find (sat::Solvable(p));
938 PoolItem itemTo = _pool.find (sat::Solvable(rp));
939 if (itemFrom && itemTo) {
940 problemSolution->addSingleAction (itemTo, INSTALL);
942 if (evrcmp(pool, s->evr, sd->evr, EVRCMP_COMPARE ) > 0)
944 string description = str::form (_("downgrade of %s to %s"), solvable2str(pool, s), solvable2str(pool, sd));
945 MIL << description << endl;
946 problemSolution->addDescription (description);
949 if (!_solv->allowarchchange && s->name == sd->name && s->arch != sd->arch && policy_illegal_archchange(_solv, s, sd))
951 string description = str::form (_("architecture change of %s to %s"), solvable2str(pool, s), solvable2str(pool, sd));
952 MIL << description << endl;
953 problemSolution->addDescription (description);
956 if (!_solv->allowvendorchange && s->name == sd->name && s->vendor != sd->vendor && policy_illegal_vendorchange(_solv, s, sd))
958 string description = str::form (_("install %s (with vendor change)\n %s\n-->\n %s") ,
959 solvable2str(pool, sd) , id2str(pool, s->vendor),
960 string(sd->vendor ? id2str(pool, sd->vendor) : " (no vendor) ").c_str() );
961 MIL << description << endl;
962 problemSolution->addDescription (description);
966 string description = str::form (_("replacement of %s with %s"), solvable2str(pool, s), solvable2str(pool, sd));
967 MIL << description << endl;
968 problemSolution->addDescription (description);
971 ERR << id2str(pool, s->name) << "-" << id2str(pool, s->evr) << "." << id2str(pool, s->arch)
972 << " or " << id2str(pool, sd->name) << "-" << id2str(pool, sd->evr) << "." << id2str(pool, sd->arch) << " not found" << endl;
978 string description = str::form (_("deinstallation of %s"), solvable2str(pool, s));
979 MIL << description << endl;
980 problemSolution->addDescription (description);
981 problemSolution->addSingleAction (itemFrom, REMOVE);
986 resolverProblem->addSolution (problemSolution,
987 problemSolution->actionCount() > 1 ? true : false); // Solutions with more than 1 action will be shown first.
988 MIL << "------------------------------------" << endl;
991 resolverProblems.push_back (resolverProblem);
994 return resolverProblems;
998 SATResolver::applySolutions (const ProblemSolutionList & solutions)
1000 for (ProblemSolutionList::const_iterator iter = solutions.begin();
1001 iter != solutions.end(); ++iter) {
1002 ProblemSolution_Ptr solution = *iter;
1003 Resolver dummyResolver(_pool);
1004 if (!solution->apply (dummyResolver))
1011 ///////////////////////////////////////////////////////////////////
1012 };// namespace detail
1013 /////////////////////////////////////////////////////////////////////
1014 /////////////////////////////////////////////////////////////////////
1015 };// namespace solver
1016 ///////////////////////////////////////////////////////////////////////
1017 ///////////////////////////////////////////////////////////////////////
1019 /////////////////////////////////////////////////////////////////////////