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
23 #include <satsolver/repo_solv.h>
24 #include <satsolver/poolarch.h>
25 #include <satsolver/evr.h>
26 #include <satsolver/poolvendor.h>
27 #include <satsolver/policy.h>
28 #include <satsolver/bitmap.h>
29 #include <satsolver/queue.h>
32 #include "zypp/solver/detail/Helper.h"
33 #include "zypp/base/String.h"
34 #include "zypp/Product.h"
35 #include "zypp/Capability.h"
36 #include "zypp/ResStatus.h"
37 #include "zypp/VendorAttr.h"
38 #include "zypp/base/LogTools.h"
39 #include "zypp/base/String.h"
40 #include "zypp/base/Gettext.h"
41 #include "zypp/base/Algorithm.h"
42 #include "zypp/ResPool.h"
43 #include "zypp/ResFilters.h"
44 #include "zypp/ZConfig.h"
45 #include "zypp/sat/Pool.h"
46 #include "zypp/sat/WhatProvides.h"
47 #include "zypp/sat/WhatObsoletes.h"
48 #include "zypp/solver/detail/SATResolver.h"
49 #include "zypp/solver/detail/ProblemSolutionCombi.h"
50 #include "zypp/solver/detail/ProblemSolutionIgnore.h"
51 #include "zypp/solver/detail/SolverQueueItemInstall.h"
52 #include "zypp/solver/detail/SolverQueueItemDelete.h"
53 #include "zypp/solver/detail/SystemCheck.h"
55 /////////////////////////////////////////////////////////////////////////
57 { ///////////////////////////////////////////////////////////////////////
58 ///////////////////////////////////////////////////////////////////////
60 { /////////////////////////////////////////////////////////////////////
61 /////////////////////////////////////////////////////////////////////
63 { ///////////////////////////////////////////////////////////////////
67 IMPL_PTR_TYPE(SATResolver);
69 //---------------------------------------------------------------------------
70 // Callbacks for SAT policies
71 //---------------------------------------------------------------------------
73 int vendorCheck( Pool *pool, Solvable *solvable1, Solvable *solvable2 )
75 return VendorAttr::instance().equivalent( IdString(solvable1->vendor),
76 IdString(solvable2->vendor) ) ? 0 : 1;
80 inline std::string itemToString( const PoolItem & item )
85 sat::Solvable slv( item.satSolvable() );
86 std::string ret( slv.asString() ); // n-v-r.a
87 if ( ! slv.isSystem() )
90 ret += slv.repository().alias();
96 inline PoolItem getPoolItem( Id id_r )
98 PoolItem ret( (sat::Solvable( id_r )) );
100 INT << "id " << id_r << " not found in ZYPP pool." << endl;
104 //---------------------------------------------------------------------------
107 SATResolver::dumpOn( std::ostream & os ) const
109 os << "<resolver>" << endl;
111 os << " fixsystem = " << _solv->fixsystem << endl;
112 os << " allowdowngrade = " << _solv->allowdowngrade << endl;
113 os << " allowarchchange = " << _solv->allowarchchange << endl;
114 os << " allowvendorchange = " << _solv->allowvendorchange << endl;
115 os << " allowuninstall = " << _solv->allowuninstall << endl;
116 os << " updatesystem = " << _solv->updatesystem << endl;
117 os << " noupdateprovide = " << _solv->noupdateprovide << endl;
118 os << " dosplitprovides = " << _solv->dosplitprovides << endl;
119 os << " onlyRequires = " << _solv->dontinstallrecommended << endl;
120 os << " ignorealreadyrecommended = " << _solv->ignorealreadyrecommended << endl;
121 os << " distupgrade = " << _distupgrade << endl;
122 os << " distupgrade_removeunsupported = " << _distupgrade_removeunsupported << endl;
123 os << " solveSrcPackages = " << _solveSrcPackages << endl;
127 return os << "<resolver/>" << endl;
130 //---------------------------------------------------------------------------
132 SATResolver::SATResolver (const ResPool & pool, Pool *SATPool)
137 , _allowdowngrade(false)
138 , _allowarchchange(false)
139 , _allowvendorchange(false)
140 , _allowuninstall(false)
141 , _updatesystem(false)
142 , _noupdateprovide(false)
143 , _dosplitprovides(false)
144 , _onlyRequires(ZConfig::instance().solver_onlyRequires())
145 , _ignorealreadyrecommended(false)
146 , _distupgrade(false)
147 , _distupgrade_removeunsupported(false)
153 SATResolver::~SATResolver()
157 //---------------------------------------------------------------------------
161 SATResolver::pool (void) const
168 SATResolver::resetItemTransaction (PoolItem item)
171 for (PoolItemList::const_iterator iter = _items_to_remove.begin();
172 iter != _items_to_remove.end(); ++iter) {
174 _items_to_remove.remove(*iter);
180 for (PoolItemList::const_iterator iter = _items_to_install.begin();
181 iter != _items_to_install.end(); ++iter) {
183 _items_to_install.remove(*iter);
190 for (PoolItemList::const_iterator iter = _items_to_keep.begin();
191 iter != _items_to_keep.end(); ++iter) {
193 _items_to_keep.remove(*iter);
200 for (PoolItemList::const_iterator iter = _items_to_lock.begin();
201 iter != _items_to_lock.end(); ++iter) {
203 _items_to_lock.remove(*iter);
213 SATResolver::addPoolItemToInstall (PoolItem item)
215 resetItemTransaction (item);
216 _items_to_install.push_back (item);
217 _items_to_install.unique ();
222 SATResolver::addPoolItemsToInstallFromList (PoolItemList & rl)
224 for (PoolItemList::const_iterator iter = rl.begin(); iter != rl.end(); iter++) {
225 addPoolItemToInstall (*iter);
231 SATResolver::addPoolItemToRemove (PoolItem item)
233 resetItemTransaction (item);
234 _items_to_remove.push_back (item);
235 _items_to_remove.unique ();
240 SATResolver::addPoolItemsToRemoveFromList (PoolItemList & rl)
242 for (PoolItemList::const_iterator iter = rl.begin(); iter != rl.end(); iter++) {
243 addPoolItemToRemove (*iter);
248 SATResolver::addPoolItemToLock (PoolItem item)
250 resetItemTransaction (item);
251 _items_to_lock.push_back (item);
252 _items_to_lock.unique ();
256 SATResolver::addPoolItemToKeep (PoolItem item)
258 resetItemTransaction (item);
259 _items_to_keep.push_back (item);
260 _items_to_keep.unique ();
263 //---------------------------------------------------------------------------
265 // copy marked item from solution back to pool
266 // if data != NULL, set as APPL_LOW (from establishPool())
269 SATSolutionToPool (PoolItem item, const ResStatus & status, const ResStatus::TransactByValue causer)
272 item.status().resetTransact (causer);
273 item.status().resetWeak ();
277 // installation/deletion
278 if (status.isToBeInstalled()) {
279 r = item.status().setToBeInstalled (causer);
280 _XDEBUG("SATSolutionToPool install returns " << item << ", " << r);
282 else if (status.isToBeUninstalledDueToUpgrade()) {
283 r = item.status().setToBeUninstalledDueToUpgrade (causer);
284 _XDEBUG("SATSolutionToPool upgrade returns " << item << ", " << r);
286 else if (status.isToBeUninstalled()) {
287 r = item.status().setToBeUninstalled (causer);
288 _XDEBUG("SATSolutionToPool remove returns " << item << ", " << r);
294 //----------------------------------------------------------------------------
295 //----------------------------------------------------------------------------
297 //----------------------------------------------------------------------------
298 //----------------------------------------------------------------------------
300 //----------------------------------------------------------------------------
301 // Helper functions for the ZYPP-Pool
302 //----------------------------------------------------------------------------
305 //------------------------------------------------------------------------------------------------------------
306 // This function loops over the pool and grabs all items
307 // It clears all previous bySolver() states also
309 // Every toBeInstalled is passed to zypp::solver:detail::Resolver.addPoolItemToInstall()
310 // Every toBeUninstalled is passed to zypp::solver:detail::Resolver.addPoolItemToRemove()
312 // Solver results must be written back to the pool.
313 //------------------------------------------------------------------------------------------------------------
316 struct SATCollectTransact : public resfilter::PoolItemFilterFunctor
318 SATResolver & resolver;
320 SATCollectTransact (SATResolver & r)
324 bool operator()( PoolItem item ) // only transacts() items go here
326 ResStatus status = item.status();
327 bool by_solver = (status.isBySolver() || status.isByApplLow());
330 item.status().resetTransact( ResStatus::APPL_LOW );// clear any solver/establish transactions
331 return true; // back out here, dont re-queue former solver result
334 if ( item.satSolvable().isKind<SrcPackage>() && ! resolver.solveSrcPackages() )
336 // Later we may continue on a per source package base.
337 return true; // dont process this source package.
340 if (status.isToBeInstalled()) {
341 resolver.addPoolItemToInstall(item); // -> install!
343 else if (status.isToBeUninstalled()) {
344 resolver.addPoolItemToRemove(item); // -> remove !
346 else if (status.isLocked()
348 resolver.addPoolItemToLock (item);
350 else if (status.isKept()
352 resolver.addPoolItemToKeep (item);
360 //----------------------------------------------------------------------------
361 //----------------------------------------------------------------------------
363 //----------------------------------------------------------------------------
364 //----------------------------------------------------------------------------
367 class CheckIfUpdate : public resfilter::PoolItemFilterFunctor
372 sat::Solvable _installed;
374 CheckIfUpdate( sat::Solvable installed_r )
375 : is_updated( false )
376 , multiversion( installed_r.multiversionInstall() )
377 , _installed( installed_r )
380 // check this item will be updated
382 bool operator()( PoolItem item )
384 if ( item.status().isToBeInstalled() )
386 if ( ! multiversion || sameNVRA( _installed, item ) )
397 class CollectPseudoInstalled : public resfilter::PoolItemFilterFunctor
400 Queue *solvableQueue;
402 CollectPseudoInstalled( Queue *queue )
403 :solvableQueue (queue)
406 // collecting PseudoInstalled items
407 bool operator()( PoolItem item )
409 if ( traits::isPseudoInstalled( item.satSolvable().kind() ) )
410 queue_push( solvableQueue, item.satSolvable().id() );
416 SATResolver::solving(const CapabilitySet & requires_caps,
417 const CapabilitySet & conflict_caps)
419 _solv = solver_create( _SATPool );
420 _solv->vendorCheckCb = &vendorCheck;
421 _solv->fixsystem = _fixsystem;
422 _solv->ignorealreadyrecommended = _ignorealreadyrecommended;
423 _solv->updatesystem = _updatesystem;
424 _solv->allowdowngrade = _allowdowngrade;
425 _solv->allowuninstall = _allowuninstall;
426 _solv->allowarchchange = _allowarchchange;
427 _solv->allowvendorchange = _allowvendorchange;
428 _solv->dosplitprovides = _dosplitprovides;
429 _solv->noupdateprovide = _noupdateprovide;
430 _solv->dontinstallrecommended = _onlyRequires;
431 _solv->distupgrade = _distupgrade;
432 _solv->distupgrade_removeunsupported = _distupgrade_removeunsupported;
434 sat::Pool::instance().prepare();
437 MIL << "Starting solving...." << endl;
439 solver_solve( _solv, &(_jobQueue) );
440 MIL << "....Solver end" << endl;
442 // copying solution back to zypp pool
443 //-----------------------------------------
444 _result_items_to_install.clear();
445 _result_items_to_remove.clear();
447 /* solvables to be installed */
448 for ( int i = 0; i < _solv->decisionq.count; ++i )
450 sat::Solvable slv( _solv->decisionq.elements[i] );
451 if ( !slv || slv.isSystem() )
454 PoolItem poolItem( slv );
455 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
456 _result_items_to_install.push_back (poolItem);
459 /* solvables to be erased */
460 Repository systemRepo( sat::Pool::instance().findSystemRepo() ); // don't create if it does not exist
461 if ( systemRepo && ! systemRepo.solvablesEmpty() )
463 bool mustCheckObsoletes = false;
464 for_( it, systemRepo.solvablesBegin(), systemRepo.solvablesEnd() )
466 if (_solv->decisionmap[it->id()] > 0)
469 // Check if this is an update
470 CheckIfUpdate info( *it );
471 PoolItem poolItem( *it );
472 invokeOnEach( _pool.byIdentBegin( poolItem ),
473 _pool.byIdentEnd( poolItem ),
474 resfilter::ByUninstalled(), // ByUninstalled
475 functor::functorRef<bool,PoolItem> (info) );
477 if (info.is_updated) {
478 SATSolutionToPool( poolItem, ResStatus::toBeUninstalledDueToUpgrade, ResStatus::SOLVER );
480 SATSolutionToPool( poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER );
481 if ( ! mustCheckObsoletes )
482 mustCheckObsoletes = true; // lazy check for UninstalledDueToObsolete
484 _result_items_to_remove.push_back (poolItem);
486 if ( mustCheckObsoletes )
488 sat::WhatObsoletes obsoleted( _result_items_to_install.begin(), _result_items_to_install.end() );
489 for_( it, obsoleted.poolItemBegin(), obsoleted.poolItemEnd() )
491 ResStatus & status( it->status() );
492 // WhatObsoletes contains installed items only!
493 if ( status.transacts() && ! status.isToBeUninstalledDueToUpgrade() )
494 status.setToBeUninstalledDueToObsolete();
499 /* solvables which are recommended */
500 for ( int i = 0; i < _solv->recommendations.count; ++i )
502 PoolItem poolItem( getPoolItem( _solv->recommendations.elements[i] ) );
503 poolItem.status().setRecommended( true );
506 /* solvables which are suggested */
507 for ( int i = 0; i < _solv->suggestions.count; ++i )
509 PoolItem poolItem( getPoolItem( _solv->suggestions.elements[i] ) );
510 poolItem.status().setSuggested( true );
513 _problem_items.clear();
514 /* solvables which are orphaned */
515 for ( int i = 0; i < _solv->orphaned.count; ++i )
517 PoolItem poolItem( getPoolItem( _solv->orphaned.elements[i] ) );
518 poolItem.status().setOrphaned( true );
519 _problem_items.push_back( poolItem );
522 /* Write validation state back to pool */
523 Queue flags, solvableQueue;
526 queue_init(&solvableQueue);
528 CollectPseudoInstalled collectPseudoInstalled(&solvableQueue);
529 invokeOnEach( _pool.begin(),
531 functor::functorRef<bool,PoolItem> (collectPseudoInstalled) );
532 solver_trivial_installable(_solv, &solvableQueue, &flags );
533 for (int i = 0; i < solvableQueue.count; i++) {
534 PoolItem item = _pool.find (sat::Solvable(solvableQueue.elements[i]));
535 item.status().setUndetermined();
537 if (flags.elements[i] == -1) {
538 item.status().setNonRelevant();
539 _XDEBUG("SATSolutionToPool(" << item << " ) nonRelevant !");
540 } else if (flags.elements[i] == 1) {
541 item.status().setSatisfied();
542 _XDEBUG("SATSolutionToPool(" << item << " ) satisfied !");
543 } else if (flags.elements[i] == 0) {
544 item.status().setBroken();
545 _XDEBUG("SATSolutionToPool(" << item << " ) broken !");
549 // Solvables which were selected due requirements which have been made by the user will
550 // be selected by APPL_LOW. We can't use any higher level, because this setting must
551 // not serve as a request for the next solver run. APPL_LOW is reset before solving.
552 for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
553 sat::WhatProvides rpmProviders(*iter);
554 for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
555 PoolItem poolItem(*iter2);
556 if (poolItem.status().isToBeInstalled()) {
557 MIL << "User requirement " << *iter << " sets " << poolItem << endl;
558 poolItem.status().setTransactByValue (ResStatus::APPL_LOW);
562 for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
563 sat::WhatProvides rpmProviders(*iter);
564 for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
565 PoolItem poolItem(*iter2);
566 if (poolItem.status().isToBeUninstalled()) {
567 MIL << "User conflict " << *iter << " sets " << poolItem << endl;
568 poolItem.status().setTransactByValue (ResStatus::APPL_LOW);
573 if (_solv->problems.count > 0 )
575 ERR << "Solverrun finished with an ERROR" << endl;
579 queue_free(&(solvableQueue));
587 SATResolver::solverInit(const PoolItemList & weakItems)
589 SATCollectTransact info (*this);
591 MIL << "SATResolver::solverInit()" << endl;
597 queue_free( &(_jobQueue) );
600 queue_init( &_jobQueue );
601 _items_to_install.clear();
602 _items_to_remove.clear();
603 _items_to_lock.clear();
604 _items_to_keep.clear();
606 invokeOnEach ( _pool.begin(), _pool.end(),
607 functor::functorRef<bool,PoolItem>(info) );
609 for (PoolItemList::const_iterator iter = weakItems.begin(); iter != weakItems.end(); iter++) {
610 Id id = (*iter)->satSolvable().id();
612 ERR << "Weaken: " << *iter << " not found" << endl;
614 MIL << "Weaken dependencies of " << *iter << endl;
615 queue_push( &(_jobQueue), SOLVER_WEAKEN_SOLVABLE_DEPS );
616 queue_push( &(_jobQueue), id );
619 // Add rules for parallel installable resolvables with different versions
620 for_( it, sat::Pool::instance().multiversionBegin(), sat::Pool::instance().multiversionEnd() )
622 queue_push( &(_jobQueue), SOLVER_NOOBSOLETES_SOLVABLE_NAME );
623 queue_push( &(_jobQueue), it->id() );
628 if ( ZConfig::instance().solverUpgradeRemoveDroppedPackages() )
630 MIL << "Checking droplists ..." << endl;
631 // Dropped packages: look for 'weakremover()' provides
632 // in dup candidates of installed products.
633 ResPoolProxy proxy( ResPool::instance().proxy() );
634 for_( it, proxy.byKindBegin<Product>(), proxy.byKindEnd<Product>() )
636 if ( (*it)->onSystem() ) // (to install) or (not to delete)
638 Product::constPtr prodCand( (*it)->candidateAsKind<Product>() );
639 if ( ! prodCand || (*it)->identicalInstalledCandidate() )
640 continue; // product no longer available or unchanged
642 CapabilitySet droplist( prodCand->droplist() );
643 dumpRangeLine( MIL << "Droplist for " << (*it)->candidateObj() << ": " << droplist.size() << " ", droplist.begin(), droplist.end() ) << endl;
644 for_( cap, droplist.begin(), droplist.end() )
646 queue_push( &_jobQueue, SOLVER_DROP_ORPHANED|SOLVER_SOLVABLE_NAME );
647 queue_push( &_jobQueue, cap->id() );
654 MIL << "Droplist processing is disabled." << endl;
660 SATResolver::solverEnd()
665 queue_free( &(_jobQueue) );
670 SATResolver::resolvePool(const CapabilitySet & requires_caps,
671 const CapabilitySet & conflict_caps,
672 const PoolItemList & weakItems,
673 const std::set<Repository> & upgradeRepos)
675 MIL << "SATResolver::resolvePool()" << endl;
678 solverInit(weakItems);
680 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
681 Id id = (*iter)->satSolvable().id();
683 ERR << "Install: " << *iter << " not found" << endl;
685 MIL << "Install " << *iter << endl;
686 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE );
687 queue_push( &(_jobQueue), id );
691 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
692 Id id = (*iter)->satSolvable().id();
694 ERR << "Delete: " << *iter << " not found" << endl;
696 MIL << "Delete " << *iter << endl;
697 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE );
698 queue_push( &(_jobQueue), id);
702 for_( iter, upgradeRepos.begin(), upgradeRepos.end() )
704 queue_push( &(_jobQueue), SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_REPO );
705 queue_push( &(_jobQueue), iter->get()->repoid );
706 MIL << "Upgrade repo " << *iter << endl;
709 for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
710 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE_PROVIDES );
711 queue_push( &(_jobQueue), iter->id() );
712 MIL << "Requires " << *iter << endl;
715 for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
716 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_PROVIDES);
717 queue_push( &(_jobQueue), iter->id() );
718 MIL << "Conflicts " << *iter << endl;
721 // set requirements for a running system
722 setSystemRequirements();
724 // set locks for the solver
728 bool ret = solving(requires_caps, conflict_caps);
731 solverEnd(); // remove solver only if no errors happend. Need it for solving problems
733 (ret?MIL:WAR) << "SATResolver::resolvePool() done. Ret:" << ret << endl;
739 SATResolver::resolveQueue(const SolverQueueItemList &requestQueue,
740 const PoolItemList & weakItems)
742 MIL << "SATResolver::resolvQueue()" << endl;
745 solverInit(weakItems);
747 // generate solver queue
748 for (SolverQueueItemList::const_iterator iter = requestQueue.begin(); iter != requestQueue.end(); iter++) {
749 (*iter)->addRule(_jobQueue);
752 // Add addition item status to the resolve-queue cause these can be set by problem resolutions
753 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
754 Id id = (*iter)->satSolvable().id();
756 ERR << "Install: " << *iter << " not found" << endl;
758 MIL << "Install " << *iter << endl;
759 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE );
760 queue_push( &(_jobQueue), id );
763 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
764 sat::detail::IdType ident( (*iter)->satSolvable().ident().id() );
765 MIL << "Delete " << *iter << ident << endl;
766 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_NAME );
767 queue_push( &(_jobQueue), ident);
770 // set requirements for a running system
771 setSystemRequirements();
773 // set locks for the solver
777 bool ret = solving();
781 solverEnd(); // remove solver only if no errors happend. Need it for solving problems
783 MIL << "SATResolver::resolveQueue() done. Ret:" << ret << endl;
788 void SATResolver::doUpdate()
790 MIL << "SATResolver::doUpdate()" << endl;
793 solverInit(PoolItemList());
795 // set requirements for a running system
796 setSystemRequirements();
798 // set locks for the solver
801 _solv = solver_create( _SATPool );
802 _solv->vendorCheckCb = &vendorCheck;
804 _solv->updatesystem = true;
805 _solv->dontinstallrecommended = true; // #FIXME dontinstallrecommended maybe set to false if it works correctly
807 sat::Pool::instance().prepare();
810 MIL << "Starting solving for update...." << endl;
812 solver_solve( _solv, &(_jobQueue) );
813 MIL << "....Solver end" << endl;
815 // copying solution back to zypp pool
816 //-----------------------------------------
818 /* solvables to be installed */
819 for (int i = 0; i < _solv->decisionq.count; i++)
822 p = _solv->decisionq.elements[i];
823 if (p < 0 || !sat::Solvable(p))
825 if (sat::Solvable(p).repository().get() == _solv->installed)
828 PoolItem poolItem = _pool.find (sat::Solvable(p));
830 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
832 ERR << "id " << p << " not found in ZYPP pool." << endl;
836 /* solvables to be erased */
837 for (int i = _solv->installed->start; i < _solv->installed->start + _solv->installed->nsolvables; i++)
839 if (_solv->decisionmap[i] > 0)
842 PoolItem poolItem( _pool.find( sat::Solvable(i) ) );
844 // Check if this is an update
845 CheckIfUpdate info( (sat::Solvable(i)) );
846 invokeOnEach( _pool.byIdentBegin( poolItem ),
847 _pool.byIdentEnd( poolItem ),
848 resfilter::ByUninstalled(), // ByUninstalled
849 functor::functorRef<bool,PoolItem> (info) );
851 if (info.is_updated) {
852 SATSolutionToPool (poolItem, ResStatus::toBeUninstalledDueToUpgrade , ResStatus::SOLVER);
854 SATSolutionToPool (poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER);
857 ERR << "id " << i << " not found in ZYPP pool." << endl;
864 MIL << "SATResolver::doUpdate() done" << endl;
869 //----------------------------------------------------------------------------
870 //----------------------------------------------------------------------------
872 //----------------------------------------------------------------------------
873 //----------------------------------------------------------------------------
875 //----------------------------------------------------------------------------
877 //----------------------------------------------------------------------------
879 struct FindPackage : public resfilter::ResObjectFilterFunctor
881 ProblemSolutionCombi *problemSolution;
882 TransactionKind action;
883 FindPackage (ProblemSolutionCombi *p, const TransactionKind act)
884 : problemSolution (p)
889 bool operator()( PoolItem p)
891 problemSolution->addSingleAction (p, action);
897 //----------------------------------------------------------------------------
898 // Checking if this solvable/item has a buddy which reflect the real
899 // user visible description of an item
900 // e.g. The release package has a buddy to the concerning product item.
901 // This user want's the message "Product foo conflicts with product bar" and
902 // NOT "package release-foo conflicts with package release-bar"
903 //----------------------------------------------------------------------------
906 PoolItem SATResolver::mapItem (const PoolItem &item)
908 sat::Solvable buddy = item.buddy();
909 if (buddy != sat::Solvable())
911 return _pool.find (buddy);
919 sat::Solvable SATResolver::mapSolvable (const Id &id)
921 PoolItem item = _pool.find (sat::Solvable(id));
922 return mapItem(item).satSolvable();
925 string SATResolver::SATprobleminfoString(Id problem, string &detail, Id &ignoreId)
928 Pool *pool = _solv->pool;
930 Id dep, source, target;
934 probr = solver_findproblemrule(_solv, problem);
935 switch (solver_problemruleinfo(_solv, &(_jobQueue), probr, &dep, &source, &target))
937 case SOLVER_PROBLEM_DISTUPGRADE_RULE:
938 s = mapSolvable (source);
939 ret = str::form (_("%s does not belong to a distupgrade repository"), s.asString().c_str());
941 case SOLVER_PROBLEM_INFARCH_RULE:
942 s = mapSolvable (source);
943 ret = str::form (_("%s has inferior architecture"), s.asString().c_str());
945 case SOLVER_PROBLEM_UPDATE_RULE:
946 s = mapSolvable (source);
947 ret = str::form (_("problem with installed package %s"), s.asString().c_str());
949 case SOLVER_PROBLEM_JOB_RULE:
950 ret = _("conflicting requests");
952 case SOLVER_PROBLEM_RPM_RULE:
953 ret = _("some dependency problem");
955 case SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP:
956 ret = str::form (_("nothing provides requested %s"), dep2str(pool, dep));
957 detail += _("Have you enabled all requested repositories?");
959 case SOLVER_PROBLEM_NOT_INSTALLABLE:
960 s = mapSolvable (source);
961 ret = str::form (_("%s is not installable"), s.asString().c_str());
963 case SOLVER_PROBLEM_NOTHING_PROVIDES_DEP:
964 ignoreId = source; // for setting weak dependencies
965 s = mapSolvable (source);
966 ret = str::form (_("nothing provides %s needed by %s"), dep2str(pool, dep), s.asString().c_str());
968 case SOLVER_PROBLEM_SAME_NAME:
969 s = mapSolvable (source);
970 s2 = mapSolvable (target);
971 ret = str::form (_("cannot install both %s and %s"), s.asString().c_str(), s2.asString().c_str());
973 case SOLVER_PROBLEM_PACKAGE_CONFLICT:
974 s = mapSolvable (source);
975 s2 = mapSolvable (target);
976 ret = str::form (_("%s conflicts with %s provided by %s"), s.asString().c_str(), dep2str(pool, dep), s2.asString().c_str());
978 case SOLVER_PROBLEM_PACKAGE_OBSOLETES:
979 s = mapSolvable (source);
980 s2 = mapSolvable (target);
981 ret = str::form (_("%s obsoletes %s provided by %s"), s.asString().c_str(), dep2str(pool, dep), s2.asString().c_str());
983 case SOLVER_PROBLEM_SELF_CONFLICT:
984 s = mapSolvable (source);
985 ret = str::form (_("solvable %s conflicts with %s provided by itself"), s.asString().c_str(), dep2str(pool, dep));
987 case SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE:
988 ignoreId = source; // for setting weak dependencies
989 s = mapSolvable (source);
991 sat::WhatProvides possibleProviders(cap);
993 // check, if a provider will be deleted
994 typedef list<PoolItem> ProviderList;
995 ProviderList providerlistInstalled, providerlistUninstalled;
996 for_( iter1, possibleProviders.begin(), possibleProviders.end() ) {
997 PoolItem provider1 = ResPool::instance().find( *iter1 );
998 // find pair of an installed/uninstalled item with the same NVR
1000 for_( iter2, possibleProviders.begin(), possibleProviders.end() ) {
1001 PoolItem provider2 = ResPool::instance().find( *iter2 );
1002 if (compareByNVR (provider1.resolvable(),provider2.resolvable()) == 0
1003 && ( (provider1.status().isInstalled() && provider2.status().isUninstalled())
1004 || (provider2.status().isInstalled() && provider1.status().isUninstalled()) )) {
1010 if (provider1.status().isInstalled())
1011 providerlistInstalled.push_back(provider1);
1013 providerlistUninstalled.push_back(provider1);
1017 ret = str::form (_("%s requires %s, but this requirement cannot be provided"), s.asString().c_str(), dep2str(pool, dep));
1018 if (providerlistInstalled.size() > 0) {
1019 detail += _("deleted providers: ");
1020 for (ProviderList::const_iterator iter = providerlistInstalled.begin(); iter != providerlistInstalled.end(); iter++) {
1021 if (iter == providerlistInstalled.begin())
1022 detail += itemToString( *iter );
1024 detail += "\n " + itemToString( mapItem(*iter) );
1027 if (providerlistUninstalled.size() > 0) {
1028 if (detail.size() > 0)
1029 detail += _("\nuninstallable providers: ");
1031 detail = _("uninstallable providers: ");
1032 for (ProviderList::const_iterator iter = providerlistUninstalled.begin(); iter != providerlistUninstalled.end(); iter++) {
1033 if (iter == providerlistUninstalled.begin())
1034 detail += itemToString( *iter );
1036 detail += "\n " + itemToString( mapItem(*iter) );
1046 SATResolver::problems ()
1048 ResolverProblemList resolverProblems;
1049 if (_solv && _solv->problems.count) {
1050 Pool *pool = _solv->pool;
1053 Id problem, solution, element;
1054 sat::Solvable s, sd;
1056 CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1057 CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1059 MIL << "Encountered problems! Here are the solutions:\n" << endl;
1062 while ((problem = solver_next_problem(_solv, problem)) != 0) {
1063 MIL << "Problem " << pcnt++ << ":" << endl;
1064 MIL << "====================================" << endl;
1067 string whatString = SATprobleminfoString (problem,detail,ignoreId);
1068 MIL << whatString << endl;
1069 MIL << "------------------------------------" << endl;
1070 ResolverProblem_Ptr resolverProblem = new ResolverProblem (whatString, detail);
1073 while ((solution = solver_next_solution(_solv, problem, solution)) != 0) {
1075 ProblemSolutionCombi *problemSolution = new ProblemSolutionCombi(resolverProblem);
1076 while ((element = solver_next_solutionelement(_solv, problem, solution, element, &p, &rp)) != 0) {
1077 if (p == SOLVER_SOLUTION_JOB) {
1078 /* job, rp is index into job queue */
1079 what = _jobQueue.elements[rp];
1080 switch (_jobQueue.elements[rp-1])
1082 case SOLVER_INSTALL_SOLVABLE: {
1083 s = mapSolvable (what);
1084 PoolItem poolItem = _pool.find (s);
1086 if (_solv->installed && s.get()->repo == _solv->installed) {
1087 problemSolution->addSingleAction (poolItem, REMOVE);
1088 string description = str::form (_("do not keep %s installed"), s.asString().c_str() );
1089 MIL << description << endl;
1090 problemSolution->addDescription (description);
1092 problemSolution->addSingleAction (poolItem, KEEP);
1093 string description = str::form (_("do not install %s"), s.asString().c_str());
1094 MIL << description << endl;
1095 problemSolution->addDescription (description);
1098 ERR << "SOLVER_INSTALL_SOLVABLE: No item found for " << s.asString() << endl;
1102 case SOLVER_ERASE_SOLVABLE: {
1103 s = mapSolvable (what);
1104 PoolItem poolItem = _pool.find (s);
1106 if (_solv->installed && s.get()->repo == _solv->installed) {
1107 problemSolution->addSingleAction (poolItem, KEEP);
1108 string description = str::form (_("keep %s"), s.asString().c_str());
1109 MIL << description << endl;
1110 problemSolution->addDescription (description);
1112 problemSolution->addSingleAction (poolItem, UNLOCK);
1113 string description = str::form (_("do not forbid installation of %s"), itemToString( poolItem ).c_str());
1114 MIL << description << endl;
1115 problemSolution->addDescription (description);
1118 ERR << "SOLVER_ERASE_SOLVABLE: No item found for " << s.asString() << endl;
1122 case SOLVER_INSTALL_SOLVABLE_NAME:
1124 IdString ident( what );
1125 SolverQueueItemInstall_Ptr install =
1126 new SolverQueueItemInstall(_pool, ident.asString(), false );
1127 problemSolution->addSingleAction (install, REMOVE_SOLVE_QUEUE_ITEM);
1129 string description = str::form (_("do not install %s"), ident.c_str() );
1130 MIL << description << endl;
1131 problemSolution->addDescription (description);
1134 case SOLVER_ERASE_SOLVABLE_NAME:
1136 // As we do not know, if this request has come from resolvePool or
1137 // resolveQueue we will have to take care for both cases.
1138 IdString ident( what );
1139 FindPackage info (problemSolution, KEEP);
1140 invokeOnEach( _pool.byIdentBegin( ident ),
1141 _pool.byIdentEnd( ident ),
1142 functor::chain (resfilter::ByInstalled (), // ByInstalled
1143 resfilter::ByTransact ()), // will be deinstalled
1144 functor::functorRef<bool,PoolItem> (info) );
1146 SolverQueueItemDelete_Ptr del =
1147 new SolverQueueItemDelete(_pool, ident.asString(), false );
1148 problemSolution->addSingleAction (del, REMOVE_SOLVE_QUEUE_ITEM);
1150 string description = str::form (_("keep %s"), ident.c_str());
1151 MIL << description << endl;
1152 problemSolution->addDescription (description);
1155 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
1157 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_REQUIRE);
1158 string description = "";
1160 // Checking if this problem solution would break your system
1161 if (system_requires.find(Capability(what)) != system_requires.end()) {
1162 // Show a better warning
1163 resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1164 resolverProblem->setDescription(_("This request will break your system!"));
1165 description = _("ignore the warning of a broken system");
1166 description += string(" (requires:")+dep2str(pool, what)+")";
1167 MIL << description << endl;
1168 problemSolution->addFrontDescription (description);
1170 description = str::form (_("do not ask to install a solvable providing %s"), dep2str(pool, what));
1171 MIL << description << endl;
1172 problemSolution->addDescription (description);
1176 case SOLVER_ERASE_SOLVABLE_PROVIDES:
1178 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_CONFLICT);
1179 string description = "";
1181 // Checking if this problem solution would break your system
1182 if (system_conflicts.find(Capability(what)) != system_conflicts.end()) {
1183 // Show a better warning
1184 resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1185 resolverProblem->setDescription(_("This request will break your system!"));
1186 description = _("ignore the warning of a broken system");
1187 description += string(" (conflicts:")+dep2str(pool, what)+")";
1188 MIL << description << endl;
1189 problemSolution->addFrontDescription (description);
1192 description = str::form (_("do not ask to delete all solvables providing %s"), dep2str(pool, what));
1193 MIL << description << endl;
1194 problemSolution->addDescription (description);
1198 case SOLVER_INSTALL_SOLVABLE_UPDATE:
1200 s = mapSolvable (what);
1201 PoolItem poolItem = _pool.find (s);
1203 if (_solv->installed && s.get()->repo == _solv->installed) {
1204 problemSolution->addSingleAction (poolItem, KEEP);
1205 string description = str::form (_("do not install most recent version of %s"), s.asString().c_str());
1206 MIL << description << endl;
1207 problemSolution->addDescription (description);
1209 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE " << poolItem << " is not selected for installation" << endl;
1212 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE: No item found for " << s.asString() << endl;
1217 MIL << "- do something different" << endl;
1218 ERR << "No valid solution available" << endl;
1221 } else if (p == SOLVER_SOLUTION_INFARCH) {
1222 s = mapSolvable (rp);
1223 PoolItem poolItem = _pool.find (s);
1224 if (_solv->installed && s.get()->repo == _solv->installed) {
1225 problemSolution->addSingleAction (poolItem, LOCK);
1226 string description = str::form (_("keep %s despite the inferior architecture"), s.asString().c_str());
1227 MIL << description << endl;
1228 problemSolution->addDescription (description);
1230 problemSolution->addSingleAction (poolItem, INSTALL);
1231 string description = str::form (_("install %s despite the inferior architecture"), s.asString().c_str());
1232 MIL << description << endl;
1233 problemSolution->addDescription (description);
1235 } else if (p == SOLVER_SOLUTION_DISTUPGRADE) {
1236 s = mapSolvable (rp);
1237 PoolItem poolItem = _pool.find (s);
1238 if (_solv->installed && s.get()->repo == _solv->installed) {
1239 problemSolution->addSingleAction (poolItem, LOCK);
1240 string description = str::form (_("keep obsolete %s"), s.asString().c_str());
1241 MIL << description << endl;
1242 problemSolution->addDescription (description);
1244 problemSolution->addSingleAction (poolItem, INSTALL);
1245 string description = str::form (_("install %s from excluded repository"), s.asString().c_str());
1246 MIL << description << endl;
1247 problemSolution->addDescription (description);
1250 /* policy, replace p with rp */
1251 s = mapSolvable (p);
1253 sd = mapSolvable (rp);
1255 PoolItem itemFrom = _pool.find (s);
1256 if (s == sd && _solv->distupgrade)
1258 PoolItem poolItem = _pool.find (s);
1260 problemSolution->addSingleAction (poolItem, LOCK); // for solver reason: NOT weak lock.
1261 string description = str::form (_("keep obsolete %s"), s.asString().c_str());
1262 MIL << description << endl;
1263 problemSolution->addDescription (description);
1265 ERR << "SOLVER_INSTALL_SOLVABLE: No item found for " << s.asString() << endl;
1272 PoolItem itemTo = _pool.find (sd);
1273 if (itemFrom && itemTo) {
1274 problemSolution->addSingleAction (itemTo, INSTALL);
1276 if (evrcmp(pool, s.get()->evr, sd.get()->evr, EVRCMP_COMPARE ) > 0)
1278 string description = str::form (_("downgrade of %s to %s"), s.asString().c_str(), sd.asString().c_str());
1279 MIL << description << endl;
1280 problemSolution->addDescription (description);
1283 if (!_solv->allowarchchange && s.get()->name == sd.get()->name && s.get()->arch != sd.get()->arch
1284 && policy_illegal_archchange(_solv, s.get(), sd.get()))
1286 string description = str::form (_("architecture change of %s to %s"), s.asString().c_str(), sd.asString().c_str());
1287 MIL << description << endl;
1288 problemSolution->addDescription (description);
1291 if (!_solv->allowvendorchange && s.get()->name == sd.get()->name && s.get()->vendor != sd.get()->vendor
1292 && policy_illegal_vendorchange(_solv, s.get(), sd.get()))
1294 IdString s_vendor( s.vendor() );
1295 IdString sd_vendor( sd.vendor() );
1296 string description = str::form (_("install %s (with vendor change)\n %s --> %s") ,
1297 sd.asString().c_str(),
1298 ( s_vendor ? s_vendor.c_str() : " (no vendor) " ),
1299 ( sd_vendor ? sd_vendor.c_str() : " (no vendor) " ) );
1300 MIL << description << endl;
1301 problemSolution->addDescription (description);
1305 string description = str::form (_("replacement of %s with %s"), s.asString().c_str(), sd.asString().c_str());
1306 MIL << description << endl;
1307 problemSolution->addDescription (description);
1310 ERR << s.asString() << " or " << sd.asString() << " not found" << endl;
1316 string description = str::form (_("deinstallation of %s"), s.asString().c_str());
1317 MIL << description << endl;
1318 problemSolution->addDescription (description);
1319 problemSolution->addSingleAction (itemFrom, REMOVE);
1324 resolverProblem->addSolution (problemSolution,
1325 problemSolution->actionCount() > 1 ? true : false); // Solutions with more than 1 action will be shown first.
1326 MIL << "------------------------------------" << endl;
1330 // There is a possibility to ignore this error by setting weak dependencies
1331 PoolItem item = _pool.find (sat::Solvable(ignoreId));
1332 ProblemSolutionIgnore *problemSolution = new ProblemSolutionIgnore(resolverProblem, item);
1333 resolverProblem->addSolution (problemSolution,
1334 false); // Solutions will be shown at the end
1335 MIL << "ignore some dependencies of " << item << endl;
1336 MIL << "------------------------------------" << endl;
1340 resolverProblems.push_back (resolverProblem);
1343 return resolverProblems;
1347 SATResolver::applySolutions (const ProblemSolutionList & solutions)
1349 for (ProblemSolutionList::const_iterator iter = solutions.begin();
1350 iter != solutions.end(); ++iter) {
1351 ProblemSolution_Ptr solution = *iter;
1352 Resolver dummyResolver(_pool);
1353 if (!solution->apply (dummyResolver))
1358 void SATResolver::setLocks()
1360 for (PoolItemList::const_iterator iter = _items_to_lock.begin(); iter != _items_to_lock.end(); iter++) {
1361 sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
1362 if (iter->status().isInstalled()) {
1363 MIL << "Lock installed item " << *iter << endl;
1364 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE );
1365 queue_push( &(_jobQueue), ident );
1367 MIL << "Lock NOT installed item " << *iter << endl;
1368 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE );
1369 queue_push( &(_jobQueue), ident );
1373 for (PoolItemList::const_iterator iter = _items_to_keep.begin(); iter != _items_to_keep.end(); iter++) {
1374 sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
1375 if (iter->status().isInstalled()) {
1376 MIL << "Keep installed item " << *iter << endl;
1377 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE | SOLVER_WEAK);
1378 queue_push( &(_jobQueue), ident );
1380 MIL << "Keep NOT installed item " << *iter << ident << endl;
1381 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE | SOLVER_WEAK);
1382 queue_push( &(_jobQueue), ident );
1387 void SATResolver::setSystemRequirements()
1389 CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1390 CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1392 for (CapabilitySet::const_iterator iter = system_requires.begin(); iter != system_requires.end(); iter++) {
1393 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE_PROVIDES);
1394 queue_push( &(_jobQueue), iter->id() );
1395 MIL << "SYSTEM Requires " << *iter << endl;
1398 for (CapabilitySet::const_iterator iter = system_conflicts.begin(); iter != system_conflicts.end(); iter++) {
1399 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_PROVIDES);
1400 queue_push( &(_jobQueue), iter->id() );
1401 MIL << "SYSTEM Conflicts " << *iter << endl;
1404 // Lock the architecture of the running systems rpm
1405 // package on distupgrade.
1406 if ( _distupgrade && ZConfig::instance().systemRoot() == "/" )
1408 ResPool pool( ResPool::instance() );
1409 IdString rpm( "rpm" );
1410 for_( it, pool.byIdentBegin(rpm), pool.byIdentEnd(rpm) )
1412 if ( (*it)->isSystem() )
1414 Capability archrule( (*it)->arch(), rpm.c_str(), Capability::PARSED );
1415 queue_push( &(_jobQueue), SOLVER_INSTALL|SOLVABLE_NAME|SOLVER_ESSENTIAL );
1416 queue_push( &(_jobQueue), archrule.id() );
1424 ///////////////////////////////////////////////////////////////////
1425 };// namespace detail
1426 /////////////////////////////////////////////////////////////////////
1427 /////////////////////////////////////////////////////////////////////
1428 };// namespace solver
1429 ///////////////////////////////////////////////////////////////////////
1430 ///////////////////////////////////////////////////////////////////////
1432 /////////////////////////////////////////////////////////////////////////