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"
45 #include "satsolver/bitmap.h"
48 /////////////////////////////////////////////////////////////////////////
50 { ///////////////////////////////////////////////////////////////////////
51 ///////////////////////////////////////////////////////////////////////
53 { /////////////////////////////////////////////////////////////////////
54 /////////////////////////////////////////////////////////////////////
56 { ///////////////////////////////////////////////////////////////////
60 IMPL_PTR_TYPE(SATResolver);
62 //---------------------------------------------------------------------------
63 // Callbacks for SAT policies
64 //---------------------------------------------------------------------------
66 int vendorCheck (Pool *pool, Solvable *solvable1, Solvable *solvable2) {
67 // DBG << "vendorCheck: " << id2str(pool, solvable1->vendor) << " <--> " << id2str(pool, solvable1->vendor) << endl;
68 return VendorAttr::instance().equivalent(id2str(pool, solvable1->vendor), id2str(pool, solvable2->vendor)) ? 0:1;
73 itemToString (PoolItem item, bool shortVersion)
78 if (item->kind() != ResTraits<zypp::Package>::kind)
79 os << item->kind() << ':';
82 os << '-' << item->edition();
83 if (item->arch() != "") {
84 os << '.' << item->arch();
86 Repository s = item->repository();
88 string alias = s.info().alias();
90 && alias != "@system")
92 os << '[' << s.info().alias() << ']';
100 //---------------------------------------------------------------------------
103 SATResolver::dumpOn( std::ostream & os ) const
106 os << " fixsystem = " << _fixsystem << endl;
107 os << " allowdowngrade = " << _allowdowngrade << endl;
108 os << " allowarchchange = " << _allowarchchange << endl;
109 os << " allowvendorchange = " << _allowvendorchange << endl;
110 os << " allowuninstall = " << _allowuninstall << endl;
111 os << " updatesystem = " << _updatesystem << endl;
112 os << " allowvirtualconflicts = " << _allowvirtualconflicts << endl;
113 os << " noupdateprovide = " << _noupdateprovide << endl;
114 os << " dosplitprovides = " << _dosplitprovides << endl;
115 os << " onlyRequires = " << _onlyRequires << endl;
116 return os << "<resolver/>" << endl;
119 //---------------------------------------------------------------------------
121 SATResolver::SATResolver (const ResPool & pool, Pool *SATPool)
126 , _allowdowngrade(false)
127 , _allowarchchange(false)
128 , _allowvendorchange(false)
129 , _allowuninstall(false)
130 , _updatesystem(false)
131 , _allowvirtualconflicts(false)
132 , _noupdateprovide(false)
133 , _dosplitprovides(false)
134 , _onlyRequires(ZConfig::instance().solver_onlyRequires())
140 SATResolver::~SATResolver()
144 //---------------------------------------------------------------------------
148 SATResolver::pool (void) const
155 SATResolver::resetItemTransaction (PoolItem item)
158 for (PoolItemList::const_iterator iter = _items_to_remove.begin();
159 iter != _items_to_remove.end(); iter++) {
161 _items_to_remove.remove(*iter);
167 for (PoolItemList::const_iterator iter = _items_to_install.begin();
168 iter != _items_to_install.end(); iter++) {
170 _items_to_install.remove(*iter);
177 for (PoolItemList::const_iterator iter = _items_to_keep.begin();
178 iter != _items_to_keep.end(); iter++) {
180 _items_to_keep.remove(*iter);
187 for (PoolItemList::const_iterator iter = _items_to_lock.begin();
188 iter != _items_to_lock.end(); iter++) {
190 _items_to_lock.remove(*iter);
197 for (PoolItemList::const_iterator iter = _items_to_update.begin();
198 iter != _items_to_update.end(); iter++) {
200 _items_to_update.remove(*iter);
210 SATResolver::addPoolItemToInstall (PoolItem item)
212 resetItemTransaction (item);
213 _items_to_install.push_back (item);
214 _items_to_install.unique ();
219 SATResolver::addPoolItemsToInstallFromList (PoolItemList & rl)
221 for (PoolItemList::const_iterator iter = rl.begin(); iter != rl.end(); iter++) {
222 addPoolItemToInstall (*iter);
228 SATResolver::addPoolItemToRemove (PoolItem item)
230 resetItemTransaction (item);
231 _items_to_remove.push_back (item);
232 _items_to_remove.unique ();
237 SATResolver::addPoolItemsToRemoveFromList (PoolItemList & rl)
239 for (PoolItemList::const_iterator iter = rl.begin(); iter != rl.end(); iter++) {
240 addPoolItemToRemove (*iter);
245 SATResolver::addPoolItemToLock (PoolItem item)
247 resetItemTransaction (item);
248 _items_to_lock.push_back (item);
249 _items_to_lock.unique ();
253 SATResolver::addPoolItemToKeep (PoolItem item)
255 resetItemTransaction (item);
256 _items_to_keep.push_back (item);
257 _items_to_keep.unique ();
260 //---------------------------------------------------------------------------
262 // copy marked item from solution back to pool
263 // if data != NULL, set as APPL_LOW (from establishPool())
266 SATSolutionToPool (PoolItem item, const ResStatus & status, const ResStatus::TransactByValue causer)
269 item.status().resetTransact (causer);
270 item.status().resetWeak ();
274 // installation/deletion
275 if (status.isToBeInstalled()) {
276 r = item.status().setToBeInstalled (causer);
277 _XDEBUG("SATSolutionToPool(" << item << ", " << status << ") install !" << r);
279 else if (status.isToBeUninstalledDueToUpgrade()) {
280 r = item.status().setToBeUninstalledDueToUpgrade (causer);
281 _XDEBUG("SATSolutionToPool(" << item << ", " << status << ") upgrade !" << r);
283 else if (status.isToBeUninstalled()) {
284 r = item.status().setToBeUninstalled (causer);
285 _XDEBUG("SATSolutionToPool(" << item << ", " << status << ") remove !" << r);
289 if (status.isRecommended()) {
290 item.status().setRecommended(true);
291 _XDEBUG("SATSolutionToPool(" << item << ", " << status << ") recommended !" << r);
293 else if (status.isSuggested()) {
294 item.status().setSuggested(true);
295 _XDEBUG("SATSolutionToPool(" << item << ", " << status << ") suggested !" << r);
302 //----------------------------------------------------------------------------
303 // helper functions for distupgrade
304 //----------------------------------------------------------------------------
306 bool SATResolver::doesObsoleteItem (PoolItem candidate, PoolItem installed) {
307 Solvable *sCandidate = _SATPool->solvables + candidate.satSolvable().id();
308 ::_Repo *installedRepo = sat::Pool::instance().systemRepo().get();
310 Id p, *pp, obsolete, *obsoleteIt;
312 if ((!installedRepo || sCandidate->repo != installedRepo) && sCandidate->obsoletes) {
313 obsoleteIt = sCandidate->repo->idarraydata + sCandidate->obsoletes;
314 while ((obsolete = *obsoleteIt++) != 0)
316 for (pp = pool_whatprovides(_SATPool, obsolete) ; (p = *pp++) != 0; ) {
317 if (p > 0 && installed.satSolvable().id() == (sat::detail::SolvableIdType)p) {
318 MIL << candidate << " obsoletes " << installed << endl;
327 //----------------------------------------------------------------------------
328 //----------------------------------------------------------------------------
330 //----------------------------------------------------------------------------
331 //----------------------------------------------------------------------------
333 //----------------------------------------------------------------------------
334 // Helper functions for the ZYPP-Pool
335 //----------------------------------------------------------------------------
338 //------------------------------------------------------------------------------------------------------------
339 // This function loops over the pool and grabs all items
340 // It clears all previous bySolver() states also
342 // Every toBeInstalled is passed to zypp::solver:detail::Resolver.addPoolItemToInstall()
343 // Every toBeUninstalled is passed to zypp::solver:detail::Resolver.addPoolItemToRemove()
345 // Solver results must be written back to the pool.
346 //------------------------------------------------------------------------------------------------------------
349 struct SATCollectTransact : public resfilter::PoolItemFilterFunctor
351 SATResolver & resolver;
353 SATCollectTransact (SATResolver & r)
357 bool operator()( PoolItem item ) // only transacts() items go here
359 ResStatus status = item.status();
360 bool by_solver = (status.isBySolver() || status.isByApplLow());
363 _XDEBUG("Resetting " << item );
364 item.status().resetTransact( ResStatus::APPL_LOW );// clear any solver/establish transactions
365 return true; // back out here, dont re-queue former solver result
368 if (status.isToBeInstalled()) {
369 resolver.addPoolItemToInstall(item); // -> install!
371 else if (status.isToBeUninstalled()) {
372 resolver.addPoolItemToRemove(item); // -> remove !
374 else if (status.isLocked()
376 resolver.addPoolItemToLock (item);
378 else if (status.isKept()
380 resolver.addPoolItemToKeep (item);
388 //----------------------------------------------------------------------------
389 //----------------------------------------------------------------------------
391 //----------------------------------------------------------------------------
392 //----------------------------------------------------------------------------
395 class CheckIfUpdate : public resfilter::PoolItemFilterFunctor
401 : is_updated( false )
404 // check this item will be installed
406 bool operator()( PoolItem item )
408 if (item.status().isToBeInstalled())
418 class SetValidate : public resfilter::PoolItemFilterFunctor
421 Map installedmap, conflictsmap;
423 SetValidate(Solver *solv)
425 solver_create_state_maps(solv, &installedmap, &conflictsmap);
430 bool operator()( PoolItem item )
432 int ret = solvable_trivial_installable_map(item.satSolvable().get(), &installedmap, &conflictsmap);
433 item.status().setUndetermined();
436 item.status().setNonRelevant();
437 _XDEBUG("SATSolutionToPool(" << item << " ) nonRelevant !");
438 } else if (ret == 1) {
439 item.status().setSatisfied();
440 _XDEBUG("SATSolutionToPool(" << item << " ) satisfied !");
441 } else if (ret == 0) {
442 item.status().setBroken();
443 _XDEBUG("SATSolutionToPool(" << item << " ) broken !");
451 SATResolver::resolvePool(const CapabilitySet & requires_caps,
452 const CapabilitySet & conflict_caps)
454 SATCollectTransact info (*this);
456 MIL << "SATResolver::resolvePool()" << endl;
462 queue_free( &(_jobQueue) );
465 queue_init( &_jobQueue );
466 _items_to_install.clear();
467 _items_to_remove.clear();
468 _items_to_lock.clear();
469 _items_to_keep.clear();
471 invokeOnEach ( _pool.begin(), _pool.end(),
472 functor::functorRef<bool,PoolItem>(info) );
474 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
477 Id id = (*iter)->satSolvable().id();
479 ERR << "Install: " << *iter << " not found" << endl;
481 MIL << "Install " << *iter << " with the SAT-Pool ID: " << id << endl;
482 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE );
483 queue_push( &(_jobQueue), id );
486 for (PoolItemList::const_iterator iter = _items_to_update.begin(); iter != _items_to_update.end(); iter++) {
489 Id id = (*iter)->satSolvable().id();
491 ERR << "Update explicit: " << *iter << " not found" << endl;
493 MIL << "Update explicit " << *iter << " with the SAT-Pool ID: " << id << endl;
494 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE_UPDATE );
495 queue_push( &(_jobQueue), id );
498 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
499 sat::detail::IdType ident( (*iter)->satSolvable().ident().id() );
500 MIL << "Delete " << *iter << " with the string ID: " << ident << endl;
501 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_NAME );
502 queue_push( &(_jobQueue), ident);
505 for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
506 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE_PROVIDES );
507 queue_push( &(_jobQueue), iter->id() );
508 MIL << "Requires " << *iter << endl;
511 for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
512 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_PROVIDES);
513 queue_push( &(_jobQueue), iter->id() );
514 MIL << "Conflicts " << *iter << endl;
517 for (PoolItemList::const_iterator iter = _items_to_lock.begin(); iter != _items_to_lock.end(); iter++) {
518 sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
519 if (iter->status().isInstalled()) {
520 MIL << "Lock installed item " << *iter << " with the string ID: " << ident << endl;
521 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE );
522 queue_push( &(_jobQueue), ident );
524 MIL << "Lock NOT installed item " << *iter << " with the string ID: " << ident << endl;
525 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE );
526 queue_push( &(_jobQueue), ident );
530 for (PoolItemList::const_iterator iter = _items_to_keep.begin(); iter != _items_to_keep.end(); iter++) {
531 sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
532 if (iter->status().isInstalled()) {
533 MIL << "Keep installed item " << *iter << " with the string ID: " << ident << endl;
534 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE | SOLVER_WEAK);
535 queue_push( &(_jobQueue), ident );
537 MIL << "Keep NOT installed item " << *iter << " with the string ID: " << ident << endl;
538 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE | SOLVER_WEAK);
539 queue_push( &(_jobQueue), ident );
543 _solv = solver_create( _SATPool, sat::Pool::instance().systemRepo().get() );
544 _solv->vendorCheckCb = &vendorCheck;
545 _solv->fixsystem = _fixsystem;
546 _solv->updatesystem = _updatesystem;
547 _solv->allowdowngrade = _allowdowngrade;
548 _solv->allowuninstall = _allowuninstall;
549 _solv->allowarchchange = _allowarchchange;
550 _solv->dosplitprovides = _dosplitprovides;
551 _solv->noupdateprovide = _noupdateprovide;
552 _solv->dontinstallrecommended = _onlyRequires;
554 sat::Pool::instance().prepare();
557 MIL << "Starting solving...." << endl;
559 solver_solve( _solv, &(_jobQueue) );
560 MIL << "....Solver end" << endl;
562 // copying solution back to zypp pool
563 //-----------------------------------------
565 if (_solv->problems.count > 0 )
567 ERR << "Solverrun finished with an ERROR" << endl;
571 /* solvables to be installed */
572 for (int i = 0; i < _solv->decisionq.count; i++)
575 p = _solv->decisionq.elements[i];
576 if (p < 0 || !sat::Solvable(p))
578 if (sat::Solvable(p).repository().get() == _solv->installed)
581 PoolItem poolItem = _pool.find (sat::Solvable(p));
583 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
585 ERR << "id " << p << " not found in ZYPP pool." << endl;
589 /* solvables to be erased */
590 for (int i = _solv->installed->start; i < _solv->installed->start + _solv->installed->nsolvables; i++)
592 if (_solv->decisionmap[i] > 0)
595 PoolItem poolItem = _pool.find (sat::Solvable(i));
597 // Check if this is an update
599 invokeOnEach( _pool.byIdentBegin( poolItem ),
600 _pool.byIdentEnd( poolItem ),
601 resfilter::ByUninstalled(), // ByUninstalled
602 functor::functorRef<bool,PoolItem> (info) );
604 if (info.is_updated) {
605 SATSolutionToPool (poolItem, ResStatus::toBeUninstalledDueToUpgrade , ResStatus::SOLVER);
607 SATSolutionToPool (poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER);
610 ERR << "id " << i << " not found in ZYPP pool." << endl;
614 /* solvables which are recommended */
615 for (int i = 0; i < _solv->recommendations.count; i++)
618 p = _solv->recommendations.elements[i];
619 if (p < 0 || !sat::Solvable(p))
622 PoolItem poolItem = _pool.find (sat::Solvable(p));
624 ResStatus status = poolItem.status();
625 status.setRecommended (true);
626 SATSolutionToPool (poolItem, status, ResStatus::SOLVER);
628 ERR << "id " << p << " not found in ZYPP pool." << endl;
632 /* solvables which are suggested */
633 for (int i = 0; i < _solv->suggestions.count; i++)
636 p = _solv->suggestions.elements[i];
637 if (p < 0 || !sat::Solvable(p))
640 PoolItem poolItem = _pool.find (sat::Solvable(p));
642 ResStatus status = poolItem.status();
643 status.setSuggested (true);
644 SATSolutionToPool (poolItem, status, ResStatus::SOLVER);
646 ERR << "id " << p << " not found in ZYPP pool." << endl;
650 /* Write validation state back to pool */
651 SetValidate infoValidate(_solv);
652 invokeOnEach( _pool.begin(),
654 functor::not_c(resfilter::byKind<Package>()), // every solvable BUT packages
655 functor::functorRef<bool,PoolItem> (infoValidate) );
660 queue_free( &(_jobQueue) );
662 MIL << "SATResolver::resolvePool() done" << endl;
667 bool SATResolver::doUpdate()
669 MIL << "SATResolver::doUpdate()" << endl;
675 queue_free( &(_jobQueue) );
678 queue_init( &_jobQueue );
680 _solv = solver_create( _SATPool, sat::Pool::instance().systemRepo().get() );
681 _solv->vendorCheckCb = &vendorCheck;
683 _solv->updatesystem = true;
684 _solv->dontinstallrecommended = true; // #FIXME dontinstallrecommended maybe set to false if it works correctly
686 sat::Pool::instance().prepare();
689 MIL << "Starting solving for update...." << endl;
691 solver_solve( _solv, &(_jobQueue) );
692 MIL << "....Solver end" << endl;
694 // copying solution back to zypp pool
695 //-----------------------------------------
697 /* solvables to be installed */
698 for (int i = 0; i < _solv->decisionq.count; i++)
701 p = _solv->decisionq.elements[i];
702 if (p < 0 || !sat::Solvable(p))
704 if (sat::Solvable(p).repository().get() == _solv->installed)
707 PoolItem poolItem = _pool.find (sat::Solvable(p));
709 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
711 ERR << "id " << p << " not found in ZYPP pool." << endl;
715 /* solvables to be erased */
716 for (int i = _solv->installed->start; i < _solv->installed->start + _solv->installed->nsolvables; i++)
718 if (_solv->decisionmap[i] > 0)
721 PoolItem poolItem = _pool.find (sat::Solvable(i));
723 // Check if this is an update
725 invokeOnEach( _pool.byIdentBegin( poolItem ),
726 _pool.byIdentEnd( poolItem ),
727 resfilter::ByUninstalled(), // ByUninstalled
728 functor::functorRef<bool,PoolItem> (info) );
730 if (info.is_updated) {
731 SATSolutionToPool (poolItem, ResStatus::toBeUninstalledDueToUpgrade , ResStatus::SOLVER);
733 SATSolutionToPool (poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER);
736 ERR << "id " << i << " not found in ZYPP pool." << endl;
743 queue_free( &(_jobQueue) );
745 MIL << "SATResolver::doUpdate() done" << endl;
751 //----------------------------------------------------------------------------
752 //----------------------------------------------------------------------------
754 //----------------------------------------------------------------------------
755 //----------------------------------------------------------------------------
757 //----------------------------------------------------------------------------
759 //----------------------------------------------------------------------------
761 struct FindPackage : public resfilter::ResObjectFilterFunctor
763 ProblemSolutionCombi *problemSolution;
764 TransactionKind action;
765 FindPackage (ProblemSolutionCombi *p, const TransactionKind act)
766 : problemSolution (p)
771 bool operator()( PoolItem p)
773 problemSolution->addSingleAction (p, action);
779 string SATResolver::SATprobleminfoString(Id problem, string &detail)
782 Pool *pool = _solv->pool;
784 Id dep, source, target;
787 probr = solver_findproblemrule(_solv, problem);
788 switch (solver_problemruleinfo(_solv, &(_jobQueue), probr, &dep, &source, &target))
790 case SOLVER_PROBLEM_UPDATE_RULE:
791 s = pool_id2solvable(pool, source);
792 ret = str::form (_("problem with installed package %s"), solvable2str(pool, s));
794 case SOLVER_PROBLEM_JOB_RULE:
795 ret = str::form (_("conflicting requests"));
797 case SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP:
798 ret = str::form (_("nothing provides requested %s"), dep2str(pool, dep));
800 case SOLVER_PROBLEM_NOT_INSTALLABLE:
801 s = pool_id2solvable(pool, source);
802 ret = str::form (_("%s is not installable"), solvable2str(pool, s));
804 case SOLVER_PROBLEM_NOTHING_PROVIDES_DEP:
805 s = pool_id2solvable(pool, source);
806 ret = str::form (_("nothing provides %s needed by %s"), dep2str(pool, dep), solvable2str(pool, s));
808 case SOLVER_PROBLEM_SAME_NAME:
809 s = pool_id2solvable(pool, source);
810 s2 = pool_id2solvable(pool, target);
811 ret = str::form (_("cannot install both %s and %s"), solvable2str(pool, s), solvable2str(pool, s2));
813 case SOLVER_PROBLEM_PACKAGE_CONFLICT:
814 s = pool_id2solvable(pool, source);
815 s2 = pool_id2solvable(pool, target);
816 ret = str::form (_("%s conflicts with %s provided by %s"), solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
818 case SOLVER_PROBLEM_PACKAGE_OBSOLETES:
819 s = pool_id2solvable(pool, source);
820 s2 = pool_id2solvable(pool, target);
821 ret = str::form (_("%s obsoletes %s provided by %s"), solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
823 case SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE:
824 s = pool_id2solvable(pool, source);
826 sat::WhatProvides possibleProviders(cap);
828 // check, if a provider will be deleted
829 typedef list<PoolItem> ProviderList;
830 ProviderList providerlistInstalled, providerlistUninstalled;
831 for_( iter1, possibleProviders.begin(), possibleProviders.end() ) {
832 PoolItem provider1 = ResPool::instance().find( *iter1 );
833 // find pair of an installed/uninstalled item with the same NVR
835 for_( iter2, possibleProviders.begin(), possibleProviders.end() ) {
836 PoolItem provider2 = ResPool::instance().find( *iter2 );
837 if (compareByNVR (provider1.resolvable(),provider2.resolvable()) == 0
838 && ( (provider1.status().isInstalled() && provider2.status().isUninstalled())
839 || (provider2.status().isInstalled() && provider1.status().isUninstalled()) )) {
845 if (provider1.status().isInstalled())
846 providerlistInstalled.push_back(provider1);
848 providerlistUninstalled.push_back(provider1);
852 ret = str::form (_("%s requires %s, but this requirement cannot be provided"), solvable2str(pool, s), dep2str(pool, dep));
853 if (providerlistInstalled.size() > 0) {
854 detail += _("deleted providers: ");
855 for (ProviderList::const_iterator iter = providerlistInstalled.begin(); iter != providerlistInstalled.end(); iter++) {
856 if (iter == providerlistInstalled.begin())
857 detail += itemToString (*iter, false);
859 detail += "\n " + itemToString (*iter, false);
862 if (providerlistUninstalled.size() > 0) {
863 if (detail.size() > 0)
864 detail += _("\nuninstallable providers: ");
866 detail = _("uninstallable providers: ");
867 for (ProviderList::const_iterator iter = providerlistUninstalled.begin(); iter != providerlistUninstalled.end(); iter++) {
868 if (iter == providerlistUninstalled.begin())
869 detail += itemToString (*iter, false);
871 detail += "\n " + itemToString (*iter, false);
881 SATResolver::problems ()
883 ResolverProblemList resolverProblems;
884 if (_solv && _solv->problems.count) {
885 Pool *pool = _solv->pool;
888 Id problem, solution, element;
891 MIL << "Encountered problems! Here are the solutions:\n" << endl;
894 while ((problem = solver_next_problem(_solv, problem)) != 0) {
895 MIL << "Problem " << pcnt++ << ":" << endl;
896 MIL << "====================================" << endl;
898 string whatString = SATprobleminfoString (problem,detail);
899 MIL << whatString << endl;
900 MIL << "------------------------------------" << endl;
901 ResolverProblem_Ptr resolverProblem = new ResolverProblem (whatString, detail);
903 while ((solution = solver_next_solution(_solv, problem, solution)) != 0) {
905 ProblemSolutionCombi *problemSolution = new ProblemSolutionCombi(resolverProblem);
906 while ((element = solver_next_solutionelement(_solv, problem, solution, element, &p, &rp)) != 0) {
908 /* job, rp is index into job queue */
909 what = _jobQueue.elements[rp];
910 switch (_jobQueue.elements[rp-1])
912 case SOLVER_INSTALL_SOLVABLE: {
913 s = pool->solvables + what;
914 PoolItem poolItem = _pool.find (sat::Solvable(what));
916 if (_solv->installed && s->repo == _solv->installed) {
917 problemSolution->addSingleAction (poolItem, REMOVE);
918 string description = str::form (_("do not keep %s installed"), solvable2str(pool, s) );
919 MIL << description << endl;
920 problemSolution->addDescription (description);
922 problemSolution->addSingleAction (poolItem, REMOVE);
923 string description = str::form (_("do not install %s"), solvable2str(pool, s));
924 MIL << description << endl;
925 problemSolution->addDescription (description);
928 ERR << "SOLVER_INSTALL_SOLVABLE: No item found for " << id2str(pool, s->name) << "-"
929 << id2str(pool, s->evr) << "." << id2str(pool, s->arch) << endl;
933 case SOLVER_ERASE_SOLVABLE: {
934 s = pool->solvables + what;
935 PoolItem poolItem = _pool.find (sat::Solvable(what));
937 if (_solv->installed && s->repo == _solv->installed) {
938 problemSolution->addSingleAction (poolItem, KEEP);
939 string description = str::form (_("keep %s"), solvable2str(pool, s));
940 MIL << description << endl;
941 problemSolution->addDescription (description);
943 problemSolution->addSingleAction (poolItem, INSTALL);
944 string description = str::form (_("do not forbid installation of %s"), solvable2str(pool, s));
945 MIL << description << endl;
946 problemSolution->addDescription (description);
949 ERR << "SOLVER_ERASE_SOLVABLE: No item found for " << id2str(pool, s->name) << "-" << id2str(pool, s->evr) << "." <<
950 id2str(pool, s->arch) << endl;
954 case SOLVER_INSTALL_SOLVABLE_NAME:
956 FindPackage info (problemSolution, KEEP);
957 IdString ident( what );
958 invokeOnEach( _pool.byIdentBegin( ident ),
959 _pool.byIdentEnd( ident ),
960 resfilter::ByUninstalled (),
961 functor::functorRef<bool,PoolItem> (info) );
962 string description = str::form (_("do not install %s"), ident.c_str() );
963 MIL << description << endl;
964 problemSolution->addDescription (description);
967 case SOLVER_ERASE_SOLVABLE_NAME:
969 FindPackage info (problemSolution, KEEP);
970 IdString ident( what );
971 invokeOnEach( _pool.byIdentBegin( ident ),
972 _pool.byIdentEnd( ident ),
973 functor::chain (resfilter::ByInstalled (), // ByInstalled
974 resfilter::ByTransact ()), // will be deinstalled
975 functor::functorRef<bool,PoolItem> (info) );
976 string description = str::form (_("keep %s"), ident.c_str());
977 MIL << description << endl;
978 problemSolution->addDescription (description);
981 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
984 FOR_PROVIDES(p, pp, what);
986 PoolItem poolItem = _pool.find (sat::Solvable(p));
987 if (poolItem.status().isToBeInstalled()
988 || poolItem.status().staysUninstalled())
989 problemSolution->addSingleAction (poolItem, KEEP);
991 string description = str::form (_("do not ask to install a solvable providing %s"), dep2str(pool, what));
992 MIL << description << endl;
993 problemSolution->addDescription (description);
996 case SOLVER_ERASE_SOLVABLE_PROVIDES:
999 FOR_PROVIDES(p, pp, what);
1001 PoolItem poolItem = _pool.find (sat::Solvable(p));
1002 if (poolItem.status().isToBeUninstalled()
1003 || poolItem.status().staysInstalled())
1004 problemSolution->addSingleAction (poolItem, KEEP);
1006 string description = str::form (_("do not ask to delete all solvables providing %s"), dep2str(pool, what));
1007 MIL << description << endl;
1008 problemSolution->addDescription (description);
1011 case SOLVER_INSTALL_SOLVABLE_UPDATE:
1013 PoolItem poolItem = _pool.find (sat::Solvable(what));
1014 s = pool->solvables + what;
1016 if (_solv->installed && s->repo == _solv->installed) {
1017 problemSolution->addSingleAction (poolItem, KEEP);
1018 string description = str::form (_("do not install most recent version of %s"), solvable2str(pool, s));
1019 MIL << description << endl;
1020 problemSolution->addDescription (description);
1022 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE " << poolItem << " is not selected for installation" << endl;
1025 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE: No item found for " << id2str(pool, s->name) << "-" << id2str(pool, s->evr) << "." <<
1026 id2str(pool, s->arch) << endl;
1031 MIL << "- do something different" << endl;
1032 ERR << "No valid solution available" << endl;
1036 /* policy, replace p with rp */
1037 s = pool->solvables + p;
1038 sd = rp ? pool->solvables + rp : 0;
1040 PoolItem itemFrom = _pool.find (sat::Solvable(p));
1045 PoolItem itemTo = _pool.find (sat::Solvable(rp));
1046 if (itemFrom && itemTo) {
1047 problemSolution->addSingleAction (itemTo, INSTALL);
1049 if (evrcmp(pool, s->evr, sd->evr, EVRCMP_COMPARE ) > 0)
1051 string description = str::form (_("downgrade of %s to %s"), solvable2str(pool, s), solvable2str(pool, sd));
1052 MIL << description << endl;
1053 problemSolution->addDescription (description);
1056 if (!_solv->allowarchchange && s->name == sd->name && s->arch != sd->arch && policy_illegal_archchange(_solv, s, sd))
1058 string description = str::form (_("architecture change of %s to %s"), solvable2str(pool, s), solvable2str(pool, sd));
1059 MIL << description << endl;
1060 problemSolution->addDescription (description);
1063 if (!_solv->allowvendorchange && s->name == sd->name && s->vendor != sd->vendor && policy_illegal_vendorchange(_solv, s, sd))
1065 string description = str::form (_("install %s (with vendor change)\n %s\n-->\n %s") ,
1066 solvable2str(pool, sd) , id2str(pool, s->vendor),
1067 string(sd->vendor ? id2str(pool, sd->vendor) : " (no vendor) ").c_str() );
1068 MIL << description << endl;
1069 problemSolution->addDescription (description);
1073 string description = str::form (_("replacement of %s with %s"), solvable2str(pool, s), solvable2str(pool, sd));
1074 MIL << description << endl;
1075 problemSolution->addDescription (description);
1078 ERR << id2str(pool, s->name) << "-" << id2str(pool, s->evr) << "." << id2str(pool, s->arch)
1079 << " or " << id2str(pool, sd->name) << "-" << id2str(pool, sd->evr) << "." << id2str(pool, sd->arch) << " not found" << endl;
1085 string description = str::form (_("deinstallation of %s"), solvable2str(pool, s));
1086 MIL << description << endl;
1087 problemSolution->addDescription (description);
1088 problemSolution->addSingleAction (itemFrom, REMOVE);
1093 resolverProblem->addSolution (problemSolution,
1094 problemSolution->actionCount() > 1 ? true : false); // Solutions with more than 1 action will be shown first.
1095 MIL << "------------------------------------" << endl;
1098 resolverProblems.push_back (resolverProblem);
1101 return resolverProblems;
1105 SATResolver::applySolutions (const ProblemSolutionList & solutions)
1107 for (ProblemSolutionList::const_iterator iter = solutions.begin();
1108 iter != solutions.end(); ++iter) {
1109 ProblemSolution_Ptr solution = *iter;
1110 Resolver dummyResolver(_pool);
1111 if (!solution->apply (dummyResolver))
1118 ///////////////////////////////////////////////////////////////////
1119 };// namespace detail
1120 /////////////////////////////////////////////////////////////////////
1121 /////////////////////////////////////////////////////////////////////
1122 };// namespace solver
1123 ///////////////////////////////////////////////////////////////////////
1124 ///////////////////////////////////////////////////////////////////////
1126 /////////////////////////////////////////////////////////////////////////