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 CapabilitySet droplist( (*it)->candidateAsKind<Product>()->droplist() );
632 dumpRangeLine( MIL << "Droplist for " << (*it)->candidateObj() << ": " << droplist.size() << " ", droplist.begin(), droplist.end() ) << endl;
633 for_( cap, droplist.begin(), droplist.end() )
635 queue_push( &_jobQueue, SOLVER_DROP_ORPHANED|SOLVER_SOLVABLE_NAME );
636 queue_push( &_jobQueue, cap->id() );
643 MIL << "Droplist processing is disabled." << endl;
649 SATResolver::solverEnd()
654 queue_free( &(_jobQueue) );
659 SATResolver::resolvePool(const CapabilitySet & requires_caps,
660 const CapabilitySet & conflict_caps,
661 const PoolItemList & weakItems,
662 const std::set<Repository> & upgradeRepos)
664 MIL << "SATResolver::resolvePool()" << endl;
667 solverInit(weakItems);
669 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
670 Id id = (*iter)->satSolvable().id();
672 ERR << "Install: " << *iter << " not found" << endl;
674 MIL << "Install " << *iter << endl;
675 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE );
676 queue_push( &(_jobQueue), id );
680 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
681 Id id = (*iter)->satSolvable().id();
683 ERR << "Delete: " << *iter << " not found" << endl;
685 MIL << "Delete " << *iter << endl;
686 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE );
687 queue_push( &(_jobQueue), id);
691 for_( iter, upgradeRepos.begin(), upgradeRepos.end() )
693 queue_push( &(_jobQueue), SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_REPO );
694 queue_push( &(_jobQueue), iter->get()->repoid );
695 MIL << "Upgrade repo " << *iter << endl;
698 for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
699 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE_PROVIDES );
700 queue_push( &(_jobQueue), iter->id() );
701 MIL << "Requires " << *iter << endl;
704 for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
705 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_PROVIDES);
706 queue_push( &(_jobQueue), iter->id() );
707 MIL << "Conflicts " << *iter << endl;
710 // set requirements for a running system
711 setSystemRequirements();
713 // set locks for the solver
717 bool ret = solving(requires_caps, conflict_caps);
720 solverEnd(); // remove solver only if no errors happend. Need it for solving problems
722 (ret?MIL:WAR) << "SATResolver::resolvePool() done. Ret:" << ret << endl;
728 SATResolver::resolveQueue(const SolverQueueItemList &requestQueue,
729 const PoolItemList & weakItems)
731 MIL << "SATResolver::resolvQueue()" << endl;
734 solverInit(weakItems);
736 // generate solver queue
737 for (SolverQueueItemList::const_iterator iter = requestQueue.begin(); iter != requestQueue.end(); iter++) {
738 (*iter)->addRule(_jobQueue);
741 // Add addition item status to the resolve-queue cause these can be set by problem resolutions
742 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
743 Id id = (*iter)->satSolvable().id();
745 ERR << "Install: " << *iter << " not found" << endl;
747 MIL << "Install " << *iter << endl;
748 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE );
749 queue_push( &(_jobQueue), id );
752 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
753 sat::detail::IdType ident( (*iter)->satSolvable().ident().id() );
754 MIL << "Delete " << *iter << ident << endl;
755 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_NAME );
756 queue_push( &(_jobQueue), ident);
759 // set requirements for a running system
760 setSystemRequirements();
762 // set locks for the solver
766 bool ret = solving();
770 solverEnd(); // remove solver only if no errors happend. Need it for solving problems
772 MIL << "SATResolver::resolveQueue() done. Ret:" << ret << endl;
777 void SATResolver::doUpdate()
779 MIL << "SATResolver::doUpdate()" << endl;
782 solverInit(PoolItemList());
784 // set requirements for a running system
785 setSystemRequirements();
787 // set locks for the solver
790 _solv = solver_create( _SATPool );
791 _solv->vendorCheckCb = &vendorCheck;
793 _solv->updatesystem = true;
794 _solv->dontinstallrecommended = true; // #FIXME dontinstallrecommended maybe set to false if it works correctly
796 sat::Pool::instance().prepare();
799 MIL << "Starting solving for update...." << endl;
801 solver_solve( _solv, &(_jobQueue) );
802 MIL << "....Solver end" << endl;
804 // copying solution back to zypp pool
805 //-----------------------------------------
807 /* solvables to be installed */
808 for (int i = 0; i < _solv->decisionq.count; i++)
811 p = _solv->decisionq.elements[i];
812 if (p < 0 || !sat::Solvable(p))
814 if (sat::Solvable(p).repository().get() == _solv->installed)
817 PoolItem poolItem = _pool.find (sat::Solvable(p));
819 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
821 ERR << "id " << p << " not found in ZYPP pool." << endl;
825 /* solvables to be erased */
826 for (int i = _solv->installed->start; i < _solv->installed->start + _solv->installed->nsolvables; i++)
828 if (_solv->decisionmap[i] > 0)
831 PoolItem poolItem = _pool.find (sat::Solvable(i));
833 // Check if this is an update
835 invokeOnEach( _pool.byIdentBegin( poolItem ),
836 _pool.byIdentEnd( poolItem ),
837 resfilter::ByUninstalled(), // ByUninstalled
838 functor::functorRef<bool,PoolItem> (info) );
840 if (info.is_updated) {
841 SATSolutionToPool (poolItem, ResStatus::toBeUninstalledDueToUpgrade , ResStatus::SOLVER);
843 SATSolutionToPool (poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER);
846 ERR << "id " << i << " not found in ZYPP pool." << endl;
853 MIL << "SATResolver::doUpdate() done" << endl;
858 //----------------------------------------------------------------------------
859 //----------------------------------------------------------------------------
861 //----------------------------------------------------------------------------
862 //----------------------------------------------------------------------------
864 //----------------------------------------------------------------------------
866 //----------------------------------------------------------------------------
868 struct FindPackage : public resfilter::ResObjectFilterFunctor
870 ProblemSolutionCombi *problemSolution;
871 TransactionKind action;
872 FindPackage (ProblemSolutionCombi *p, const TransactionKind act)
873 : problemSolution (p)
878 bool operator()( PoolItem p)
880 problemSolution->addSingleAction (p, action);
886 //----------------------------------------------------------------------------
887 // Checking if this solvable/item has a buddy which reflect the real
888 // user visible description of an item
889 // e.g. The release package has a buddy to the concerning product item.
890 // This user want's the message "Product foo conflicts with product bar" and
891 // NOT "package release-foo conflicts with package release-bar"
892 //----------------------------------------------------------------------------
895 PoolItem SATResolver::mapItem (const PoolItem &item)
897 sat::Solvable buddy = item.buddy();
898 if (buddy != sat::Solvable())
900 return _pool.find (buddy);
908 sat::Solvable SATResolver::mapSolvable (const Id &id)
910 PoolItem item = _pool.find (sat::Solvable(id));
911 return mapItem(item).satSolvable();
914 string SATResolver::SATprobleminfoString(Id problem, string &detail, Id &ignoreId)
917 Pool *pool = _solv->pool;
919 Id dep, source, target;
923 probr = solver_findproblemrule(_solv, problem);
924 switch (solver_problemruleinfo(_solv, &(_jobQueue), probr, &dep, &source, &target))
926 case SOLVER_PROBLEM_DISTUPGRADE_RULE:
927 s = mapSolvable (source);
928 ret = str::form (_("%s does not belong to a distupgrade repository"), s.asString().c_str());
930 case SOLVER_PROBLEM_INFARCH_RULE:
931 s = mapSolvable (source);
932 ret = str::form (_("%s has inferior architecture"), s.asString().c_str());
934 case SOLVER_PROBLEM_UPDATE_RULE:
935 s = mapSolvable (source);
936 ret = str::form (_("problem with installed package %s"), s.asString().c_str());
938 case SOLVER_PROBLEM_JOB_RULE:
939 ret = _("conflicting requests");
941 case SOLVER_PROBLEM_RPM_RULE:
942 ret = _("some dependency problem");
944 case SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP:
945 ret = str::form (_("nothing provides requested %s"), dep2str(pool, dep));
946 detail += _("Have you enabled all requested repositories?");
948 case SOLVER_PROBLEM_NOT_INSTALLABLE:
949 s = mapSolvable (source);
950 ret = str::form (_("%s is not installable"), s.asString().c_str());
952 case SOLVER_PROBLEM_NOTHING_PROVIDES_DEP:
953 ignoreId = source; // for setting weak dependencies
954 s = mapSolvable (source);
955 ret = str::form (_("nothing provides %s needed by %s"), dep2str(pool, dep), s.asString().c_str());
957 case SOLVER_PROBLEM_SAME_NAME:
958 s = mapSolvable (source);
959 s2 = mapSolvable (target);
960 ret = str::form (_("cannot install both %s and %s"), s.asString().c_str(), s2.asString().c_str());
962 case SOLVER_PROBLEM_PACKAGE_CONFLICT:
963 s = mapSolvable (source);
964 s2 = mapSolvable (target);
965 ret = str::form (_("%s conflicts with %s provided by %s"), s.asString().c_str(), dep2str(pool, dep), s2.asString().c_str());
967 case SOLVER_PROBLEM_PACKAGE_OBSOLETES:
968 s = mapSolvable (source);
969 s2 = mapSolvable (target);
970 ret = str::form (_("%s obsoletes %s provided by %s"), s.asString().c_str(), dep2str(pool, dep), s2.asString().c_str());
972 case SOLVER_PROBLEM_SELF_CONFLICT:
973 s = mapSolvable (source);
974 ret = str::form (_("solvable %s conflicts with %s provided by itself"), s.asString().c_str(), dep2str(pool, dep));
976 case SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE:
977 ignoreId = source; // for setting weak dependencies
978 s = mapSolvable (source);
980 sat::WhatProvides possibleProviders(cap);
982 // check, if a provider will be deleted
983 typedef list<PoolItem> ProviderList;
984 ProviderList providerlistInstalled, providerlistUninstalled;
985 for_( iter1, possibleProviders.begin(), possibleProviders.end() ) {
986 PoolItem provider1 = ResPool::instance().find( *iter1 );
987 // find pair of an installed/uninstalled item with the same NVR
989 for_( iter2, possibleProviders.begin(), possibleProviders.end() ) {
990 PoolItem provider2 = ResPool::instance().find( *iter2 );
991 if (compareByNVR (provider1.resolvable(),provider2.resolvable()) == 0
992 && ( (provider1.status().isInstalled() && provider2.status().isUninstalled())
993 || (provider2.status().isInstalled() && provider1.status().isUninstalled()) )) {
999 if (provider1.status().isInstalled())
1000 providerlistInstalled.push_back(provider1);
1002 providerlistUninstalled.push_back(provider1);
1006 ret = str::form (_("%s requires %s, but this requirement cannot be provided"), s.asString().c_str(), dep2str(pool, dep));
1007 if (providerlistInstalled.size() > 0) {
1008 detail += _("deleted providers: ");
1009 for (ProviderList::const_iterator iter = providerlistInstalled.begin(); iter != providerlistInstalled.end(); iter++) {
1010 if (iter == providerlistInstalled.begin())
1011 detail += itemToString( *iter );
1013 detail += "\n " + itemToString( mapItem(*iter) );
1016 if (providerlistUninstalled.size() > 0) {
1017 if (detail.size() > 0)
1018 detail += _("\nuninstallable providers: ");
1020 detail = _("uninstallable providers: ");
1021 for (ProviderList::const_iterator iter = providerlistUninstalled.begin(); iter != providerlistUninstalled.end(); iter++) {
1022 if (iter == providerlistUninstalled.begin())
1023 detail += itemToString( *iter );
1025 detail += "\n " + itemToString( mapItem(*iter) );
1035 SATResolver::problems ()
1037 ResolverProblemList resolverProblems;
1038 if (_solv && _solv->problems.count) {
1039 Pool *pool = _solv->pool;
1042 Id problem, solution, element;
1043 sat::Solvable s, sd;
1045 CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1046 CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1048 MIL << "Encountered problems! Here are the solutions:\n" << endl;
1051 while ((problem = solver_next_problem(_solv, problem)) != 0) {
1052 MIL << "Problem " << pcnt++ << ":" << endl;
1053 MIL << "====================================" << endl;
1056 string whatString = SATprobleminfoString (problem,detail,ignoreId);
1057 MIL << whatString << endl;
1058 MIL << "------------------------------------" << endl;
1059 ResolverProblem_Ptr resolverProblem = new ResolverProblem (whatString, detail);
1062 while ((solution = solver_next_solution(_solv, problem, solution)) != 0) {
1064 ProblemSolutionCombi *problemSolution = new ProblemSolutionCombi(resolverProblem);
1065 while ((element = solver_next_solutionelement(_solv, problem, solution, element, &p, &rp)) != 0) {
1066 if (p == SOLVER_SOLUTION_JOB) {
1067 /* job, rp is index into job queue */
1068 what = _jobQueue.elements[rp];
1069 switch (_jobQueue.elements[rp-1])
1071 case SOLVER_INSTALL_SOLVABLE: {
1072 s = mapSolvable (what);
1073 PoolItem poolItem = _pool.find (s);
1075 if (_solv->installed && s.get()->repo == _solv->installed) {
1076 problemSolution->addSingleAction (poolItem, REMOVE);
1077 string description = str::form (_("do not keep %s installed"), s.asString().c_str() );
1078 MIL << description << endl;
1079 problemSolution->addDescription (description);
1081 problemSolution->addSingleAction (poolItem, KEEP);
1082 string description = str::form (_("do not install %s"), s.asString().c_str());
1083 MIL << description << endl;
1084 problemSolution->addDescription (description);
1087 ERR << "SOLVER_INSTALL_SOLVABLE: No item found for " << s.asString() << endl;
1091 case SOLVER_ERASE_SOLVABLE: {
1092 s = mapSolvable (what);
1093 PoolItem poolItem = _pool.find (s);
1095 if (_solv->installed && s.get()->repo == _solv->installed) {
1096 problemSolution->addSingleAction (poolItem, KEEP);
1097 string description = str::form (_("keep %s"), s.asString().c_str());
1098 MIL << description << endl;
1099 problemSolution->addDescription (description);
1101 problemSolution->addSingleAction (poolItem, UNLOCK);
1102 string description = str::form (_("do not forbid installation of %s"), itemToString( poolItem ).c_str());
1103 MIL << description << endl;
1104 problemSolution->addDescription (description);
1107 ERR << "SOLVER_ERASE_SOLVABLE: No item found for " << s.asString() << endl;
1111 case SOLVER_INSTALL_SOLVABLE_NAME:
1113 IdString ident( what );
1114 SolverQueueItemInstall_Ptr install =
1115 new SolverQueueItemInstall(_pool, ident.asString(), false );
1116 problemSolution->addSingleAction (install, REMOVE_SOLVE_QUEUE_ITEM);
1118 string description = str::form (_("do not install %s"), ident.c_str() );
1119 MIL << description << endl;
1120 problemSolution->addDescription (description);
1123 case SOLVER_ERASE_SOLVABLE_NAME:
1125 // As we do not know, if this request has come from resolvePool or
1126 // resolveQueue we will have to take care for both cases.
1127 IdString ident( what );
1128 FindPackage info (problemSolution, KEEP);
1129 invokeOnEach( _pool.byIdentBegin( ident ),
1130 _pool.byIdentEnd( ident ),
1131 functor::chain (resfilter::ByInstalled (), // ByInstalled
1132 resfilter::ByTransact ()), // will be deinstalled
1133 functor::functorRef<bool,PoolItem> (info) );
1135 SolverQueueItemDelete_Ptr del =
1136 new SolverQueueItemDelete(_pool, ident.asString(), false );
1137 problemSolution->addSingleAction (del, REMOVE_SOLVE_QUEUE_ITEM);
1139 string description = str::form (_("keep %s"), ident.c_str());
1140 MIL << description << endl;
1141 problemSolution->addDescription (description);
1144 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
1146 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_REQUIRE);
1147 string description = "";
1149 // Checking if this problem solution would break your system
1150 if (system_requires.find(Capability(what)) != system_requires.end()) {
1151 // Show a better warning
1152 resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1153 resolverProblem->setDescription(_("This request will break your system!"));
1154 description = _("ignore the warning of a broken system");
1155 description += string(" (requires:")+dep2str(pool, what)+")";
1156 MIL << description << endl;
1157 problemSolution->addFrontDescription (description);
1159 description = str::form (_("do not ask to install a solvable providing %s"), dep2str(pool, what));
1160 MIL << description << endl;
1161 problemSolution->addDescription (description);
1165 case SOLVER_ERASE_SOLVABLE_PROVIDES:
1167 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_CONFLICT);
1168 string description = "";
1170 // Checking if this problem solution would break your system
1171 if (system_conflicts.find(Capability(what)) != system_conflicts.end()) {
1172 // Show a better warning
1173 resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1174 resolverProblem->setDescription(_("This request will break your system!"));
1175 description = _("ignore the warning of a broken system");
1176 description += string(" (conflicts:")+dep2str(pool, what)+")";
1177 MIL << description << endl;
1178 problemSolution->addFrontDescription (description);
1181 description = str::form (_("do not ask to delete all solvables providing %s"), dep2str(pool, what));
1182 MIL << description << endl;
1183 problemSolution->addDescription (description);
1187 case SOLVER_INSTALL_SOLVABLE_UPDATE:
1189 s = mapSolvable (what);
1190 PoolItem poolItem = _pool.find (s);
1192 if (_solv->installed && s.get()->repo == _solv->installed) {
1193 problemSolution->addSingleAction (poolItem, KEEP);
1194 string description = str::form (_("do not install most recent version of %s"), s.asString().c_str());
1195 MIL << description << endl;
1196 problemSolution->addDescription (description);
1198 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE " << poolItem << " is not selected for installation" << endl;
1201 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE: No item found for " << s.asString() << endl;
1206 MIL << "- do something different" << endl;
1207 ERR << "No valid solution available" << endl;
1210 } else if (p == SOLVER_SOLUTION_INFARCH) {
1211 s = mapSolvable (rp);
1212 PoolItem poolItem = _pool.find (s);
1213 if (_solv->installed && s.get()->repo == _solv->installed) {
1214 problemSolution->addSingleAction (poolItem, KEEP);
1215 string description = str::form (_("keep %s despite the inferior architecture"), s.asString().c_str());
1216 MIL << description << endl;
1217 problemSolution->addDescription (description);
1219 problemSolution->addSingleAction (poolItem, INSTALL);
1220 string description = str::form (_("install %s despite the inferior architecture"), s.asString().c_str());
1221 MIL << description << endl;
1222 problemSolution->addDescription (description);
1224 } else if (p == SOLVER_SOLUTION_DISTUPGRADE) {
1225 s = mapSolvable (rp);
1226 PoolItem poolItem = _pool.find (s);
1227 if (_solv->installed && s.get()->repo == _solv->installed) {
1228 problemSolution->addSingleAction (poolItem, KEEP);
1229 string description = str::form (_("keep obsolete %s"), s.asString().c_str());
1230 MIL << description << endl;
1231 problemSolution->addDescription (description);
1233 problemSolution->addSingleAction (poolItem, INSTALL);
1234 string description = str::form (_("install %s from excluded repository"), s.asString().c_str());
1235 MIL << description << endl;
1236 problemSolution->addDescription (description);
1239 /* policy, replace p with rp */
1240 s = mapSolvable (p);
1242 sd = mapSolvable (rp);
1244 PoolItem itemFrom = _pool.find (s);
1245 if (s == sd && _solv->distupgrade)
1247 PoolItem poolItem = _pool.find (s);
1249 problemSolution->addSingleAction (poolItem, LOCK); // for solver reason: NOT weak lock.
1250 string description = str::form (_("keep %s"), s.asString().c_str());
1251 MIL << description << endl;
1252 problemSolution->addDescription (description);
1254 ERR << "SOLVER_INSTALL_SOLVABLE: No item found for " << s.asString() << endl;
1261 PoolItem itemTo = _pool.find (sd);
1262 if (itemFrom && itemTo) {
1263 problemSolution->addSingleAction (itemTo, INSTALL);
1265 if (evrcmp(pool, s.get()->evr, sd.get()->evr, EVRCMP_COMPARE ) > 0)
1267 string description = str::form (_("downgrade of %s to %s"), s.asString().c_str(), sd.asString().c_str());
1268 MIL << description << endl;
1269 problemSolution->addDescription (description);
1272 if (!_solv->allowarchchange && s.get()->name == sd.get()->name && s.get()->arch != sd.get()->arch
1273 && policy_illegal_archchange(_solv, s.get(), sd.get()))
1275 string description = str::form (_("architecture change of %s to %s"), s.asString().c_str(), sd.asString().c_str());
1276 MIL << description << endl;
1277 problemSolution->addDescription (description);
1280 if (!_solv->allowvendorchange && s.get()->name == sd.get()->name && s.get()->vendor != sd.get()->vendor
1281 && policy_illegal_vendorchange(_solv, s.get(), sd.get()))
1283 IdString s_vendor( s.vendor() );
1284 IdString sd_vendor( sd.vendor() );
1285 string description = str::form (_("install %s (with vendor change)\n %s --> %s") ,
1286 sd.asString().c_str(),
1287 ( s_vendor ? s_vendor.c_str() : " (no vendor) " ),
1288 ( sd_vendor ? sd_vendor.c_str() : " (no vendor) " ) );
1289 MIL << description << endl;
1290 problemSolution->addDescription (description);
1294 string description = str::form (_("replacement of %s with %s"), s.asString().c_str(), sd.asString().c_str());
1295 MIL << description << endl;
1296 problemSolution->addDescription (description);
1299 ERR << s.asString() << " or " << sd.asString() << " not found" << endl;
1305 string description = str::form (_("deinstallation of %s"), s.asString().c_str());
1306 MIL << description << endl;
1307 problemSolution->addDescription (description);
1308 problemSolution->addSingleAction (itemFrom, REMOVE);
1313 resolverProblem->addSolution (problemSolution,
1314 problemSolution->actionCount() > 1 ? true : false); // Solutions with more than 1 action will be shown first.
1315 MIL << "------------------------------------" << endl;
1319 // There is a possibility to ignore this error by setting weak dependencies
1320 PoolItem item = _pool.find (sat::Solvable(ignoreId));
1321 ProblemSolutionIgnore *problemSolution = new ProblemSolutionIgnore(resolverProblem, item);
1322 resolverProblem->addSolution (problemSolution,
1323 false); // Solutions will be shown at the end
1324 MIL << "ignore some dependencies of " << item << endl;
1325 MIL << "------------------------------------" << endl;
1329 resolverProblems.push_back (resolverProblem);
1332 return resolverProblems;
1336 SATResolver::applySolutions (const ProblemSolutionList & solutions)
1338 for (ProblemSolutionList::const_iterator iter = solutions.begin();
1339 iter != solutions.end(); ++iter) {
1340 ProblemSolution_Ptr solution = *iter;
1341 Resolver dummyResolver(_pool);
1342 if (!solution->apply (dummyResolver))
1347 void SATResolver::setLocks()
1349 for (PoolItemList::const_iterator iter = _items_to_lock.begin(); iter != _items_to_lock.end(); iter++) {
1350 sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
1351 if (iter->status().isInstalled()) {
1352 MIL << "Lock installed item " << *iter << endl;
1353 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE );
1354 queue_push( &(_jobQueue), ident );
1356 MIL << "Lock NOT installed item " << *iter << endl;
1357 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE );
1358 queue_push( &(_jobQueue), ident );
1362 for (PoolItemList::const_iterator iter = _items_to_keep.begin(); iter != _items_to_keep.end(); iter++) {
1363 sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
1364 if (iter->status().isInstalled()) {
1365 MIL << "Keep installed item " << *iter << endl;
1366 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE | SOLVER_WEAK);
1367 queue_push( &(_jobQueue), ident );
1369 MIL << "Keep NOT installed item " << *iter << ident << endl;
1370 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE | SOLVER_WEAK);
1371 queue_push( &(_jobQueue), ident );
1376 void SATResolver::setSystemRequirements()
1378 CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1379 CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1381 for (CapabilitySet::const_iterator iter = system_requires.begin(); iter != system_requires.end(); iter++) {
1382 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE_PROVIDES);
1383 queue_push( &(_jobQueue), iter->id() );
1384 MIL << "SYSTEM Requires " << *iter << endl;
1387 for (CapabilitySet::const_iterator iter = system_conflicts.begin(); iter != system_conflicts.end(); iter++) {
1388 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_PROVIDES);
1389 queue_push( &(_jobQueue), iter->id() );
1390 MIL << "SYSTEM Conflicts " << *iter << endl;
1393 // Lock the architecture of the running systems rpm
1394 // package on distupgrade.
1395 if ( _distupgrade && ZConfig::instance().systemRoot() == "/" )
1397 ResPool pool( ResPool::instance() );
1398 IdString rpm( "rpm" );
1399 for_( it, pool.byIdentBegin(rpm), pool.byIdentEnd(rpm) )
1401 if ( (*it)->isSystem() )
1403 Capability archrule( (*it)->arch(), rpm.c_str(), Capability::PARSED );
1404 queue_push( &(_jobQueue), SOLVER_INSTALL|SOLVABLE_NAME|SOLVER_ESSENTIAL );
1405 queue_push( &(_jobQueue), archrule.id() );
1413 ///////////////////////////////////////////////////////////////////
1414 };// namespace detail
1415 /////////////////////////////////////////////////////////////////////
1416 /////////////////////////////////////////////////////////////////////
1417 };// namespace solver
1418 ///////////////////////////////////////////////////////////////////////
1419 ///////////////////////////////////////////////////////////////////////
1421 /////////////////////////////////////////////////////////////////////////