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
373 : is_updated( false )
376 // check this item will be installed
378 bool operator()( PoolItem item )
380 if (item.status().isToBeInstalled())
390 class CollectPseudoInstalled : public resfilter::PoolItemFilterFunctor
393 Queue *solvableQueue;
395 CollectPseudoInstalled( Queue *queue )
396 :solvableQueue (queue)
399 // collecting PseudoInstalled items
400 bool operator()( PoolItem item )
402 if ( traits::isPseudoInstalled( item.satSolvable().kind() ) )
403 queue_push( solvableQueue, item.satSolvable().id() );
409 SATResolver::solving(const CapabilitySet & requires_caps,
410 const CapabilitySet & conflict_caps)
412 _solv = solver_create( _SATPool );
413 _solv->vendorCheckCb = &vendorCheck;
414 _solv->fixsystem = _fixsystem;
415 _solv->ignorealreadyrecommended = _ignorealreadyrecommended;
416 _solv->updatesystem = _updatesystem;
417 _solv->allowdowngrade = _allowdowngrade;
418 _solv->allowuninstall = _allowuninstall;
419 _solv->allowarchchange = _allowarchchange;
420 _solv->allowvendorchange = _allowvendorchange;
421 _solv->dosplitprovides = _dosplitprovides;
422 _solv->noupdateprovide = _noupdateprovide;
423 _solv->dontinstallrecommended = _onlyRequires;
424 _solv->distupgrade = _distupgrade;
425 _solv->distupgrade_removeunsupported = _distupgrade_removeunsupported;
427 sat::Pool::instance().prepare();
430 MIL << "Starting solving...." << endl;
432 solver_solve( _solv, &(_jobQueue) );
433 MIL << "....Solver end" << endl;
435 // copying solution back to zypp pool
436 //-----------------------------------------
437 _result_items_to_install.clear();
438 _result_items_to_remove.clear();
440 /* solvables to be installed */
441 for ( int i = 0; i < _solv->decisionq.count; ++i )
443 sat::Solvable slv( _solv->decisionq.elements[i] );
444 if ( !slv || slv.isSystem() )
447 PoolItem poolItem( slv );
448 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
449 _result_items_to_install.push_back (poolItem);
452 /* solvables to be erased */
453 Repository systemRepo( sat::Pool::instance().findSystemRepo() ); // don't create if it does not exist
454 if ( systemRepo && ! systemRepo.solvablesEmpty() )
456 bool mustCheckObsoletes = false;
457 for_( it, systemRepo.solvablesBegin(), systemRepo.solvablesEnd() )
459 if (_solv->decisionmap[it->id()] > 0)
462 PoolItem poolItem( *it );
463 // Check if this is an update
465 invokeOnEach( _pool.byIdentBegin( poolItem ),
466 _pool.byIdentEnd( poolItem ),
467 resfilter::ByUninstalled(), // ByUninstalled
468 functor::functorRef<bool,PoolItem> (info) );
470 if (info.is_updated) {
471 SATSolutionToPool( poolItem, ResStatus::toBeUninstalledDueToUpgrade, ResStatus::SOLVER );
473 SATSolutionToPool( poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER );
474 if ( ! mustCheckObsoletes )
475 mustCheckObsoletes = true; // lazy check for UninstalledDueToObsolete
477 _result_items_to_remove.push_back (poolItem);
479 if ( mustCheckObsoletes )
481 sat::WhatObsoletes obsoleted( _result_items_to_install.begin(), _result_items_to_install.end() );
482 for_( it, obsoleted.poolItemBegin(), obsoleted.poolItemEnd() )
484 ResStatus & status( it->status() );
485 // WhatObsoletes contains installed items only!
486 if ( status.transacts() && ! status.isToBeUninstalledDueToUpgrade() )
487 status.setToBeUninstalledDueToObsolete();
492 /* solvables which are recommended */
493 for ( int i = 0; i < _solv->recommendations.count; ++i )
495 PoolItem poolItem( getPoolItem( _solv->recommendations.elements[i] ) );
496 poolItem.status().setRecommended( true );
499 /* solvables which are suggested */
500 for ( int i = 0; i < _solv->suggestions.count; ++i )
502 PoolItem poolItem( getPoolItem( _solv->suggestions.elements[i] ) );
503 poolItem.status().setSuggested( true );
506 _problem_items.clear();
507 /* solvables which are orphaned */
508 for ( int i = 0; i < _solv->orphaned.count; ++i )
510 PoolItem poolItem( getPoolItem( _solv->orphaned.elements[i] ) );
511 poolItem.status().setOrphaned( true );
512 _problem_items.push_back( poolItem );
515 /* Write validation state back to pool */
516 Queue flags, solvableQueue;
519 queue_init(&solvableQueue);
521 CollectPseudoInstalled collectPseudoInstalled(&solvableQueue);
522 invokeOnEach( _pool.begin(),
524 functor::functorRef<bool,PoolItem> (collectPseudoInstalled) );
525 solver_trivial_installable(_solv, &solvableQueue, &flags );
526 for (int i = 0; i < solvableQueue.count; i++) {
527 PoolItem item = _pool.find (sat::Solvable(solvableQueue.elements[i]));
528 item.status().setUndetermined();
530 if (flags.elements[i] == -1) {
531 item.status().setNonRelevant();
532 _XDEBUG("SATSolutionToPool(" << item << " ) nonRelevant !");
533 } else if (flags.elements[i] == 1) {
534 item.status().setSatisfied();
535 _XDEBUG("SATSolutionToPool(" << item << " ) satisfied !");
536 } else if (flags.elements[i] == 0) {
537 item.status().setBroken();
538 _XDEBUG("SATSolutionToPool(" << item << " ) broken !");
542 // Solvables which were selected due requirements which have been made by the user will
543 // be selected by APPL_LOW. We can't use any higher level, because this setting must
544 // not serve as a request for the next solver run. APPL_LOW is reset before solving.
545 for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
546 sat::WhatProvides rpmProviders(*iter);
547 for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
548 PoolItem poolItem(*iter2);
549 if (poolItem.status().isToBeInstalled()) {
550 MIL << "User requirement " << *iter << " sets " << poolItem << endl;
551 poolItem.status().setTransactByValue (ResStatus::APPL_LOW);
555 for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
556 sat::WhatProvides rpmProviders(*iter);
557 for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
558 PoolItem poolItem(*iter2);
559 if (poolItem.status().isToBeUninstalled()) {
560 MIL << "User conflict " << *iter << " sets " << poolItem << endl;
561 poolItem.status().setTransactByValue (ResStatus::APPL_LOW);
566 if (_solv->problems.count > 0 )
568 ERR << "Solverrun finished with an ERROR" << endl;
572 queue_free(&(solvableQueue));
580 SATResolver::solverInit(const PoolItemList & weakItems)
582 SATCollectTransact info (*this);
584 MIL << "SATResolver::solverInit()" << endl;
590 queue_free( &(_jobQueue) );
593 queue_init( &_jobQueue );
594 _items_to_install.clear();
595 _items_to_remove.clear();
596 _items_to_lock.clear();
597 _items_to_keep.clear();
599 invokeOnEach ( _pool.begin(), _pool.end(),
600 functor::functorRef<bool,PoolItem>(info) );
602 for (PoolItemList::const_iterator iter = weakItems.begin(); iter != weakItems.end(); iter++) {
603 Id id = (*iter)->satSolvable().id();
605 ERR << "Weaken: " << *iter << " not found" << endl;
607 MIL << "Weaken dependencies of " << *iter << endl;
608 queue_push( &(_jobQueue), SOLVER_WEAKEN_SOLVABLE_DEPS );
609 queue_push( &(_jobQueue), id );
612 // Add rules for parallel installable resolvables with different versions
613 std::set<IdString> parallel = ZConfig::instance().multiversion();
614 for (std::set<IdString>::const_iterator it = parallel.begin(); it != parallel.end(); ++it) {
615 queue_push( &(_jobQueue), SOLVER_NOOBSOLETES_SOLVABLE_NAME );
616 queue_push( &(_jobQueue), it->id() );
621 if ( ZConfig::instance().solverUpgradeRemoveDroppedPackages() )
623 MIL << "Checking droplists ..." << endl;
624 // Dropped packages: look for 'weakremover()' provides
625 // in dup candidates of installed products.
626 ResPoolProxy proxy( ResPool::instance().proxy() );
627 for_( it, proxy.byKindBegin<Product>(), proxy.byKindEnd<Product>() )
629 if ( (*it)->onSystem() ) // (to install) or (not to delete)
631 Product::constPtr prodCand( (*it)->candidateAsKind<Product>() );
633 continue; // product no longer available
635 CapabilitySet droplist( prodCand->droplist() );
636 dumpRangeLine( MIL << "Droplist for " << (*it)->candidateObj() << ": " << droplist.size() << " ", droplist.begin(), droplist.end() ) << endl;
637 for_( cap, droplist.begin(), droplist.end() )
639 queue_push( &_jobQueue, SOLVER_DROP_ORPHANED|SOLVER_SOLVABLE_NAME );
640 queue_push( &_jobQueue, cap->id() );
647 MIL << "Droplist processing is disabled." << endl;
653 SATResolver::solverEnd()
658 queue_free( &(_jobQueue) );
663 SATResolver::resolvePool(const CapabilitySet & requires_caps,
664 const CapabilitySet & conflict_caps,
665 const PoolItemList & weakItems,
666 const std::set<Repository> & upgradeRepos)
668 MIL << "SATResolver::resolvePool()" << endl;
671 solverInit(weakItems);
673 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
674 Id id = (*iter)->satSolvable().id();
676 ERR << "Install: " << *iter << " not found" << endl;
678 MIL << "Install " << *iter << endl;
679 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE );
680 queue_push( &(_jobQueue), id );
684 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
685 Id id = (*iter)->satSolvable().id();
687 ERR << "Delete: " << *iter << " not found" << endl;
689 MIL << "Delete " << *iter << endl;
690 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE );
691 queue_push( &(_jobQueue), id);
695 for_( iter, upgradeRepos.begin(), upgradeRepos.end() )
697 queue_push( &(_jobQueue), SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_REPO );
698 queue_push( &(_jobQueue), iter->get()->repoid );
699 MIL << "Upgrade repo " << *iter << endl;
702 for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
703 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE_PROVIDES );
704 queue_push( &(_jobQueue), iter->id() );
705 MIL << "Requires " << *iter << endl;
708 for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
709 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_PROVIDES);
710 queue_push( &(_jobQueue), iter->id() );
711 MIL << "Conflicts " << *iter << endl;
714 // set requirements for a running system
715 setSystemRequirements();
717 // set locks for the solver
721 bool ret = solving(requires_caps, conflict_caps);
724 solverEnd(); // remove solver only if no errors happend. Need it for solving problems
726 (ret?MIL:WAR) << "SATResolver::resolvePool() done. Ret:" << ret << endl;
732 SATResolver::resolveQueue(const SolverQueueItemList &requestQueue,
733 const PoolItemList & weakItems)
735 MIL << "SATResolver::resolvQueue()" << endl;
738 solverInit(weakItems);
740 // generate solver queue
741 for (SolverQueueItemList::const_iterator iter = requestQueue.begin(); iter != requestQueue.end(); iter++) {
742 (*iter)->addRule(_jobQueue);
745 // Add addition item status to the resolve-queue cause these can be set by problem resolutions
746 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
747 Id id = (*iter)->satSolvable().id();
749 ERR << "Install: " << *iter << " not found" << endl;
751 MIL << "Install " << *iter << endl;
752 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE );
753 queue_push( &(_jobQueue), id );
756 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
757 sat::detail::IdType ident( (*iter)->satSolvable().ident().id() );
758 MIL << "Delete " << *iter << ident << endl;
759 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_NAME );
760 queue_push( &(_jobQueue), ident);
763 // set requirements for a running system
764 setSystemRequirements();
766 // set locks for the solver
770 bool ret = solving();
774 solverEnd(); // remove solver only if no errors happend. Need it for solving problems
776 MIL << "SATResolver::resolveQueue() done. Ret:" << ret << endl;
781 void SATResolver::doUpdate()
783 MIL << "SATResolver::doUpdate()" << endl;
786 solverInit(PoolItemList());
788 // set requirements for a running system
789 setSystemRequirements();
791 // set locks for the solver
794 _solv = solver_create( _SATPool );
795 _solv->vendorCheckCb = &vendorCheck;
797 _solv->updatesystem = true;
798 _solv->dontinstallrecommended = true; // #FIXME dontinstallrecommended maybe set to false if it works correctly
800 sat::Pool::instance().prepare();
803 MIL << "Starting solving for update...." << endl;
805 solver_solve( _solv, &(_jobQueue) );
806 MIL << "....Solver end" << endl;
808 // copying solution back to zypp pool
809 //-----------------------------------------
811 /* solvables to be installed */
812 for (int i = 0; i < _solv->decisionq.count; i++)
815 p = _solv->decisionq.elements[i];
816 if (p < 0 || !sat::Solvable(p))
818 if (sat::Solvable(p).repository().get() == _solv->installed)
821 PoolItem poolItem = _pool.find (sat::Solvable(p));
823 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
825 ERR << "id " << p << " not found in ZYPP pool." << endl;
829 /* solvables to be erased */
830 for (int i = _solv->installed->start; i < _solv->installed->start + _solv->installed->nsolvables; i++)
832 if (_solv->decisionmap[i] > 0)
835 PoolItem poolItem = _pool.find (sat::Solvable(i));
837 // Check if this is an update
839 invokeOnEach( _pool.byIdentBegin( poolItem ),
840 _pool.byIdentEnd( poolItem ),
841 resfilter::ByUninstalled(), // ByUninstalled
842 functor::functorRef<bool,PoolItem> (info) );
844 if (info.is_updated) {
845 SATSolutionToPool (poolItem, ResStatus::toBeUninstalledDueToUpgrade , ResStatus::SOLVER);
847 SATSolutionToPool (poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER);
850 ERR << "id " << i << " not found in ZYPP pool." << endl;
857 MIL << "SATResolver::doUpdate() done" << endl;
862 //----------------------------------------------------------------------------
863 //----------------------------------------------------------------------------
865 //----------------------------------------------------------------------------
866 //----------------------------------------------------------------------------
868 //----------------------------------------------------------------------------
870 //----------------------------------------------------------------------------
872 struct FindPackage : public resfilter::ResObjectFilterFunctor
874 ProblemSolutionCombi *problemSolution;
875 TransactionKind action;
876 FindPackage (ProblemSolutionCombi *p, const TransactionKind act)
877 : problemSolution (p)
882 bool operator()( PoolItem p)
884 problemSolution->addSingleAction (p, action);
890 //----------------------------------------------------------------------------
891 // Checking if this solvable/item has a buddy which reflect the real
892 // user visible description of an item
893 // e.g. The release package has a buddy to the concerning product item.
894 // This user want's the message "Product foo conflicts with product bar" and
895 // NOT "package release-foo conflicts with package release-bar"
896 //----------------------------------------------------------------------------
899 PoolItem SATResolver::mapItem (const PoolItem &item)
901 sat::Solvable buddy = item.buddy();
902 if (buddy != sat::Solvable())
904 return _pool.find (buddy);
912 sat::Solvable SATResolver::mapSolvable (const Id &id)
914 PoolItem item = _pool.find (sat::Solvable(id));
915 return mapItem(item).satSolvable();
918 string SATResolver::SATprobleminfoString(Id problem, string &detail, Id &ignoreId)
921 Pool *pool = _solv->pool;
923 Id dep, source, target;
927 probr = solver_findproblemrule(_solv, problem);
928 switch (solver_problemruleinfo(_solv, &(_jobQueue), probr, &dep, &source, &target))
930 case SOLVER_PROBLEM_DISTUPGRADE_RULE:
931 s = mapSolvable (source);
932 ret = str::form (_("%s does not belong to a distupgrade repository"), s.asString().c_str());
934 case SOLVER_PROBLEM_INFARCH_RULE:
935 s = mapSolvable (source);
936 ret = str::form (_("%s has inferior architecture"), s.asString().c_str());
938 case SOLVER_PROBLEM_UPDATE_RULE:
939 s = mapSolvable (source);
940 ret = str::form (_("problem with installed package %s"), s.asString().c_str());
942 case SOLVER_PROBLEM_JOB_RULE:
943 ret = _("conflicting requests");
945 case SOLVER_PROBLEM_RPM_RULE:
946 ret = _("some dependency problem");
948 case SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP:
949 ret = str::form (_("nothing provides requested %s"), dep2str(pool, dep));
950 detail += _("Have you enabled all requested repositories?");
952 case SOLVER_PROBLEM_NOT_INSTALLABLE:
953 s = mapSolvable (source);
954 ret = str::form (_("%s is not installable"), s.asString().c_str());
956 case SOLVER_PROBLEM_NOTHING_PROVIDES_DEP:
957 ignoreId = source; // for setting weak dependencies
958 s = mapSolvable (source);
959 ret = str::form (_("nothing provides %s needed by %s"), dep2str(pool, dep), s.asString().c_str());
961 case SOLVER_PROBLEM_SAME_NAME:
962 s = mapSolvable (source);
963 s2 = mapSolvable (target);
964 ret = str::form (_("cannot install both %s and %s"), s.asString().c_str(), s2.asString().c_str());
966 case SOLVER_PROBLEM_PACKAGE_CONFLICT:
967 s = mapSolvable (source);
968 s2 = mapSolvable (target);
969 ret = str::form (_("%s conflicts with %s provided by %s"), s.asString().c_str(), dep2str(pool, dep), s2.asString().c_str());
971 case SOLVER_PROBLEM_PACKAGE_OBSOLETES:
972 s = mapSolvable (source);
973 s2 = mapSolvable (target);
974 ret = str::form (_("%s obsoletes %s provided by %s"), s.asString().c_str(), dep2str(pool, dep), s2.asString().c_str());
976 case SOLVER_PROBLEM_SELF_CONFLICT:
977 s = mapSolvable (source);
978 ret = str::form (_("solvable %s conflicts with %s provided by itself"), s.asString().c_str(), dep2str(pool, dep));
980 case SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE:
981 ignoreId = source; // for setting weak dependencies
982 s = mapSolvable (source);
984 sat::WhatProvides possibleProviders(cap);
986 // check, if a provider will be deleted
987 typedef list<PoolItem> ProviderList;
988 ProviderList providerlistInstalled, providerlistUninstalled;
989 for_( iter1, possibleProviders.begin(), possibleProviders.end() ) {
990 PoolItem provider1 = ResPool::instance().find( *iter1 );
991 // find pair of an installed/uninstalled item with the same NVR
993 for_( iter2, possibleProviders.begin(), possibleProviders.end() ) {
994 PoolItem provider2 = ResPool::instance().find( *iter2 );
995 if (compareByNVR (provider1.resolvable(),provider2.resolvable()) == 0
996 && ( (provider1.status().isInstalled() && provider2.status().isUninstalled())
997 || (provider2.status().isInstalled() && provider1.status().isUninstalled()) )) {
1003 if (provider1.status().isInstalled())
1004 providerlistInstalled.push_back(provider1);
1006 providerlistUninstalled.push_back(provider1);
1010 ret = str::form (_("%s requires %s, but this requirement cannot be provided"), s.asString().c_str(), dep2str(pool, dep));
1011 if (providerlistInstalled.size() > 0) {
1012 detail += _("deleted providers: ");
1013 for (ProviderList::const_iterator iter = providerlistInstalled.begin(); iter != providerlistInstalled.end(); iter++) {
1014 if (iter == providerlistInstalled.begin())
1015 detail += itemToString( *iter );
1017 detail += "\n " + itemToString( mapItem(*iter) );
1020 if (providerlistUninstalled.size() > 0) {
1021 if (detail.size() > 0)
1022 detail += _("\nuninstallable providers: ");
1024 detail = _("uninstallable providers: ");
1025 for (ProviderList::const_iterator iter = providerlistUninstalled.begin(); iter != providerlistUninstalled.end(); iter++) {
1026 if (iter == providerlistUninstalled.begin())
1027 detail += itemToString( *iter );
1029 detail += "\n " + itemToString( mapItem(*iter) );
1039 SATResolver::problems ()
1041 ResolverProblemList resolverProblems;
1042 if (_solv && _solv->problems.count) {
1043 Pool *pool = _solv->pool;
1046 Id problem, solution, element;
1047 sat::Solvable s, sd;
1049 CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1050 CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1052 MIL << "Encountered problems! Here are the solutions:\n" << endl;
1055 while ((problem = solver_next_problem(_solv, problem)) != 0) {
1056 MIL << "Problem " << pcnt++ << ":" << endl;
1057 MIL << "====================================" << endl;
1060 string whatString = SATprobleminfoString (problem,detail,ignoreId);
1061 MIL << whatString << endl;
1062 MIL << "------------------------------------" << endl;
1063 ResolverProblem_Ptr resolverProblem = new ResolverProblem (whatString, detail);
1066 while ((solution = solver_next_solution(_solv, problem, solution)) != 0) {
1068 ProblemSolutionCombi *problemSolution = new ProblemSolutionCombi(resolverProblem);
1069 while ((element = solver_next_solutionelement(_solv, problem, solution, element, &p, &rp)) != 0) {
1070 if (p == SOLVER_SOLUTION_JOB) {
1071 /* job, rp is index into job queue */
1072 what = _jobQueue.elements[rp];
1073 switch (_jobQueue.elements[rp-1])
1075 case SOLVER_INSTALL_SOLVABLE: {
1076 s = mapSolvable (what);
1077 PoolItem poolItem = _pool.find (s);
1079 if (_solv->installed && s.get()->repo == _solv->installed) {
1080 problemSolution->addSingleAction (poolItem, REMOVE);
1081 string description = str::form (_("do not keep %s installed"), s.asString().c_str() );
1082 MIL << description << endl;
1083 problemSolution->addDescription (description);
1085 problemSolution->addSingleAction (poolItem, KEEP);
1086 string description = str::form (_("do not install %s"), s.asString().c_str());
1087 MIL << description << endl;
1088 problemSolution->addDescription (description);
1091 ERR << "SOLVER_INSTALL_SOLVABLE: No item found for " << s.asString() << endl;
1095 case SOLVER_ERASE_SOLVABLE: {
1096 s = mapSolvable (what);
1097 PoolItem poolItem = _pool.find (s);
1099 if (_solv->installed && s.get()->repo == _solv->installed) {
1100 problemSolution->addSingleAction (poolItem, KEEP);
1101 string description = str::form (_("keep %s"), s.asString().c_str());
1102 MIL << description << endl;
1103 problemSolution->addDescription (description);
1105 problemSolution->addSingleAction (poolItem, UNLOCK);
1106 string description = str::form (_("do not forbid installation of %s"), itemToString( poolItem ).c_str());
1107 MIL << description << endl;
1108 problemSolution->addDescription (description);
1111 ERR << "SOLVER_ERASE_SOLVABLE: No item found for " << s.asString() << endl;
1115 case SOLVER_INSTALL_SOLVABLE_NAME:
1117 IdString ident( what );
1118 SolverQueueItemInstall_Ptr install =
1119 new SolverQueueItemInstall(_pool, ident.asString(), false );
1120 problemSolution->addSingleAction (install, REMOVE_SOLVE_QUEUE_ITEM);
1122 string description = str::form (_("do not install %s"), ident.c_str() );
1123 MIL << description << endl;
1124 problemSolution->addDescription (description);
1127 case SOLVER_ERASE_SOLVABLE_NAME:
1129 // As we do not know, if this request has come from resolvePool or
1130 // resolveQueue we will have to take care for both cases.
1131 IdString ident( what );
1132 FindPackage info (problemSolution, KEEP);
1133 invokeOnEach( _pool.byIdentBegin( ident ),
1134 _pool.byIdentEnd( ident ),
1135 functor::chain (resfilter::ByInstalled (), // ByInstalled
1136 resfilter::ByTransact ()), // will be deinstalled
1137 functor::functorRef<bool,PoolItem> (info) );
1139 SolverQueueItemDelete_Ptr del =
1140 new SolverQueueItemDelete(_pool, ident.asString(), false );
1141 problemSolution->addSingleAction (del, REMOVE_SOLVE_QUEUE_ITEM);
1143 string description = str::form (_("keep %s"), ident.c_str());
1144 MIL << description << endl;
1145 problemSolution->addDescription (description);
1148 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
1150 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_REQUIRE);
1151 string description = "";
1153 // Checking if this problem solution would break your system
1154 if (system_requires.find(Capability(what)) != system_requires.end()) {
1155 // Show a better warning
1156 resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1157 resolverProblem->setDescription(_("This request will break your system!"));
1158 description = _("ignore the warning of a broken system");
1159 description += string(" (requires:")+dep2str(pool, what)+")";
1160 MIL << description << endl;
1161 problemSolution->addFrontDescription (description);
1163 description = str::form (_("do not ask to install a solvable providing %s"), dep2str(pool, what));
1164 MIL << description << endl;
1165 problemSolution->addDescription (description);
1169 case SOLVER_ERASE_SOLVABLE_PROVIDES:
1171 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_CONFLICT);
1172 string description = "";
1174 // Checking if this problem solution would break your system
1175 if (system_conflicts.find(Capability(what)) != system_conflicts.end()) {
1176 // Show a better warning
1177 resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1178 resolverProblem->setDescription(_("This request will break your system!"));
1179 description = _("ignore the warning of a broken system");
1180 description += string(" (conflicts:")+dep2str(pool, what)+")";
1181 MIL << description << endl;
1182 problemSolution->addFrontDescription (description);
1185 description = str::form (_("do not ask to delete all solvables providing %s"), dep2str(pool, what));
1186 MIL << description << endl;
1187 problemSolution->addDescription (description);
1191 case SOLVER_INSTALL_SOLVABLE_UPDATE:
1193 s = mapSolvable (what);
1194 PoolItem poolItem = _pool.find (s);
1196 if (_solv->installed && s.get()->repo == _solv->installed) {
1197 problemSolution->addSingleAction (poolItem, KEEP);
1198 string description = str::form (_("do not install most recent version of %s"), s.asString().c_str());
1199 MIL << description << endl;
1200 problemSolution->addDescription (description);
1202 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE " << poolItem << " is not selected for installation" << endl;
1205 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE: No item found for " << s.asString() << 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, LOCK);
1219 string description = str::form (_("keep %s despite the inferior architecture"), s.asString().c_str());
1220 MIL << description << endl;
1221 problemSolution->addDescription (description);
1223 problemSolution->addSingleAction (poolItem, INSTALL);
1224 string description = str::form (_("install %s despite the inferior architecture"), s.asString().c_str());
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, LOCK);
1233 string description = str::form (_("keep obsolete %s"), s.asString().c_str());
1234 MIL << description << endl;
1235 problemSolution->addDescription (description);
1237 problemSolution->addSingleAction (poolItem, INSTALL);
1238 string description = str::form (_("install %s from excluded repository"), s.asString().c_str());
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"), s.asString().c_str());
1255 MIL << description << endl;
1256 problemSolution->addDescription (description);
1258 ERR << "SOLVER_INSTALL_SOLVABLE: No item found for " << s.asString() << endl;
1265 PoolItem itemTo = _pool.find (sd);
1266 if (itemFrom && itemTo) {
1267 problemSolution->addSingleAction (itemTo, INSTALL);
1269 if (evrcmp(pool, s.get()->evr, sd.get()->evr, EVRCMP_COMPARE ) > 0)
1271 string description = str::form (_("downgrade of %s to %s"), s.asString().c_str(), sd.asString().c_str());
1272 MIL << description << endl;
1273 problemSolution->addDescription (description);
1276 if (!_solv->allowarchchange && s.get()->name == sd.get()->name && s.get()->arch != sd.get()->arch
1277 && policy_illegal_archchange(_solv, s.get(), sd.get()))
1279 string description = str::form (_("architecture change of %s to %s"), s.asString().c_str(), sd.asString().c_str());
1280 MIL << description << endl;
1281 problemSolution->addDescription (description);
1284 if (!_solv->allowvendorchange && s.get()->name == sd.get()->name && s.get()->vendor != sd.get()->vendor
1285 && policy_illegal_vendorchange(_solv, s.get(), sd.get()))
1287 IdString s_vendor( s.vendor() );
1288 IdString sd_vendor( sd.vendor() );
1289 string description = str::form (_("install %s (with vendor change)\n %s --> %s") ,
1290 sd.asString().c_str(),
1291 ( s_vendor ? s_vendor.c_str() : " (no vendor) " ),
1292 ( sd_vendor ? sd_vendor.c_str() : " (no vendor) " ) );
1293 MIL << description << endl;
1294 problemSolution->addDescription (description);
1298 string description = str::form (_("replacement of %s with %s"), s.asString().c_str(), sd.asString().c_str());
1299 MIL << description << endl;
1300 problemSolution->addDescription (description);
1303 ERR << s.asString() << " or " << sd.asString() << " not found" << endl;
1309 string description = str::form (_("deinstallation of %s"), s.asString().c_str());
1310 MIL << description << endl;
1311 problemSolution->addDescription (description);
1312 problemSolution->addSingleAction (itemFrom, REMOVE);
1317 resolverProblem->addSolution (problemSolution,
1318 problemSolution->actionCount() > 1 ? true : false); // Solutions with more than 1 action will be shown first.
1319 MIL << "------------------------------------" << endl;
1323 // There is a possibility to ignore this error by setting weak dependencies
1324 PoolItem item = _pool.find (sat::Solvable(ignoreId));
1325 ProblemSolutionIgnore *problemSolution = new ProblemSolutionIgnore(resolverProblem, item);
1326 resolverProblem->addSolution (problemSolution,
1327 false); // Solutions will be shown at the end
1328 MIL << "ignore some dependencies of " << item << endl;
1329 MIL << "------------------------------------" << endl;
1333 resolverProblems.push_back (resolverProblem);
1336 return resolverProblems;
1340 SATResolver::applySolutions (const ProblemSolutionList & solutions)
1342 for (ProblemSolutionList::const_iterator iter = solutions.begin();
1343 iter != solutions.end(); ++iter) {
1344 ProblemSolution_Ptr solution = *iter;
1345 Resolver dummyResolver(_pool);
1346 if (!solution->apply (dummyResolver))
1351 void SATResolver::setLocks()
1353 for (PoolItemList::const_iterator iter = _items_to_lock.begin(); iter != _items_to_lock.end(); iter++) {
1354 sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
1355 if (iter->status().isInstalled()) {
1356 MIL << "Lock installed item " << *iter << endl;
1357 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE );
1358 queue_push( &(_jobQueue), ident );
1360 MIL << "Lock NOT installed item " << *iter << endl;
1361 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE );
1362 queue_push( &(_jobQueue), ident );
1366 for (PoolItemList::const_iterator iter = _items_to_keep.begin(); iter != _items_to_keep.end(); iter++) {
1367 sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
1368 if (iter->status().isInstalled()) {
1369 MIL << "Keep installed item " << *iter << endl;
1370 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE | SOLVER_WEAK);
1371 queue_push( &(_jobQueue), ident );
1373 MIL << "Keep NOT installed item " << *iter << ident << endl;
1374 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE | SOLVER_WEAK);
1375 queue_push( &(_jobQueue), ident );
1380 void SATResolver::setSystemRequirements()
1382 CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1383 CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1385 for (CapabilitySet::const_iterator iter = system_requires.begin(); iter != system_requires.end(); iter++) {
1386 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE_PROVIDES);
1387 queue_push( &(_jobQueue), iter->id() );
1388 MIL << "SYSTEM Requires " << *iter << endl;
1391 for (CapabilitySet::const_iterator iter = system_conflicts.begin(); iter != system_conflicts.end(); iter++) {
1392 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_PROVIDES);
1393 queue_push( &(_jobQueue), iter->id() );
1394 MIL << "SYSTEM Conflicts " << *iter << endl;
1397 // Lock the architecture of the running systems rpm
1398 // package on distupgrade.
1399 if ( _distupgrade && ZConfig::instance().systemRoot() == "/" )
1401 ResPool pool( ResPool::instance() );
1402 IdString rpm( "rpm" );
1403 for_( it, pool.byIdentBegin(rpm), pool.byIdentEnd(rpm) )
1405 if ( (*it)->isSystem() )
1407 Capability archrule( (*it)->arch(), rpm.c_str(), Capability::PARSED );
1408 queue_push( &(_jobQueue), SOLVER_INSTALL|SOLVABLE_NAME|SOLVER_ESSENTIAL );
1409 queue_push( &(_jobQueue), archrule.id() );
1417 ///////////////////////////////////////////////////////////////////
1418 };// namespace detail
1419 /////////////////////////////////////////////////////////////////////
1420 /////////////////////////////////////////////////////////////////////
1421 };// namespace solver
1422 ///////////////////////////////////////////////////////////////////////
1423 ///////////////////////////////////////////////////////////////////////
1425 /////////////////////////////////////////////////////////////////////////