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 <solv/repo_solv.h>
24 #include <solv/poolarch.h>
26 #include <solv/poolvendor.h>
27 #include <solv/policy.h>
28 #include <solv/bitmap.h>
29 #include <solv/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"
54 #include "zypp/sat/Transaction.h"
55 #include "zypp/sat/Queue.h"
57 /////////////////////////////////////////////////////////////////////////
59 { ///////////////////////////////////////////////////////////////////////
60 ///////////////////////////////////////////////////////////////////////
62 { /////////////////////////////////////////////////////////////////////
63 /////////////////////////////////////////////////////////////////////
65 { ///////////////////////////////////////////////////////////////////
69 IMPL_PTR_TYPE(SATResolver);
71 #define MAYBE_CLEANDEPS (cleandepsOnRemove()?SOLVER_CLEANDEPS:0)
73 //---------------------------------------------------------------------------
74 // Callbacks for SAT policies
75 //---------------------------------------------------------------------------
77 int vendorCheck( Pool *pool, Solvable *solvable1, Solvable *solvable2 )
79 return VendorAttr::instance().equivalent( IdString(solvable1->vendor),
80 IdString(solvable2->vendor) ) ? 0 : 1;
84 inline std::string itemToString( const PoolItem & item )
89 sat::Solvable slv( item.satSolvable() );
90 std::string ret( slv.asString() ); // n-v-r.a
91 if ( ! slv.isSystem() )
94 ret += slv.repository().alias();
100 inline PoolItem getPoolItem( Id id_r )
102 PoolItem ret( (sat::Solvable( id_r )) );
104 INT << "id " << id_r << " not found in ZYPP pool." << endl;
108 //---------------------------------------------------------------------------
111 SATResolver::dumpOn( std::ostream & os ) const
113 os << "<resolver>" << endl;
115 // os << " fixsystem = " << _solv->fixsystem << endl;
116 // os << " updatesystem = " << _solv->updatesystem << endl;
117 os << " allowdowngrade = " << solver_get_flag(_solv, SOLVER_FLAG_ALLOW_DOWNGRADE) << endl;
118 os << " allowarchchange = " << solver_get_flag(_solv, SOLVER_FLAG_ALLOW_ARCHCHANGE) << endl;
119 os << " allowvendorchange = " << solver_get_flag(_solv, SOLVER_FLAG_ALLOW_VENDORCHANGE) << endl;
120 os << " allowuninstall = " << solver_get_flag(_solv, SOLVER_FLAG_ALLOW_UNINSTALL) << endl;
121 os << " noupdateprovide = " << solver_get_flag(_solv, SOLVER_FLAG_NO_UPDATEPROVIDE) << endl;
122 os << " dosplitprovides = " << solver_get_flag(_solv, SOLVER_FLAG_SPLITPROVIDES) << endl;
123 os << " onlyRequires = " << solver_get_flag(_solv, SOLVER_FLAG_IGNORE_RECOMMENDED) << endl;
124 os << " ignorealreadyrecommended = " << !solver_get_flag(_solv, SOLVER_FLAG_ADD_ALREADY_RECOMMENDED) << endl;
125 os << " distupgrade = " << _distupgrade << endl;
126 os << " distupgrade_removeunsupported = " << _distupgrade_removeunsupported << endl;
127 os << " solveSrcPackages = " << _solveSrcPackages << endl;
128 os << " cleandepsOnRemove = " << _cleandepsOnRemove << endl;
132 return os << "<resolver/>" << endl;
135 //---------------------------------------------------------------------------
137 SATResolver::SATResolver (const ResPool & pool, Pool *SATPool)
142 , _allowdowngrade(false)
143 , _allowarchchange(false)
144 , _allowvendorchange(ZConfig::instance().solver_allowVendorChange())
145 , _allowuninstall(false)
146 , _updatesystem(false)
147 , _noupdateprovide(false)
148 , _dosplitprovides(false)
149 , _onlyRequires(ZConfig::instance().solver_onlyRequires())
150 , _ignorealreadyrecommended(false)
151 , _distupgrade(false)
152 , _distupgrade_removeunsupported(false)
153 , _solveSrcPackages(false)
154 , _cleandepsOnRemove(ZConfig::instance().solver_cleandepsOnRemove())
159 SATResolver::~SATResolver()
164 //---------------------------------------------------------------------------
167 SATResolver::pool (void) const
173 SATResolver::resetItemTransaction (PoolItem item)
176 for (PoolItemList::const_iterator iter = _items_to_remove.begin();
177 iter != _items_to_remove.end(); ++iter) {
179 _items_to_remove.remove(*iter);
185 for (PoolItemList::const_iterator iter = _items_to_install.begin();
186 iter != _items_to_install.end(); ++iter) {
188 _items_to_install.remove(*iter);
195 for (PoolItemList::const_iterator iter = _items_to_keep.begin();
196 iter != _items_to_keep.end(); ++iter) {
198 _items_to_keep.remove(*iter);
205 for (PoolItemList::const_iterator iter = _items_to_lock.begin();
206 iter != _items_to_lock.end(); ++iter) {
208 _items_to_lock.remove(*iter);
218 SATResolver::addPoolItemToInstall (PoolItem item)
220 resetItemTransaction (item);
221 _items_to_install.push_back (item);
222 _items_to_install.unique ();
227 SATResolver::addPoolItemsToInstallFromList (PoolItemList & rl)
229 for (PoolItemList::const_iterator iter = rl.begin(); iter != rl.end(); iter++) {
230 addPoolItemToInstall (*iter);
236 SATResolver::addPoolItemToRemove (PoolItem item)
238 resetItemTransaction (item);
239 _items_to_remove.push_back (item);
240 _items_to_remove.unique ();
245 SATResolver::addPoolItemsToRemoveFromList (PoolItemList & rl)
247 for (PoolItemList::const_iterator iter = rl.begin(); iter != rl.end(); iter++) {
248 addPoolItemToRemove (*iter);
253 SATResolver::addPoolItemToLock (PoolItem item)
255 resetItemTransaction (item);
256 _items_to_lock.push_back (item);
257 _items_to_lock.unique ();
261 SATResolver::addPoolItemToKeep (PoolItem item)
263 resetItemTransaction (item);
264 _items_to_keep.push_back (item);
265 _items_to_keep.unique ();
268 //---------------------------------------------------------------------------
270 // copy marked item from solution back to pool
271 // if data != NULL, set as APPL_LOW (from establishPool())
274 SATSolutionToPool (PoolItem item, const ResStatus & status, const ResStatus::TransactByValue causer)
277 item.status().resetTransact (causer);
278 item.status().resetWeak ();
282 // installation/deletion
283 if (status.isToBeInstalled()) {
284 r = item.status().setToBeInstalled (causer);
285 _XDEBUG("SATSolutionToPool install returns " << item << ", " << r);
287 else if (status.isToBeUninstalledDueToUpgrade()) {
288 r = item.status().setToBeUninstalledDueToUpgrade (causer);
289 _XDEBUG("SATSolutionToPool upgrade returns " << item << ", " << r);
291 else if (status.isToBeUninstalled()) {
292 r = item.status().setToBeUninstalled (causer);
293 _XDEBUG("SATSolutionToPool remove returns " << item << ", " << r);
299 //----------------------------------------------------------------------------
300 //----------------------------------------------------------------------------
302 //----------------------------------------------------------------------------
303 //----------------------------------------------------------------------------
305 //----------------------------------------------------------------------------
306 // Helper functions for the ZYPP-Pool
307 //----------------------------------------------------------------------------
310 //------------------------------------------------------------------------------------------------------------
311 // This function loops over the pool and grabs all items
312 // It clears all previous bySolver() states also
314 // Every toBeInstalled is passed to zypp::solver:detail::Resolver.addPoolItemToInstall()
315 // Every toBeUninstalled is passed to zypp::solver:detail::Resolver.addPoolItemToRemove()
317 // Solver results must be written back to the pool.
318 //------------------------------------------------------------------------------------------------------------
321 struct SATCollectTransact : public resfilter::PoolItemFilterFunctor
323 SATResolver & resolver;
325 SATCollectTransact (SATResolver & r)
329 bool operator()( PoolItem item ) // only transacts() items go here
331 ResStatus status = item.status();
332 bool by_solver = (status.isBySolver() || status.isByApplLow());
335 item.status().resetTransact( ResStatus::APPL_LOW );// clear any solver/establish transactions
336 return true; // back out here, dont re-queue former solver result
339 if ( item.satSolvable().isKind<SrcPackage>() && ! resolver.solveSrcPackages() )
341 // Later we may continue on a per source package base.
342 return true; // dont process this source package.
345 if (status.isToBeInstalled()) {
346 resolver.addPoolItemToInstall(item); // -> install!
348 else if (status.isToBeUninstalled()) {
349 resolver.addPoolItemToRemove(item); // -> remove !
351 else if (status.isLocked()
353 resolver.addPoolItemToLock (item);
355 else if (status.isKept()
357 resolver.addPoolItemToKeep (item);
365 //----------------------------------------------------------------------------
366 //----------------------------------------------------------------------------
368 //----------------------------------------------------------------------------
369 //----------------------------------------------------------------------------
372 class CheckIfUpdate : public resfilter::PoolItemFilterFunctor
377 sat::Solvable _installed;
379 CheckIfUpdate( sat::Solvable installed_r )
380 : is_updated( false )
381 , multiversion( installed_r.multiversionInstall() )
382 , _installed( installed_r )
385 // check this item will be updated
387 bool operator()( PoolItem item )
389 if ( item.status().isToBeInstalled() )
391 if ( ! multiversion || sameNVRA( _installed, item ) )
402 class CollectPseudoInstalled : public resfilter::PoolItemFilterFunctor
405 Queue *solvableQueue;
407 CollectPseudoInstalled( Queue *queue )
408 :solvableQueue (queue)
411 // collecting PseudoInstalled items
412 bool operator()( PoolItem item )
414 if ( traits::isPseudoInstalled( item.satSolvable().kind() ) )
415 queue_push( solvableQueue, item.satSolvable().id() );
421 SATResolver::solving(const CapabilitySet & requires_caps,
422 const CapabilitySet & conflict_caps)
424 _solv = solver_create( _SATPool );
425 _solv->vendorCheckCb = &vendorCheck;
427 queue_push( &(_jobQueue), SOLVER_VERIFY|SOLVER_SOLVABLE_ALL);
428 queue_push( &(_jobQueue), 0 );
431 queue_push( &(_jobQueue), SOLVER_UPDATE|SOLVER_SOLVABLE_ALL);
432 queue_push( &(_jobQueue), 0 );
435 queue_push( &(_jobQueue), SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_ALL);
436 queue_push( &(_jobQueue), 0 );
438 if (_distupgrade_removeunsupported) {
439 queue_push( &(_jobQueue), SOLVER_DROP_ORPHANED|SOLVER_SOLVABLE_ALL);
440 queue_push( &(_jobQueue), 0 );
442 solver_set_flag(_solv, SOLVER_FLAG_ADD_ALREADY_RECOMMENDED, !_ignorealreadyrecommended);
443 solver_set_flag(_solv, SOLVER_FLAG_ALLOW_DOWNGRADE, _allowdowngrade);
444 solver_set_flag(_solv, SOLVER_FLAG_ALLOW_UNINSTALL, _allowuninstall);
445 solver_set_flag(_solv, SOLVER_FLAG_ALLOW_ARCHCHANGE, _allowarchchange);
446 solver_set_flag(_solv, SOLVER_FLAG_ALLOW_VENDORCHANGE, _allowvendorchange);
447 solver_set_flag(_solv, SOLVER_FLAG_SPLITPROVIDES, _dosplitprovides);
448 solver_set_flag(_solv, SOLVER_FLAG_NO_UPDATEPROVIDE, _noupdateprovide);
449 solver_set_flag(_solv, SOLVER_FLAG_IGNORE_RECOMMENDED, _onlyRequires);
451 sat::Pool::instance().prepareForSolving();
454 MIL << "Starting solving...." << endl;
456 solver_solve( _solv, &(_jobQueue) );
457 MIL << "....Solver end" << endl;
459 // copying solution back to zypp pool
460 //-----------------------------------------
461 _result_items_to_install.clear();
462 _result_items_to_remove.clear();
464 /* solvables to be installed */
466 queue_init(&decisionq);
467 solver_get_decisionqueue(_solv, &decisionq);
468 for ( int i = 0; i < decisionq.count; ++i )
470 sat::Solvable slv( decisionq.elements[i] );
471 if ( !slv || slv.isSystem() )
474 PoolItem poolItem( slv );
475 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
476 _result_items_to_install.push_back (poolItem);
478 queue_free(&decisionq);
480 /* solvables to be erased */
481 Repository systemRepo( sat::Pool::instance().findSystemRepo() ); // don't create if it does not exist
482 if ( systemRepo && ! systemRepo.solvablesEmpty() )
484 bool mustCheckObsoletes = false;
485 for_( it, systemRepo.solvablesBegin(), systemRepo.solvablesEnd() )
487 if (solver_get_decisionlevel(_solv, it->id()) > 0)
490 // Check if this is an update
491 CheckIfUpdate info( *it );
492 PoolItem poolItem( *it );
493 invokeOnEach( _pool.byIdentBegin( poolItem ),
494 _pool.byIdentEnd( poolItem ),
495 resfilter::ByUninstalled(), // ByUninstalled
496 functor::functorRef<bool,PoolItem> (info) );
498 if (info.is_updated) {
499 SATSolutionToPool( poolItem, ResStatus::toBeUninstalledDueToUpgrade, ResStatus::SOLVER );
501 SATSolutionToPool( poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER );
502 if ( ! mustCheckObsoletes )
503 mustCheckObsoletes = true; // lazy check for UninstalledDueToObsolete
505 _result_items_to_remove.push_back (poolItem);
507 if ( mustCheckObsoletes )
509 sat::WhatObsoletes obsoleted( _result_items_to_install.begin(), _result_items_to_install.end() );
510 for_( it, obsoleted.poolItemBegin(), obsoleted.poolItemEnd() )
512 ResStatus & status( it->status() );
513 // WhatObsoletes contains installed items only!
514 if ( status.transacts() && ! status.isToBeUninstalledDueToUpgrade() )
515 status.setToBeUninstalledDueToObsolete();
520 Queue recommendations;
524 queue_init(&recommendations);
525 queue_init(&suggestions);
526 queue_init(&orphaned);
527 queue_init(&unneeded);
528 solver_get_recommendations(_solv, &recommendations, &suggestions, 0);
529 solver_get_orphaned(_solv, &orphaned);
530 solver_get_unneeded(_solv, &unneeded, 1);
531 /* solvables which are recommended */
532 for ( int i = 0; i < recommendations.count; ++i )
534 PoolItem poolItem( getPoolItem( recommendations.elements[i] ) );
535 poolItem.status().setRecommended( true );
538 /* solvables which are suggested */
539 for ( int i = 0; i < suggestions.count; ++i )
541 PoolItem poolItem( getPoolItem( suggestions.elements[i] ) );
542 poolItem.status().setSuggested( true );
545 _problem_items.clear();
546 /* solvables which are orphaned */
547 for ( int i = 0; i < orphaned.count; ++i )
549 PoolItem poolItem( getPoolItem( orphaned.elements[i] ) );
550 poolItem.status().setOrphaned( true );
551 _problem_items.push_back( poolItem );
554 /* solvables which are unneeded */
555 for ( int i = 0; i < unneeded.count; ++i )
557 PoolItem poolItem( getPoolItem( unneeded.elements[i] ) );
558 poolItem.status().setUnneeded( true );
561 queue_free(&recommendations);
562 queue_free(&suggestions);
563 queue_free(&orphaned);
564 queue_free(&unneeded);
566 /* Write validation state back to pool */
567 Queue flags, solvableQueue;
570 queue_init(&solvableQueue);
572 CollectPseudoInstalled collectPseudoInstalled(&solvableQueue);
573 invokeOnEach( _pool.begin(),
575 functor::functorRef<bool,PoolItem> (collectPseudoInstalled) );
576 solver_trivial_installable(_solv, &solvableQueue, &flags );
577 for (int i = 0; i < solvableQueue.count; i++) {
578 PoolItem item = _pool.find (sat::Solvable(solvableQueue.elements[i]));
579 item.status().setUndetermined();
581 if (flags.elements[i] == -1) {
582 item.status().setNonRelevant();
583 _XDEBUG("SATSolutionToPool(" << item << " ) nonRelevant !");
584 } else if (flags.elements[i] == 1) {
585 item.status().setSatisfied();
586 _XDEBUG("SATSolutionToPool(" << item << " ) satisfied !");
587 } else if (flags.elements[i] == 0) {
588 item.status().setBroken();
589 _XDEBUG("SATSolutionToPool(" << item << " ) broken !");
592 queue_free(&(solvableQueue));
596 // Solvables which were selected due requirements which have been made by the user will
597 // be selected by APPL_LOW. We can't use any higher level, because this setting must
598 // not serve as a request for the next solver run. APPL_LOW is reset before solving.
599 for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
600 sat::WhatProvides rpmProviders(*iter);
601 for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
602 PoolItem poolItem(*iter2);
603 if (poolItem.status().isToBeInstalled()) {
604 MIL << "User requirement " << *iter << " sets " << poolItem << endl;
605 poolItem.status().setTransactByValue (ResStatus::APPL_LOW);
609 for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
610 sat::WhatProvides rpmProviders(*iter);
611 for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
612 PoolItem poolItem(*iter2);
613 if (poolItem.status().isToBeUninstalled()) {
614 MIL << "User conflict " << *iter << " sets " << poolItem << endl;
615 poolItem.status().setTransactByValue (ResStatus::APPL_LOW);
620 if (solver_problem_count(_solv) > 0 )
622 ERR << "Solverrun finished with an ERROR" << endl;
631 SATResolver::solverInit(const PoolItemList & weakItems)
633 SATCollectTransact info (*this);
635 MIL << "SATResolver::solverInit()" << endl;
640 queue_init( &_jobQueue );
641 _items_to_install.clear();
642 _items_to_remove.clear();
643 _items_to_lock.clear();
644 _items_to_keep.clear();
646 invokeOnEach ( _pool.begin(), _pool.end(),
647 functor::functorRef<bool,PoolItem>(info) );
649 for (PoolItemList::const_iterator iter = weakItems.begin(); iter != weakItems.end(); iter++) {
650 Id id = (*iter)->satSolvable().id();
652 ERR << "Weaken: " << *iter << " not found" << endl;
654 MIL << "Weaken dependencies of " << *iter << endl;
655 queue_push( &(_jobQueue), SOLVER_WEAKENDEPS | SOLVER_SOLVABLE );
656 queue_push( &(_jobQueue), id );
659 // Add rules for parallel installable resolvables with different versions
660 for_( it, sat::Pool::instance().multiversionBegin(), sat::Pool::instance().multiversionEnd() )
662 queue_push( &(_jobQueue), SOLVER_NOOBSOLETES | SOLVER_SOLVABLE_NAME );
663 queue_push( &(_jobQueue), it->id() );
666 if ( cleandepsOnRemove() )
668 // Add all items known to be installed by user request (not solver selected).
669 for_( it, sat::Pool::instance().onSystemByUserBegin(), sat::Pool::instance().onSystemByUserEnd() )
671 queue_push( &(_jobQueue), SOLVER_USERINSTALLED | SOLVER_SOLVABLE_NAME );
672 queue_push( &(_jobQueue), it->id() );
678 if ( ZConfig::instance().solverUpgradeRemoveDroppedPackages() )
680 MIL << "Checking droplists ..." << endl;
681 // Dropped packages: look for 'weakremover()' provides
682 // in dup candidates of installed products.
683 ResPoolProxy proxy( ResPool::instance().proxy() );
684 for_( it, proxy.byKindBegin<Product>(), proxy.byKindEnd<Product>() )
686 if ( (*it)->onSystem() ) // (to install) or (not to delete)
688 Product::constPtr prodCand( (*it)->candidateAsKind<Product>() );
689 if ( ! prodCand || (*it)->identicalInstalledCandidate() )
690 continue; // product no longer available or unchanged
692 CapabilitySet droplist( prodCand->droplist() );
693 dumpRangeLine( MIL << "Droplist for " << (*it)->candidateObj() << ": " << droplist.size() << " ", droplist.begin(), droplist.end() ) << endl;
694 for_( cap, droplist.begin(), droplist.end() )
696 queue_push( &_jobQueue, SOLVER_DROP_ORPHANED | SOLVER_SOLVABLE_NAME );
697 queue_push( &_jobQueue, cap->id() );
704 MIL << "Droplist processing is disabled." << endl;
710 SATResolver::solverEnd()
717 queue_free( &(_jobQueue) );
723 SATResolver::resolvePool(const CapabilitySet & requires_caps,
724 const CapabilitySet & conflict_caps,
725 const PoolItemList & weakItems,
726 const std::set<Repository> & upgradeRepos)
728 MIL << "SATResolver::resolvePool()" << endl;
731 solverInit(weakItems);
733 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
734 Id id = (*iter)->satSolvable().id();
736 ERR << "Install: " << *iter << " not found" << endl;
738 MIL << "Install " << *iter << endl;
739 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
740 queue_push( &(_jobQueue), id );
744 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
745 Id id = (*iter)->satSolvable().id();
747 ERR << "Delete: " << *iter << " not found" << endl;
749 MIL << "Delete " << *iter << endl;
750 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE | MAYBE_CLEANDEPS );
751 queue_push( &(_jobQueue), id);
755 for_( iter, upgradeRepos.begin(), upgradeRepos.end() )
757 queue_push( &(_jobQueue), SOLVER_DISTUPGRADE | SOLVER_SOLVABLE_REPO );
758 queue_push( &(_jobQueue), iter->get()->repoid );
759 MIL << "Upgrade repo " << *iter << endl;
762 for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
763 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES );
764 queue_push( &(_jobQueue), iter->id() );
765 MIL << "Requires " << *iter << endl;
768 for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
769 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES | MAYBE_CLEANDEPS );
770 queue_push( &(_jobQueue), iter->id() );
771 MIL << "Conflicts " << *iter << endl;
774 // set requirements for a running system
775 setSystemRequirements();
777 // set locks for the solver
781 bool ret = solving(requires_caps, conflict_caps);
783 (ret?MIL:WAR) << "SATResolver::resolvePool() done. Ret:" << ret << endl;
789 SATResolver::resolveQueue(const SolverQueueItemList &requestQueue,
790 const PoolItemList & weakItems)
792 MIL << "SATResolver::resolvQueue()" << endl;
795 solverInit(weakItems);
797 // generate solver queue
798 for (SolverQueueItemList::const_iterator iter = requestQueue.begin(); iter != requestQueue.end(); iter++) {
799 (*iter)->addRule(_jobQueue);
802 // Add addition item status to the resolve-queue cause these can be set by problem resolutions
803 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
804 Id id = (*iter)->satSolvable().id();
806 ERR << "Install: " << *iter << " not found" << endl;
808 MIL << "Install " << *iter << endl;
809 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
810 queue_push( &(_jobQueue), id );
813 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
814 sat::detail::IdType ident( (*iter)->satSolvable().ident().id() );
815 MIL << "Delete " << *iter << ident << endl;
816 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_NAME | MAYBE_CLEANDEPS );
817 queue_push( &(_jobQueue), ident);
820 // set requirements for a running system
821 setSystemRequirements();
823 // set locks for the solver
827 bool ret = solving();
829 MIL << "SATResolver::resolveQueue() done. Ret:" << ret << endl;
833 /** \todo duplicate code to be joined with \ref solving. */
834 void SATResolver::doUpdate()
836 MIL << "SATResolver::doUpdate()" << endl;
839 solverInit(PoolItemList());
841 // set requirements for a running system
842 setSystemRequirements();
844 // set locks for the solver
847 _solv = solver_create( _SATPool );
848 _solv->vendorCheckCb = &vendorCheck;
850 queue_push( &(_jobQueue), SOLVER_VERIFY|SOLVER_SOLVABLE_ALL);
851 queue_push( &(_jobQueue), 0 );
854 queue_push( &(_jobQueue), SOLVER_UPDATE|SOLVER_SOLVABLE_ALL);
855 queue_push( &(_jobQueue), 0 );
858 queue_push( &(_jobQueue), SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_ALL);
859 queue_push( &(_jobQueue), 0 );
861 if (_distupgrade_removeunsupported) {
862 queue_push( &(_jobQueue), SOLVER_DROP_ORPHANED|SOLVER_SOLVABLE_ALL);
863 queue_push( &(_jobQueue), 0 );
865 solver_set_flag(_solv, SOLVER_FLAG_ADD_ALREADY_RECOMMENDED, !_ignorealreadyrecommended);
866 solver_set_flag(_solv, SOLVER_FLAG_ALLOW_DOWNGRADE, _allowdowngrade);
867 solver_set_flag(_solv, SOLVER_FLAG_ALLOW_UNINSTALL, _allowuninstall);
868 solver_set_flag(_solv, SOLVER_FLAG_ALLOW_ARCHCHANGE, _allowarchchange);
869 solver_set_flag(_solv, SOLVER_FLAG_ALLOW_VENDORCHANGE, _allowvendorchange);
870 solver_set_flag(_solv, SOLVER_FLAG_SPLITPROVIDES, _dosplitprovides);
871 solver_set_flag(_solv, SOLVER_FLAG_NO_UPDATEPROVIDE, _noupdateprovide);
872 solver_set_flag(_solv, SOLVER_FLAG_IGNORE_RECOMMENDED, _onlyRequires);
874 sat::Pool::instance().prepareForSolving();
877 MIL << "Starting solving for update...." << endl;
879 solver_solve( _solv, &(_jobQueue) );
880 MIL << "....Solver end" << endl;
882 // copying solution back to zypp pool
883 //-----------------------------------------
885 /* solvables to be installed */
887 queue_init(&decisionq);
888 solver_get_decisionqueue(_solv, &decisionq);
889 for (int i = 0; i < decisionq.count; i++)
892 p = decisionq.elements[i];
893 if (p < 0 || !sat::Solvable(p))
895 if (sat::Solvable(p).repository().get() == _solv->pool->installed)
898 PoolItem poolItem = _pool.find (sat::Solvable(p));
900 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
902 ERR << "id " << p << " not found in ZYPP pool." << endl;
905 queue_free(&decisionq);
907 /* solvables to be erased */
908 for (int i = _solv->pool->installed->start; i < _solv->pool->installed->start + _solv->pool->installed->nsolvables; i++)
910 if (solver_get_decisionlevel(_solv, i) > 0)
913 PoolItem poolItem( _pool.find( sat::Solvable(i) ) );
915 // Check if this is an update
916 CheckIfUpdate info( (sat::Solvable(i)) );
917 invokeOnEach( _pool.byIdentBegin( poolItem ),
918 _pool.byIdentEnd( poolItem ),
919 resfilter::ByUninstalled(), // ByUninstalled
920 functor::functorRef<bool,PoolItem> (info) );
922 if (info.is_updated) {
923 SATSolutionToPool (poolItem, ResStatus::toBeUninstalledDueToUpgrade , ResStatus::SOLVER);
925 SATSolutionToPool (poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER);
928 ERR << "id " << i << " not found in ZYPP pool." << endl;
931 MIL << "SATResolver::doUpdate() done" << endl;
936 //----------------------------------------------------------------------------
937 //----------------------------------------------------------------------------
939 //----------------------------------------------------------------------------
940 //----------------------------------------------------------------------------
942 //----------------------------------------------------------------------------
944 //----------------------------------------------------------------------------
946 struct FindPackage : public resfilter::ResObjectFilterFunctor
948 ProblemSolutionCombi *problemSolution;
949 TransactionKind action;
950 FindPackage (ProblemSolutionCombi *p, const TransactionKind act)
951 : problemSolution (p)
956 bool operator()( PoolItem p)
958 problemSolution->addSingleAction (p, action);
964 //----------------------------------------------------------------------------
965 // Checking if this solvable/item has a buddy which reflect the real
966 // user visible description of an item
967 // e.g. The release package has a buddy to the concerning product item.
968 // This user want's the message "Product foo conflicts with product bar" and
969 // NOT "package release-foo conflicts with package release-bar"
970 // (ma: that's why we should map just packages to buddies, not vice versa)
971 //----------------------------------------------------------------------------
972 inline sat::Solvable mapBuddy( const PoolItem & item_r )
974 if ( item_r.satSolvable().isKind<Package>() )
976 sat::Solvable buddy = item_r.buddy();
980 return item_r.satSolvable();
982 inline sat::Solvable mapBuddy( sat::Solvable item_r )
983 { return mapBuddy( PoolItem( item_r ) ); }
985 PoolItem SATResolver::mapItem ( const PoolItem & item )
986 { return PoolItem( mapBuddy( item ) ); }
988 sat::Solvable SATResolver::mapSolvable ( const Id & id )
989 { return mapBuddy( sat::Solvable(id) ); }
991 string SATResolver::SATprobleminfoString(Id problem, string &detail, Id &ignoreId)
994 Pool *pool = _solv->pool;
996 Id dep, source, target;
1000 probr = solver_findproblemrule(_solv, problem);
1001 switch (solver_ruleinfo(_solv, probr, &source, &target, &dep))
1003 case SOLVER_RULE_DISTUPGRADE:
1004 s = mapSolvable (source);
1005 ret = str::form (_("%s does not belong to a distupgrade repository"), s.asString().c_str());
1007 case SOLVER_RULE_INFARCH:
1008 s = mapSolvable (source);
1009 ret = str::form (_("%s has inferior architecture"), s.asString().c_str());
1011 case SOLVER_RULE_UPDATE:
1012 s = mapSolvable (source);
1013 ret = str::form (_("problem with installed package %s"), s.asString().c_str());
1015 case SOLVER_RULE_JOB:
1016 ret = _("conflicting requests");
1018 case SOLVER_RULE_RPM:
1019 ret = _("some dependency problem");
1021 case SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP:
1022 ret = str::form (_("nothing provides requested %s"), pool_dep2str(pool, dep));
1023 detail += _("Have you enabled all requested repositories?");
1025 case SOLVER_RULE_RPM_NOT_INSTALLABLE:
1026 s = mapSolvable (source);
1027 ret = str::form (_("%s is not installable"), s.asString().c_str());
1029 case SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP:
1030 ignoreId = source; // for setting weak dependencies
1031 s = mapSolvable (source);
1032 ret = str::form (_("nothing provides %s needed by %s"), pool_dep2str(pool, dep), s.asString().c_str());
1034 case SOLVER_RULE_RPM_SAME_NAME:
1035 s = mapSolvable (source);
1036 s2 = mapSolvable (target);
1037 ret = str::form (_("cannot install both %s and %s"), s.asString().c_str(), s2.asString().c_str());
1039 case SOLVER_RULE_RPM_PACKAGE_CONFLICT:
1040 s = mapSolvable (source);
1041 s2 = mapSolvable (target);
1042 ret = str::form (_("%s conflicts with %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1044 case SOLVER_RULE_RPM_PACKAGE_OBSOLETES:
1045 s = mapSolvable (source);
1046 s2 = mapSolvable (target);
1047 ret = str::form (_("%s obsoletes %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1049 case SOLVER_RULE_RPM_INSTALLEDPKG_OBSOLETES:
1050 s = mapSolvable (source);
1051 s2 = mapSolvable (target);
1052 ret = str::form (_("installed %s obsoletes %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1054 case SOLVER_RULE_RPM_SELF_CONFLICT:
1055 s = mapSolvable (source);
1056 ret = str::form (_("solvable %s conflicts with %s provided by itself"), s.asString().c_str(), pool_dep2str(pool, dep));
1058 case SOLVER_RULE_RPM_PACKAGE_REQUIRES:
1059 ignoreId = source; // for setting weak dependencies
1060 s = mapSolvable (source);
1061 Capability cap(dep);
1062 sat::WhatProvides possibleProviders(cap);
1064 // check, if a provider will be deleted
1065 typedef list<PoolItem> ProviderList;
1066 ProviderList providerlistInstalled, providerlistUninstalled;
1067 for_( iter1, possibleProviders.begin(), possibleProviders.end() ) {
1068 PoolItem provider1 = ResPool::instance().find( *iter1 );
1069 // find pair of an installed/uninstalled item with the same NVR
1071 for_( iter2, possibleProviders.begin(), possibleProviders.end() ) {
1072 PoolItem provider2 = ResPool::instance().find( *iter2 );
1073 if (compareByNVR (provider1.resolvable(),provider2.resolvable()) == 0
1074 && ( (provider1.status().isInstalled() && provider2.status().isUninstalled())
1075 || (provider2.status().isInstalled() && provider1.status().isUninstalled()) )) {
1081 if (provider1.status().isInstalled())
1082 providerlistInstalled.push_back(provider1);
1084 providerlistUninstalled.push_back(provider1);
1088 ret = str::form (_("%s requires %s, but this requirement cannot be provided"), s.asString().c_str(), pool_dep2str(pool, dep));
1089 if (providerlistInstalled.size() > 0) {
1090 detail += _("deleted providers: ");
1091 for (ProviderList::const_iterator iter = providerlistInstalled.begin(); iter != providerlistInstalled.end(); iter++) {
1092 if (iter == providerlistInstalled.begin())
1093 detail += itemToString( *iter );
1095 detail += "\n " + itemToString( mapItem(*iter) );
1098 if (providerlistUninstalled.size() > 0) {
1099 if (detail.size() > 0)
1100 detail += _("\nuninstallable providers: ");
1102 detail = _("uninstallable providers: ");
1103 for (ProviderList::const_iterator iter = providerlistUninstalled.begin(); iter != providerlistUninstalled.end(); iter++) {
1104 if (iter == providerlistUninstalled.begin())
1105 detail += itemToString( *iter );
1107 detail += "\n " + itemToString( mapItem(*iter) );
1117 SATResolver::problems ()
1119 ResolverProblemList resolverProblems;
1120 if (_solv && solver_problem_count(_solv)) {
1121 Pool *pool = _solv->pool;
1124 Id problem, solution, element;
1125 sat::Solvable s, sd;
1127 CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1128 CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1130 MIL << "Encountered problems! Here are the solutions:\n" << endl;
1133 while ((problem = solver_next_problem(_solv, problem)) != 0) {
1134 MIL << "Problem " << pcnt++ << ":" << endl;
1135 MIL << "====================================" << endl;
1138 string whatString = SATprobleminfoString (problem,detail,ignoreId);
1139 MIL << whatString << endl;
1140 MIL << "------------------------------------" << endl;
1141 ResolverProblem_Ptr resolverProblem = new ResolverProblem (whatString, detail);
1144 while ((solution = solver_next_solution(_solv, problem, solution)) != 0) {
1146 ProblemSolutionCombi *problemSolution = new ProblemSolutionCombi(resolverProblem);
1147 while ((element = solver_next_solutionelement(_solv, problem, solution, element, &p, &rp)) != 0) {
1148 if (p == SOLVER_SOLUTION_JOB) {
1149 /* job, rp is index into job queue */
1150 what = _jobQueue.elements[rp];
1151 switch (_jobQueue.elements[rp-1]&(SOLVER_SELECTMASK|SOLVER_JOBMASK))
1153 case SOLVER_INSTALL | SOLVER_SOLVABLE: {
1154 s = mapSolvable (what);
1155 PoolItem poolItem = _pool.find (s);
1157 if (pool->installed && s.get()->repo == pool->installed) {
1158 problemSolution->addSingleAction (poolItem, REMOVE);
1159 string description = str::form (_("do not keep %s installed"), s.asString().c_str() );
1160 MIL << description << endl;
1161 problemSolution->addDescription (description);
1163 problemSolution->addSingleAction (poolItem, KEEP);
1164 string description = str::form (_("do not install %s"), s.asString().c_str());
1165 MIL << description << endl;
1166 problemSolution->addDescription (description);
1169 ERR << "SOLVER_INSTALL_SOLVABLE: No item found for " << s.asString() << endl;
1173 case SOLVER_ERASE | SOLVER_SOLVABLE: {
1174 s = mapSolvable (what);
1175 PoolItem poolItem = _pool.find (s);
1177 if (pool->installed && s.get()->repo == pool->installed) {
1178 problemSolution->addSingleAction (poolItem, KEEP);
1179 string description = str::form (_("keep %s"), s.asString().c_str());
1180 MIL << description << endl;
1181 problemSolution->addDescription (description);
1183 problemSolution->addSingleAction (poolItem, UNLOCK);
1184 string description = str::form (_("do not forbid installation of %s"), itemToString( poolItem ).c_str());
1185 MIL << description << endl;
1186 problemSolution->addDescription (description);
1189 ERR << "SOLVER_ERASE_SOLVABLE: No item found for " << s.asString() << endl;
1193 case SOLVER_INSTALL | SOLVER_SOLVABLE_NAME:
1195 IdString ident( what );
1196 SolverQueueItemInstall_Ptr install =
1197 new SolverQueueItemInstall(_pool, ident.asString(), false );
1198 problemSolution->addSingleAction (install, REMOVE_SOLVE_QUEUE_ITEM);
1200 string description = str::form (_("do not install %s"), ident.c_str() );
1201 MIL << description << endl;
1202 problemSolution->addDescription (description);
1205 case SOLVER_ERASE | SOLVER_SOLVABLE_NAME:
1207 // As we do not know, if this request has come from resolvePool or
1208 // resolveQueue we will have to take care for both cases.
1209 IdString ident( what );
1210 FindPackage info (problemSolution, KEEP);
1211 invokeOnEach( _pool.byIdentBegin( ident ),
1212 _pool.byIdentEnd( ident ),
1213 functor::chain (resfilter::ByInstalled (), // ByInstalled
1214 resfilter::ByTransact ()), // will be deinstalled
1215 functor::functorRef<bool,PoolItem> (info) );
1217 SolverQueueItemDelete_Ptr del =
1218 new SolverQueueItemDelete(_pool, ident.asString(), false );
1219 problemSolution->addSingleAction (del, REMOVE_SOLVE_QUEUE_ITEM);
1221 string description = str::form (_("keep %s"), ident.c_str());
1222 MIL << description << endl;
1223 problemSolution->addDescription (description);
1226 case SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES:
1228 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_REQUIRE);
1229 string description = "";
1231 // Checking if this problem solution would break your system
1232 if (system_requires.find(Capability(what)) != system_requires.end()) {
1233 // Show a better warning
1234 resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1235 resolverProblem->setDescription(_("This request will break your system!"));
1236 description = _("ignore the warning of a broken system");
1237 description += string(" (requires:")+pool_dep2str(pool, what)+")";
1238 MIL << description << endl;
1239 problemSolution->addFrontDescription (description);
1241 description = str::form (_("do not ask to install a solvable providing %s"), pool_dep2str(pool, what));
1242 MIL << description << endl;
1243 problemSolution->addDescription (description);
1247 case SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES:
1249 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_CONFLICT);
1250 string description = "";
1252 // Checking if this problem solution would break your system
1253 if (system_conflicts.find(Capability(what)) != system_conflicts.end()) {
1254 // Show a better warning
1255 resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1256 resolverProblem->setDescription(_("This request will break your system!"));
1257 description = _("ignore the warning of a broken system");
1258 description += string(" (conflicts:")+pool_dep2str(pool, what)+")";
1259 MIL << description << endl;
1260 problemSolution->addFrontDescription (description);
1263 description = str::form (_("do not ask to delete all solvables providing %s"), pool_dep2str(pool, what));
1264 MIL << description << endl;
1265 problemSolution->addDescription (description);
1269 case SOLVER_UPDATE | SOLVER_SOLVABLE:
1271 s = mapSolvable (what);
1272 PoolItem poolItem = _pool.find (s);
1274 if (pool->installed && s.get()->repo == pool->installed) {
1275 problemSolution->addSingleAction (poolItem, KEEP);
1276 string description = str::form (_("do not install most recent version of %s"), s.asString().c_str());
1277 MIL << description << endl;
1278 problemSolution->addDescription (description);
1280 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE " << poolItem << " is not selected for installation" << endl;
1283 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE: No item found for " << s.asString() << endl;
1288 MIL << "- do something different" << endl;
1289 ERR << "No valid solution available" << endl;
1292 } else if (p == SOLVER_SOLUTION_INFARCH) {
1293 s = mapSolvable (rp);
1294 PoolItem poolItem = _pool.find (s);
1295 if (pool->installed && s.get()->repo == pool->installed) {
1296 problemSolution->addSingleAction (poolItem, LOCK);
1297 string description = str::form (_("keep %s despite the inferior architecture"), s.asString().c_str());
1298 MIL << description << endl;
1299 problemSolution->addDescription (description);
1301 problemSolution->addSingleAction (poolItem, INSTALL);
1302 string description = str::form (_("install %s despite the inferior architecture"), s.asString().c_str());
1303 MIL << description << endl;
1304 problemSolution->addDescription (description);
1306 } else if (p == SOLVER_SOLUTION_DISTUPGRADE) {
1307 s = mapSolvable (rp);
1308 PoolItem poolItem = _pool.find (s);
1309 if (pool->installed && s.get()->repo == pool->installed) {
1310 problemSolution->addSingleAction (poolItem, LOCK);
1311 string description = str::form (_("keep obsolete %s"), s.asString().c_str());
1312 MIL << description << endl;
1313 problemSolution->addDescription (description);
1315 problemSolution->addSingleAction (poolItem, INSTALL);
1316 string description = str::form (_("install %s from excluded repository"), s.asString().c_str());
1317 MIL << description << endl;
1318 problemSolution->addDescription (description);
1321 /* policy, replace p with rp */
1322 s = mapSolvable (p);
1323 PoolItem itemFrom = _pool.find (s);
1328 sd = mapSolvable (rp);
1329 PoolItem itemTo = _pool.find (sd);
1330 if (itemFrom && itemTo) {
1331 problemSolution->addSingleAction (itemTo, INSTALL);
1332 int illegal = policy_is_illegal(_solv, s.get(), sd.get(), 0);
1334 if ((illegal & POLICY_ILLEGAL_DOWNGRADE) != 0)
1336 string description = str::form (_("downgrade of %s to %s"), s.asString().c_str(), sd.asString().c_str());
1337 MIL << description << endl;
1338 problemSolution->addDescription (description);
1341 if ((illegal & POLICY_ILLEGAL_ARCHCHANGE) != 0)
1343 string description = str::form (_("architecture change of %s to %s"), s.asString().c_str(), sd.asString().c_str());
1344 MIL << description << endl;
1345 problemSolution->addDescription (description);
1348 if ((illegal & POLICY_ILLEGAL_VENDORCHANGE) != 0)
1350 IdString s_vendor( s.vendor() );
1351 IdString sd_vendor( sd.vendor() );
1352 string description = str::form (_("install %s (with vendor change)\n %s --> %s") ,
1353 sd.asString().c_str(),
1354 ( s_vendor ? s_vendor.c_str() : " (no vendor) " ),
1355 ( sd_vendor ? sd_vendor.c_str() : " (no vendor) " ) );
1356 MIL << description << endl;
1357 problemSolution->addDescription (description);
1361 string description = str::form (_("replacement of %s with %s"), s.asString().c_str(), sd.asString().c_str());
1362 MIL << description << endl;
1363 problemSolution->addDescription (description);
1366 ERR << s.asString() << " or " << sd.asString() << " not found" << endl;
1372 string description = str::form (_("deinstallation of %s"), s.asString().c_str());
1373 MIL << description << endl;
1374 problemSolution->addDescription (description);
1375 problemSolution->addSingleAction (itemFrom, REMOVE);
1380 resolverProblem->addSolution (problemSolution,
1381 problemSolution->actionCount() > 1 ? true : false); // Solutions with more than 1 action will be shown first.
1382 MIL << "------------------------------------" << endl;
1386 // There is a possibility to ignore this error by setting weak dependencies
1387 PoolItem item = _pool.find (sat::Solvable(ignoreId));
1388 ProblemSolutionIgnore *problemSolution = new ProblemSolutionIgnore(resolverProblem, item);
1389 resolverProblem->addSolution (problemSolution,
1390 false); // Solutions will be shown at the end
1391 MIL << "ignore some dependencies of " << item << endl;
1392 MIL << "------------------------------------" << endl;
1396 resolverProblems.push_back (resolverProblem);
1399 return resolverProblems;
1403 SATResolver::applySolutions (const ProblemSolutionList & solutions)
1405 for (ProblemSolutionList::const_iterator iter = solutions.begin();
1406 iter != solutions.end(); ++iter) {
1407 ProblemSolution_Ptr solution = *iter;
1408 Resolver dummyResolver(_pool);
1409 if (!solution->apply (dummyResolver))
1414 void SATResolver::setLocks()
1416 for (PoolItemList::const_iterator iter = _items_to_lock.begin(); iter != _items_to_lock.end(); ++iter) {
1417 sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
1418 if (iter->status().isInstalled()) {
1419 MIL << "Lock installed item " << *iter << endl;
1420 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
1421 queue_push( &(_jobQueue), ident );
1423 MIL << "Lock NOT installed item " << *iter << endl;
1424 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE | MAYBE_CLEANDEPS );
1425 queue_push( &(_jobQueue), ident );
1429 ///////////////////////////////////////////////////////////////////
1430 // Weak locks: Ignore if an item with this name is already installed.
1431 // If it's not installed try to keep it this way using a weak delete
1432 ///////////////////////////////////////////////////////////////////
1433 std::set<IdString> unifiedByName;
1434 for (PoolItemList::const_iterator iter = _items_to_keep.begin(); iter != _items_to_keep.end(); ++iter) {
1435 IdString ident( (*iter)->satSolvable().ident() );
1436 if ( unifiedByName.insert( ident ).second )
1438 if ( ! ui::Selectable::get( *iter )->hasInstalledObj() )
1440 MIL << "Keep NOT installed name " << ident << " (" << *iter << ")" << endl;
1441 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_NAME | SOLVER_WEAK | MAYBE_CLEANDEPS );
1442 queue_push( &(_jobQueue), ident.id() );
1448 void SATResolver::setSystemRequirements()
1450 CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1451 CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1453 for (CapabilitySet::const_iterator iter = system_requires.begin(); iter != system_requires.end(); ++iter) {
1454 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES );
1455 queue_push( &(_jobQueue), iter->id() );
1456 MIL << "SYSTEM Requires " << *iter << endl;
1459 for (CapabilitySet::const_iterator iter = system_conflicts.begin(); iter != system_conflicts.end(); ++iter) {
1460 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES | MAYBE_CLEANDEPS );
1461 queue_push( &(_jobQueue), iter->id() );
1462 MIL << "SYSTEM Conflicts " << *iter << endl;
1465 // Lock the architecture of the running systems rpm
1466 // package on distupgrade.
1467 if ( _distupgrade && ZConfig::instance().systemRoot() == "/" )
1469 ResPool pool( ResPool::instance() );
1470 IdString rpm( "rpm" );
1471 for_( it, pool.byIdentBegin(rpm), pool.byIdentEnd(rpm) )
1473 if ( (*it)->isSystem() )
1475 Capability archrule( (*it)->arch(), rpm.c_str(), Capability::PARSED );
1476 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_NAME | SOLVER_ESSENTIAL );
1477 queue_push( &(_jobQueue), archrule.id() );
1485 ///////////////////////////////////////////////////////////////////
1486 };// namespace detail
1487 /////////////////////////////////////////////////////////////////////
1488 /////////////////////////////////////////////////////////////////////
1489 };// namespace solver
1490 ///////////////////////////////////////////////////////////////////////
1491 ///////////////////////////////////////////////////////////////////////
1493 /////////////////////////////////////////////////////////////////////////