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
108 os << " fixsystem = " << _fixsystem << endl;
109 os << " allowdowngrade = " << _allowdowngrade << endl;
110 os << " allowarchchange = " << _allowarchchange << endl;
111 os << " allowvendorchange = " << _allowvendorchange << endl;
112 os << " allowuninstall = " << _allowuninstall << endl;
113 os << " updatesystem = " << _updatesystem << endl;
114 os << " allowvirtualconflicts = " << _allowvirtualconflicts << endl;
115 os << " noupdateprovide = " << _noupdateprovide << endl;
116 os << " dosplitprovides = " << _dosplitprovides << endl;
117 os << " onlyRequires = " << _onlyRequires << endl;
118 return os << "<resolver/>" << endl;
121 //---------------------------------------------------------------------------
123 SATResolver::SATResolver (const ResPool & pool, Pool *SATPool)
128 , _allowdowngrade(false)
129 , _allowarchchange(false)
130 , _allowvendorchange(false)
131 , _allowuninstall(false)
132 , _updatesystem(false)
133 , _allowvirtualconflicts(false)
134 , _noupdateprovide(false)
135 , _dosplitprovides(false)
136 , _onlyRequires(ZConfig::instance().solver_onlyRequires())
142 SATResolver::~SATResolver()
146 //---------------------------------------------------------------------------
150 SATResolver::pool (void) const
157 SATResolver::addPoolItemToInstall (PoolItem item)
160 for (PoolItemList::const_iterator iter = _items_to_remove.begin();
161 iter != _items_to_remove.end(); iter++) {
163 _items_to_remove.remove(*iter);
169 _items_to_install.push_back (item);
170 _items_to_install.unique ();
176 SATResolver::addPoolItemsToInstallFromList (PoolItemList & rl)
178 for (PoolItemList::const_iterator iter = rl.begin(); iter != rl.end(); iter++) {
179 addPoolItemToInstall (*iter);
185 SATResolver::addPoolItemToRemove (PoolItem item)
188 for (PoolItemList::const_iterator iter = _items_to_install.begin();
189 iter != _items_to_install.end(); iter++) {
191 _items_to_install.remove(*iter);
197 _items_to_remove.push_back (item);
198 _items_to_remove.unique ();
204 SATResolver::addPoolItemsToRemoveFromList (PoolItemList & rl)
206 for (PoolItemList::const_iterator iter = rl.begin(); iter != rl.end(); iter++) {
207 addPoolItemToRemove (*iter);
212 SATResolver::addPoolItemToLock (PoolItem item)
214 _items_to_lock.push_back (item);
215 _items_to_lock.unique ();
219 //---------------------------------------------------------------------------
221 // copy marked item from solution back to pool
222 // if data != NULL, set as APPL_LOW (from establishPool())
225 SATSolutionToPool (PoolItem item, const ResStatus & status, const ResStatus::TransactByValue causer)
228 if (triggeredSolution.find(item) != triggeredSolution.end()) {
229 _XDEBUG("SATSolutionToPool(" << item << ") is already in the pool --> skip");
234 triggeredSolution.insert(item);
236 // resetting transaction only
237 item.status().resetTransact (causer);
241 if (status.isToBeInstalled()) {
242 r = item.status().setToBeInstalled (causer);
243 _XDEBUG("SATSolutionToPool(" << item << ", " << status << ") install !" << r);
245 else if (status.isToBeUninstalledDueToUpgrade()) {
246 r = item.status().setToBeUninstalledDueToUpgrade (causer);
247 _XDEBUG("SATSolutionToPool(" << item << ", " << status << ") upgrade !" << r);
249 else if (status.isToBeUninstalled()) {
250 r = item.status().setToBeUninstalled (causer);
251 _XDEBUG("SATSolutionToPool(" << item << ", " << status << ") remove !" << r);
253 else if (status.isRecommended()) {
254 item.status().setRecommended(true);
255 _XDEBUG("SATSolutionToPool(" << item << ", " << status << ") recommended !" << r);
257 else if (status.isSuggested()) {
258 item.status().setSuggested(true);
259 _XDEBUG("SATSolutionToPool(" << item << ", " << status << ") suggested !" << r);
261 _XDEBUG("SATSolutionToPool(" << item << ", " << status << ") unchanged !");
267 //----------------------------------------------------------------------------
268 // helper functions for distupgrade
269 //----------------------------------------------------------------------------
271 bool SATResolver::doesObsoleteItem (PoolItem candidate, PoolItem installed) {
272 Solvable *sCandidate = _SATPool->solvables + candidate.satSolvable().id();
273 ::_Repo *installedRepo = sat::Pool::instance().systemRepo().get();
275 Id p, *pp, obsolete, *obsoleteIt;
277 if ((!installedRepo || sCandidate->repo != installedRepo) && sCandidate->obsoletes) {
278 obsoleteIt = sCandidate->repo->idarraydata + sCandidate->obsoletes;
279 while ((obsolete = *obsoleteIt++) != 0)
281 for (pp = pool_whatprovides(_SATPool, obsolete) ; (p = *pp++) != 0; ) {
282 if (p > 0 && installed.satSolvable().id() == (sat::detail::SolvableIdType)p) {
283 MIL << candidate << " obsoletes " << installed << endl;
292 //----------------------------------------------------------------------------
293 //----------------------------------------------------------------------------
295 //----------------------------------------------------------------------------
296 //----------------------------------------------------------------------------
298 //----------------------------------------------------------------------------
299 // Helper functions for the ZYPP-Pool
300 //----------------------------------------------------------------------------
303 //------------------------------------------------------------------------------------------------------------
304 // This function loops over the pool and grabs all items
305 // It clears all previous bySolver() states also
307 // Every toBeInstalled is passed to zypp::solver:detail::Resolver.addPoolItemToInstall()
308 // Every toBeUninstalled is passed to zypp::solver:detail::Resolver.addPoolItemToRemove()
310 // Solver results must be written back to the pool.
311 //------------------------------------------------------------------------------------------------------------
314 struct SATCollectTransact : public resfilter::PoolItemFilterFunctor
316 SATResolver & resolver;
318 SATCollectTransact (SATResolver & r)
322 bool operator()( PoolItem item ) // only transacts() items go here
324 ResStatus status = item.status();
325 bool by_solver = (status.isBySolver() || status.isByApplLow());
328 _XDEBUG("Resetting " << item );
329 item.status().resetTransact( ResStatus::APPL_LOW );// clear any solver/establish transactions
330 return true; // back out here, dont re-queue former solver result
333 if (status.isToBeInstalled()) {
334 resolver.addPoolItemToInstall(item); // -> install!
336 else if (status.isToBeUninstalled()) {
337 resolver.addPoolItemToRemove(item); // -> remove !
339 else if (status.isLocked()
342 resolver.addPoolItemToLock (item);
350 //----------------------------------------------------------------------------
351 //----------------------------------------------------------------------------
353 //----------------------------------------------------------------------------
354 //----------------------------------------------------------------------------
357 class CheckIfUpdate : public resfilter::PoolItemFilterFunctor
363 : is_updated( false )
366 // check this item will be installed
368 bool operator()( PoolItem item )
370 if (item.status().isToBeInstalled())
381 SATResolver::resolvePool(const CapabilitySet & requires_caps,
382 const CapabilitySet & conflict_caps)
384 SATCollectTransact info (*this);
386 MIL << "SATResolver::resolvePool()" << endl;
392 queue_free( &(_jobQueue) );
395 queue_init( &_jobQueue );
396 _items_to_install.clear();
397 _items_to_remove.clear();
398 _items_to_lock.clear();
400 invokeOnEach ( _pool.begin(), _pool.end(),
401 functor::functorRef<bool,PoolItem>(info) );
403 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
406 Id id = (*iter)->satSolvable().id();
408 ERR << "Install: " << *iter << " not found" << endl;
410 MIL << "Install " << *iter << " with the SAT-Pool ID: " << id << endl;
411 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE );
412 queue_push( &(_jobQueue), id );
415 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
416 sat::detail::IdType ident( (*iter)->satSolvable().ident().id() );
417 MIL << "Delete " << *iter << " with the string ID: " << ident << endl;
418 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_NAME );
419 queue_push( &(_jobQueue), ident);
422 for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
423 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE_PROVIDES );
424 queue_push( &(_jobQueue), iter->id() );
425 MIL << "Requires " << *iter << endl;
428 for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
429 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_PROVIDES);
430 queue_push( &(_jobQueue), iter->id() );
431 MIL << "Conflicts " << *iter << endl;
434 for (PoolItemList::const_iterator iter = _items_to_lock.begin(); iter != _items_to_lock.end(); iter++) {
435 sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
436 if (iter->status().isInstalled()) {
437 MIL << "Lock installed item " << *iter << " with the string ID: " << ident << endl;
438 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE );
439 queue_push( &(_jobQueue), ident );
441 MIL << "Lock NOT installed item " << *iter << " with the string ID: " << ident << endl;
442 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE );
443 queue_push( &(_jobQueue), ident );
447 _solv = solver_create( _SATPool, sat::Pool::instance().systemRepo().get() );
448 _solv->vendorCheckCb = &vendorCheck;
449 _solv->fixsystem = _fixsystem;
450 _solv->updatesystem = _updatesystem;
451 _solv->allowdowngrade = _allowdowngrade;
452 _solv->allowuninstall = _allowuninstall;
453 _solv->allowarchchange = _allowarchchange;
454 _solv->dosplitprovides = _dosplitprovides;
455 _solv->noupdateprovide = _noupdateprovide;
456 _solv->dontinstallrecommended = _onlyRequires;
458 sat::Pool::instance().prepare();
461 MIL << "Starting solving...." << endl;
463 solver_solve( _solv, &(_jobQueue) );
464 MIL << "....Solver end" << endl;
466 // copying solution back to zypp pool
467 //-----------------------------------------
469 if (_solv->problems.count > 0 )
471 ERR << "Solverrun finished with an ERROR" << endl;
475 /* solvables to be installed */
476 for (int i = 0; i < _solv->decisionq.count; i++)
479 p = _solv->decisionq.elements[i];
480 if (p < 0 || !sat::Solvable(p))
482 if (sat::Solvable(p).repository().get() == _solv->installed)
485 PoolItem poolItem = _pool.find (sat::Solvable(p));
487 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
489 ERR << "id " << p << " not found in ZYPP pool." << endl;
493 /* solvables to be erased */
494 for (int i = _solv->installed->start; i < _solv->installed->start + _solv->installed->nsolvables; i++)
496 if (_solv->decisionmap[i] > 0)
499 PoolItem poolItem = _pool.find (sat::Solvable(i));
501 // Check if this is an update
503 invokeOnEach( _pool.byIdentBegin( poolItem ),
504 _pool.byIdentEnd( poolItem ),
505 resfilter::ByUninstalled(), // ByUninstalled
506 functor::functorRef<bool,PoolItem> (info) );
508 if (info.is_updated) {
509 SATSolutionToPool (poolItem, ResStatus::toBeUninstalledDueToUpgrade , ResStatus::SOLVER);
511 SATSolutionToPool (poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER);
514 ERR << "id " << i << " not found in ZYPP pool." << endl;
518 /* solvables which are recommended */
519 for (int i = 0; i < _solv->recommendations.count; i++)
522 p = _solv->recommendations.elements[i];
523 if (p < 0 || !sat::Solvable(p))
526 PoolItem poolItem = _pool.find (sat::Solvable(p));
528 ResStatus status = poolItem.status();
529 status.setRecommended (true);
530 SATSolutionToPool (poolItem, status, ResStatus::SOLVER);
532 ERR << "id " << p << " not found in ZYPP pool." << endl;
536 /* solvables which are suggested */
537 for (int i = 0; i < _solv->suggestions.count; i++)
540 p = _solv->suggestions.elements[i];
541 if (p < 0 || !sat::Solvable(p))
544 PoolItem poolItem = _pool.find (sat::Solvable(p));
546 ResStatus status = poolItem.status();
547 status.setSuggested (true);
548 SATSolutionToPool (poolItem, status, ResStatus::SOLVER);
550 ERR << "id " << p << " not found in ZYPP pool." << endl;
557 queue_free( &(_jobQueue) );
559 MIL << "SATResolver::resolvePool() done" << endl;
564 bool SATResolver::doUpdate()
566 MIL << "SATResolver::doUpdate()" << endl;
572 queue_free( &(_jobQueue) );
575 queue_init( &_jobQueue );
577 _solv = solver_create( _SATPool, sat::Pool::instance().systemRepo().get() );
578 _solv->vendorCheckCb = &vendorCheck;
580 _solv->updatesystem = true;
581 _solv->dontinstallrecommended = true; // #FIXME dontinstallrecommended maybe set to false if it works correctly
583 sat::Pool::instance().prepare();
586 MIL << "Starting solving for update...." << endl;
588 solver_solve( _solv, &(_jobQueue) );
589 MIL << "....Solver end" << endl;
591 // copying solution back to zypp pool
592 //-----------------------------------------
594 /* solvables to be installed */
595 for (int i = 0; i < _solv->decisionq.count; i++)
598 p = _solv->decisionq.elements[i];
599 if (p < 0 || !sat::Solvable(p))
601 if (sat::Solvable(p).repository().get() == _solv->installed)
604 PoolItem poolItem = _pool.find (sat::Solvable(p));
606 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
608 ERR << "id " << p << " not found in ZYPP pool." << endl;
612 /* solvables to be erased */
613 for (int i = _solv->installed->start; i < _solv->installed->start + _solv->installed->nsolvables; i++)
615 if (_solv->decisionmap[i] > 0)
618 PoolItem poolItem = _pool.find (sat::Solvable(i));
620 // Check if this is an update
622 invokeOnEach( _pool.byIdentBegin( poolItem ),
623 _pool.byIdentEnd( poolItem ),
624 resfilter::ByUninstalled(), // ByUninstalled
625 functor::functorRef<bool,PoolItem> (info) );
627 if (info.is_updated) {
628 SATSolutionToPool (poolItem, ResStatus::toBeUninstalledDueToUpgrade , ResStatus::SOLVER);
630 SATSolutionToPool (poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER);
633 ERR << "id " << i << " not found in ZYPP pool." << endl;
640 queue_free( &(_jobQueue) );
642 MIL << "SATResolver::doUpdate() done" << endl;
648 //----------------------------------------------------------------------------
649 //----------------------------------------------------------------------------
651 //----------------------------------------------------------------------------
652 //----------------------------------------------------------------------------
654 //----------------------------------------------------------------------------
656 //----------------------------------------------------------------------------
658 struct FindPackage : public resfilter::ResObjectFilterFunctor
660 ProblemSolutionCombi *problemSolution;
661 TransactionKind action;
662 FindPackage (ProblemSolutionCombi *p, const TransactionKind act)
663 : problemSolution (p)
668 bool operator()( PoolItem p)
670 problemSolution->addSingleAction (p, action);
676 string SATResolver::SATprobleminfoString(Id problem, string &detail)
679 Pool *pool = _solv->pool;
681 Id dep, source, target;
684 probr = solver_findproblemrule(_solv, problem);
685 switch (solver_problemruleinfo(_solv, &(_jobQueue), probr, &dep, &source, &target))
687 case SOLVER_PROBLEM_UPDATE_RULE:
688 s = pool_id2solvable(pool, source);
689 ret = str::form (_("problem with installed package %s"), solvable2str(pool, s));
691 case SOLVER_PROBLEM_JOB_RULE:
692 ret = str::form (_("conflicting requests"));
694 case SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP:
695 ret = str::form (_("nothing provides requested %s"), dep2str(pool, dep));
697 case SOLVER_PROBLEM_NOT_INSTALLABLE:
698 s = pool_id2solvable(pool, source);
699 ret = str::form (_("%s is not installable"), solvable2str(pool, s));
701 case SOLVER_PROBLEM_NOTHING_PROVIDES_DEP:
702 s = pool_id2solvable(pool, source);
703 ret = str::form (_("nothing provides %s needed by %s"), dep2str(pool, dep), solvable2str(pool, s));
705 case SOLVER_PROBLEM_SAME_NAME:
706 s = pool_id2solvable(pool, source);
707 s2 = pool_id2solvable(pool, target);
708 ret = str::form (_("cannot install both %s and %s"), solvable2str(pool, s), solvable2str(pool, s2));
710 case SOLVER_PROBLEM_PACKAGE_CONFLICT:
711 s = pool_id2solvable(pool, source);
712 s2 = pool_id2solvable(pool, target);
713 ret = str::form (_("%s conflicts with %s provided by %s"), solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
715 case SOLVER_PROBLEM_PACKAGE_OBSOLETES:
716 s = pool_id2solvable(pool, source);
717 s2 = pool_id2solvable(pool, target);
718 ret = str::form (_("%s obsoletes %s provided by %s"), solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
720 case SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE:
721 s = pool_id2solvable(pool, source);
723 sat::WhatProvides possibleProviders(cap);
725 // check, if a provider will be deleted
726 typedef list<PoolItem> ProviderList;
727 ProviderList providerlistInstalled, providerlistUninstalled;
728 for_( iter1, possibleProviders.begin(), possibleProviders.end() ) {
729 PoolItem provider1 = ResPool::instance().find( *iter1 );
730 // find pair of an installed/uninstalled item with the same NVR
732 for_( iter2, possibleProviders.begin(), possibleProviders.end() ) {
733 PoolItem provider2 = ResPool::instance().find( *iter2 );
734 if (compareByNVR (provider1.resolvable(),provider2.resolvable()) == 0
735 && ( (provider1.status().isInstalled() && provider2.status().isUninstalled())
736 || (provider2.status().isInstalled() && provider1.status().isUninstalled()) )) {
742 if (provider1.status().isInstalled())
743 providerlistInstalled.push_back(provider1);
745 providerlistUninstalled.push_back(provider1);
749 ret = str::form (_("%s requires %s, but this requirement cannot be provided"), solvable2str(pool, s), dep2str(pool, dep));
750 if (providerlistInstalled.size() > 0) {
751 detail += _("deleted providers: ");
752 for (ProviderList::const_iterator iter = providerlistInstalled.begin(); iter != providerlistInstalled.end(); iter++) {
753 if (iter == providerlistInstalled.begin())
754 detail += itemToString (*iter, false);
756 detail += "\n " + itemToString (*iter, false);
759 if (providerlistUninstalled.size() > 0) {
760 if (detail.size() > 0)
761 detail += _("\nuninstallable providers: ");
763 detail = _("uninstallable providers: ");
764 for (ProviderList::const_iterator iter = providerlistUninstalled.begin(); iter != providerlistUninstalled.end(); iter++) {
765 if (iter == providerlistUninstalled.begin())
766 detail += itemToString (*iter, false);
768 detail += "\n " + itemToString (*iter, false);
778 SATResolver::problems ()
780 ResolverProblemList resolverProblems;
781 if (_solv && _solv->problems.count) {
782 Pool *pool = _solv->pool;
785 Id problem, solution, element;
788 MIL << "Encountered problems! Here are the solutions:\n" << endl;
791 while ((problem = solver_next_problem(_solv, problem)) != 0) {
792 MIL << "Problem " << pcnt++ << ":" << endl;
793 MIL << "====================================" << endl;
795 string whatString = SATprobleminfoString (problem,detail);
796 MIL << whatString << endl;
797 MIL << "------------------------------------" << endl;
798 ResolverProblem_Ptr resolverProblem = new ResolverProblem (whatString, detail);
800 while ((solution = solver_next_solution(_solv, problem, solution)) != 0) {
802 ProblemSolutionCombi *problemSolution = new ProblemSolutionCombi(resolverProblem);
803 while ((element = solver_next_solutionelement(_solv, problem, solution, element, &p, &rp)) != 0) {
805 /* job, rp is index into job queue */
806 what = _jobQueue.elements[rp];
807 switch (_jobQueue.elements[rp-1])
809 case SOLVER_INSTALL_SOLVABLE: {
810 s = pool->solvables + what;
811 PoolItem poolItem = _pool.find (sat::Solvable(what));
813 if (_solv->installed && s->repo == _solv->installed) {
814 problemSolution->addSingleAction (poolItem, REMOVE);
815 string description = str::form (_("do not keep %s installed"), solvable2str(pool, s) );
816 MIL << description << endl;
817 problemSolution->addDescription (description);
819 problemSolution->addSingleAction (poolItem, REMOVE);
820 string description = str::form (_("do not install %s"), solvable2str(pool, s));
821 MIL << description << endl;
822 problemSolution->addDescription (description);
825 ERR << "SOLVER_INSTALL_SOLVABLE: No item found for " << id2str(pool, s->name) << "-"
826 << id2str(pool, s->evr) << "." << id2str(pool, s->arch) << endl;
830 case SOLVER_ERASE_SOLVABLE: {
831 s = pool->solvables + what;
832 PoolItem poolItem = _pool.find (sat::Solvable(what));
834 if (_solv->installed && s->repo == _solv->installed) {
835 problemSolution->addSingleAction (poolItem, KEEP);
836 string description = str::form (_("keep %s"), solvable2str(pool, s));
837 MIL << description << endl;
838 problemSolution->addDescription (description);
840 problemSolution->addSingleAction (poolItem, INSTALL);
841 string description = str::form (_("do not forbid installation of %s"), solvable2str(pool, s));
842 MIL << description << endl;
843 problemSolution->addDescription (description);
846 ERR << "SOLVER_ERASE_SOLVABLE: No item found for " << id2str(pool, s->name) << "-" << id2str(pool, s->evr) << "." <<
847 id2str(pool, s->arch) << endl;
851 case SOLVER_INSTALL_SOLVABLE_NAME:
853 FindPackage info (problemSolution, KEEP);
854 IdString ident( what );
855 invokeOnEach( _pool.byIdentBegin( ident ),
856 _pool.byIdentEnd( ident ),
857 resfilter::ByUninstalled (),
858 functor::functorRef<bool,PoolItem> (info) );
859 string description = str::form (_("do not install %s"), ident.c_str() );
860 MIL << description << endl;
861 problemSolution->addDescription (description);
864 case SOLVER_ERASE_SOLVABLE_NAME:
866 FindPackage info (problemSolution, KEEP);
867 IdString ident( what );
868 invokeOnEach( _pool.byIdentBegin( ident ),
869 _pool.byIdentEnd( ident ),
870 functor::chain (resfilter::ByInstalled (), // ByInstalled
871 resfilter::ByTransact ()), // will be deinstalled
872 functor::functorRef<bool,PoolItem> (info) );
873 string description = str::form (_("keep %s"), ident.c_str());
874 MIL << description << endl;
875 problemSolution->addDescription (description);
878 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
881 FOR_PROVIDES(p, pp, what);
883 PoolItem poolItem = _pool.find (sat::Solvable(p));
884 if (poolItem.status().isToBeInstalled()
885 || poolItem.status().staysUninstalled())
886 problemSolution->addSingleAction (poolItem, KEEP);
888 string description = str::form (_("do not ask to install a solvable providing %s"), dep2str(pool, what));
889 MIL << description << endl;
890 problemSolution->addDescription (description);
893 case SOLVER_ERASE_SOLVABLE_PROVIDES:
896 FOR_PROVIDES(p, pp, what);
898 PoolItem poolItem = _pool.find (sat::Solvable(p));
899 if (poolItem.status().isToBeUninstalled()
900 || poolItem.status().staysInstalled())
901 problemSolution->addSingleAction (poolItem, KEEP);
903 string description = str::form (_("do not ask to delete all solvables providing %s"), dep2str(pool, what));
904 MIL << description << endl;
905 problemSolution->addDescription (description);
908 case SOLVER_INSTALL_SOLVABLE_UPDATE:
910 PoolItem poolItem = _pool.find (sat::Solvable(what));
911 s = pool->solvables + what;
913 if (_solv->installed && s->repo == _solv->installed) {
914 problemSolution->addSingleAction (poolItem, KEEP);
915 string description = str::form (_("do not install most recent version of %s"), solvable2str(pool, s));
916 MIL << description << endl;
917 problemSolution->addDescription (description);
919 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE " << poolItem << " is not selected for installation" << endl;
922 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE: No item found for " << id2str(pool, s->name) << "-" << id2str(pool, s->evr) << "." <<
923 id2str(pool, s->arch) << endl;
928 MIL << "- do something different" << endl;
929 ERR << "No valid solution available" << endl;
933 /* policy, replace p with rp */
934 s = pool->solvables + p;
935 sd = rp ? pool->solvables + rp : 0;
937 PoolItem itemFrom = _pool.find (sat::Solvable(p));
942 PoolItem itemTo = _pool.find (sat::Solvable(rp));
943 if (itemFrom && itemTo) {
944 problemSolution->addSingleAction (itemTo, INSTALL);
946 if (evrcmp(pool, s->evr, sd->evr, EVRCMP_COMPARE ) > 0)
948 string description = str::form (_("downgrade of %s to %s"), solvable2str(pool, s), solvable2str(pool, sd));
949 MIL << description << endl;
950 problemSolution->addDescription (description);
953 if (!_solv->allowarchchange && s->name == sd->name && s->arch != sd->arch && policy_illegal_archchange(_solv, s, sd))
955 string description = str::form (_("architecture change of %s to %s"), solvable2str(pool, s), solvable2str(pool, sd));
956 MIL << description << endl;
957 problemSolution->addDescription (description);
960 if (!_solv->allowvendorchange && s->name == sd->name && s->vendor != sd->vendor && policy_illegal_vendorchange(_solv, s, sd))
962 string description = str::form (_("install %s (with vendor change)\n %s\n-->\n %s") ,
963 solvable2str(pool, sd) , id2str(pool, s->vendor),
964 string(sd->vendor ? id2str(pool, sd->vendor) : " (no vendor) ").c_str() );
965 MIL << description << endl;
966 problemSolution->addDescription (description);
970 string description = str::form (_("replacement of %s with %s"), solvable2str(pool, s), solvable2str(pool, sd));
971 MIL << description << endl;
972 problemSolution->addDescription (description);
975 ERR << id2str(pool, s->name) << "-" << id2str(pool, s->evr) << "." << id2str(pool, s->arch)
976 << " or " << id2str(pool, sd->name) << "-" << id2str(pool, sd->evr) << "." << id2str(pool, sd->arch) << " not found" << endl;
982 string description = str::form (_("deinstallation of %s"), solvable2str(pool, s));
983 MIL << description << endl;
984 problemSolution->addDescription (description);
985 problemSolution->addSingleAction (itemFrom, REMOVE);
990 resolverProblem->addSolution (problemSolution,
991 problemSolution->actionCount() > 1 ? true : false); // Solutions with more than 1 action will be shown first.
992 MIL << "------------------------------------" << endl;
995 resolverProblems.push_back (resolverProblem);
998 return resolverProblems;
1002 SATResolver::applySolutions (const ProblemSolutionList & solutions)
1004 for (ProblemSolutionList::const_iterator iter = solutions.begin();
1005 iter != solutions.end(); ++iter) {
1006 ProblemSolution_Ptr solution = *iter;
1007 Resolver dummyResolver(_pool);
1008 if (!solution->apply (dummyResolver))
1015 ///////////////////////////////////////////////////////////////////
1016 };// namespace detail
1017 /////////////////////////////////////////////////////////////////////
1018 /////////////////////////////////////////////////////////////////////
1019 };// namespace solver
1020 ///////////////////////////////////////////////////////////////////////
1021 ///////////////////////////////////////////////////////////////////////
1023 /////////////////////////////////////////////////////////////////////////