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 #define ZYPP_USE_RESOLVER_INTERNALS
34 #include "zypp/base/String.h"
35 #include "zypp/Product.h"
36 #include "zypp/Capability.h"
37 #include "zypp/ResStatus.h"
38 #include "zypp/VendorAttr.h"
39 #include "zypp/base/LogTools.h"
40 #include "zypp/base/String.h"
41 #include "zypp/base/Gettext.h"
42 #include "zypp/base/Algorithm.h"
43 #include "zypp/ResPool.h"
44 #include "zypp/ResFilters.h"
45 #include "zypp/ZConfig.h"
46 #include "zypp/sat/Pool.h"
47 #include "zypp/sat/WhatProvides.h"
48 #include "zypp/sat/WhatObsoletes.h"
49 #include "zypp/solver/detail/Resolver.h"
50 #include "zypp/solver/detail/SATResolver.h"
51 #include "zypp/solver/detail/ProblemSolutionCombi.h"
52 #include "zypp/solver/detail/ProblemSolutionIgnore.h"
53 #include "zypp/solver/detail/SolverQueueItemInstall.h"
54 #include "zypp/solver/detail/SolverQueueItemDelete.h"
55 #include "zypp/solver/detail/SystemCheck.h"
56 #include "zypp/solver/detail/SolutionAction.h"
57 #include "zypp/solver/detail/SolverQueueItem.h"
58 #include "zypp/sat/Transaction.h"
59 #include "zypp/sat/Queue.h"
61 #include "zypp/sat/detail/PoolImpl.h"
63 #define XDEBUG(x) do { if (base::logger::isExcessive()) XXX << x << std::endl;} while (0)
65 /////////////////////////////////////////////////////////////////////////
67 { ///////////////////////////////////////////////////////////////////////
69 /////////////////////////////////////////////////////////////////////////
72 inline bool HACKENV( const char * var_r, bool default_r )
75 const char * val = ::getenv( var_r );
78 ret = str::strToBool( val, default_r );
79 if ( ret != default_r )
80 INT << "HACKENV " << var_r << " = " << ret << endl;
85 /////////////////////////////////////////////////////////////////////////
87 ///////////////////////////////////////////////////////////////////////
89 { /////////////////////////////////////////////////////////////////////
90 /////////////////////////////////////////////////////////////////////
92 { ///////////////////////////////////////////////////////////////////
96 IMPL_PTR_TYPE(SATResolver);
98 #define MAYBE_CLEANDEPS (cleandepsOnRemove()?SOLVER_CLEANDEPS:0)
100 //---------------------------------------------------------------------------
101 // Callbacks for SAT policies
102 //---------------------------------------------------------------------------
104 int vendorCheck( sat::detail::CPool *pool, Solvable *solvable1, Solvable *solvable2 )
106 return VendorAttr::instance().equivalent( IdString(solvable1->vendor),
107 IdString(solvable2->vendor) ) ? 0 : 1;
111 inline std::string itemToString( const PoolItem & item )
114 return std::string();
116 sat::Solvable slv( item.satSolvable() );
117 std::string ret( slv.asString() ); // n-v-r.a
118 if ( ! slv.isSystem() )
121 ret += slv.repository().alias();
127 inline PoolItem getPoolItem( Id id_r )
129 PoolItem ret( (sat::Solvable( id_r )) );
131 INT << "id " << id_r << " not found in ZYPP pool." << endl;
135 //---------------------------------------------------------------------------
138 SATResolver::dumpOn( std::ostream & os ) const
140 os << "<resolver>" << endl;
142 #define OUTS(X) os << " " << #X << "\t= " << solver_get_flag(_satSolver, SOLVER_FLAG_##X) << endl
143 OUTS( ALLOW_DOWNGRADE );
144 OUTS( ALLOW_ARCHCHANGE );
145 OUTS( ALLOW_VENDORCHANGE );
146 OUTS( ALLOW_UNINSTALL );
147 OUTS( NO_UPDATEPROVIDE );
148 OUTS( SPLITPROVIDES );
149 OUTS( IGNORE_RECOMMENDED );
150 OUTS( ADD_ALREADY_RECOMMENDED );
151 OUTS( NO_INFARCHCHECK );
152 OUTS( ALLOW_NAMECHANGE );
153 OUTS( KEEP_EXPLICIT_OBSOLETES );
154 OUTS( BEST_OBEY_POLICY );
155 OUTS( NO_AUTOTARGET );
156 OUTS( DUP_ALLOW_DOWNGRADE );
157 OUTS( DUP_ALLOW_ARCHCHANGE );
158 OUTS( DUP_ALLOW_VENDORCHANGE );
159 OUTS( DUP_ALLOW_NAMECHANGE );
160 OUTS( KEEP_ORPHANS );
161 OUTS( BREAK_ORPHANS );
162 OUTS( FOCUS_INSTALLED );
163 OUTS( YUM_OBSOLETES );
165 os << " distupgrade = " << _distupgrade << endl;
166 os << " distupgrade_removeunsupported = " << _distupgrade_removeunsupported << endl;
167 os << " solveSrcPackages = " << _solveSrcPackages << endl;
168 os << " cleandepsOnRemove = " << _cleandepsOnRemove << endl;
169 os << " fixsystem = " << _fixsystem << endl;
173 return os << "<resolver/>" << endl;
176 //---------------------------------------------------------------------------
178 SATResolver::SATResolver (const ResPool & pool, sat::detail::CPool *satPool)
183 , _allowdowngrade(false)
184 , _allowarchchange(false)
185 , _allowvendorchange(ZConfig::instance().solver_allowVendorChange())
186 , _allowuninstall(false)
187 , _updatesystem(false)
188 , _noupdateprovide(false)
189 , _dosplitprovides(true)
190 , _onlyRequires(ZConfig::instance().solver_onlyRequires())
191 , _ignorealreadyrecommended(true)
192 , _distupgrade(false)
193 , _distupgrade_removeunsupported(false)
194 , _dup_allowdowngrade ( ZConfig::instance().solver_dupAllowDowngrade() )
195 , _dup_allownamechange ( ZConfig::instance().solver_dupAllowNameChange() )
196 , _dup_allowarchchange ( ZConfig::instance().solver_dupAllowArchChange() )
197 , _dup_allowvendorchange ( ZConfig::instance().solver_dupAllowVendorChange() )
198 , _solveSrcPackages(false)
199 , _cleandepsOnRemove(ZConfig::instance().solver_cleandepsOnRemove())
204 SATResolver::~SATResolver()
209 //---------------------------------------------------------------------------
212 SATResolver::pool (void) const
217 //---------------------------------------------------------------------------
219 // copy marked item from solution back to pool
220 // if data != NULL, set as APPL_LOW (from establishPool())
223 SATSolutionToPool (PoolItem item, const ResStatus & status, const ResStatus::TransactByValue causer)
226 item.status().resetTransact (causer);
227 item.status().resetWeak ();
231 // installation/deletion
232 if (status.isToBeInstalled()) {
233 r = item.status().setToBeInstalled (causer);
234 XDEBUG("SATSolutionToPool install returns " << item << ", " << r);
236 else if (status.isToBeUninstalledDueToUpgrade()) {
237 r = item.status().setToBeUninstalledDueToUpgrade (causer);
238 XDEBUG("SATSolutionToPool upgrade returns " << item << ", " << r);
240 else if (status.isToBeUninstalled()) {
241 r = item.status().setToBeUninstalled (causer);
242 XDEBUG("SATSolutionToPool remove returns " << item << ", " << r);
248 //----------------------------------------------------------------------------
249 //----------------------------------------------------------------------------
251 //----------------------------------------------------------------------------
252 //----------------------------------------------------------------------------
253 /////////////////////////////////////////////////////////////////////////
254 /// \class SATCollectTransact
255 /// \brief Commit helper functor distributing PoolItem by status into lists
257 /// On the fly it clears all PoolItem bySolver/ByApplLow status.
258 /// The lists are cleared in the Ctor, populated by \ref operator().
259 /////////////////////////////////////////////////////////////////////////
260 struct SATCollectTransact : public resfilter::PoolItemFilterFunctor
262 SATCollectTransact( PoolItemList & items_to_install_r,
263 PoolItemList & items_to_remove_r,
264 PoolItemList & items_to_lock_r,
265 PoolItemList & items_to_keep_r,
266 bool solveSrcPackages_r )
267 : _items_to_install( items_to_install_r )
268 , _items_to_remove( items_to_remove_r )
269 , _items_to_lock( items_to_lock_r )
270 , _items_to_keep( items_to_keep_r )
271 , _solveSrcPackages( solveSrcPackages_r )
273 _items_to_install.clear();
274 _items_to_remove.clear();
275 _items_to_lock.clear();
276 _items_to_keep.clear();
279 bool operator()( const PoolItem & item_r )
282 ResStatus & itemStatus( item_r.status() );
283 bool by_solver = ( itemStatus.isBySolver() || itemStatus.isByApplLow() );
287 // Clear former solver/establish resultd
288 itemStatus.resetTransact( ResStatus::APPL_LOW );
289 return true; // -> back out here, don't re-queue former results
292 if ( !_solveSrcPackages && item_r.isKind<SrcPackage>() )
294 // Later we may continue on a per source package base.
295 return true; // dont process this source package.
298 switch ( itemStatus.getTransactValue() )
300 case ResStatus::TRANSACT:
301 itemStatus.isUninstalled() ? _items_to_install.push_back( item_r )
302 : _items_to_remove.push_back( item_r ); break;
303 case ResStatus::LOCKED: _items_to_lock.push_back( item_r ); break;
304 case ResStatus::KEEP_STATE: _items_to_keep.push_back( item_r ); break;
310 PoolItemList & _items_to_install;
311 PoolItemList & _items_to_remove;
312 PoolItemList & _items_to_lock;
313 PoolItemList & _items_to_keep;
314 bool _solveSrcPackages;
317 /////////////////////////////////////////////////////////////////////////
320 //----------------------------------------------------------------------------
321 //----------------------------------------------------------------------------
323 //----------------------------------------------------------------------------
324 //----------------------------------------------------------------------------
327 class CheckIfUpdate : public resfilter::PoolItemFilterFunctor
331 sat::Solvable _installed;
333 CheckIfUpdate( const sat::Solvable & installed_r )
334 : is_updated( false )
335 , _installed( installed_r )
338 // check this item will be updated
340 bool operator()( const PoolItem & item )
342 if ( item.status().isToBeInstalled() )
344 if ( ! item.multiversionInstall() || sameNVRA( _installed, item ) )
355 class CollectPseudoInstalled : public resfilter::PoolItemFilterFunctor
358 Queue *solvableQueue;
360 CollectPseudoInstalled( Queue *queue )
361 :solvableQueue (queue)
364 // collecting PseudoInstalled items
365 bool operator()( PoolItem item )
367 if ( traits::isPseudoInstalled( item.satSolvable().kind() ) )
368 queue_push( solvableQueue, item.satSolvable().id() );
374 SATResolver::solving(const CapabilitySet & requires_caps,
375 const CapabilitySet & conflict_caps)
377 _satSolver = solver_create( _satPool );
378 ::pool_set_custom_vendorcheck( _satPool, &vendorCheck );
380 queue_push( &(_jobQueue), SOLVER_VERIFY|SOLVER_SOLVABLE_ALL);
381 queue_push( &(_jobQueue), 0 );
384 queue_push( &(_jobQueue), SOLVER_UPDATE|SOLVER_SOLVABLE_ALL);
385 queue_push( &(_jobQueue), 0 );
388 queue_push( &(_jobQueue), SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_ALL);
389 queue_push( &(_jobQueue), 0 );
391 if (_distupgrade_removeunsupported) {
392 queue_push( &(_jobQueue), SOLVER_DROP_ORPHANED|SOLVER_SOLVABLE_ALL);
393 queue_push( &(_jobQueue), 0 );
395 solver_set_flag(_satSolver, SOLVER_FLAG_ADD_ALREADY_RECOMMENDED, !_ignorealreadyrecommended);
396 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_DOWNGRADE, _allowdowngrade);
397 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_UNINSTALL, _allowuninstall);
398 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_ARCHCHANGE, _allowarchchange);
399 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_VENDORCHANGE, _allowvendorchange);
400 solver_set_flag(_satSolver, SOLVER_FLAG_SPLITPROVIDES, _dosplitprovides);
401 solver_set_flag(_satSolver, SOLVER_FLAG_NO_UPDATEPROVIDE, _noupdateprovide);
402 solver_set_flag(_satSolver, SOLVER_FLAG_IGNORE_RECOMMENDED, _onlyRequires);
403 solver_set_flag(_satSolver, SOLVER_FLAG_DUP_ALLOW_DOWNGRADE, _dup_allowdowngrade );
404 solver_set_flag(_satSolver, SOLVER_FLAG_DUP_ALLOW_NAMECHANGE, _dup_allownamechange );
405 solver_set_flag(_satSolver, SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE, _dup_allowarchchange );
406 solver_set_flag(_satSolver, SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE, _dup_allowvendorchange );
408 #define HACKENV(X,D) solver_set_flag(_satSolver, X, env::HACKENV( #X, D ) );
409 HACKENV( SOLVER_FLAG_DUP_ALLOW_DOWNGRADE, _dup_allowdowngrade );
410 HACKENV( SOLVER_FLAG_DUP_ALLOW_NAMECHANGE, _dup_allownamechange );
411 HACKENV( SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE, _dup_allowarchchange );
412 HACKENV( SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE,_dup_allowvendorchange );
415 sat::Pool::instance().prepareForSolving();
418 MIL << "Starting solving...." << endl;
420 solver_solve( _satSolver, &(_jobQueue) );
421 MIL << "....Solver end" << endl;
423 // copying solution back to zypp pool
424 //-----------------------------------------
425 _result_items_to_install.clear();
426 _result_items_to_remove.clear();
428 /* solvables to be installed */
430 queue_init(&decisionq);
431 solver_get_decisionqueue(_satSolver, &decisionq);
432 for ( int i = 0; i < decisionq.count; ++i )
434 sat::Solvable slv( decisionq.elements[i] );
435 if ( !slv || slv.isSystem() )
438 PoolItem poolItem( slv );
439 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
440 _result_items_to_install.push_back( poolItem );
442 queue_free(&decisionq);
444 /* solvables to be erased */
445 Repository systemRepo( sat::Pool::instance().findSystemRepo() ); // don't create if it does not exist
446 if ( systemRepo && ! systemRepo.solvablesEmpty() )
448 bool mustCheckObsoletes = false;
449 for_( it, systemRepo.solvablesBegin(), systemRepo.solvablesEnd() )
451 if (solver_get_decisionlevel(_satSolver, it->id()) > 0)
454 // Check if this is an update
455 CheckIfUpdate info( *it );
456 PoolItem poolItem( *it );
457 invokeOnEach( _pool.byIdentBegin( poolItem ),
458 _pool.byIdentEnd( poolItem ),
459 resfilter::ByUninstalled(), // ByUninstalled
460 functor::functorRef<bool,PoolItem> (info) );
462 if (info.is_updated) {
463 SATSolutionToPool( poolItem, ResStatus::toBeUninstalledDueToUpgrade, ResStatus::SOLVER );
465 SATSolutionToPool( poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER );
466 if ( ! mustCheckObsoletes )
467 mustCheckObsoletes = true; // lazy check for UninstalledDueToObsolete
469 _result_items_to_remove.push_back (poolItem);
471 if ( mustCheckObsoletes )
473 sat::WhatObsoletes obsoleted( _result_items_to_install.begin(), _result_items_to_install.end() );
474 for_( it, obsoleted.poolItemBegin(), obsoleted.poolItemEnd() )
476 ResStatus & status( it->status() );
477 // WhatObsoletes contains installed items only!
478 if ( status.transacts() && ! status.isToBeUninstalledDueToUpgrade() )
479 status.setToBeUninstalledDueToObsolete();
484 Queue recommendations;
488 queue_init(&recommendations);
489 queue_init(&suggestions);
490 queue_init(&orphaned);
491 queue_init(&unneeded);
492 solver_get_recommendations(_satSolver, &recommendations, &suggestions, 0);
493 solver_get_orphaned(_satSolver, &orphaned);
494 solver_get_unneeded(_satSolver, &unneeded, 1);
495 /* solvables which are recommended */
496 for ( int i = 0; i < recommendations.count; ++i )
498 PoolItem poolItem( getPoolItem( recommendations.elements[i] ) );
499 poolItem.status().setRecommended( true );
502 /* solvables which are suggested */
503 for ( int i = 0; i < suggestions.count; ++i )
505 PoolItem poolItem( getPoolItem( suggestions.elements[i] ) );
506 poolItem.status().setSuggested( true );
509 _problem_items.clear();
510 /* solvables which are orphaned */
511 for ( int i = 0; i < orphaned.count; ++i )
513 PoolItem poolItem( getPoolItem( orphaned.elements[i] ) );
514 poolItem.status().setOrphaned( true );
515 _problem_items.push_back( poolItem );
518 /* solvables which are unneeded */
519 for ( int i = 0; i < unneeded.count; ++i )
521 PoolItem poolItem( getPoolItem( unneeded.elements[i] ) );
522 poolItem.status().setUnneeded( true );
525 queue_free(&recommendations);
526 queue_free(&suggestions);
527 queue_free(&orphaned);
528 queue_free(&unneeded);
530 /* Write validation state back to pool */
531 Queue flags, solvableQueue;
534 queue_init(&solvableQueue);
536 CollectPseudoInstalled collectPseudoInstalled(&solvableQueue);
537 invokeOnEach( _pool.begin(),
539 functor::functorRef<bool,PoolItem> (collectPseudoInstalled) );
540 solver_trivial_installable(_satSolver, &solvableQueue, &flags );
541 for (int i = 0; i < solvableQueue.count; i++) {
542 PoolItem item = _pool.find (sat::Solvable(solvableQueue.elements[i]));
543 item.status().setUndetermined();
545 if (flags.elements[i] == -1) {
546 item.status().setNonRelevant();
547 XDEBUG("SATSolutionToPool(" << item << " ) nonRelevant !");
548 } else if (flags.elements[i] == 1) {
549 item.status().setSatisfied();
550 XDEBUG("SATSolutionToPool(" << item << " ) satisfied !");
551 } else if (flags.elements[i] == 0) {
552 item.status().setBroken();
553 XDEBUG("SATSolutionToPool(" << item << " ) broken !");
556 queue_free(&(solvableQueue));
560 // Solvables which were selected due requirements which have been made by the user will
561 // be selected by APPL_LOW. We can't use any higher level, because this setting must
562 // not serve as a request for the next solver run. APPL_LOW is reset before solving.
563 for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
564 sat::WhatProvides rpmProviders(*iter);
565 for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
566 PoolItem poolItem(*iter2);
567 if (poolItem.status().isToBeInstalled()) {
568 MIL << "User requirement " << *iter << " sets " << poolItem << endl;
569 poolItem.status().setTransactByValue (ResStatus::APPL_LOW);
573 for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
574 sat::WhatProvides rpmProviders(*iter);
575 for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
576 PoolItem poolItem(*iter2);
577 if (poolItem.status().isToBeUninstalled()) {
578 MIL << "User conflict " << *iter << " sets " << poolItem << endl;
579 poolItem.status().setTransactByValue (ResStatus::APPL_LOW);
584 if (solver_problem_count(_satSolver) > 0 )
586 ERR << "Solverrun finished with an ERROR" << endl;
595 SATResolver::solverInit(const PoolItemList & weakItems)
598 MIL << "SATResolver::solverInit()" << endl;
602 queue_init( &_jobQueue );
604 // clear and rebuild: _items_to_install, _items_to_remove, _items_to_lock, _items_to_keep
606 SATCollectTransact collector( _items_to_install, _items_to_remove, _items_to_lock, _items_to_keep, solveSrcPackages() );
607 invokeOnEach ( _pool.begin(), _pool.end(), functor::functorRef<bool,PoolItem>( collector ) );
610 for (PoolItemList::const_iterator iter = weakItems.begin(); iter != weakItems.end(); iter++) {
611 Id id = (*iter)->satSolvable().id();
613 ERR << "Weaken: " << *iter << " not found" << endl;
615 MIL << "Weaken dependencies of " << *iter << endl;
616 queue_push( &(_jobQueue), SOLVER_WEAKENDEPS | SOLVER_SOLVABLE );
617 queue_push( &(_jobQueue), id );
620 // Ad rules for changed requestedLocales
621 const auto & trackedLocaleIds( myPool().trackedLocaleIds() );
622 for ( const auto & locale : trackedLocaleIds.added() )
624 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES );
625 queue_push( &(_jobQueue), Capability( ResolverNamespace::language, IdString(locale) ).id() );
628 for ( const auto & locale : trackedLocaleIds.removed() )
630 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES | SOLVER_CLEANDEPS ); // needs uncond. SOLVER_CLEANDEPS!
631 queue_push( &(_jobQueue), Capability( ResolverNamespace::language, IdString(locale) ).id() );
634 // Add rules for parallel installable resolvables with different versions
635 for ( const sat::Solvable & solv : myPool().multiversionList() )
637 queue_push( &(_jobQueue), SOLVER_NOOBSOLETES | SOLVER_SOLVABLE );
638 queue_push( &(_jobQueue), solv.id() );
641 ::pool_add_userinstalled_jobs(_satPool, sat::Pool::instance().autoInstalled(), &(_jobQueue), GET_USERINSTALLED_NAMES|GET_USERINSTALLED_INVERTED);
645 if ( ZConfig::instance().solverUpgradeRemoveDroppedPackages() )
647 MIL << "Checking droplists ..." << endl;
648 // Dropped packages: look for 'weakremover()' provides
649 // in dup candidates of installed products.
650 ResPoolProxy proxy( ResPool::instance().proxy() );
651 for_( it, proxy.byKindBegin<Product>(), proxy.byKindEnd<Product>() )
653 if ( (*it)->onSystem() ) // (to install) or (not to delete)
655 Product::constPtr prodCand( (*it)->candidateAsKind<Product>() );
657 continue; // product no longer available
659 CapabilitySet droplist( prodCand->droplist() );
660 dumpRangeLine( MIL << "Droplist for " << (*it)->candidateObj() << ": " << droplist.size() << " ", droplist.begin(), droplist.end() ) << endl;
661 for_( cap, droplist.begin(), droplist.end() )
663 queue_push( &_jobQueue, SOLVER_DROP_ORPHANED | SOLVER_SOLVABLE_NAME );
664 queue_push( &_jobQueue, cap->id() );
671 MIL << "Droplist processing is disabled." << endl;
677 SATResolver::solverEnd()
682 solver_free(_satSolver);
684 queue_free( &(_jobQueue) );
690 SATResolver::resolvePool(const CapabilitySet & requires_caps,
691 const CapabilitySet & conflict_caps,
692 const PoolItemList & weakItems,
693 const std::set<Repository> & upgradeRepos)
695 MIL << "SATResolver::resolvePool()" << endl;
698 solverInit(weakItems);
700 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
701 Id id = (*iter)->satSolvable().id();
703 ERR << "Install: " << *iter << " not found" << endl;
705 MIL << "Install " << *iter << endl;
706 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
707 queue_push( &(_jobQueue), id );
711 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
712 Id id = (*iter)->satSolvable().id();
714 ERR << "Delete: " << *iter << " not found" << endl;
716 MIL << "Delete " << *iter << endl;
717 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE | MAYBE_CLEANDEPS );
718 queue_push( &(_jobQueue), id);
722 for_( iter, upgradeRepos.begin(), upgradeRepos.end() )
724 queue_push( &(_jobQueue), SOLVER_DISTUPGRADE | SOLVER_SOLVABLE_REPO );
725 queue_push( &(_jobQueue), iter->get()->repoid );
726 MIL << "Upgrade repo " << *iter << endl;
729 for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
730 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES );
731 queue_push( &(_jobQueue), iter->id() );
732 MIL << "Requires " << *iter << endl;
735 for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
736 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES | MAYBE_CLEANDEPS );
737 queue_push( &(_jobQueue), iter->id() );
738 MIL << "Conflicts " << *iter << endl;
741 // set requirements for a running system
742 setSystemRequirements();
744 // set locks for the solver
748 bool ret = solving(requires_caps, conflict_caps);
750 (ret?MIL:WAR) << "SATResolver::resolvePool() done. Ret:" << ret << endl;
756 SATResolver::resolveQueue(const SolverQueueItemList &requestQueue,
757 const PoolItemList & weakItems)
759 MIL << "SATResolver::resolvQueue()" << endl;
762 solverInit(weakItems);
764 // generate solver queue
765 for (SolverQueueItemList::const_iterator iter = requestQueue.begin(); iter != requestQueue.end(); iter++) {
766 (*iter)->addRule(_jobQueue);
769 // Add addition item status to the resolve-queue cause these can be set by problem resolutions
770 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
771 Id id = (*iter)->satSolvable().id();
773 ERR << "Install: " << *iter << " not found" << endl;
775 MIL << "Install " << *iter << endl;
776 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
777 queue_push( &(_jobQueue), id );
780 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
781 sat::detail::IdType ident( (*iter)->satSolvable().ident().id() );
782 MIL << "Delete " << *iter << ident << endl;
783 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_NAME | MAYBE_CLEANDEPS );
784 queue_push( &(_jobQueue), ident);
787 // set requirements for a running system
788 setSystemRequirements();
790 // set locks for the solver
794 bool ret = solving();
796 MIL << "SATResolver::resolveQueue() done. Ret:" << ret << endl;
800 /** \todo duplicate code to be joined with \ref solving. */
801 void SATResolver::doUpdate()
803 MIL << "SATResolver::doUpdate()" << endl;
806 solverInit(PoolItemList());
808 // set requirements for a running system
809 setSystemRequirements();
811 // set locks for the solver
814 _satSolver = solver_create( _satPool );
815 ::pool_set_custom_vendorcheck( _satPool, &vendorCheck );
817 queue_push( &(_jobQueue), SOLVER_VERIFY|SOLVER_SOLVABLE_ALL);
818 queue_push( &(_jobQueue), 0 );
821 queue_push( &(_jobQueue), SOLVER_UPDATE|SOLVER_SOLVABLE_ALL);
822 queue_push( &(_jobQueue), 0 );
825 queue_push( &(_jobQueue), SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_ALL);
826 queue_push( &(_jobQueue), 0 );
828 if (_distupgrade_removeunsupported) {
829 queue_push( &(_jobQueue), SOLVER_DROP_ORPHANED|SOLVER_SOLVABLE_ALL);
830 queue_push( &(_jobQueue), 0 );
832 solver_set_flag(_satSolver, SOLVER_FLAG_ADD_ALREADY_RECOMMENDED, !_ignorealreadyrecommended);
833 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_DOWNGRADE, _allowdowngrade);
834 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_UNINSTALL, _allowuninstall);
835 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_ARCHCHANGE, _allowarchchange);
836 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_VENDORCHANGE, _allowvendorchange);
837 solver_set_flag(_satSolver, SOLVER_FLAG_SPLITPROVIDES, _dosplitprovides);
838 solver_set_flag(_satSolver, SOLVER_FLAG_NO_UPDATEPROVIDE, _noupdateprovide);
839 solver_set_flag(_satSolver, SOLVER_FLAG_IGNORE_RECOMMENDED, _onlyRequires);
841 sat::Pool::instance().prepareForSolving();
844 MIL << "Starting solving for update...." << endl;
846 solver_solve( _satSolver, &(_jobQueue) );
847 MIL << "....Solver end" << endl;
849 // copying solution back to zypp pool
850 //-----------------------------------------
852 /* solvables to be installed */
854 queue_init(&decisionq);
855 solver_get_decisionqueue(_satSolver, &decisionq);
856 for (int i = 0; i < decisionq.count; i++)
859 p = decisionq.elements[i];
860 if (p < 0 || !sat::Solvable(p))
862 if (sat::Solvable(p).repository().get() == _satSolver->pool->installed)
865 PoolItem poolItem = _pool.find (sat::Solvable(p));
867 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
869 ERR << "id " << p << " not found in ZYPP pool." << endl;
872 queue_free(&decisionq);
874 /* solvables to be erased */
875 for (int i = _satSolver->pool->installed->start; i < _satSolver->pool->installed->start + _satSolver->pool->installed->nsolvables; i++)
877 if (solver_get_decisionlevel(_satSolver, i) > 0)
880 PoolItem poolItem( _pool.find( sat::Solvable(i) ) );
882 // Check if this is an update
883 CheckIfUpdate info( (sat::Solvable(i)) );
884 invokeOnEach( _pool.byIdentBegin( poolItem ),
885 _pool.byIdentEnd( poolItem ),
886 resfilter::ByUninstalled(), // ByUninstalled
887 functor::functorRef<bool,PoolItem> (info) );
889 if (info.is_updated) {
890 SATSolutionToPool (poolItem, ResStatus::toBeUninstalledDueToUpgrade , ResStatus::SOLVER);
892 SATSolutionToPool (poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER);
895 ERR << "id " << i << " not found in ZYPP pool." << endl;
898 MIL << "SATResolver::doUpdate() done" << endl;
903 //----------------------------------------------------------------------------
904 //----------------------------------------------------------------------------
906 //----------------------------------------------------------------------------
907 //----------------------------------------------------------------------------
909 //----------------------------------------------------------------------------
911 //----------------------------------------------------------------------------
913 struct FindPackage : public resfilter::ResObjectFilterFunctor
915 ProblemSolutionCombi *problemSolution;
916 TransactionKind action;
917 FindPackage (ProblemSolutionCombi *p, const TransactionKind act)
918 : problemSolution (p)
923 bool operator()( PoolItem p)
925 problemSolution->addSingleAction (p, action);
931 //----------------------------------------------------------------------------
932 // Checking if this solvable/item has a buddy which reflect the real
933 // user visible description of an item
934 // e.g. The release package has a buddy to the concerning product item.
935 // This user want's the message "Product foo conflicts with product bar" and
936 // NOT "package release-foo conflicts with package release-bar"
937 // (ma: that's why we should map just packages to buddies, not vice versa)
938 //----------------------------------------------------------------------------
939 inline sat::Solvable mapBuddy( const PoolItem & item_r )
941 if ( item_r.satSolvable().isKind<Package>() )
943 sat::Solvable buddy = item_r.buddy();
947 return item_r.satSolvable();
949 inline sat::Solvable mapBuddy( sat::Solvable item_r )
950 { return mapBuddy( PoolItem( item_r ) ); }
952 PoolItem SATResolver::mapItem ( const PoolItem & item )
953 { return PoolItem( mapBuddy( item ) ); }
955 sat::Solvable SATResolver::mapSolvable ( const Id & id )
956 { return mapBuddy( sat::Solvable(id) ); }
958 string SATResolver::SATprobleminfoString(Id problem, string &detail, Id &ignoreId)
961 sat::detail::CPool *pool = _satSolver->pool;
963 Id dep, source, target;
968 // FIXME: solver_findallproblemrules to get all rules for this problem
969 // (the 'most relevabt' one returned by solver_findproblemrule is embedded
970 probr = solver_findproblemrule(_satSolver, problem);
971 switch (solver_ruleinfo(_satSolver, probr, &source, &target, &dep))
973 case SOLVER_RULE_DISTUPGRADE:
974 s = mapSolvable (source);
975 ret = str::form (_("%s does not belong to a distupgrade repository"), s.asString().c_str());
977 case SOLVER_RULE_INFARCH:
978 s = mapSolvable (source);
979 ret = str::form (_("%s has inferior architecture"), s.asString().c_str());
981 case SOLVER_RULE_UPDATE:
982 s = mapSolvable (source);
983 ret = str::form (_("problem with installed package %s"), s.asString().c_str());
985 case SOLVER_RULE_JOB:
986 ret = _("conflicting requests");
988 case SOLVER_RULE_RPM:
989 ret = _("some dependency problem");
991 case SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP:
992 ret = str::form (_("nothing provides requested %s"), pool_dep2str(pool, dep));
993 detail += _("Have you enabled all requested repositories?");
995 case SOLVER_RULE_JOB_UNKNOWN_PACKAGE:
996 ret = str::form (_("package %s does not exist"), pool_dep2str(pool, dep));
997 detail += _("Have you enabled all requested repositories?");
999 case SOLVER_RULE_JOB_UNSUPPORTED:
1000 ret = _("unsupported request");
1002 case SOLVER_RULE_JOB_PROVIDED_BY_SYSTEM:
1003 ret = str::form (_("%s is provided by the system and cannot be erased"), pool_dep2str(pool, dep));
1005 case SOLVER_RULE_RPM_NOT_INSTALLABLE:
1006 s = mapSolvable (source);
1007 ret = str::form (_("%s is not installable"), s.asString().c_str());
1009 case SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP:
1010 ignoreId = source; // for setting weak dependencies
1011 s = mapSolvable (source);
1012 ret = str::form (_("nothing provides %s needed by %s"), pool_dep2str(pool, dep), s.asString().c_str());
1014 case SOLVER_RULE_RPM_SAME_NAME:
1015 s = mapSolvable (source);
1016 s2 = mapSolvable (target);
1017 ret = str::form (_("cannot install both %s and %s"), s.asString().c_str(), s2.asString().c_str());
1019 case SOLVER_RULE_RPM_PACKAGE_CONFLICT:
1020 s = mapSolvable (source);
1021 s2 = mapSolvable (target);
1022 ret = str::form (_("%s conflicts with %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1024 case SOLVER_RULE_RPM_PACKAGE_OBSOLETES:
1025 s = mapSolvable (source);
1026 s2 = mapSolvable (target);
1027 ret = str::form (_("%s obsoletes %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1029 case SOLVER_RULE_RPM_INSTALLEDPKG_OBSOLETES:
1030 s = mapSolvable (source);
1031 s2 = mapSolvable (target);
1032 ret = str::form (_("installed %s obsoletes %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1034 case SOLVER_RULE_RPM_SELF_CONFLICT:
1035 s = mapSolvable (source);
1036 ret = str::form (_("solvable %s conflicts with %s provided by itself"), s.asString().c_str(), pool_dep2str(pool, dep));
1038 case SOLVER_RULE_RPM_PACKAGE_REQUIRES:
1039 ignoreId = source; // for setting weak dependencies
1040 s = mapSolvable (source);
1041 Capability cap(dep);
1042 sat::WhatProvides possibleProviders(cap);
1044 // check, if a provider will be deleted
1045 typedef list<PoolItem> ProviderList;
1046 ProviderList providerlistInstalled, providerlistUninstalled;
1047 for_( iter1, possibleProviders.begin(), possibleProviders.end() ) {
1048 PoolItem provider1 = ResPool::instance().find( *iter1 );
1049 // find pair of an installed/uninstalled item with the same NVR
1051 for_( iter2, possibleProviders.begin(), possibleProviders.end() ) {
1052 PoolItem provider2 = ResPool::instance().find( *iter2 );
1053 if (compareByNVR (provider1,provider2) == 0
1054 && ( (provider1.status().isInstalled() && provider2.status().isUninstalled())
1055 || (provider2.status().isInstalled() && provider1.status().isUninstalled()) )) {
1061 if (provider1.status().isInstalled())
1062 providerlistInstalled.push_back(provider1);
1064 providerlistUninstalled.push_back(provider1);
1068 ret = str::form (_("%s requires %s, but this requirement cannot be provided"), s.asString().c_str(), pool_dep2str(pool, dep));
1069 if (providerlistInstalled.size() > 0) {
1070 detail += _("deleted providers: ");
1071 for (ProviderList::const_iterator iter = providerlistInstalled.begin(); iter != providerlistInstalled.end(); iter++) {
1072 if (iter == providerlistInstalled.begin())
1073 detail += itemToString( *iter );
1075 detail += "\n " + itemToString( mapItem(*iter) );
1078 if (providerlistUninstalled.size() > 0) {
1079 if (detail.size() > 0)
1080 detail += _("\nuninstallable providers: ");
1082 detail = _("uninstallable providers: ");
1083 for (ProviderList::const_iterator iter = providerlistUninstalled.begin(); iter != providerlistUninstalled.end(); iter++) {
1084 if (iter == providerlistUninstalled.begin())
1085 detail += itemToString( *iter );
1087 detail += "\n " + itemToString( mapItem(*iter) );
1097 SATResolver::problems ()
1099 ResolverProblemList resolverProblems;
1100 if (_satSolver && solver_problem_count(_satSolver)) {
1101 sat::detail::CPool *pool = _satSolver->pool;
1104 Id problem, solution, element;
1105 sat::Solvable s, sd;
1107 CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1108 CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1110 MIL << "Encountered problems! Here are the solutions:\n" << endl;
1113 while ((problem = solver_next_problem(_satSolver, problem)) != 0) {
1114 MIL << "Problem " << pcnt++ << ":" << endl;
1115 MIL << "====================================" << endl;
1118 string whatString = SATprobleminfoString (problem,detail,ignoreId);
1119 MIL << whatString << endl;
1120 MIL << "------------------------------------" << endl;
1121 ResolverProblem_Ptr resolverProblem = new ResolverProblem (whatString, detail);
1124 while ((solution = solver_next_solution(_satSolver, problem, solution)) != 0) {
1126 ProblemSolutionCombi *problemSolution = new ProblemSolutionCombi;
1127 while ((element = solver_next_solutionelement(_satSolver, problem, solution, element, &p, &rp)) != 0) {
1128 if (p == SOLVER_SOLUTION_JOB) {
1129 /* job, rp is index into job queue */
1130 what = _jobQueue.elements[rp];
1131 switch (_jobQueue.elements[rp-1]&(SOLVER_SELECTMASK|SOLVER_JOBMASK))
1133 case SOLVER_INSTALL | SOLVER_SOLVABLE: {
1134 s = mapSolvable (what);
1135 PoolItem poolItem = _pool.find (s);
1137 if (pool->installed && s.get()->repo == pool->installed) {
1138 problemSolution->addSingleAction (poolItem, REMOVE);
1139 string description = str::form (_("remove lock to allow removal of %s"), s.asString().c_str() );
1140 MIL << description << endl;
1141 problemSolution->addDescription (description);
1143 problemSolution->addSingleAction (poolItem, KEEP);
1144 string description = str::form (_("do not install %s"), s.asString().c_str());
1145 MIL << description << endl;
1146 problemSolution->addDescription (description);
1149 ERR << "SOLVER_INSTALL_SOLVABLE: No item found for " << s.asString() << endl;
1153 case SOLVER_ERASE | 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, KEEP);
1159 string description = str::form (_("keep %s"), s.asString().c_str());
1160 MIL << description << endl;
1161 problemSolution->addDescription (description);
1163 problemSolution->addSingleAction (poolItem, UNLOCK);
1164 string description = str::form (_("remove lock to allow installation of %s"), itemToString( poolItem ).c_str());
1165 MIL << description << endl;
1166 problemSolution->addDescription (description);
1169 ERR << "SOLVER_ERASE_SOLVABLE: No item found for " << s.asString() << endl;
1173 case SOLVER_INSTALL | SOLVER_SOLVABLE_NAME:
1175 IdString ident( what );
1176 SolverQueueItemInstall_Ptr install =
1177 new SolverQueueItemInstall(_pool, ident.asString(), false );
1178 problemSolution->addSingleAction (install, REMOVE_SOLVE_QUEUE_ITEM);
1180 string description = str::form (_("do not install %s"), ident.c_str() );
1181 MIL << description << endl;
1182 problemSolution->addDescription (description);
1185 case SOLVER_ERASE | SOLVER_SOLVABLE_NAME:
1187 // As we do not know, if this request has come from resolvePool or
1188 // resolveQueue we will have to take care for both cases.
1189 IdString ident( what );
1190 FindPackage info (problemSolution, KEEP);
1191 invokeOnEach( _pool.byIdentBegin( ident ),
1192 _pool.byIdentEnd( ident ),
1193 functor::chain (resfilter::ByInstalled (), // ByInstalled
1194 resfilter::ByTransact ()), // will be deinstalled
1195 functor::functorRef<bool,PoolItem> (info) );
1197 SolverQueueItemDelete_Ptr del =
1198 new SolverQueueItemDelete(_pool, ident.asString(), false );
1199 problemSolution->addSingleAction (del, REMOVE_SOLVE_QUEUE_ITEM);
1201 string description = str::form (_("keep %s"), ident.c_str());
1202 MIL << description << endl;
1203 problemSolution->addDescription (description);
1206 case SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES:
1208 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_REQUIRE);
1209 string description = "";
1211 // Checking if this problem solution would break your system
1212 if (system_requires.find(Capability(what)) != system_requires.end()) {
1213 // Show a better warning
1214 resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1215 resolverProblem->setDescription(_("This request will break your system!"));
1216 description = _("ignore the warning of a broken system");
1217 description += string(" (requires:")+pool_dep2str(pool, what)+")";
1218 MIL << description << endl;
1219 problemSolution->addFrontDescription (description);
1221 description = str::form (_("do not ask to install a solvable providing %s"), pool_dep2str(pool, what));
1222 MIL << description << endl;
1223 problemSolution->addDescription (description);
1227 case SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES:
1229 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_CONFLICT);
1230 string description = "";
1232 // Checking if this problem solution would break your system
1233 if (system_conflicts.find(Capability(what)) != system_conflicts.end()) {
1234 // Show a better warning
1235 resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1236 resolverProblem->setDescription(_("This request will break your system!"));
1237 description = _("ignore the warning of a broken system");
1238 description += string(" (conflicts:")+pool_dep2str(pool, what)+")";
1239 MIL << description << endl;
1240 problemSolution->addFrontDescription (description);
1243 description = str::form (_("do not ask to delete all solvables providing %s"), pool_dep2str(pool, what));
1244 MIL << description << endl;
1245 problemSolution->addDescription (description);
1249 case SOLVER_UPDATE | SOLVER_SOLVABLE:
1251 s = mapSolvable (what);
1252 PoolItem poolItem = _pool.find (s);
1254 if (pool->installed && s.get()->repo == pool->installed) {
1255 problemSolution->addSingleAction (poolItem, KEEP);
1256 string description = str::form (_("do not install most recent version of %s"), s.asString().c_str());
1257 MIL << description << endl;
1258 problemSolution->addDescription (description);
1260 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE " << poolItem << " is not selected for installation" << endl;
1263 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE: No item found for " << s.asString() << endl;
1268 MIL << "- do something different" << endl;
1269 ERR << "No valid solution available" << endl;
1272 } else if (p == SOLVER_SOLUTION_INFARCH) {
1273 s = mapSolvable (rp);
1274 PoolItem poolItem = _pool.find (s);
1275 if (pool->installed && s.get()->repo == pool->installed) {
1276 problemSolution->addSingleAction (poolItem, LOCK);
1277 string description = str::form (_("keep %s despite the inferior architecture"), s.asString().c_str());
1278 MIL << description << endl;
1279 problemSolution->addDescription (description);
1281 problemSolution->addSingleAction (poolItem, INSTALL);
1282 string description = str::form (_("install %s despite the inferior architecture"), s.asString().c_str());
1283 MIL << description << endl;
1284 problemSolution->addDescription (description);
1286 } else if (p == SOLVER_SOLUTION_DISTUPGRADE) {
1287 s = mapSolvable (rp);
1288 PoolItem poolItem = _pool.find (s);
1289 if (pool->installed && s.get()->repo == pool->installed) {
1290 problemSolution->addSingleAction (poolItem, LOCK);
1291 string description = str::form (_("keep obsolete %s"), s.asString().c_str());
1292 MIL << description << endl;
1293 problemSolution->addDescription (description);
1295 problemSolution->addSingleAction (poolItem, INSTALL);
1296 string description = str::form (_("install %s from excluded repository"), s.asString().c_str());
1297 MIL << description << endl;
1298 problemSolution->addDescription (description);
1301 /* policy, replace p with rp */
1302 s = mapSolvable (p);
1303 PoolItem itemFrom = _pool.find (s);
1308 sd = mapSolvable (rp);
1309 PoolItem itemTo = _pool.find (sd);
1310 if (itemFrom && itemTo) {
1311 problemSolution->addSingleAction (itemTo, INSTALL);
1312 int illegal = policy_is_illegal(_satSolver, s.get(), sd.get(), 0);
1314 if ((illegal & POLICY_ILLEGAL_DOWNGRADE) != 0)
1316 string description = str::form (_("downgrade of %s to %s"), s.asString().c_str(), sd.asString().c_str());
1317 MIL << description << endl;
1318 problemSolution->addDescription (description);
1321 if ((illegal & POLICY_ILLEGAL_ARCHCHANGE) != 0)
1323 string description = str::form (_("architecture change of %s to %s"), s.asString().c_str(), sd.asString().c_str());
1324 MIL << description << endl;
1325 problemSolution->addDescription (description);
1328 if ((illegal & POLICY_ILLEGAL_VENDORCHANGE) != 0)
1330 IdString s_vendor( s.vendor() );
1331 IdString sd_vendor( sd.vendor() );
1332 string description = str::form (_("install %s (with vendor change)\n %s --> %s") ,
1333 sd.asString().c_str(),
1334 ( s_vendor ? s_vendor.c_str() : " (no vendor) " ),
1335 ( sd_vendor ? sd_vendor.c_str() : " (no vendor) " ) );
1336 MIL << description << endl;
1337 problemSolution->addDescription (description);
1341 string description = str::form (_("replacement of %s with %s"), s.asString().c_str(), sd.asString().c_str());
1342 MIL << description << endl;
1343 problemSolution->addDescription (description);
1346 ERR << s.asString() << " or " << sd.asString() << " not found" << endl;
1352 string description = str::form (_("deinstallation of %s"), s.asString().c_str());
1353 MIL << description << endl;
1354 problemSolution->addDescription (description);
1355 problemSolution->addSingleAction (itemFrom, REMOVE);
1360 resolverProblem->addSolution (problemSolution,
1361 problemSolution->actionCount() > 1 ? true : false); // Solutions with more than 1 action will be shown first.
1362 MIL << "------------------------------------" << endl;
1366 // There is a possibility to ignore this error by setting weak dependencies
1367 PoolItem item = _pool.find (sat::Solvable(ignoreId));
1368 ProblemSolutionIgnore *problemSolution = new ProblemSolutionIgnore(item);
1369 resolverProblem->addSolution (problemSolution,
1370 false); // Solutions will be shown at the end
1371 MIL << "ignore some dependencies of " << item << endl;
1372 MIL << "------------------------------------" << endl;
1376 resolverProblems.push_back (resolverProblem);
1379 return resolverProblems;
1382 void SATResolver::applySolutions( const ProblemSolutionList & solutions )
1383 { Resolver( _pool ).applySolutions( solutions ); }
1385 void SATResolver::setLocks()
1387 for (PoolItemList::const_iterator iter = _items_to_lock.begin(); iter != _items_to_lock.end(); ++iter) {
1388 sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
1389 if (iter->status().isInstalled()) {
1390 MIL << "Lock installed item " << *iter << endl;
1391 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
1392 queue_push( &(_jobQueue), ident );
1394 MIL << "Lock NOT installed item " << *iter << endl;
1395 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE | MAYBE_CLEANDEPS );
1396 queue_push( &(_jobQueue), ident );
1400 ///////////////////////////////////////////////////////////////////
1401 // Weak locks: Ignore if an item with this name is already installed.
1402 // If it's not installed try to keep it this way using a weak delete
1403 ///////////////////////////////////////////////////////////////////
1404 std::set<IdString> unifiedByName;
1405 for (PoolItemList::const_iterator iter = _items_to_keep.begin(); iter != _items_to_keep.end(); ++iter) {
1406 IdString ident( (*iter)->satSolvable().ident() );
1407 if ( unifiedByName.insert( ident ).second )
1409 if ( ! ui::Selectable::get( *iter )->hasInstalledObj() )
1411 MIL << "Keep NOT installed name " << ident << " (" << *iter << ")" << endl;
1412 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_NAME | SOLVER_WEAK | MAYBE_CLEANDEPS );
1413 queue_push( &(_jobQueue), ident.id() );
1419 void SATResolver::setSystemRequirements()
1421 CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1422 CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1424 for (CapabilitySet::const_iterator iter = system_requires.begin(); iter != system_requires.end(); ++iter) {
1425 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES );
1426 queue_push( &(_jobQueue), iter->id() );
1427 MIL << "SYSTEM Requires " << *iter << endl;
1430 for (CapabilitySet::const_iterator iter = system_conflicts.begin(); iter != system_conflicts.end(); ++iter) {
1431 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES | MAYBE_CLEANDEPS );
1432 queue_push( &(_jobQueue), iter->id() );
1433 MIL << "SYSTEM Conflicts " << *iter << endl;
1436 // Lock the architecture of the running systems rpm
1437 // package on distupgrade.
1438 if ( _distupgrade && ZConfig::instance().systemRoot() == "/" )
1440 ResPool pool( ResPool::instance() );
1441 IdString rpm( "rpm" );
1442 for_( it, pool.byIdentBegin(rpm), pool.byIdentEnd(rpm) )
1444 if ( (*it)->isSystem() )
1446 Capability archrule( (*it)->arch(), rpm.c_str(), Capability::PARSED );
1447 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_NAME | SOLVER_ESSENTIAL );
1448 queue_push( &(_jobQueue), archrule.id() );
1455 sat::StringQueue SATResolver::autoInstalled() const
1457 sat::StringQueue ret;
1459 ::solver_get_userinstalled( _satSolver, ret, GET_USERINSTALLED_NAMES|GET_USERINSTALLED_INVERTED );
1463 sat::StringQueue SATResolver::userInstalled() const
1465 sat::StringQueue ret;
1467 ::solver_get_userinstalled( _satSolver, ret, GET_USERINSTALLED_NAMES );
1472 ///////////////////////////////////////////////////////////////////
1473 };// namespace detail
1474 /////////////////////////////////////////////////////////////////////
1475 /////////////////////////////////////////////////////////////////////
1476 };// namespace solver
1477 ///////////////////////////////////////////////////////////////////////
1478 ///////////////////////////////////////////////////////////////////////
1480 /////////////////////////////////////////////////////////////////////////