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/Pool.h"
35 #include "zypp/sat/WhatProvides.h"
36 #include "zypp/solver/detail/SATResolver.h"
37 #include "zypp/solver/detail/ProblemSolutionCombi.h"
38 #include "zypp/solver/detail/ProblemSolutionIgnore.h"
39 #include "zypp/solver/detail/SolverQueueItemInstall.h"
40 #include "zypp/solver/detail/SolverQueueItemDelete.h"
41 #include "zypp/solver/detail/SystemCheck.h"
44 #include "satsolver/repo_solv.h"
45 #include "satsolver/poolarch.h"
46 #include "satsolver/evr.h"
47 #include "satsolver/poolvendor.h"
48 #include "satsolver/policy.h"
49 #include "satsolver/bitmap.h"
50 #include "satsolver/queue.h"
53 /////////////////////////////////////////////////////////////////////////
55 { ///////////////////////////////////////////////////////////////////////
56 ///////////////////////////////////////////////////////////////////////
58 { /////////////////////////////////////////////////////////////////////
59 /////////////////////////////////////////////////////////////////////
61 { ///////////////////////////////////////////////////////////////////
65 IMPL_PTR_TYPE(SATResolver);
67 //---------------------------------------------------------------------------
68 // Callbacks for SAT policies
69 //---------------------------------------------------------------------------
71 int vendorCheck (Pool *pool, Solvable *solvable1, Solvable *solvable2) {
72 // DBG << "vendorCheck: " << id2str(pool, solvable1->vendor) << " <--> " << id2str(pool, solvable1->vendor) << endl;
73 return VendorAttr::instance().equivalent(id2str(pool, solvable1->vendor), id2str(pool, solvable2->vendor)) ? 0:1;
78 itemToString (PoolItem item, bool shortVersion)
83 if (item->kind() != ResKind::package)
84 os << item->kind() << ':';
87 os << '-' << item->edition();
88 if (item->arch() != "") {
89 os << '.' << item->arch();
91 Repository s = item->repository();
93 string alias = s.info().alias();
95 && alias != "@system")
97 os << '[' << s.info().alias() << ']';
105 //---------------------------------------------------------------------------
108 SATResolver::dumpOn( std::ostream & os ) const
110 os << "<resolver>" << endl;
112 os << " fixsystem = " << _solv->fixsystem << endl;
113 os << " allowdowngrade = " << _solv->allowdowngrade << endl;
114 os << " allowarchchange = " << _solv->allowarchchange << endl;
115 os << " allowvendorchange = " << _solv->allowvendorchange << endl;
116 os << " allowuninstall = " << _solv->allowuninstall << endl;
117 os << " updatesystem = " << _solv->updatesystem << endl;
118 os << " allowvirtualconflicts = " << _solv->allowvirtualconflicts << endl;
119 os << " noupdateprovide = " << _solv->noupdateprovide << endl;
120 os << " dosplitprovides = " << _solv->dosplitprovides << endl;
121 os << " onlyRequires = " << _solv->dontinstallrecommended << endl;
122 os << " ignorealreadyrecommended = " << _solv->ignorealreadyrecommended << endl;
123 os << " distupgrade = " << _distupgrade << endl;
124 os << " distupgrade_removeunsupported = " << _distupgrade_removeunsupported << endl;
129 return os << "<resolver/>" << endl;
132 //---------------------------------------------------------------------------
134 SATResolver::SATResolver (const ResPool & pool, Pool *SATPool)
139 , _allowdowngrade(false)
140 , _allowarchchange(false)
141 , _allowvendorchange(false)
142 , _allowuninstall(false)
143 , _updatesystem(false)
144 , _allowvirtualconflicts(false)
145 , _noupdateprovide(false)
146 , _dosplitprovides(false)
147 , _onlyRequires(ZConfig::instance().solver_onlyRequires())
148 , _ignorealreadyrecommended(false)
149 , _distupgrade(false)
150 , _distupgrade_removeunsupported(false)
156 SATResolver::~SATResolver()
160 //---------------------------------------------------------------------------
164 SATResolver::pool (void) const
171 SATResolver::resetItemTransaction (PoolItem item)
174 for (PoolItemList::const_iterator iter = _items_to_remove.begin();
175 iter != _items_to_remove.end(); iter++) {
177 _items_to_remove.remove(*iter);
183 for (PoolItemList::const_iterator iter = _items_to_install.begin();
184 iter != _items_to_install.end(); iter++) {
186 _items_to_install.remove(*iter);
193 for (PoolItemList::const_iterator iter = _items_to_keep.begin();
194 iter != _items_to_keep.end(); iter++) {
196 _items_to_keep.remove(*iter);
203 for (PoolItemList::const_iterator iter = _items_to_lock.begin();
204 iter != _items_to_lock.end(); iter++) {
206 _items_to_lock.remove(*iter);
216 SATResolver::addPoolItemToInstall (PoolItem item)
218 resetItemTransaction (item);
219 _items_to_install.push_back (item);
220 _items_to_install.unique ();
225 SATResolver::addPoolItemsToInstallFromList (PoolItemList & rl)
227 for (PoolItemList::const_iterator iter = rl.begin(); iter != rl.end(); iter++) {
228 addPoolItemToInstall (*iter);
234 SATResolver::addPoolItemToRemove (PoolItem item)
236 resetItemTransaction (item);
237 _items_to_remove.push_back (item);
238 _items_to_remove.unique ();
243 SATResolver::addPoolItemsToRemoveFromList (PoolItemList & rl)
245 for (PoolItemList::const_iterator iter = rl.begin(); iter != rl.end(); iter++) {
246 addPoolItemToRemove (*iter);
251 SATResolver::addPoolItemToLock (PoolItem item)
253 resetItemTransaction (item);
254 _items_to_lock.push_back (item);
255 _items_to_lock.unique ();
259 SATResolver::addPoolItemToKeep (PoolItem item)
261 resetItemTransaction (item);
262 _items_to_keep.push_back (item);
263 _items_to_keep.unique ();
266 //---------------------------------------------------------------------------
268 // copy marked item from solution back to pool
269 // if data != NULL, set as APPL_LOW (from establishPool())
272 SATSolutionToPool (PoolItem item, const ResStatus & status, const ResStatus::TransactByValue causer)
275 item.status().resetTransact (causer);
276 item.status().resetWeak ();
280 // installation/deletion
281 if (status.isToBeInstalled()) {
282 r = item.status().setToBeInstalled (causer);
283 _XDEBUG("SATSolutionToPool install returns " << item << ", " << r);
285 else if (status.isToBeUninstalledDueToUpgrade()) {
286 r = item.status().setToBeUninstalledDueToUpgrade (causer);
287 _XDEBUG("SATSolutionToPool upgrade returns " << item << ", " << r);
289 else if (status.isToBeUninstalled()) {
290 r = item.status().setToBeUninstalled (causer);
291 _XDEBUG("SATSolutionToPool remove returns " << item << ", " << r);
298 //----------------------------------------------------------------------------
299 // helper functions for distupgrade
300 //----------------------------------------------------------------------------
302 bool SATResolver::doesObsoleteItem (PoolItem candidate, PoolItem installed) {
303 Solvable *sCandidate = _SATPool->solvables + candidate.satSolvable().id();
304 ::_Repo *installedRepo = sat::Pool::instance().systemRepo().get();
306 Id p, pp, obsolete, *obsoleteIt;
308 if ((!installedRepo || sCandidate->repo != installedRepo) && sCandidate->obsoletes) {
309 obsoleteIt = sCandidate->repo->idarraydata + sCandidate->obsoletes;
310 while ((obsolete = *obsoleteIt++) != 0)
312 for (pp = pool_whatprovides(_SATPool, obsolete); (p = _SATPool->whatprovidesdata[pp++]) != 0; ) {
313 if (p > 0 && installed.satSolvable().id() == (sat::detail::SolvableIdType)p) {
314 MIL << candidate << " obsoletes " << installed << endl;
323 //----------------------------------------------------------------------------
324 //----------------------------------------------------------------------------
326 //----------------------------------------------------------------------------
327 //----------------------------------------------------------------------------
329 //----------------------------------------------------------------------------
330 // Helper functions for the ZYPP-Pool
331 //----------------------------------------------------------------------------
334 //------------------------------------------------------------------------------------------------------------
335 // This function loops over the pool and grabs all items
336 // It clears all previous bySolver() states also
338 // Every toBeInstalled is passed to zypp::solver:detail::Resolver.addPoolItemToInstall()
339 // Every toBeUninstalled is passed to zypp::solver:detail::Resolver.addPoolItemToRemove()
341 // Solver results must be written back to the pool.
342 //------------------------------------------------------------------------------------------------------------
345 struct SATCollectTransact : public resfilter::PoolItemFilterFunctor
347 SATResolver & resolver;
349 SATCollectTransact (SATResolver & r)
353 bool operator()( PoolItem item ) // only transacts() items go here
355 ResStatus status = item.status();
356 bool by_solver = (status.isBySolver() || status.isByApplLow());
359 item.status().resetTransact( ResStatus::APPL_LOW );// clear any solver/establish transactions
360 return true; // back out here, dont re-queue former solver result
363 if (status.isToBeInstalled()) {
364 resolver.addPoolItemToInstall(item); // -> install!
366 else if (status.isToBeUninstalled()) {
367 resolver.addPoolItemToRemove(item); // -> remove !
369 else if (status.isLocked()
371 resolver.addPoolItemToLock (item);
373 else if (status.isKept()
375 resolver.addPoolItemToKeep (item);
383 //----------------------------------------------------------------------------
384 //----------------------------------------------------------------------------
386 //----------------------------------------------------------------------------
387 //----------------------------------------------------------------------------
390 class CheckIfUpdate : public resfilter::PoolItemFilterFunctor
396 : is_updated( false )
399 // check this item will be installed
401 bool operator()( PoolItem item )
403 if (item.status().isToBeInstalled())
413 class CollectNonePackages : public resfilter::PoolItemFilterFunctor
416 Queue *solvableQueue;
418 CollectNonePackages( Queue *queue )
419 :solvableQueue (queue)
422 // collecting none packges
424 bool operator()( PoolItem item )
426 queue_push(solvableQueue, item.satSolvable().id());
432 SATResolver::solving()
434 _solv = solver_create( _SATPool );
435 _solv->vendorCheckCb = &vendorCheck;
436 _solv->fixsystem = _fixsystem;
437 _solv->ignorealreadyrecommended = _ignorealreadyrecommended;
438 _solv->updatesystem = _updatesystem;
439 _solv->allowdowngrade = _allowdowngrade;
440 _solv->allowuninstall = _allowuninstall;
441 _solv->allowarchchange = _allowarchchange;
442 _solv->allowvendorchange = _allowvendorchange;
443 _solv->allowvirtualconflicts = _allowvirtualconflicts;
444 _solv->dosplitprovides = _dosplitprovides;
445 _solv->noupdateprovide = _noupdateprovide;
446 _solv->dontinstallrecommended = _onlyRequires;
447 _solv->distupgrade = _distupgrade;
448 _solv->distupgrade_removeunsupported = _distupgrade_removeunsupported;
450 sat::Pool::instance().prepare();
453 MIL << "Starting solving...." << endl;
455 solver_solve( _solv, &(_jobQueue) );
456 MIL << "....Solver end" << endl;
458 // copying solution back to zypp pool
459 //-----------------------------------------
460 _result_items_to_install.clear();
461 _result_items_to_remove.clear();
463 /* solvables to be installed */
464 for (int i = 0; i < _solv->decisionq.count; i++)
467 p = _solv->decisionq.elements[i];
468 if (p < 0 || !sat::Solvable(p) || sat::Solvable(p).isSystem())
471 PoolItem poolItem((sat::Solvable(p)));
473 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
474 _result_items_to_install.push_back (poolItem);
476 ERR << "id " << p << " not found in ZYPP pool." << endl;
480 /* solvables to be erased */
481 Repository systemRepo( sat::Pool::instance().findSystemRepo() ); // don't create if it does not exist
482 for_( it, systemRepo.solvablesBegin(), systemRepo.solvablesEnd() )
484 if (_solv->decisionmap[it->id()] > 0)
487 PoolItem poolItem( *it );
488 // Check if this is an update
490 invokeOnEach( _pool.byIdentBegin( poolItem ),
491 _pool.byIdentEnd( poolItem ),
492 resfilter::ByUninstalled(), // ByUninstalled
493 functor::functorRef<bool,PoolItem> (info) );
495 if (info.is_updated) {
496 SATSolutionToPool (poolItem, ResStatus::toBeUninstalledDueToUpgrade , ResStatus::SOLVER);
498 SATSolutionToPool (poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER);
500 _result_items_to_remove.push_back (poolItem);
503 /* solvables which are recommended */
504 for (int i = 0; i < _solv->recommendations.count; i++)
507 p = _solv->recommendations.elements[i];
508 if (p < 0 || !sat::Solvable(p))
511 PoolItem poolItem = _pool.find (sat::Solvable(p));
513 poolItem.status().setRecommended(true);
514 _XDEBUG("SATSolutionToPool(" << poolItem << ") recommended !");
516 ERR << "id " << p << " not found in ZYPP pool." << endl;
520 /* solvables which are suggested */
521 for (int i = 0; i < _solv->suggestions.count; i++)
524 p = _solv->suggestions.elements[i];
525 if (p < 0 || !sat::Solvable(p))
528 PoolItem poolItem = _pool.find (sat::Solvable(p));
530 poolItem.status().setSuggested(true);
531 _XDEBUG("SATSolutionToPool(" << poolItem << ") suggested !");
533 ERR << "id " << p << " not found in ZYPP pool." << endl;
537 _problem_items.clear();
538 /* solvables which are no longer supported */
539 for (int i = 0; i < _solv->orphaned.count; i++)
542 p = _solv->orphaned.elements[i];
543 if (p < 0 || !sat::Solvable(p))
546 PoolItem poolItem = _pool.find (sat::Solvable(p));
548 _problem_items.push_back(poolItem);
549 _XDEBUG( poolItem << " orphaned !");
551 ERR << "id " << p << " not found in ZYPP pool." << endl;
555 /* Write validation state back to pool */
557 Queue flags, solvableQueue;
560 queue_init(&solvableQueue);
562 CollectNonePackages collectNonePackages(&solvableQueue);
563 invokeOnEach( _pool.begin(),
565 functor::not_c(resfilter::byKind<Package>()), // every solvable BUT packages
566 functor::functorRef<bool,PoolItem> (collectNonePackages) );
567 solver_create_state_maps(_solv, &installedmap, 0);
568 pool_trivial_installable(_solv->pool, &installedmap, &solvableQueue, &flags);
569 for (int i = 0; i < solvableQueue.count; i++) {
570 PoolItem item = _pool.find (sat::Solvable(solvableQueue.elements[i]));
571 item.status().setUndetermined();
573 if (flags.elements[i] == -1) {
574 item.status().setNonRelevant();
575 _XDEBUG("SATSolutionToPool(" << item << " ) nonRelevant !");
576 } else if (flags.elements[i] == 1) {
577 item.status().setSatisfied();
578 _XDEBUG("SATSolutionToPool(" << item << " ) satisfied !");
579 } else if (flags.elements[i] == 0) {
580 item.status().setBroken();
581 _XDEBUG("SATSolutionToPool(" << item << " ) broken !");
585 if (_solv->problems.count > 0 )
587 ERR << "Solverrun finished with an ERROR" << endl;
591 map_free(&installedmap);
592 queue_free(&(solvableQueue));
600 SATResolver::solverInit(const PoolItemList & weakItems)
602 SATCollectTransact info (*this);
604 MIL << "SATResolver::solverInit()" << endl;
610 queue_free( &(_jobQueue) );
613 queue_init( &_jobQueue );
614 _items_to_install.clear();
615 _items_to_remove.clear();
616 _items_to_lock.clear();
617 _items_to_keep.clear();
619 invokeOnEach ( _pool.begin(), _pool.end(),
620 functor::functorRef<bool,PoolItem>(info) );
622 for (PoolItemList::const_iterator iter = weakItems.begin(); iter != weakItems.end(); iter++) {
623 Id id = (*iter)->satSolvable().id();
625 ERR << "Weaken: " << *iter << " not found" << endl;
627 MIL << "Weaken dependencies of " << *iter << endl;
628 queue_push( &(_jobQueue), SOLVER_WEAKEN_SOLVABLE_DEPS );
629 queue_push( &(_jobQueue), id );
632 // Add rules for parallel installable resolvables with different versions
633 std::set<IdString> parallel = ZConfig::instance().multiversion();
634 for (std::set<IdString>::const_iterator it = parallel.begin(); it != parallel.end(); ++it) {
635 queue_push( &(_jobQueue), SOLVER_NOOBSOLETES_SOLVABLE_NAME );
636 queue_push( &(_jobQueue), it->id() );
641 SATResolver::solverEnd()
646 queue_free( &(_jobQueue) );
651 SATResolver::resolvePool(const CapabilitySet & requires_caps,
652 const CapabilitySet & conflict_caps,
653 const PoolItemList & weakItems)
655 MIL << "SATResolver::resolvePool()" << endl;
658 solverInit(weakItems);
660 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
661 Id id = (*iter)->satSolvable().id();
663 ERR << "Install: " << *iter << " not found" << endl;
665 MIL << "Install " << *iter << endl;
666 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE );
667 queue_push( &(_jobQueue), id );
671 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
672 Id id = (*iter)->satSolvable().id();
674 ERR << "Delete: " << *iter << " not found" << endl;
676 MIL << "Delete " << *iter << endl;
677 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE );
678 queue_push( &(_jobQueue), id);
682 for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
683 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE_PROVIDES );
684 queue_push( &(_jobQueue), iter->id() );
685 MIL << "Requires " << *iter << endl;
688 for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
689 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_PROVIDES);
690 queue_push( &(_jobQueue), iter->id() );
691 MIL << "Conflicts " << *iter << endl;
694 // set requirements for a running system
695 setSystemRequirements();
697 // set locks for the solver
701 bool ret = solving();
704 solverEnd(); // remove solver only if no errors happend. Need it for solving problems
706 MIL << "SATResolver::resolvePool() done. Ret:" << ret << endl;
712 SATResolver::resolveQueue(const SolverQueueItemList &requestQueue,
713 const PoolItemList & weakItems)
715 MIL << "SATResolver::resolvQueue()" << endl;
718 solverInit(weakItems);
720 // generate solver queue
721 for (SolverQueueItemList::const_iterator iter = requestQueue.begin(); iter != requestQueue.end(); iter++) {
722 (*iter)->addRule(_jobQueue);
725 // Add addition item status to the resolve-queue cause these can be set by problem resolutions
726 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
727 Id id = (*iter)->satSolvable().id();
729 ERR << "Install: " << *iter << " not found" << endl;
731 MIL << "Install " << *iter << endl;
732 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE );
733 queue_push( &(_jobQueue), id );
736 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
737 sat::detail::IdType ident( (*iter)->satSolvable().ident().id() );
738 MIL << "Delete " << *iter << ident << endl;
739 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_NAME );
740 queue_push( &(_jobQueue), ident);
743 // set requirements for a running system
744 setSystemRequirements();
746 // set locks for the solver
750 bool ret = solving();
754 solverEnd(); // remove solver only if no errors happend. Need it for solving problems
756 MIL << "SATResolver::resolveQueue() done. Ret:" << ret << endl;
761 void SATResolver::doUpdate()
763 MIL << "SATResolver::doUpdate()" << endl;
766 solverInit(PoolItemList());
768 // set requirements for a running system
769 setSystemRequirements();
771 // set locks for the solver
774 _solv = solver_create( _SATPool );
775 _solv->vendorCheckCb = &vendorCheck;
777 _solv->updatesystem = true;
778 _solv->dontinstallrecommended = true; // #FIXME dontinstallrecommended maybe set to false if it works correctly
780 sat::Pool::instance().prepare();
783 MIL << "Starting solving for update...." << endl;
785 solver_solve( _solv, &(_jobQueue) );
786 MIL << "....Solver end" << endl;
788 // copying solution back to zypp pool
789 //-----------------------------------------
791 /* solvables to be installed */
792 for (int i = 0; i < _solv->decisionq.count; i++)
795 p = _solv->decisionq.elements[i];
796 if (p < 0 || !sat::Solvable(p))
798 if (sat::Solvable(p).repository().get() == _solv->installed)
801 PoolItem poolItem = _pool.find (sat::Solvable(p));
803 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
805 ERR << "id " << p << " not found in ZYPP pool." << endl;
809 /* solvables to be erased */
810 for (int i = _solv->installed->start; i < _solv->installed->start + _solv->installed->nsolvables; i++)
812 if (_solv->decisionmap[i] > 0)
815 PoolItem poolItem = _pool.find (sat::Solvable(i));
817 // Check if this is an update
819 invokeOnEach( _pool.byIdentBegin( poolItem ),
820 _pool.byIdentEnd( poolItem ),
821 resfilter::ByUninstalled(), // ByUninstalled
822 functor::functorRef<bool,PoolItem> (info) );
824 if (info.is_updated) {
825 SATSolutionToPool (poolItem, ResStatus::toBeUninstalledDueToUpgrade , ResStatus::SOLVER);
827 SATSolutionToPool (poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER);
830 ERR << "id " << i << " not found in ZYPP pool." << endl;
837 MIL << "SATResolver::doUpdate() done" << endl;
842 //----------------------------------------------------------------------------
843 //----------------------------------------------------------------------------
845 //----------------------------------------------------------------------------
846 //----------------------------------------------------------------------------
848 //----------------------------------------------------------------------------
850 //----------------------------------------------------------------------------
852 struct FindPackage : public resfilter::ResObjectFilterFunctor
854 ProblemSolutionCombi *problemSolution;
855 TransactionKind action;
856 FindPackage (ProblemSolutionCombi *p, const TransactionKind act)
857 : problemSolution (p)
862 bool operator()( PoolItem p)
864 problemSolution->addSingleAction (p, action);
870 //----------------------------------------------------------------------------
871 // Checking if this solvable/item has a buddy which reflect the real
872 // user visible description of an item
873 // e.g. The release package has a buddy to the concerning product item.
874 // This user want's the message "Product foo conflicts with product bar" and
875 // NOT "package release-foo conflicts with package release-bar"
876 //----------------------------------------------------------------------------
879 PoolItem SATResolver::mapItem (const PoolItem &item)
881 sat::Solvable buddy = item.buddy();
882 if (buddy != sat::Solvable())
884 return _pool.find (buddy);
892 sat::Solvable SATResolver::mapSolvable (const Id &id)
894 PoolItem item = _pool.find (sat::Solvable(id));
895 return mapItem(item).satSolvable();
898 string SATResolver::SATprobleminfoString(Id problem, string &detail, Id &ignoreId)
901 Pool *pool = _solv->pool;
903 Id dep, source, target;
907 probr = solver_findproblemrule(_solv, problem);
908 switch (solver_problemruleinfo(_solv, &(_jobQueue), probr, &dep, &source, &target))
910 case SOLVER_PROBLEM_UPDATE_RULE:
911 s = mapSolvable (source);
912 ret = str::form (_("problem with installed package %s"), solvable2str(pool, s.get()));
914 case SOLVER_PROBLEM_JOB_RULE:
915 ret = str::form (_("conflicting requests"));
917 case SOLVER_PROBLEM_RPM_RULE:
918 ret = str::form (_("some dependency problem"));
920 case SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP:
921 ret = str::form (_("nothing provides requested %s"), dep2str(pool, dep));
922 detail += _("Have you enabled all requested repositories?");
924 case SOLVER_PROBLEM_NOT_INSTALLABLE:
925 s = mapSolvable (source);
926 ret = str::form (_("%s is not installable"), solvable2str(pool, s.get()));
928 case SOLVER_PROBLEM_NOTHING_PROVIDES_DEP:
929 s = mapSolvable (source);
930 ret = str::form (_("nothing provides %s needed by %s"), dep2str(pool, dep), solvable2str(pool, s.get()));
932 case SOLVER_PROBLEM_SAME_NAME:
933 s = mapSolvable (source);
934 s2 = mapSolvable (target);
935 ret = str::form (_("cannot install both %s and %s"), solvable2str(pool, s.get()), solvable2str(pool, s2.get()));
937 case SOLVER_PROBLEM_PACKAGE_CONFLICT:
938 s = mapSolvable (source);
939 s2 = mapSolvable (target);
940 ret = str::form (_("%s conflicts with %s provided by %s"), solvable2str(pool, s.get()), dep2str(pool, dep), solvable2str(pool, s2.get()));
942 case SOLVER_PROBLEM_PACKAGE_OBSOLETES:
943 s = mapSolvable (source);
944 s2 = mapSolvable (target);
945 ret = str::form (_("%s obsoletes %s provided by %s"), solvable2str(pool, s.get()), dep2str(pool, dep), solvable2str(pool, s2.get()));
947 case SOLVER_PROBLEM_SELF_CONFLICT:
948 s = mapSolvable (source);
949 ret = str::form (_("Solvable %s conflicts with %s provided by itself"), solvable2str(pool, s.get()), dep2str(pool, dep));
951 case SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE:
952 ignoreId = source; // for setting weak dependencies
953 s = mapSolvable (source);
955 sat::WhatProvides possibleProviders(cap);
957 // check, if a provider will be deleted
958 typedef list<PoolItem> ProviderList;
959 ProviderList providerlistInstalled, providerlistUninstalled;
960 for_( iter1, possibleProviders.begin(), possibleProviders.end() ) {
961 PoolItem provider1 = ResPool::instance().find( *iter1 );
962 // find pair of an installed/uninstalled item with the same NVR
964 for_( iter2, possibleProviders.begin(), possibleProviders.end() ) {
965 PoolItem provider2 = ResPool::instance().find( *iter2 );
966 if (compareByNVR (provider1.resolvable(),provider2.resolvable()) == 0
967 && ( (provider1.status().isInstalled() && provider2.status().isUninstalled())
968 || (provider2.status().isInstalled() && provider1.status().isUninstalled()) )) {
974 if (provider1.status().isInstalled())
975 providerlistInstalled.push_back(provider1);
977 providerlistUninstalled.push_back(provider1);
981 ret = str::form (_("%s requires %s, but this requirement cannot be provided"), solvable2str(pool, s.get()), dep2str(pool, dep));
982 if (providerlistInstalled.size() > 0) {
983 detail += _("deleted providers: ");
984 for (ProviderList::const_iterator iter = providerlistInstalled.begin(); iter != providerlistInstalled.end(); iter++) {
985 if (iter == providerlistInstalled.begin())
986 detail += itemToString (*iter, false);
988 detail += "\n " + itemToString (mapItem(*iter), false);
991 if (providerlistUninstalled.size() > 0) {
992 if (detail.size() > 0)
993 detail += _("\nuninstallable providers: ");
995 detail = _("uninstallable providers: ");
996 for (ProviderList::const_iterator iter = providerlistUninstalled.begin(); iter != providerlistUninstalled.end(); iter++) {
997 if (iter == providerlistUninstalled.begin())
998 detail += itemToString (*iter, false);
1000 detail += "\n " + itemToString (mapItem(*iter), false);
1010 SATResolver::problems ()
1012 ResolverProblemList resolverProblems;
1013 if (_solv && _solv->problems.count) {
1014 Pool *pool = _solv->pool;
1017 Id problem, solution, element;
1018 sat::Solvable s, sd;
1020 CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1021 CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1023 MIL << "Encountered problems! Here are the solutions:\n" << endl;
1026 while ((problem = solver_next_problem(_solv, problem)) != 0) {
1027 MIL << "Problem " << pcnt++ << ":" << endl;
1028 MIL << "====================================" << endl;
1031 string whatString = SATprobleminfoString (problem,detail,ignoreId);
1032 MIL << whatString << endl;
1033 MIL << "------------------------------------" << endl;
1034 ResolverProblem_Ptr resolverProblem = new ResolverProblem (whatString, detail);
1037 while ((solution = solver_next_solution(_solv, problem, solution)) != 0) {
1039 ProblemSolutionCombi *problemSolution = new ProblemSolutionCombi(resolverProblem);
1040 while ((element = solver_next_solutionelement(_solv, problem, solution, element, &p, &rp)) != 0) {
1042 /* job, rp is index into job queue */
1043 what = _jobQueue.elements[rp];
1044 switch (_jobQueue.elements[rp-1])
1046 case SOLVER_INSTALL_SOLVABLE: {
1047 s = mapSolvable (what);
1048 PoolItem poolItem = _pool.find (s);
1050 if (_solv->installed && s.get()->repo == _solv->installed) {
1051 problemSolution->addSingleAction (poolItem, REMOVE);
1052 string description = str::form (_("do not keep %s installed"), solvable2str(pool, s.get()) );
1053 MIL << description << endl;
1054 problemSolution->addDescription (description);
1056 problemSolution->addSingleAction (poolItem, KEEP);
1057 string description = str::form (_("do not install %s"), solvable2str(pool, s.get()));
1058 MIL << description << endl;
1059 problemSolution->addDescription (description);
1062 ERR << "SOLVER_INSTALL_SOLVABLE: No item found for " << id2str(pool, s.get()->name) << "-"
1063 << id2str(pool, s.get()->evr) << "." << id2str(pool, s.get()->arch) << endl;
1067 case SOLVER_ERASE_SOLVABLE: {
1068 s = mapSolvable (what);
1069 PoolItem poolItem = _pool.find (s);
1071 if (_solv->installed && s.get()->repo == _solv->installed) {
1072 problemSolution->addSingleAction (poolItem, KEEP);
1073 string description = str::form (_("keep %s"), solvable2str(pool, s.get()));
1074 MIL << description << endl;
1075 problemSolution->addDescription (description);
1077 problemSolution->addSingleAction (poolItem, UNLOCK);
1078 string description = str::form (_("do not forbid installation of %s"), itemToString(poolItem, false).c_str());
1079 MIL << description << endl;
1080 problemSolution->addDescription (description);
1083 ERR << "SOLVER_ERASE_SOLVABLE: No item found for " << id2str(pool, s.get()->name) << "-" << id2str(pool, s.get()->evr) << "." <<
1084 id2str(pool, s.get()->arch) << endl;
1088 case SOLVER_INSTALL_SOLVABLE_NAME:
1090 IdString ident( what );
1091 SolverQueueItemInstall_Ptr install =
1092 new SolverQueueItemInstall(_pool, ident.asString(), false );
1093 problemSolution->addSingleAction (install, REMOVE_SOLVE_QUEUE_ITEM);
1095 string description = str::form (_("do not install %s"), ident.c_str() );
1096 MIL << description << endl;
1097 problemSolution->addDescription (description);
1100 case SOLVER_ERASE_SOLVABLE_NAME:
1102 // As we do not know, if this request has come from resolvePool or
1103 // resolveQueue we will have to take care for both cases.
1104 IdString ident( what );
1105 FindPackage info (problemSolution, KEEP);
1106 invokeOnEach( _pool.byIdentBegin( ident ),
1107 _pool.byIdentEnd( ident ),
1108 functor::chain (resfilter::ByInstalled (), // ByInstalled
1109 resfilter::ByTransact ()), // will be deinstalled
1110 functor::functorRef<bool,PoolItem> (info) );
1112 SolverQueueItemDelete_Ptr del =
1113 new SolverQueueItemDelete(_pool, ident.asString(), false );
1114 problemSolution->addSingleAction (del, REMOVE_SOLVE_QUEUE_ITEM);
1116 string description = str::form (_("keep %s"), ident.c_str());
1117 MIL << description << endl;
1118 problemSolution->addDescription (description);
1121 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
1123 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_REQUIRE);
1124 string description = "";
1126 // Checking if this problem solution would break your system
1127 if (system_requires.find(Capability(what)) != system_requires.end()) {
1128 // Show a better warning
1129 resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1130 resolverProblem->setDescription(_("This request will break your system!"));
1131 description = _("ignore the warning of a broken system");
1133 description = str::form (_("do not ask to install a solvable providing %s"), dep2str(pool, what));
1135 MIL << description << endl;
1136 problemSolution->addDescription (description);
1139 case SOLVER_ERASE_SOLVABLE_PROVIDES:
1141 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_CONFLICT);
1142 string description = "";
1144 // Checking if this problem solution would break your system
1145 if (system_conflicts.find(Capability(what)) != system_conflicts.end()) {
1146 // Show a better warning
1147 resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1148 resolverProblem->setDescription(_("This request will break your system!"));
1149 description = _("ignore the warning of a broken system");
1151 description = str::form (_("do not ask to delete all solvables providing %s"), dep2str(pool, what));
1153 MIL << description << endl;
1154 problemSolution->addDescription (description);
1157 case SOLVER_INSTALL_SOLVABLE_UPDATE:
1159 s = mapSolvable (what);
1160 PoolItem poolItem = _pool.find (s);
1162 if (_solv->installed && s.get()->repo == _solv->installed) {
1163 problemSolution->addSingleAction (poolItem, KEEP);
1164 string description = str::form (_("do not install most recent version of %s"), solvable2str(pool, s.get()));
1165 MIL << description << endl;
1166 problemSolution->addDescription (description);
1168 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE " << poolItem << " is not selected for installation" << endl;
1171 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE: No item found for " << id2str(pool, s.get()->name) << "-" << id2str(pool, s.get()->evr) << "." <<
1172 id2str(pool, s.get()->arch) << endl;
1177 MIL << "- do something different" << endl;
1178 ERR << "No valid solution available" << endl;
1182 /* policy, replace p with rp */
1183 s = mapSolvable (p);
1185 sd = mapSolvable (rp);
1187 PoolItem itemFrom = _pool.find (s);
1188 if (s == sd && _solv->distupgrade)
1190 PoolItem poolItem = _pool.find (s);
1192 problemSolution->addSingleAction (poolItem, LOCK); // for solver reason: NOT weak lock.
1193 string description = str::form (_("keep %s"), solvable2str(pool, s.get()));
1194 MIL << description << endl;
1195 problemSolution->addDescription (description);
1197 ERR << "SOLVER_INSTALL_SOLVABLE: No item found for " << id2str(pool, s.get()->name) << "-"
1198 << id2str(pool, s.get()->evr) << "." << id2str(pool, s.get()->arch) << endl;
1205 PoolItem itemTo = _pool.find (sd);
1206 if (itemFrom && itemTo) {
1207 problemSolution->addSingleAction (itemTo, INSTALL);
1209 if (evrcmp(pool, s.get()->evr, sd.get()->evr, EVRCMP_COMPARE ) > 0)
1211 string description = str::form (_("downgrade of %s to %s"), solvable2str(pool, s.get()), solvable2str(pool, sd.get()));
1212 MIL << description << endl;
1213 problemSolution->addDescription (description);
1216 if (!_solv->allowarchchange && s.get()->name == sd.get()->name && s.get()->arch != sd.get()->arch
1217 && policy_illegal_archchange(_solv, s.get(), sd.get()))
1219 string description = str::form (_("architecture change of %s to %s"), solvable2str(pool, s.get()), solvable2str(pool, sd.get()));
1220 MIL << description << endl;
1221 problemSolution->addDescription (description);
1224 if (!_solv->allowvendorchange && s.get()->name == sd.get()->name && s.get()->vendor != sd.get()->vendor
1225 && policy_illegal_vendorchange(_solv, s.get(), sd.get()))
1227 string description = str::form (_("install %s (with vendor change)\n %s\n-->\n %s") ,
1228 solvable2str(pool, sd.get()) , id2str(pool, s.get()->vendor),
1229 string(sd.get()->vendor ? id2str(pool, sd.get()->vendor) : " (no vendor) ").c_str() );
1230 MIL << description << endl;
1231 problemSolution->addDescription (description);
1235 string description = str::form (_("replacement of %s with %s"), solvable2str(pool, s.get()), solvable2str(pool, sd.get()));
1236 MIL << description << endl;
1237 problemSolution->addDescription (description);
1240 ERR << id2str(pool, s.get()->name) << "-" << id2str(pool, s.get()->evr) << "." << id2str(pool, s.get()->arch)
1241 << " or " << id2str(pool, sd.get()->name) << "-" << id2str(pool, sd.get()->evr) << "." << id2str(pool, sd.get()->arch) << " not found" << endl;
1247 string description = str::form (_("deinstallation of %s"), solvable2str(pool, s.get()));
1248 MIL << description << endl;
1249 problemSolution->addDescription (description);
1250 problemSolution->addSingleAction (itemFrom, REMOVE);
1255 resolverProblem->addSolution (problemSolution,
1256 problemSolution->actionCount() > 1 ? true : false); // Solutions with more than 1 action will be shown first.
1257 MIL << "------------------------------------" << endl;
1261 // There is a possibility to ignore this error by setting weak dependencies
1262 PoolItem item = _pool.find (sat::Solvable(ignoreId));
1263 ProblemSolutionIgnore *problemSolution = new ProblemSolutionIgnore(resolverProblem, item);
1264 resolverProblem->addSolution (problemSolution,
1265 false); // Solutions will be shown at the end
1266 MIL << "Ignore some dependencies of " << item << endl;
1267 MIL << "------------------------------------" << endl;
1271 resolverProblems.push_back (resolverProblem);
1274 return resolverProblems;
1278 SATResolver::applySolutions (const ProblemSolutionList & solutions)
1280 for (ProblemSolutionList::const_iterator iter = solutions.begin();
1281 iter != solutions.end(); ++iter) {
1282 ProblemSolution_Ptr solution = *iter;
1283 Resolver dummyResolver(_pool);
1284 if (!solution->apply (dummyResolver))
1289 void SATResolver::setLocks()
1291 for (PoolItemList::const_iterator iter = _items_to_lock.begin(); iter != _items_to_lock.end(); iter++) {
1292 sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
1293 if (iter->status().isInstalled()) {
1294 MIL << "Lock installed item " << *iter << endl;
1295 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE );
1296 queue_push( &(_jobQueue), ident );
1298 MIL << "Lock NOT installed item " << *iter << endl;
1299 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE );
1300 queue_push( &(_jobQueue), ident );
1304 for (PoolItemList::const_iterator iter = _items_to_keep.begin(); iter != _items_to_keep.end(); iter++) {
1305 sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
1306 if (iter->status().isInstalled()) {
1307 MIL << "Keep installed item " << *iter << endl;
1308 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE | SOLVER_WEAK);
1309 queue_push( &(_jobQueue), ident );
1311 MIL << "Keep NOT installed item " << *iter << ident << endl;
1312 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE | SOLVER_WEAK);
1313 queue_push( &(_jobQueue), ident );
1318 void SATResolver::setSystemRequirements()
1320 CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1321 CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1323 for (CapabilitySet::const_iterator iter = system_requires.begin(); iter != system_requires.end(); iter++) {
1324 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE_PROVIDES );
1325 queue_push( &(_jobQueue), iter->id() );
1326 MIL << "SYSTEM Requires " << *iter << endl;
1329 for (CapabilitySet::const_iterator iter = system_conflicts.begin(); iter != system_conflicts.end(); iter++) {
1330 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_PROVIDES);
1331 queue_push( &(_jobQueue), iter->id() );
1332 MIL << "SYSTEM Conflicts " << *iter << endl;
1337 ///////////////////////////////////////////////////////////////////
1338 };// namespace detail
1339 /////////////////////////////////////////////////////////////////////
1340 /////////////////////////////////////////////////////////////////////
1341 };// namespace solver
1342 ///////////////////////////////////////////////////////////////////////
1343 ///////////////////////////////////////////////////////////////////////
1345 /////////////////////////////////////////////////////////////////////////