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(const CapabilitySet & requires_caps,
433 const CapabilitySet & conflict_caps)
435 _solv = solver_create( _SATPool );
436 _solv->vendorCheckCb = &vendorCheck;
437 _solv->fixsystem = _fixsystem;
438 _solv->ignorealreadyrecommended = _ignorealreadyrecommended;
439 _solv->updatesystem = _updatesystem;
440 _solv->allowdowngrade = _allowdowngrade;
441 _solv->allowuninstall = _allowuninstall;
442 _solv->allowarchchange = _allowarchchange;
443 _solv->allowvendorchange = _allowvendorchange;
444 _solv->allowvirtualconflicts = _allowvirtualconflicts;
445 _solv->dosplitprovides = _dosplitprovides;
446 _solv->noupdateprovide = _noupdateprovide;
447 _solv->dontinstallrecommended = _onlyRequires;
448 _solv->distupgrade = _distupgrade;
449 _solv->distupgrade_removeunsupported = _distupgrade_removeunsupported;
451 sat::Pool::instance().prepare();
454 MIL << "Starting solving...." << endl;
456 solver_solve( _solv, &(_jobQueue) );
457 MIL << "....Solver end" << endl;
459 // copying solution back to zypp pool
460 //-----------------------------------------
461 _result_items_to_install.clear();
462 _result_items_to_remove.clear();
464 /* solvables to be installed */
465 for (int i = 0; i < _solv->decisionq.count; i++)
468 p = _solv->decisionq.elements[i];
469 if (p < 0 || !sat::Solvable(p) || sat::Solvable(p).isSystem())
472 PoolItem poolItem((sat::Solvable(p)));
474 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
475 _result_items_to_install.push_back (poolItem);
477 ERR << "id " << p << " not found in ZYPP pool." << endl;
481 /* solvables to be erased */
482 Repository systemRepo( sat::Pool::instance().findSystemRepo() ); // don't create if it does not exist
483 for_( it, systemRepo.solvablesBegin(), systemRepo.solvablesEnd() )
485 if (_solv->decisionmap[it->id()] > 0)
488 PoolItem poolItem( *it );
489 // Check if this is an update
491 invokeOnEach( _pool.byIdentBegin( poolItem ),
492 _pool.byIdentEnd( poolItem ),
493 resfilter::ByUninstalled(), // ByUninstalled
494 functor::functorRef<bool,PoolItem> (info) );
496 if (info.is_updated) {
497 SATSolutionToPool (poolItem, ResStatus::toBeUninstalledDueToUpgrade , ResStatus::SOLVER);
499 SATSolutionToPool (poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER);
501 _result_items_to_remove.push_back (poolItem);
504 /* solvables which are recommended */
505 for (int i = 0; i < _solv->recommendations.count; i++)
508 p = _solv->recommendations.elements[i];
509 if (p < 0 || !sat::Solvable(p))
512 PoolItem poolItem = _pool.find (sat::Solvable(p));
514 poolItem.status().setRecommended(true);
515 _XDEBUG("SATSolutionToPool(" << poolItem << ") recommended !");
517 ERR << "id " << p << " not found in ZYPP pool." << endl;
521 /* solvables which are suggested */
522 for (int i = 0; i < _solv->suggestions.count; i++)
525 p = _solv->suggestions.elements[i];
526 if (p < 0 || !sat::Solvable(p))
529 PoolItem poolItem = _pool.find (sat::Solvable(p));
531 poolItem.status().setSuggested(true);
532 _XDEBUG("SATSolutionToPool(" << poolItem << ") suggested !");
534 ERR << "id " << p << " not found in ZYPP pool." << endl;
538 _problem_items.clear();
539 /* solvables which are no longer supported */
540 for (int i = 0; i < _solv->orphaned.count; i++)
543 p = _solv->orphaned.elements[i];
544 if (p < 0 || !sat::Solvable(p))
547 PoolItem poolItem = _pool.find (sat::Solvable(p));
549 _problem_items.push_back(poolItem);
550 _XDEBUG( poolItem << " orphaned !");
552 ERR << "id " << p << " not found in ZYPP pool." << endl;
556 /* Write validation state back to pool */
558 Queue flags, solvableQueue;
561 queue_init(&solvableQueue);
563 CollectNonePackages collectNonePackages(&solvableQueue);
564 invokeOnEach( _pool.begin(),
566 functor::not_c(resfilter::byKind<Package>()), // every solvable BUT packages
567 functor::functorRef<bool,PoolItem> (collectNonePackages) );
568 solver_create_state_maps(_solv, &installedmap, 0);
569 pool_trivial_installable(_solv->pool, &installedmap, &solvableQueue, &flags);
570 for (int i = 0; i < solvableQueue.count; i++) {
571 PoolItem item = _pool.find (sat::Solvable(solvableQueue.elements[i]));
572 item.status().setUndetermined();
574 if (flags.elements[i] == -1) {
575 item.status().setNonRelevant();
576 _XDEBUG("SATSolutionToPool(" << item << " ) nonRelevant !");
577 } else if (flags.elements[i] == 1) {
578 item.status().setSatisfied();
579 _XDEBUG("SATSolutionToPool(" << item << " ) satisfied !");
580 } else if (flags.elements[i] == 0) {
581 item.status().setBroken();
582 _XDEBUG("SATSolutionToPool(" << item << " ) broken !");
586 // Solvables which were selected due requirements which have been made by the user will
587 // be selected by APPL_LOW. We can't use any higher level, because this setting must
588 // not serve as a request for the next solver run. APPL_LOW is reset before solving.
589 for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
590 sat::WhatProvides rpmProviders(*iter);
591 for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
592 PoolItem poolItem(*iter2);
593 if (poolItem.status().isToBeInstalled()) {
594 MIL << "User requirement " << *iter << " sets " << poolItem << endl;
595 poolItem.status().setTransactByValue (ResStatus::APPL_LOW);
599 for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
600 sat::WhatProvides rpmProviders(*iter);
601 for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
602 PoolItem poolItem(*iter2);
603 if (poolItem.status().isToBeUninstalled()) {
604 MIL << "User conflict " << *iter << " sets " << poolItem << endl;
605 poolItem.status().setTransactByValue (ResStatus::APPL_LOW);
610 if (_solv->problems.count > 0 )
612 ERR << "Solverrun finished with an ERROR" << endl;
616 map_free(&installedmap);
617 queue_free(&(solvableQueue));
625 SATResolver::solverInit(const PoolItemList & weakItems)
627 SATCollectTransact info (*this);
629 MIL << "SATResolver::solverInit()" << endl;
635 queue_free( &(_jobQueue) );
638 queue_init( &_jobQueue );
639 _items_to_install.clear();
640 _items_to_remove.clear();
641 _items_to_lock.clear();
642 _items_to_keep.clear();
644 invokeOnEach ( _pool.begin(), _pool.end(),
645 functor::functorRef<bool,PoolItem>(info) );
647 for (PoolItemList::const_iterator iter = weakItems.begin(); iter != weakItems.end(); iter++) {
648 Id id = (*iter)->satSolvable().id();
650 ERR << "Weaken: " << *iter << " not found" << endl;
652 MIL << "Weaken dependencies of " << *iter << endl;
653 queue_push( &(_jobQueue), SOLVER_WEAKEN_SOLVABLE_DEPS );
654 queue_push( &(_jobQueue), id );
657 // Add rules for parallel installable resolvables with different versions
658 std::set<IdString> parallel = ZConfig::instance().multiversion();
659 for (std::set<IdString>::const_iterator it = parallel.begin(); it != parallel.end(); ++it) {
660 queue_push( &(_jobQueue), SOLVER_NOOBSOLETES_SOLVABLE_NAME );
661 queue_push( &(_jobQueue), it->id() );
666 SATResolver::solverEnd()
671 queue_free( &(_jobQueue) );
676 SATResolver::resolvePool(const CapabilitySet & requires_caps,
677 const CapabilitySet & conflict_caps,
678 const PoolItemList & weakItems)
680 MIL << "SATResolver::resolvePool()" << endl;
683 solverInit(weakItems);
685 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
686 Id id = (*iter)->satSolvable().id();
688 ERR << "Install: " << *iter << " not found" << endl;
690 MIL << "Install " << *iter << endl;
691 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE );
692 queue_push( &(_jobQueue), id );
696 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
697 Id id = (*iter)->satSolvable().id();
699 ERR << "Delete: " << *iter << " not found" << endl;
701 MIL << "Delete " << *iter << endl;
702 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE );
703 queue_push( &(_jobQueue), id);
707 for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
708 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE_PROVIDES );
709 queue_push( &(_jobQueue), iter->id() );
710 MIL << "Requires " << *iter << endl;
713 for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
714 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_PROVIDES);
715 queue_push( &(_jobQueue), iter->id() );
716 MIL << "Conflicts " << *iter << endl;
719 // set requirements for a running system
720 setSystemRequirements();
722 // set locks for the solver
726 bool ret = solving(requires_caps, conflict_caps);
729 solverEnd(); // remove solver only if no errors happend. Need it for solving problems
731 MIL << "SATResolver::resolvePool() done. Ret:" << ret << endl;
737 SATResolver::resolveQueue(const SolverQueueItemList &requestQueue,
738 const PoolItemList & weakItems)
740 MIL << "SATResolver::resolvQueue()" << endl;
743 solverInit(weakItems);
745 // generate solver queue
746 for (SolverQueueItemList::const_iterator iter = requestQueue.begin(); iter != requestQueue.end(); iter++) {
747 (*iter)->addRule(_jobQueue);
750 // Add addition item status to the resolve-queue cause these can be set by problem resolutions
751 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
752 Id id = (*iter)->satSolvable().id();
754 ERR << "Install: " << *iter << " not found" << endl;
756 MIL << "Install " << *iter << endl;
757 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE );
758 queue_push( &(_jobQueue), id );
761 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
762 sat::detail::IdType ident( (*iter)->satSolvable().ident().id() );
763 MIL << "Delete " << *iter << ident << endl;
764 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_NAME );
765 queue_push( &(_jobQueue), ident);
768 // set requirements for a running system
769 setSystemRequirements();
771 // set locks for the solver
775 bool ret = solving();
779 solverEnd(); // remove solver only if no errors happend. Need it for solving problems
781 MIL << "SATResolver::resolveQueue() done. Ret:" << ret << endl;
786 void SATResolver::doUpdate()
788 MIL << "SATResolver::doUpdate()" << endl;
791 solverInit(PoolItemList());
793 // set requirements for a running system
794 setSystemRequirements();
796 // set locks for the solver
799 _solv = solver_create( _SATPool );
800 _solv->vendorCheckCb = &vendorCheck;
802 _solv->updatesystem = true;
803 _solv->dontinstallrecommended = true; // #FIXME dontinstallrecommended maybe set to false if it works correctly
805 sat::Pool::instance().prepare();
808 MIL << "Starting solving for update...." << endl;
810 solver_solve( _solv, &(_jobQueue) );
811 MIL << "....Solver end" << endl;
813 // copying solution back to zypp pool
814 //-----------------------------------------
816 /* solvables to be installed */
817 for (int i = 0; i < _solv->decisionq.count; i++)
820 p = _solv->decisionq.elements[i];
821 if (p < 0 || !sat::Solvable(p))
823 if (sat::Solvable(p).repository().get() == _solv->installed)
826 PoolItem poolItem = _pool.find (sat::Solvable(p));
828 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
830 ERR << "id " << p << " not found in ZYPP pool." << endl;
834 /* solvables to be erased */
835 for (int i = _solv->installed->start; i < _solv->installed->start + _solv->installed->nsolvables; i++)
837 if (_solv->decisionmap[i] > 0)
840 PoolItem poolItem = _pool.find (sat::Solvable(i));
842 // Check if this is an update
844 invokeOnEach( _pool.byIdentBegin( poolItem ),
845 _pool.byIdentEnd( poolItem ),
846 resfilter::ByUninstalled(), // ByUninstalled
847 functor::functorRef<bool,PoolItem> (info) );
849 if (info.is_updated) {
850 SATSolutionToPool (poolItem, ResStatus::toBeUninstalledDueToUpgrade , ResStatus::SOLVER);
852 SATSolutionToPool (poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER);
855 ERR << "id " << i << " not found in ZYPP pool." << endl;
862 MIL << "SATResolver::doUpdate() done" << endl;
867 //----------------------------------------------------------------------------
868 //----------------------------------------------------------------------------
870 //----------------------------------------------------------------------------
871 //----------------------------------------------------------------------------
873 //----------------------------------------------------------------------------
875 //----------------------------------------------------------------------------
877 struct FindPackage : public resfilter::ResObjectFilterFunctor
879 ProblemSolutionCombi *problemSolution;
880 TransactionKind action;
881 FindPackage (ProblemSolutionCombi *p, const TransactionKind act)
882 : problemSolution (p)
887 bool operator()( PoolItem p)
889 problemSolution->addSingleAction (p, action);
895 //----------------------------------------------------------------------------
896 // Checking if this solvable/item has a buddy which reflect the real
897 // user visible description of an item
898 // e.g. The release package has a buddy to the concerning product item.
899 // This user want's the message "Product foo conflicts with product bar" and
900 // NOT "package release-foo conflicts with package release-bar"
901 //----------------------------------------------------------------------------
904 PoolItem SATResolver::mapItem (const PoolItem &item)
906 sat::Solvable buddy = item.buddy();
907 if (buddy != sat::Solvable())
909 return _pool.find (buddy);
917 sat::Solvable SATResolver::mapSolvable (const Id &id)
919 PoolItem item = _pool.find (sat::Solvable(id));
920 return mapItem(item).satSolvable();
923 string SATResolver::SATprobleminfoString(Id problem, string &detail, Id &ignoreId)
926 Pool *pool = _solv->pool;
928 Id dep, source, target;
932 probr = solver_findproblemrule(_solv, problem);
933 switch (solver_problemruleinfo(_solv, &(_jobQueue), probr, &dep, &source, &target))
935 case SOLVER_PROBLEM_DISTUPGRADE_RULE:
936 s = mapSolvable (source);
937 ret = str::form (_("%s does not belong to a distupgrade repository"), solvable2str(pool, s.get()));
939 case SOLVER_PROBLEM_INFARCH_RULE:
940 s = mapSolvable (source);
941 ret = str::form (_("%s has inferior architecture"), solvable2str(pool, s.get()));
943 case SOLVER_PROBLEM_UPDATE_RULE:
944 s = mapSolvable (source);
945 ret = str::form (_("problem with installed package %s"), solvable2str(pool, s.get()));
947 case SOLVER_PROBLEM_JOB_RULE:
948 ret = str::form (_("conflicting requests"));
950 case SOLVER_PROBLEM_RPM_RULE:
951 ret = str::form (_("some dependency problem"));
953 case SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP:
954 ret = str::form (_("nothing provides requested %s"), dep2str(pool, dep));
955 detail += _("Have you enabled all requested repositories?");
957 case SOLVER_PROBLEM_NOT_INSTALLABLE:
958 s = mapSolvable (source);
959 ret = str::form (_("%s is not installable"), solvable2str(pool, s.get()));
961 case SOLVER_PROBLEM_NOTHING_PROVIDES_DEP:
962 s = mapSolvable (source);
963 ret = str::form (_("nothing provides %s needed by %s"), dep2str(pool, dep), solvable2str(pool, s.get()));
965 case SOLVER_PROBLEM_SAME_NAME:
966 s = mapSolvable (source);
967 s2 = mapSolvable (target);
968 ret = str::form (_("cannot install both %s and %s"), solvable2str(pool, s.get()), solvable2str(pool, s2.get()));
970 case SOLVER_PROBLEM_PACKAGE_CONFLICT:
971 s = mapSolvable (source);
972 s2 = mapSolvable (target);
973 ret = str::form (_("%s conflicts with %s provided by %s"), solvable2str(pool, s.get()), dep2str(pool, dep), solvable2str(pool, s2.get()));
975 case SOLVER_PROBLEM_PACKAGE_OBSOLETES:
976 s = mapSolvable (source);
977 s2 = mapSolvable (target);
978 ret = str::form (_("%s obsoletes %s provided by %s"), solvable2str(pool, s.get()), dep2str(pool, dep), solvable2str(pool, s2.get()));
980 case SOLVER_PROBLEM_SELF_CONFLICT:
981 s = mapSolvable (source);
982 ret = str::form (_("solvable %s conflicts with %s provided by itself"), solvable2str(pool, s.get()), dep2str(pool, dep));
984 case SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE:
985 ignoreId = source; // for setting weak dependencies
986 s = mapSolvable (source);
988 sat::WhatProvides possibleProviders(cap);
990 // check, if a provider will be deleted
991 typedef list<PoolItem> ProviderList;
992 ProviderList providerlistInstalled, providerlistUninstalled;
993 for_( iter1, possibleProviders.begin(), possibleProviders.end() ) {
994 PoolItem provider1 = ResPool::instance().find( *iter1 );
995 // find pair of an installed/uninstalled item with the same NVR
997 for_( iter2, possibleProviders.begin(), possibleProviders.end() ) {
998 PoolItem provider2 = ResPool::instance().find( *iter2 );
999 if (compareByNVR (provider1.resolvable(),provider2.resolvable()) == 0
1000 && ( (provider1.status().isInstalled() && provider2.status().isUninstalled())
1001 || (provider2.status().isInstalled() && provider1.status().isUninstalled()) )) {
1007 if (provider1.status().isInstalled())
1008 providerlistInstalled.push_back(provider1);
1010 providerlistUninstalled.push_back(provider1);
1014 ret = str::form (_("%s requires %s, but this requirement cannot be provided"), solvable2str(pool, s.get()), dep2str(pool, dep));
1015 if (providerlistInstalled.size() > 0) {
1016 detail += _("deleted providers: ");
1017 for (ProviderList::const_iterator iter = providerlistInstalled.begin(); iter != providerlistInstalled.end(); iter++) {
1018 if (iter == providerlistInstalled.begin())
1019 detail += itemToString (*iter, false);
1021 detail += "\n " + itemToString (mapItem(*iter), false);
1024 if (providerlistUninstalled.size() > 0) {
1025 if (detail.size() > 0)
1026 detail += _("\nuninstallable providers: ");
1028 detail = _("uninstallable providers: ");
1029 for (ProviderList::const_iterator iter = providerlistUninstalled.begin(); iter != providerlistUninstalled.end(); iter++) {
1030 if (iter == providerlistUninstalled.begin())
1031 detail += itemToString (*iter, false);
1033 detail += "\n " + itemToString (mapItem(*iter), false);
1043 SATResolver::problems ()
1045 ResolverProblemList resolverProblems;
1046 if (_solv && _solv->problems.count) {
1047 Pool *pool = _solv->pool;
1050 Id problem, solution, element;
1051 sat::Solvable s, sd;
1053 CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1054 CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1056 MIL << "Encountered problems! Here are the solutions:\n" << endl;
1059 while ((problem = solver_next_problem(_solv, problem)) != 0) {
1060 MIL << "Problem " << pcnt++ << ":" << endl;
1061 MIL << "====================================" << endl;
1064 string whatString = SATprobleminfoString (problem,detail,ignoreId);
1065 MIL << whatString << endl;
1066 MIL << "------------------------------------" << endl;
1067 ResolverProblem_Ptr resolverProblem = new ResolverProblem (whatString, detail);
1070 while ((solution = solver_next_solution(_solv, problem, solution)) != 0) {
1072 ProblemSolutionCombi *problemSolution = new ProblemSolutionCombi(resolverProblem);
1073 while ((element = solver_next_solutionelement(_solv, problem, solution, element, &p, &rp)) != 0) {
1074 if (p == SOLVER_SOLUTION_JOB) {
1075 /* job, rp is index into job queue */
1076 what = _jobQueue.elements[rp];
1077 switch (_jobQueue.elements[rp-1])
1079 case SOLVER_INSTALL_SOLVABLE: {
1080 s = mapSolvable (what);
1081 PoolItem poolItem = _pool.find (s);
1083 if (_solv->installed && s.get()->repo == _solv->installed) {
1084 problemSolution->addSingleAction (poolItem, REMOVE);
1085 string description = str::form (_("do not keep %s installed"), solvable2str(pool, s.get()) );
1086 MIL << description << endl;
1087 problemSolution->addDescription (description);
1089 problemSolution->addSingleAction (poolItem, KEEP);
1090 string description = str::form (_("do not install %s"), solvable2str(pool, s.get()));
1091 MIL << description << endl;
1092 problemSolution->addDescription (description);
1095 ERR << "SOLVER_INSTALL_SOLVABLE: No item found for " << id2str(pool, s.get()->name) << "-"
1096 << id2str(pool, s.get()->evr) << "." << id2str(pool, s.get()->arch) << endl;
1100 case SOLVER_ERASE_SOLVABLE: {
1101 s = mapSolvable (what);
1102 PoolItem poolItem = _pool.find (s);
1104 if (_solv->installed && s.get()->repo == _solv->installed) {
1105 problemSolution->addSingleAction (poolItem, KEEP);
1106 string description = str::form (_("keep %s"), solvable2str(pool, s.get()));
1107 MIL << description << endl;
1108 problemSolution->addDescription (description);
1110 problemSolution->addSingleAction (poolItem, UNLOCK);
1111 string description = str::form (_("do not forbid installation of %s"), itemToString(poolItem, false).c_str());
1112 MIL << description << endl;
1113 problemSolution->addDescription (description);
1116 ERR << "SOLVER_ERASE_SOLVABLE: No item found for " << id2str(pool, s.get()->name) << "-" << id2str(pool, s.get()->evr) << "." <<
1117 id2str(pool, s.get()->arch) << endl;
1121 case SOLVER_INSTALL_SOLVABLE_NAME:
1123 IdString ident( what );
1124 SolverQueueItemInstall_Ptr install =
1125 new SolverQueueItemInstall(_pool, ident.asString(), false );
1126 problemSolution->addSingleAction (install, REMOVE_SOLVE_QUEUE_ITEM);
1128 string description = str::form (_("do not install %s"), ident.c_str() );
1129 MIL << description << endl;
1130 problemSolution->addDescription (description);
1133 case SOLVER_ERASE_SOLVABLE_NAME:
1135 // As we do not know, if this request has come from resolvePool or
1136 // resolveQueue we will have to take care for both cases.
1137 IdString ident( what );
1138 FindPackage info (problemSolution, KEEP);
1139 invokeOnEach( _pool.byIdentBegin( ident ),
1140 _pool.byIdentEnd( ident ),
1141 functor::chain (resfilter::ByInstalled (), // ByInstalled
1142 resfilter::ByTransact ()), // will be deinstalled
1143 functor::functorRef<bool,PoolItem> (info) );
1145 SolverQueueItemDelete_Ptr del =
1146 new SolverQueueItemDelete(_pool, ident.asString(), false );
1147 problemSolution->addSingleAction (del, REMOVE_SOLVE_QUEUE_ITEM);
1149 string description = str::form (_("keep %s"), ident.c_str());
1150 MIL << description << endl;
1151 problemSolution->addDescription (description);
1154 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
1156 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_REQUIRE);
1157 string description = "";
1159 // Checking if this problem solution would break your system
1160 if (system_requires.find(Capability(what)) != system_requires.end()) {
1161 // Show a better warning
1162 resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1163 resolverProblem->setDescription(_("This request will break your system!"));
1164 description = _("ignore the warning of a broken system");
1166 description = str::form (_("do not ask to install a solvable providing %s"), dep2str(pool, what));
1168 MIL << description << endl;
1169 problemSolution->addDescription (description);
1172 case SOLVER_ERASE_SOLVABLE_PROVIDES:
1174 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_CONFLICT);
1175 string description = "";
1177 // Checking if this problem solution would break your system
1178 if (system_conflicts.find(Capability(what)) != system_conflicts.end()) {
1179 // Show a better warning
1180 resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1181 resolverProblem->setDescription(_("This request will break your system!"));
1182 description = _("ignore the warning of a broken system");
1184 description = str::form (_("do not ask to delete all solvables providing %s"), dep2str(pool, what));
1186 MIL << description << endl;
1187 problemSolution->addDescription (description);
1190 case SOLVER_INSTALL_SOLVABLE_UPDATE:
1192 s = mapSolvable (what);
1193 PoolItem poolItem = _pool.find (s);
1195 if (_solv->installed && s.get()->repo == _solv->installed) {
1196 problemSolution->addSingleAction (poolItem, KEEP);
1197 string description = str::form (_("do not install most recent version of %s"), solvable2str(pool, s.get()));
1198 MIL << description << endl;
1199 problemSolution->addDescription (description);
1201 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE " << poolItem << " is not selected for installation" << endl;
1204 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE: No item found for " << id2str(pool, s.get()->name) << "-" << id2str(pool, s.get()->evr) << "." <<
1205 id2str(pool, s.get()->arch) << endl;
1210 MIL << "- do something different" << endl;
1211 ERR << "No valid solution available" << endl;
1214 } else if (p == SOLVER_SOLUTION_INFARCH) {
1215 s = mapSolvable (rp);
1216 PoolItem poolItem = _pool.find (s);
1217 if (_solv->installed && s.get()->repo == _solv->installed) {
1218 problemSolution->addSingleAction (poolItem, KEEP);
1219 string description = str::form (_("keep %s despite the inferior architecture"), solvable2str(pool, s.get()));
1220 MIL << description << endl;
1221 problemSolution->addDescription (description);
1223 problemSolution->addSingleAction (poolItem, INSTALL);
1224 string description = str::form (_("install %s despite the inferior architecture"), solvable2str(pool, s.get()));
1225 MIL << description << endl;
1226 problemSolution->addDescription (description);
1228 } else if (p == SOLVER_SOLUTION_DISTUPGRADE) {
1229 s = mapSolvable (rp);
1230 PoolItem poolItem = _pool.find (s);
1231 if (_solv->installed && s.get()->repo == _solv->installed) {
1232 problemSolution->addSingleAction (poolItem, KEEP);
1233 string description = str::form (_("keep obsolete %s"), solvable2str(pool, s.get()));
1234 MIL << description << endl;
1235 problemSolution->addDescription (description);
1237 problemSolution->addSingleAction (poolItem, INSTALL);
1238 string description = str::form (_("install %s from excluded repository"), solvable2str(pool, s.get()));
1239 MIL << description << endl;
1240 problemSolution->addDescription (description);
1243 /* policy, replace p with rp */
1244 s = mapSolvable (p);
1246 sd = mapSolvable (rp);
1248 PoolItem itemFrom = _pool.find (s);
1249 if (s == sd && _solv->distupgrade)
1251 PoolItem poolItem = _pool.find (s);
1253 problemSolution->addSingleAction (poolItem, LOCK); // for solver reason: NOT weak lock.
1254 string description = str::form (_("keep %s"), solvable2str(pool, s.get()));
1255 MIL << description << endl;
1256 problemSolution->addDescription (description);
1258 ERR << "SOLVER_INSTALL_SOLVABLE: No item found for " << id2str(pool, s.get()->name) << "-"
1259 << id2str(pool, s.get()->evr) << "." << id2str(pool, s.get()->arch) << endl;
1266 PoolItem itemTo = _pool.find (sd);
1267 if (itemFrom && itemTo) {
1268 problemSolution->addSingleAction (itemTo, INSTALL);
1270 if (evrcmp(pool, s.get()->evr, sd.get()->evr, EVRCMP_COMPARE ) > 0)
1272 string description = str::form (_("downgrade of %s to %s"), solvable2str(pool, s.get()), solvable2str(pool, sd.get()));
1273 MIL << description << endl;
1274 problemSolution->addDescription (description);
1277 if (!_solv->allowarchchange && s.get()->name == sd.get()->name && s.get()->arch != sd.get()->arch
1278 && policy_illegal_archchange(_solv, s.get(), sd.get()))
1280 string description = str::form (_("architecture change of %s to %s"), solvable2str(pool, s.get()), solvable2str(pool, sd.get()));
1281 MIL << description << endl;
1282 problemSolution->addDescription (description);
1285 if (!_solv->allowvendorchange && s.get()->name == sd.get()->name && s.get()->vendor != sd.get()->vendor
1286 && policy_illegal_vendorchange(_solv, s.get(), sd.get()))
1288 string description = str::form (_("install %s (with vendor change)\n %s\n-->\n %s") ,
1289 solvable2str(pool, sd.get()) , id2str(pool, s.get()->vendor),
1290 string(sd.get()->vendor ? id2str(pool, sd.get()->vendor) : " (no vendor) ").c_str() );
1291 MIL << description << endl;
1292 problemSolution->addDescription (description);
1296 string description = str::form (_("replacement of %s with %s"), solvable2str(pool, s.get()), solvable2str(pool, sd.get()));
1297 MIL << description << endl;
1298 problemSolution->addDescription (description);
1301 ERR << id2str(pool, s.get()->name) << "-" << id2str(pool, s.get()->evr) << "." << id2str(pool, s.get()->arch)
1302 << " or " << id2str(pool, sd.get()->name) << "-" << id2str(pool, sd.get()->evr) << "." << id2str(pool, sd.get()->arch) << " not found" << endl;
1308 string description = str::form (_("deinstallation of %s"), solvable2str(pool, s.get()));
1309 MIL << description << endl;
1310 problemSolution->addDescription (description);
1311 problemSolution->addSingleAction (itemFrom, REMOVE);
1316 resolverProblem->addSolution (problemSolution,
1317 problemSolution->actionCount() > 1 ? true : false); // Solutions with more than 1 action will be shown first.
1318 MIL << "------------------------------------" << endl;
1322 // There is a possibility to ignore this error by setting weak dependencies
1323 PoolItem item = _pool.find (sat::Solvable(ignoreId));
1324 ProblemSolutionIgnore *problemSolution = new ProblemSolutionIgnore(resolverProblem, item);
1325 resolverProblem->addSolution (problemSolution,
1326 false); // Solutions will be shown at the end
1327 MIL << "ignore some dependencies of " << item << endl;
1328 MIL << "------------------------------------" << endl;
1332 resolverProblems.push_back (resolverProblem);
1335 return resolverProblems;
1339 SATResolver::applySolutions (const ProblemSolutionList & solutions)
1341 for (ProblemSolutionList::const_iterator iter = solutions.begin();
1342 iter != solutions.end(); ++iter) {
1343 ProblemSolution_Ptr solution = *iter;
1344 Resolver dummyResolver(_pool);
1345 if (!solution->apply (dummyResolver))
1350 void SATResolver::setLocks()
1352 for (PoolItemList::const_iterator iter = _items_to_lock.begin(); iter != _items_to_lock.end(); iter++) {
1353 sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
1354 if (iter->status().isInstalled()) {
1355 MIL << "Lock installed item " << *iter << endl;
1356 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE );
1357 queue_push( &(_jobQueue), ident );
1359 MIL << "Lock NOT installed item " << *iter << endl;
1360 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE );
1361 queue_push( &(_jobQueue), ident );
1365 for (PoolItemList::const_iterator iter = _items_to_keep.begin(); iter != _items_to_keep.end(); iter++) {
1366 sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
1367 if (iter->status().isInstalled()) {
1368 MIL << "Keep installed item " << *iter << endl;
1369 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE | SOLVER_WEAK);
1370 queue_push( &(_jobQueue), ident );
1372 MIL << "Keep NOT installed item " << *iter << ident << endl;
1373 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE | SOLVER_WEAK);
1374 queue_push( &(_jobQueue), ident );
1379 void SATResolver::setSystemRequirements()
1381 CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1382 CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1384 for (CapabilitySet::const_iterator iter = system_requires.begin(); iter != system_requires.end(); iter++) {
1385 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE_PROVIDES);
1386 queue_push( &(_jobQueue), iter->id() );
1387 MIL << "SYSTEM Requires " << *iter << endl;
1390 for (CapabilitySet::const_iterator iter = system_conflicts.begin(); iter != system_conflicts.end(); iter++) {
1391 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_PROVIDES);
1392 queue_push( &(_jobQueue), iter->id() );
1393 MIL << "SYSTEM Conflicts " << *iter << endl;
1396 // try to prefer none architecture change if possible
1397 // So the architecture of the "rpm" package should be prefered
1399 Capability cap("rpm");
1400 sat::WhatProvides rpmProviders(cap);
1401 for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
1402 if (iter2->isSystem()) {
1403 sat::detail::IdType nid = iter2->ident().id();
1404 nid = rel2id(_SATPool,
1406 iter2->arch().id(), REL_ARCH, true);
1409 bool addRule = false;
1410 Capability cap(nid);
1411 sat::WhatProvides rpmProviders(cap);
1412 for_( iter3, rpmProviders.begin(), rpmProviders.end() ) {
1413 if ( !(iter3->isSystem())) {
1422 queue_push(&(_jobQueue), SOLVER_INSTALL|SOLVABLE_NAME|SOLVER_ESSENTIAL);
1423 queue_push(&(_jobQueue), nid);
1430 ///////////////////////////////////////////////////////////////////
1431 };// namespace detail
1432 /////////////////////////////////////////////////////////////////////
1433 /////////////////////////////////////////////////////////////////////
1434 };// namespace solver
1435 ///////////////////////////////////////////////////////////////////////
1436 ///////////////////////////////////////////////////////////////////////
1438 /////////////////////////////////////////////////////////////////////////