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/LogTools.h"
35 #include "zypp/base/Gettext.h"
36 #include "zypp/base/Algorithm.h"
38 #include "zypp/ZConfig.h"
39 #include "zypp/Product.h"
40 #include "zypp/sat/WhatProvides.h"
41 #include "zypp/sat/WhatObsoletes.h"
42 #include "zypp/sat/detail/PoolImpl.h"
44 #include "zypp/solver/detail/Resolver.h"
45 #include "zypp/solver/detail/SATResolver.h"
47 #include "zypp/solver/detail/ProblemSolutionCombi.h"
48 #include "zypp/solver/detail/ProblemSolutionIgnore.h"
49 #include "zypp/solver/detail/SolverQueueItemInstall.h"
50 #include "zypp/solver/detail/SolverQueueItemDelete.h"
51 #include "zypp/solver/detail/SystemCheck.h"
52 #include "zypp/solver/detail/SolutionAction.h"
53 #include "zypp/solver/detail/SolverQueueItem.h"
55 #define XDEBUG(x) do { if (base::logger::isExcessive()) XXX << x << std::endl;} while (0)
57 #undef ZYPP_BASE_LOGGER_LOGGROUP
58 #define ZYPP_BASE_LOGGER_LOGGROUP "zypp::solver"
60 /////////////////////////////////////////////////////////////////////////
62 { ///////////////////////////////////////////////////////////////////////
63 ///////////////////////////////////////////////////////////////////////
65 { /////////////////////////////////////////////////////////////////////
66 /////////////////////////////////////////////////////////////////////
68 { ///////////////////////////////////////////////////////////////////
70 ///////////////////////////////////////////////////////////////////////
73 inline void solverSetFocus( sat::detail::CSolver & satSolver_r, const ResolverFocus & focus_r )
77 case ResolverFocus::Default: // fallthrough to Job
78 case ResolverFocus::Job:
79 solver_set_flag( &satSolver_r, SOLVER_FLAG_FOCUS_INSTALLED, 0 );
80 solver_set_flag( &satSolver_r, SOLVER_FLAG_FOCUS_BEST, 0 );
82 case ResolverFocus::Installed:
83 solver_set_flag( &satSolver_r, SOLVER_FLAG_FOCUS_INSTALLED, 1 );
84 solver_set_flag( &satSolver_r, SOLVER_FLAG_FOCUS_BEST, 0 );
86 case ResolverFocus::Update:
87 solver_set_flag( &satSolver_r, SOLVER_FLAG_FOCUS_INSTALLED, 0 );
88 solver_set_flag( &satSolver_r, SOLVER_FLAG_FOCUS_BEST, 1 );
94 ///////////////////////////////////////////////////////////////////////
99 IMPL_PTR_TYPE(SATResolver);
101 #define MAYBE_CLEANDEPS (cleandepsOnRemove()?SOLVER_CLEANDEPS:0)
103 //---------------------------------------------------------------------------
104 // Callbacks for SAT policies
105 //---------------------------------------------------------------------------
107 int vendorCheck( sat::detail::CPool *pool, Solvable *solvable1, Solvable *solvable2 )
109 return VendorAttr::instance().equivalent( IdString(solvable1->vendor),
110 IdString(solvable2->vendor) ) ? 0 : 1;
114 inline std::string itemToString( const PoolItem & item )
117 return std::string();
119 sat::Solvable slv( item.satSolvable() );
120 std::string ret( slv.asString() ); // n-v-r.a
121 if ( ! slv.isSystem() )
124 ret += slv.repository().alias();
130 inline PoolItem getPoolItem( Id id_r )
132 PoolItem ret( (sat::Solvable( id_r )) );
134 INT << "id " << id_r << " not found in ZYPP pool." << endl;
138 //---------------------------------------------------------------------------
141 SATResolver::dumpOn( std::ostream & os ) const
143 os << "<resolver>" << endl;
145 #define OUTS(X) os << " " << #X << "\t= " << solver_get_flag(_satSolver, SOLVER_FLAG_##X) << endl
146 OUTS( ALLOW_DOWNGRADE );
147 OUTS( ALLOW_ARCHCHANGE );
148 OUTS( ALLOW_VENDORCHANGE );
149 OUTS( ALLOW_NAMECHANGE );
150 OUTS( ALLOW_UNINSTALL );
151 OUTS( NO_UPDATEPROVIDE );
152 OUTS( SPLITPROVIDES );
153 OUTS( IGNORE_RECOMMENDED );
154 OUTS( ADD_ALREADY_RECOMMENDED );
155 OUTS( NO_INFARCHCHECK );
156 OUTS( KEEP_EXPLICIT_OBSOLETES );
157 OUTS( BEST_OBEY_POLICY );
158 OUTS( NO_AUTOTARGET );
159 OUTS( DUP_ALLOW_DOWNGRADE );
160 OUTS( DUP_ALLOW_ARCHCHANGE );
161 OUTS( DUP_ALLOW_VENDORCHANGE );
162 OUTS( DUP_ALLOW_NAMECHANGE );
163 OUTS( KEEP_ORPHANS );
164 OUTS( BREAK_ORPHANS );
165 OUTS( YUM_OBSOLETES );
167 os << " focus = " << _focus << endl;
168 os << " distupgrade = " << _distupgrade << endl;
169 os << " distupgrade_removeunsupported = " << _distupgrade_removeunsupported << endl;
170 os << " solveSrcPackages = " << _solveSrcPackages << endl;
171 os << " cleandepsOnRemove = " << _cleandepsOnRemove << endl;
172 os << " fixsystem = " << _fixsystem << endl;
176 return os << "<resolver/>" << endl;
179 //---------------------------------------------------------------------------
181 // NOTE: flag defaults must be in sync with ZVARDEFAULT in Resolver.cc
182 SATResolver::SATResolver (const ResPool & pool, sat::detail::CPool *satPool)
186 , _focus ( ZConfig::instance().solver_focus() )
188 , _allowdowngrade ( false )
189 , _allownamechange ( true ) // bsc#1071466
190 , _allowarchchange ( false )
191 , _allowvendorchange ( ZConfig::instance().solver_allowVendorChange() )
192 , _allowuninstall ( false )
193 , _updatesystem(false)
194 , _noupdateprovide ( false )
195 , _dosplitprovides ( true )
196 , _onlyRequires (ZConfig::instance().solver_onlyRequires())
197 , _ignorealreadyrecommended(true)
198 , _distupgrade(false)
199 , _distupgrade_removeunsupported(false)
200 , _dup_allowdowngrade ( ZConfig::instance().solver_dupAllowDowngrade() )
201 , _dup_allownamechange ( ZConfig::instance().solver_dupAllowNameChange() )
202 , _dup_allowarchchange ( ZConfig::instance().solver_dupAllowArchChange() )
203 , _dup_allowvendorchange ( ZConfig::instance().solver_dupAllowVendorChange() )
204 , _solveSrcPackages(false)
205 , _cleandepsOnRemove(ZConfig::instance().solver_cleandepsOnRemove())
210 SATResolver::~SATResolver()
215 //---------------------------------------------------------------------------
218 SATResolver::pool (void) const
223 //---------------------------------------------------------------------------
225 // copy marked item from solution back to pool
226 // if data != NULL, set as APPL_LOW (from establishPool())
229 SATSolutionToPool (PoolItem item, const ResStatus & status, const ResStatus::TransactByValue causer)
232 item.status().resetTransact (causer);
233 item.status().resetWeak ();
237 // installation/deletion
238 if (status.isToBeInstalled()) {
239 r = item.status().setToBeInstalled (causer);
240 XDEBUG("SATSolutionToPool install returns " << item << ", " << r);
242 else if (status.isToBeUninstalledDueToUpgrade()) {
243 r = item.status().setToBeUninstalledDueToUpgrade (causer);
244 XDEBUG("SATSolutionToPool upgrade returns " << item << ", " << r);
246 else if (status.isToBeUninstalled()) {
247 r = item.status().setToBeUninstalled (causer);
248 XDEBUG("SATSolutionToPool remove returns " << item << ", " << r);
254 //----------------------------------------------------------------------------
255 //----------------------------------------------------------------------------
257 //----------------------------------------------------------------------------
258 //----------------------------------------------------------------------------
259 /////////////////////////////////////////////////////////////////////////
260 /// \class SATCollectTransact
261 /// \brief Commit helper functor distributing PoolItem by status into lists
263 /// On the fly it clears all PoolItem bySolver/ByApplLow status.
264 /// The lists are cleared in the Ctor, populated by \ref operator().
265 /////////////////////////////////////////////////////////////////////////
266 struct SATCollectTransact : public resfilter::PoolItemFilterFunctor
268 SATCollectTransact( PoolItemList & items_to_install_r,
269 PoolItemList & items_to_remove_r,
270 PoolItemList & items_to_lock_r,
271 PoolItemList & items_to_keep_r,
272 bool solveSrcPackages_r )
273 : _items_to_install( items_to_install_r )
274 , _items_to_remove( items_to_remove_r )
275 , _items_to_lock( items_to_lock_r )
276 , _items_to_keep( items_to_keep_r )
277 , _solveSrcPackages( solveSrcPackages_r )
279 _items_to_install.clear();
280 _items_to_remove.clear();
281 _items_to_lock.clear();
282 _items_to_keep.clear();
285 bool operator()( const PoolItem & item_r )
288 ResStatus & itemStatus( item_r.status() );
289 bool by_solver = ( itemStatus.isBySolver() || itemStatus.isByApplLow() );
293 // Clear former solver/establish resultd
294 itemStatus.resetTransact( ResStatus::APPL_LOW );
295 return true; // -> back out here, don't re-queue former results
298 if ( !_solveSrcPackages && item_r.isKind<SrcPackage>() )
300 // Later we may continue on a per source package base.
301 return true; // dont process this source package.
304 switch ( itemStatus.getTransactValue() )
306 case ResStatus::TRANSACT:
307 itemStatus.isUninstalled() ? _items_to_install.push_back( item_r )
308 : _items_to_remove.push_back( item_r ); break;
309 case ResStatus::LOCKED: _items_to_lock.push_back( item_r ); break;
310 case ResStatus::KEEP_STATE: _items_to_keep.push_back( item_r ); break;
316 PoolItemList & _items_to_install;
317 PoolItemList & _items_to_remove;
318 PoolItemList & _items_to_lock;
319 PoolItemList & _items_to_keep;
320 bool _solveSrcPackages;
323 /////////////////////////////////////////////////////////////////////////
326 //----------------------------------------------------------------------------
327 //----------------------------------------------------------------------------
329 //----------------------------------------------------------------------------
330 //----------------------------------------------------------------------------
333 class CheckIfUpdate : public resfilter::PoolItemFilterFunctor
337 sat::Solvable _installed;
339 CheckIfUpdate( const sat::Solvable & installed_r )
340 : is_updated( false )
341 , _installed( installed_r )
344 // check this item will be updated
346 bool operator()( const PoolItem & item )
348 if ( item.status().isToBeInstalled() )
350 if ( ! item.multiversionInstall() || sameNVRA( _installed, item ) )
361 class CollectPseudoInstalled : public resfilter::PoolItemFilterFunctor
364 Queue *solvableQueue;
366 CollectPseudoInstalled( Queue *queue )
367 :solvableQueue (queue)
370 // collecting PseudoInstalled items
371 bool operator()( PoolItem item )
373 if ( traits::isPseudoInstalled( item.satSolvable().kind() ) )
374 queue_push( solvableQueue, item.satSolvable().id() );
380 SATResolver::solving(const CapabilitySet & requires_caps,
381 const CapabilitySet & conflict_caps)
383 _satSolver = solver_create( _satPool );
384 ::pool_set_custom_vendorcheck( _satPool, &vendorCheck );
386 queue_push( &(_jobQueue), SOLVER_VERIFY|SOLVER_SOLVABLE_ALL);
387 queue_push( &(_jobQueue), 0 );
390 queue_push( &(_jobQueue), SOLVER_UPDATE|SOLVER_SOLVABLE_ALL);
391 queue_push( &(_jobQueue), 0 );
394 queue_push( &(_jobQueue), SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_ALL);
395 queue_push( &(_jobQueue), 0 );
397 if (_distupgrade_removeunsupported) {
398 queue_push( &(_jobQueue), SOLVER_DROP_ORPHANED|SOLVER_SOLVABLE_ALL);
399 queue_push( &(_jobQueue), 0 );
401 solverSetFocus( *_satSolver, _focus );
402 solver_set_flag(_satSolver, SOLVER_FLAG_ADD_ALREADY_RECOMMENDED, !_ignorealreadyrecommended);
403 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_DOWNGRADE, _allowdowngrade);
404 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_NAMECHANGE, _allownamechange);
405 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_ARCHCHANGE, _allowarchchange);
406 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_VENDORCHANGE, _allowvendorchange);
407 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_UNINSTALL, _allowuninstall);
408 solver_set_flag(_satSolver, SOLVER_FLAG_NO_UPDATEPROVIDE, _noupdateprovide);
409 solver_set_flag(_satSolver, SOLVER_FLAG_SPLITPROVIDES, _dosplitprovides);
410 solver_set_flag(_satSolver, SOLVER_FLAG_IGNORE_RECOMMENDED, false); // resolve recommended namespaces
411 solver_set_flag(_satSolver, SOLVER_FLAG_ONLY_NAMESPACE_RECOMMENDED, _onlyRequires); //
412 solver_set_flag(_satSolver, SOLVER_FLAG_DUP_ALLOW_DOWNGRADE, _dup_allowdowngrade );
413 solver_set_flag(_satSolver, SOLVER_FLAG_DUP_ALLOW_NAMECHANGE, _dup_allownamechange );
414 solver_set_flag(_satSolver, SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE, _dup_allowarchchange );
415 solver_set_flag(_satSolver, SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE, _dup_allowvendorchange );
417 sat::Pool::instance().prepare();
420 MIL << "Starting solving...." << endl;
422 if ( solver_solve( _satSolver, &(_jobQueue) ) == 0 )
424 // bsc#1155819: Weakremovers of future product not evaluated.
425 // Do a 2nd run to cleanup weakremovers() of to be installed
426 // Produtcs unless removeunsupported is active (cleans up all).
429 if ( _distupgrade_removeunsupported )
430 MIL << "Droplist processing not needed. RemoveUnsupported is On." << endl;
431 else if ( ! ZConfig::instance().solverUpgradeRemoveDroppedPackages() )
432 MIL << "Droplist processing is disabled in ZConfig." << endl;
435 bool resolve = false;
436 MIL << "Checking droplists ..." << endl;
437 // get Solvables to be installed...
438 sat::SolvableQueue decisionq;
439 solver_get_decisionqueue( _satSolver, decisionq );
440 for ( sat::Solvable::IdType slvid : decisionq )
442 sat::Solvable slv { slvid };
443 // get product buddies (they carry the weakremover)...
444 static const Capability productCap { "product()" };
445 if ( slv && slv.provides().matches( productCap ) )
447 CapabilitySet droplist { slv.valuesOfNamespace( "weakremover" ) };
448 MIL << "Droplist for " << slv << ": size " << droplist.size() << endl;
449 if ( !droplist.empty() )
451 for ( const auto & cap : droplist )
453 INT << " => " << cap << endl;
454 queue_push( &_jobQueue, SOLVER_DROP_ORPHANED | SOLVER_SOLVABLE_NAME );
455 queue_push( &_jobQueue, cap.id() );
457 // PIN product - a safety net to prevent cleanup from changing the decision for this product
458 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
459 queue_push( &(_jobQueue), slvid );
465 solver_solve( _satSolver, &(_jobQueue) );
469 MIL << "....Solver end" << endl;
471 // copying solution back to zypp pool
472 //-----------------------------------------
473 _result_items_to_install.clear();
474 _result_items_to_remove.clear();
476 /* solvables to be installed */
478 queue_init(&decisionq);
479 solver_get_decisionqueue(_satSolver, &decisionq);
480 for ( int i = 0; i < decisionq.count; ++i )
482 sat::Solvable slv( decisionq.elements[i] );
483 if ( !slv || slv.isSystem() )
486 PoolItem poolItem( slv );
487 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
488 _result_items_to_install.push_back( poolItem );
490 queue_free(&decisionq);
492 /* solvables to be erased */
493 Repository systemRepo( sat::Pool::instance().findSystemRepo() ); // don't create if it does not exist
494 if ( systemRepo && ! systemRepo.solvablesEmpty() )
496 bool mustCheckObsoletes = false;
497 for_( it, systemRepo.solvablesBegin(), systemRepo.solvablesEnd() )
499 if (solver_get_decisionlevel(_satSolver, it->id()) > 0)
502 // Check if this is an update
503 CheckIfUpdate info( *it );
504 PoolItem poolItem( *it );
505 invokeOnEach( _pool.byIdentBegin( poolItem ),
506 _pool.byIdentEnd( poolItem ),
507 resfilter::ByUninstalled(), // ByUninstalled
508 functor::functorRef<bool,PoolItem> (info) );
510 if (info.is_updated) {
511 SATSolutionToPool( poolItem, ResStatus::toBeUninstalledDueToUpgrade, ResStatus::SOLVER );
513 SATSolutionToPool( poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER );
514 if ( ! mustCheckObsoletes )
515 mustCheckObsoletes = true; // lazy check for UninstalledDueToObsolete
517 _result_items_to_remove.push_back (poolItem);
519 if ( mustCheckObsoletes )
521 sat::WhatObsoletes obsoleted( _result_items_to_install.begin(), _result_items_to_install.end() );
522 for_( it, obsoleted.poolItemBegin(), obsoleted.poolItemEnd() )
524 ResStatus & status( it->status() );
525 // WhatObsoletes contains installed items only!
526 if ( status.transacts() && ! status.isToBeUninstalledDueToUpgrade() )
527 status.setToBeUninstalledDueToObsolete();
532 Queue recommendations;
536 queue_init(&recommendations);
537 queue_init(&suggestions);
538 queue_init(&orphaned);
539 queue_init(&unneeded);
540 solver_get_recommendations(_satSolver, &recommendations, &suggestions, 0);
541 solver_get_orphaned(_satSolver, &orphaned);
542 solver_get_unneeded(_satSolver, &unneeded, 1);
543 /* solvables which are recommended */
544 for ( int i = 0; i < recommendations.count; ++i )
546 PoolItem poolItem( getPoolItem( recommendations.elements[i] ) );
547 poolItem.status().setRecommended( true );
550 /* solvables which are suggested */
551 for ( int i = 0; i < suggestions.count; ++i )
553 PoolItem poolItem( getPoolItem( suggestions.elements[i] ) );
554 poolItem.status().setSuggested( true );
557 _problem_items.clear();
558 /* solvables which are orphaned */
559 for ( int i = 0; i < orphaned.count; ++i )
561 PoolItem poolItem( getPoolItem( orphaned.elements[i] ) );
562 poolItem.status().setOrphaned( true );
563 _problem_items.push_back( poolItem );
566 /* solvables which are unneeded */
567 for ( int i = 0; i < unneeded.count; ++i )
569 PoolItem poolItem( getPoolItem( unneeded.elements[i] ) );
570 poolItem.status().setUnneeded( true );
573 queue_free(&recommendations);
574 queue_free(&suggestions);
575 queue_free(&orphaned);
576 queue_free(&unneeded);
578 /* Write validation state back to pool */
579 Queue flags, solvableQueue;
582 queue_init(&solvableQueue);
584 CollectPseudoInstalled collectPseudoInstalled(&solvableQueue);
585 invokeOnEach( _pool.begin(),
587 functor::functorRef<bool,PoolItem> (collectPseudoInstalled) );
588 solver_trivial_installable(_satSolver, &solvableQueue, &flags );
589 for (int i = 0; i < solvableQueue.count; i++) {
590 PoolItem item = _pool.find (sat::Solvable(solvableQueue.elements[i]));
591 item.status().setUndetermined();
593 if (flags.elements[i] == -1) {
594 item.status().setNonRelevant();
595 XDEBUG("SATSolutionToPool(" << item << " ) nonRelevant !");
596 } else if (flags.elements[i] == 1) {
597 item.status().setSatisfied();
598 XDEBUG("SATSolutionToPool(" << item << " ) satisfied !");
599 } else if (flags.elements[i] == 0) {
600 item.status().setBroken();
601 XDEBUG("SATSolutionToPool(" << item << " ) broken !");
604 queue_free(&(solvableQueue));
608 // Solvables which were selected due requirements which have been made by the user will
609 // be selected by APPL_LOW. We can't use any higher level, because this setting must
610 // not serve as a request for the next solver run. APPL_LOW is reset before solving.
611 for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
612 sat::WhatProvides rpmProviders(*iter);
613 for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
614 PoolItem poolItem(*iter2);
615 if (poolItem.status().isToBeInstalled()) {
616 MIL << "User requirement " << *iter << " sets " << poolItem << endl;
617 poolItem.status().setTransactByValue (ResStatus::APPL_LOW);
621 for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
622 sat::WhatProvides rpmProviders(*iter);
623 for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
624 PoolItem poolItem(*iter2);
625 if (poolItem.status().isToBeUninstalled()) {
626 MIL << "User conflict " << *iter << " sets " << poolItem << endl;
627 poolItem.status().setTransactByValue (ResStatus::APPL_LOW);
632 if (solver_problem_count(_satSolver) > 0 )
634 ERR << "Solverrun finished with an ERROR" << endl;
643 SATResolver::solverInit(const PoolItemList & weakItems)
646 MIL << "SATResolver::solverInit()" << endl;
650 queue_init( &_jobQueue );
652 // clear and rebuild: _items_to_install, _items_to_remove, _items_to_lock, _items_to_keep
654 SATCollectTransact collector( _items_to_install, _items_to_remove, _items_to_lock, _items_to_keep, solveSrcPackages() );
655 invokeOnEach ( _pool.begin(), _pool.end(), functor::functorRef<bool,PoolItem>( collector ) );
658 for (PoolItemList::const_iterator iter = weakItems.begin(); iter != weakItems.end(); iter++) {
659 Id id = (*iter)->satSolvable().id();
661 ERR << "Weaken: " << *iter << " not found" << endl;
663 MIL << "Weaken dependencies of " << *iter << endl;
664 queue_push( &(_jobQueue), SOLVER_WEAKENDEPS | SOLVER_SOLVABLE );
665 queue_push( &(_jobQueue), id );
668 // Ad rules for retracted patches and packages
670 queue_push( &(_jobQueue), SOLVER_BLACKLIST|SOLVER_SOLVABLE_PROVIDES );
671 queue_push( &(_jobQueue), sat::Solvable::retractedToken.id() );
672 queue_push( &(_jobQueue), SOLVER_BLACKLIST|SOLVER_SOLVABLE_PROVIDES );
673 queue_push( &(_jobQueue), sat::Solvable::ptfToken.id() );
676 // Ad rules for changed requestedLocales
678 const auto & trackedLocaleIds( myPool().trackedLocaleIds() );
680 // just track changed locakes
681 for ( const auto & locale : trackedLocaleIds.added() )
683 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES );
684 queue_push( &(_jobQueue), Capability( ResolverNamespace::language, IdString(locale) ).id() );
687 for ( const auto & locale : trackedLocaleIds.removed() )
689 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES | SOLVER_CLEANDEPS ); // needs uncond. SOLVER_CLEANDEPS!
690 queue_push( &(_jobQueue), Capability( ResolverNamespace::language, IdString(locale) ).id() );
694 // Add rules for parallel installable resolvables with different versions
695 for ( const sat::Solvable & solv : myPool().multiversionList() )
697 queue_push( &(_jobQueue), SOLVER_NOOBSOLETES | SOLVER_SOLVABLE );
698 queue_push( &(_jobQueue), solv.id() );
701 ::pool_add_userinstalled_jobs(_satPool, sat::Pool::instance().autoInstalled(), &(_jobQueue), GET_USERINSTALLED_NAMES|GET_USERINSTALLED_INVERTED);
705 SATResolver::solverEnd()
710 solver_free(_satSolver);
712 queue_free( &(_jobQueue) );
718 SATResolver::resolvePool(const CapabilitySet & requires_caps,
719 const CapabilitySet & conflict_caps,
720 const PoolItemList & weakItems,
721 const std::set<Repository> & upgradeRepos)
723 MIL << "SATResolver::resolvePool()" << endl;
726 solverInit(weakItems);
728 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
729 Id id = (*iter)->satSolvable().id();
731 ERR << "Install: " << *iter << " not found" << endl;
733 MIL << "Install " << *iter << endl;
734 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
735 queue_push( &(_jobQueue), id );
739 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
740 Id id = (*iter)->satSolvable().id();
742 ERR << "Delete: " << *iter << " not found" << endl;
744 MIL << "Delete " << *iter << endl;
745 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE | MAYBE_CLEANDEPS );
746 queue_push( &(_jobQueue), id);
750 for_( iter, upgradeRepos.begin(), upgradeRepos.end() )
752 queue_push( &(_jobQueue), SOLVER_DISTUPGRADE | SOLVER_SOLVABLE_REPO );
753 queue_push( &(_jobQueue), iter->get()->repoid );
754 MIL << "Upgrade repo " << *iter << endl;
757 for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
758 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES );
759 queue_push( &(_jobQueue), iter->id() );
760 MIL << "Requires " << *iter << endl;
763 for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
764 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES | MAYBE_CLEANDEPS );
765 queue_push( &(_jobQueue), iter->id() );
766 MIL << "Conflicts " << *iter << endl;
769 // set requirements for a running system
770 setSystemRequirements();
772 // set locks for the solver
776 bool ret = solving(requires_caps, conflict_caps);
778 (ret?MIL:WAR) << "SATResolver::resolvePool() done. Ret:" << ret << endl;
784 SATResolver::resolveQueue(const SolverQueueItemList &requestQueue,
785 const PoolItemList & weakItems)
787 MIL << "SATResolver::resolvQueue()" << endl;
790 solverInit(weakItems);
792 // generate solver queue
793 for (SolverQueueItemList::const_iterator iter = requestQueue.begin(); iter != requestQueue.end(); iter++) {
794 (*iter)->addRule(_jobQueue);
797 // Add addition item status to the resolve-queue cause these can be set by problem resolutions
798 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
799 Id id = (*iter)->satSolvable().id();
801 ERR << "Install: " << *iter << " not found" << endl;
803 MIL << "Install " << *iter << endl;
804 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
805 queue_push( &(_jobQueue), id );
808 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
809 sat::detail::IdType ident( (*iter)->satSolvable().ident().id() );
810 MIL << "Delete " << *iter << ident << endl;
811 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_NAME | MAYBE_CLEANDEPS );
812 queue_push( &(_jobQueue), ident);
815 // set requirements for a running system
816 setSystemRequirements();
818 // set locks for the solver
822 bool ret = solving();
824 MIL << "SATResolver::resolveQueue() done. Ret:" << ret << endl;
828 /** \todo duplicate code to be joined with \ref solving. */
829 void SATResolver::doUpdate()
831 MIL << "SATResolver::doUpdate()" << endl;
834 solverInit(PoolItemList());
836 // set requirements for a running system
837 setSystemRequirements();
839 // set locks for the solver
842 _satSolver = solver_create( _satPool );
843 ::pool_set_custom_vendorcheck( _satPool, &vendorCheck );
845 queue_push( &(_jobQueue), SOLVER_VERIFY|SOLVER_SOLVABLE_ALL);
846 queue_push( &(_jobQueue), 0 );
849 queue_push( &(_jobQueue), SOLVER_UPDATE|SOLVER_SOLVABLE_ALL);
850 queue_push( &(_jobQueue), 0 );
853 queue_push( &(_jobQueue), SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_ALL);
854 queue_push( &(_jobQueue), 0 );
856 if (_distupgrade_removeunsupported) {
857 queue_push( &(_jobQueue), SOLVER_DROP_ORPHANED|SOLVER_SOLVABLE_ALL);
858 queue_push( &(_jobQueue), 0 );
860 solverSetFocus( *_satSolver, _focus );
861 solver_set_flag(_satSolver, SOLVER_FLAG_ADD_ALREADY_RECOMMENDED, !_ignorealreadyrecommended);
862 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_DOWNGRADE, _allowdowngrade);
863 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_NAMECHANGE, _allownamechange);
864 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_ARCHCHANGE, _allowarchchange);
865 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_VENDORCHANGE, _allowvendorchange);
866 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_UNINSTALL, _allowuninstall);
867 solver_set_flag(_satSolver, SOLVER_FLAG_NO_UPDATEPROVIDE, _noupdateprovide);
868 solver_set_flag(_satSolver, SOLVER_FLAG_SPLITPROVIDES, _dosplitprovides);
869 solver_set_flag(_satSolver, SOLVER_FLAG_IGNORE_RECOMMENDED, false); // resolve recommended namespaces
870 solver_set_flag(_satSolver, SOLVER_FLAG_ONLY_NAMESPACE_RECOMMENDED, _onlyRequires); //
872 sat::Pool::instance().prepare();
875 MIL << "Starting solving for update...." << endl;
877 solver_solve( _satSolver, &(_jobQueue) );
878 MIL << "....Solver end" << endl;
880 // copying solution back to zypp pool
881 //-----------------------------------------
883 /* solvables to be installed */
885 queue_init(&decisionq);
886 solver_get_decisionqueue(_satSolver, &decisionq);
887 for (int i = 0; i < decisionq.count; i++)
890 p = decisionq.elements[i];
891 if (p < 0 || !sat::Solvable(p))
893 if (sat::Solvable(p).repository().get() == _satSolver->pool->installed)
896 PoolItem poolItem = _pool.find (sat::Solvable(p));
898 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
900 ERR << "id " << p << " not found in ZYPP pool." << endl;
903 queue_free(&decisionq);
905 /* solvables to be erased */
906 for (int i = _satSolver->pool->installed->start; i < _satSolver->pool->installed->start + _satSolver->pool->installed->nsolvables; i++)
908 if (solver_get_decisionlevel(_satSolver, i) > 0)
911 PoolItem poolItem( _pool.find( sat::Solvable(i) ) );
913 // Check if this is an update
914 CheckIfUpdate info( (sat::Solvable(i)) );
915 invokeOnEach( _pool.byIdentBegin( poolItem ),
916 _pool.byIdentEnd( poolItem ),
917 resfilter::ByUninstalled(), // ByUninstalled
918 functor::functorRef<bool,PoolItem> (info) );
920 if (info.is_updated) {
921 SATSolutionToPool (poolItem, ResStatus::toBeUninstalledDueToUpgrade , ResStatus::SOLVER);
923 SATSolutionToPool (poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER);
926 ERR << "id " << i << " not found in ZYPP pool." << endl;
929 MIL << "SATResolver::doUpdate() done" << endl;
934 //----------------------------------------------------------------------------
935 //----------------------------------------------------------------------------
937 //----------------------------------------------------------------------------
938 //----------------------------------------------------------------------------
940 //----------------------------------------------------------------------------
942 //----------------------------------------------------------------------------
944 struct FindPackage : public resfilter::ResObjectFilterFunctor
946 ProblemSolutionCombi *problemSolution;
947 TransactionKind action;
948 FindPackage (ProblemSolutionCombi *p, const TransactionKind act)
949 : problemSolution (p)
954 bool operator()( PoolItem p)
956 problemSolution->addSingleAction (p, action);
962 //----------------------------------------------------------------------------
963 // Checking if this solvable/item has a buddy which reflect the real
964 // user visible description of an item
965 // e.g. The release package has a buddy to the concerning product item.
966 // This user want's the message "Product foo conflicts with product bar" and
967 // NOT "package release-foo conflicts with package release-bar"
968 // (ma: that's why we should map just packages to buddies, not vice versa)
969 //----------------------------------------------------------------------------
970 inline sat::Solvable mapBuddy( const PoolItem & item_r )
972 if ( item_r.satSolvable().isKind<Package>() )
974 sat::Solvable buddy = item_r.buddy();
978 return item_r.satSolvable();
980 inline sat::Solvable mapBuddy( sat::Solvable item_r )
981 { return mapBuddy( PoolItem( item_r ) ); }
983 PoolItem SATResolver::mapItem ( const PoolItem & item )
984 { return PoolItem( mapBuddy( item ) ); }
986 sat::Solvable SATResolver::mapSolvable ( const Id & id )
987 { return mapBuddy( sat::Solvable(id) ); }
989 std::vector<std::string> SATResolver::SATgetCompleteProblemInfoStrings ( Id problem )
991 std::vector<std::string> ret;
993 solver_findallproblemrules( _satSolver, problem, problems );
997 //filter out generic rule information if more explicit ones are available
998 for ( sat::Queue::size_type i = 0; i < problems.size(); i++ ) {
999 SolverRuleinfo ruleClass = solver_ruleclass( _satSolver, problems[i]);
1000 if ( ruleClass != SolverRuleinfo::SOLVER_RULE_UPDATE && ruleClass != SolverRuleinfo::SOLVER_RULE_JOB ) {
1005 for ( sat::Queue::size_type i = 0; i < problems.size(); i++ ) {
1006 SolverRuleinfo ruleClass = solver_ruleclass( _satSolver, problems[i]);
1007 if ( nobad && ( ruleClass == SolverRuleinfo::SOLVER_RULE_UPDATE || ruleClass == SolverRuleinfo::SOLVER_RULE_JOB ) ) {
1013 std::string pInfo = SATproblemRuleInfoString( problems[i], detail, ignore );
1015 //we get the same string multiple times, reduce the noise
1016 if ( std::find( ret.begin(), ret.end(), pInfo ) == ret.end() )
1017 ret.push_back( pInfo );
1022 string SATResolver::SATprobleminfoString(Id problem, string &detail, Id &ignoreId)
1024 // FIXME: solver_findallproblemrules to get all rules for this problem
1025 // (the 'most relevabt' one returned by solver_findproblemrule is embedded
1026 Id probr = solver_findproblemrule(_satSolver, problem);
1027 return SATproblemRuleInfoString( probr, detail, ignoreId );
1030 std::string SATResolver::SATproblemRuleInfoString (Id probr, std::string &detail, Id &ignoreId)
1033 sat::detail::CPool *pool = _satSolver->pool;
1034 Id dep, source, target;
1035 SolverRuleinfo type = solver_ruleinfo(_satSolver, probr, &source, &target, &dep);
1039 sat::Solvable s = mapSolvable( source );
1040 sat::Solvable s2 = mapSolvable( target );
1042 // @FIXME, these strings are a duplicate copied from the libsolv library
1043 // to provide translations. Instead of having duplicate code we should
1044 // translate those strings directly in libsolv
1047 case SOLVER_RULE_DISTUPGRADE:
1048 ret = str::form (_("%s does not belong to a distupgrade repository"), s.asString().c_str());
1050 case SOLVER_RULE_INFARCH:
1051 ret = str::form (_("%s has inferior architecture"), s.asString().c_str());
1053 case SOLVER_RULE_UPDATE:
1054 ret = str::form (_("problem with installed package %s"), s.asString().c_str());
1056 case SOLVER_RULE_JOB:
1057 ret = _("conflicting requests");
1059 case SOLVER_RULE_PKG:
1060 ret = _("some dependency problem");
1062 case SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP:
1063 ret = str::form (_("nothing provides requested %s"), pool_dep2str(pool, dep));
1064 detail += _("Have you enabled all requested repositories?");
1066 case SOLVER_RULE_JOB_UNKNOWN_PACKAGE:
1067 ret = str::form (_("package %s does not exist"), pool_dep2str(pool, dep));
1068 detail += _("Have you enabled all requested repositories?");
1070 case SOLVER_RULE_JOB_UNSUPPORTED:
1071 ret = _("unsupported request");
1073 case SOLVER_RULE_JOB_PROVIDED_BY_SYSTEM:
1074 ret = str::form (_("%s is provided by the system and cannot be erased"), pool_dep2str(pool, dep));
1076 case SOLVER_RULE_PKG_NOT_INSTALLABLE:
1077 ret = str::form (_("%s is not installable"), s.asString().c_str());
1079 case SOLVER_RULE_PKG_NOTHING_PROVIDES_DEP:
1080 ignoreId = source; // for setting weak dependencies
1081 ret = str::form (_("nothing provides %s needed by %s"), pool_dep2str(pool, dep), s.asString().c_str());
1083 case SOLVER_RULE_PKG_SAME_NAME:
1084 ret = str::form (_("cannot install both %s and %s"), s.asString().c_str(), s2.asString().c_str());
1086 case SOLVER_RULE_PKG_CONFLICTS:
1087 ret = str::form (_("%s conflicts with %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1089 case SOLVER_RULE_PKG_OBSOLETES:
1090 ret = str::form (_("%s obsoletes %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1092 case SOLVER_RULE_PKG_INSTALLED_OBSOLETES:
1093 ret = str::form (_("installed %s obsoletes %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1095 case SOLVER_RULE_PKG_SELF_CONFLICT:
1096 ret = str::form (_("solvable %s conflicts with %s provided by itself"), s.asString().c_str(), pool_dep2str(pool, dep));
1098 case SOLVER_RULE_PKG_REQUIRES: {
1099 ignoreId = source; // for setting weak dependencies
1100 Capability cap(dep);
1101 sat::WhatProvides possibleProviders(cap);
1103 // check, if a provider will be deleted
1104 typedef list<PoolItem> ProviderList;
1105 ProviderList providerlistInstalled, providerlistUninstalled;
1106 for_( iter1, possibleProviders.begin(), possibleProviders.end() ) {
1107 PoolItem provider1 = ResPool::instance().find( *iter1 );
1108 // find pair of an installed/uninstalled item with the same NVR
1110 for_( iter2, possibleProviders.begin(), possibleProviders.end() ) {
1111 PoolItem provider2 = ResPool::instance().find( *iter2 );
1112 if (compareByNVR (provider1,provider2) == 0
1113 && ( (provider1.status().isInstalled() && provider2.status().isUninstalled())
1114 || (provider2.status().isInstalled() && provider1.status().isUninstalled()) )) {
1120 if (provider1.status().isInstalled())
1121 providerlistInstalled.push_back(provider1);
1123 providerlistUninstalled.push_back(provider1);
1127 ret = str::form (_("%s requires %s, but this requirement cannot be provided"), s.asString().c_str(), pool_dep2str(pool, dep));
1128 if (providerlistInstalled.size() > 0) {
1129 detail += _("deleted providers: ");
1130 for (ProviderList::const_iterator iter = providerlistInstalled.begin(); iter != providerlistInstalled.end(); iter++) {
1131 if (iter == providerlistInstalled.begin())
1132 detail += itemToString( *iter );
1134 detail += "\n " + itemToString( mapItem(*iter) );
1137 if (providerlistUninstalled.size() > 0) {
1138 if (detail.size() > 0)
1139 detail += _("\nnot installable providers: ");
1141 detail = _("not installable providers: ");
1142 for (ProviderList::const_iterator iter = providerlistUninstalled.begin(); iter != providerlistUninstalled.end(); iter++) {
1143 if (iter == providerlistUninstalled.begin())
1144 detail += itemToString( *iter );
1146 detail += "\n " + itemToString( mapItem(*iter) );
1152 DBG << "Unknown rule type(" << type << ") going to query libsolv for rule information." << endl;
1153 ret = str::asString( ::solver_problemruleinfo2str( _satSolver, type, static_cast<Id>(s.id()), static_cast<Id>(s2.id()), dep ) );
1161 SATResolver::problems ()
1163 ResolverProblemList resolverProblems;
1164 if (_satSolver && solver_problem_count(_satSolver)) {
1165 sat::detail::CPool *pool = _satSolver->pool;
1168 Id problem, solution, element;
1169 sat::Solvable s, sd;
1171 CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1172 CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1174 MIL << "Encountered problems! Here are the solutions:\n" << endl;
1177 while ((problem = solver_next_problem(_satSolver, problem)) != 0) {
1178 MIL << "Problem " << pcnt++ << ":" << endl;
1179 MIL << "====================================" << endl;
1182 string whatString = SATprobleminfoString (problem,detail,ignoreId);
1183 MIL << whatString << endl;
1184 MIL << "------------------------------------" << endl;
1185 ResolverProblem_Ptr resolverProblem = new ResolverProblem (whatString, detail, SATgetCompleteProblemInfoStrings( problem ));
1188 while ((solution = solver_next_solution(_satSolver, problem, solution)) != 0) {
1190 ProblemSolutionCombi *problemSolution = new ProblemSolutionCombi;
1191 while ((element = solver_next_solutionelement(_satSolver, problem, solution, element, &p, &rp)) != 0) {
1192 if (p == SOLVER_SOLUTION_JOB) {
1193 /* job, rp is index into job queue */
1194 what = _jobQueue.elements[rp];
1195 switch (_jobQueue.elements[rp-1]&(SOLVER_SELECTMASK|SOLVER_JOBMASK))
1197 case SOLVER_INSTALL | SOLVER_SOLVABLE: {
1198 s = mapSolvable (what);
1199 PoolItem poolItem = _pool.find (s);
1201 if (pool->installed && s.get()->repo == pool->installed) {
1202 problemSolution->addSingleAction (poolItem, REMOVE);
1203 string description = str::form (_("remove lock to allow removal of %s"), s.asString().c_str() );
1204 MIL << description << endl;
1205 problemSolution->addDescription (description);
1207 problemSolution->addSingleAction (poolItem, KEEP);
1208 string description = str::form (_("do not install %s"), s.asString().c_str());
1209 MIL << description << endl;
1210 problemSolution->addDescription (description);
1213 ERR << "SOLVER_INSTALL_SOLVABLE: No item found for " << s.asString() << endl;
1217 case SOLVER_ERASE | SOLVER_SOLVABLE: {
1218 s = mapSolvable (what);
1219 PoolItem poolItem = _pool.find (s);
1221 if (pool->installed && s.get()->repo == pool->installed) {
1222 problemSolution->addSingleAction (poolItem, KEEP);
1223 string description = str::form (_("keep %s"), s.asString().c_str());
1224 MIL << description << endl;
1225 problemSolution->addDescription (description);
1227 problemSolution->addSingleAction (poolItem, UNLOCK);
1228 string description = str::form (_("remove lock to allow installation of %s"), itemToString( poolItem ).c_str());
1229 MIL << description << endl;
1230 problemSolution->addDescription (description);
1233 ERR << "SOLVER_ERASE_SOLVABLE: No item found for " << s.asString() << endl;
1237 case SOLVER_INSTALL | SOLVER_SOLVABLE_NAME:
1239 IdString ident( what );
1240 SolverQueueItemInstall_Ptr install =
1241 new SolverQueueItemInstall(_pool, ident.asString(), false );
1242 problemSolution->addSingleAction (install, REMOVE_SOLVE_QUEUE_ITEM);
1244 string description = str::form (_("do not install %s"), ident.c_str() );
1245 MIL << description << endl;
1246 problemSolution->addDescription (description);
1249 case SOLVER_ERASE | SOLVER_SOLVABLE_NAME:
1251 // As we do not know, if this request has come from resolvePool or
1252 // resolveQueue we will have to take care for both cases.
1253 IdString ident( what );
1254 FindPackage info (problemSolution, KEEP);
1255 invokeOnEach( _pool.byIdentBegin( ident ),
1256 _pool.byIdentEnd( ident ),
1257 functor::chain (resfilter::ByInstalled (), // ByInstalled
1258 resfilter::ByTransact ()), // will be deinstalled
1259 functor::functorRef<bool,PoolItem> (info) );
1261 SolverQueueItemDelete_Ptr del =
1262 new SolverQueueItemDelete(_pool, ident.asString(), false );
1263 problemSolution->addSingleAction (del, REMOVE_SOLVE_QUEUE_ITEM);
1265 string description = str::form (_("keep %s"), ident.c_str());
1266 MIL << description << endl;
1267 problemSolution->addDescription (description);
1270 case SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES:
1272 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_REQUIRE);
1273 string description = "";
1275 // Checking if this problem solution would break your system
1276 if (system_requires.find(Capability(what)) != system_requires.end()) {
1277 // Show a better warning
1278 resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1279 resolverProblem->setDescription(_("This request will break your system!"));
1280 description = _("ignore the warning of a broken system");
1281 description += string(" (requires:")+pool_dep2str(pool, what)+")";
1282 MIL << description << endl;
1283 problemSolution->addFrontDescription (description);
1285 description = str::form (_("do not ask to install a solvable providing %s"), pool_dep2str(pool, what));
1286 MIL << description << endl;
1287 problemSolution->addDescription (description);
1291 case SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES:
1293 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_CONFLICT);
1294 string description = "";
1296 // Checking if this problem solution would break your system
1297 if (system_conflicts.find(Capability(what)) != system_conflicts.end()) {
1298 // Show a better warning
1299 resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1300 resolverProblem->setDescription(_("This request will break your system!"));
1301 description = _("ignore the warning of a broken system");
1302 description += string(" (conflicts:")+pool_dep2str(pool, what)+")";
1303 MIL << description << endl;
1304 problemSolution->addFrontDescription (description);
1307 description = str::form (_("do not ask to delete all solvables providing %s"), pool_dep2str(pool, what));
1308 MIL << description << endl;
1309 problemSolution->addDescription (description);
1313 case SOLVER_UPDATE | SOLVER_SOLVABLE:
1315 s = mapSolvable (what);
1316 PoolItem poolItem = _pool.find (s);
1318 if (pool->installed && s.get()->repo == pool->installed) {
1319 problemSolution->addSingleAction (poolItem, KEEP);
1320 string description = str::form (_("do not install most recent version of %s"), s.asString().c_str());
1321 MIL << description << endl;
1322 problemSolution->addDescription (description);
1324 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE " << poolItem << " is not selected for installation" << endl;
1327 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE: No item found for " << s.asString() << endl;
1332 MIL << "- do something different" << endl;
1333 ERR << "No valid solution available" << endl;
1336 } else if (p == SOLVER_SOLUTION_INFARCH) {
1337 s = mapSolvable (rp);
1338 PoolItem poolItem = _pool.find (s);
1339 if (pool->installed && s.get()->repo == pool->installed) {
1340 problemSolution->addSingleAction (poolItem, LOCK);
1341 string description = str::form (_("keep %s despite the inferior architecture"), s.asString().c_str());
1342 MIL << description << endl;
1343 problemSolution->addDescription (description);
1345 problemSolution->addSingleAction (poolItem, INSTALL);
1346 string description = str::form (_("install %s despite the inferior architecture"), s.asString().c_str());
1347 MIL << description << endl;
1348 problemSolution->addDescription (description);
1350 } else if (p == SOLVER_SOLUTION_DISTUPGRADE) {
1351 s = mapSolvable (rp);
1352 PoolItem poolItem = _pool.find (s);
1353 if (pool->installed && s.get()->repo == pool->installed) {
1354 problemSolution->addSingleAction (poolItem, LOCK);
1355 string description = str::form (_("keep obsolete %s"), s.asString().c_str());
1356 MIL << description << endl;
1357 problemSolution->addDescription (description);
1359 problemSolution->addSingleAction (poolItem, INSTALL);
1360 string description = str::form (_("install %s from excluded repository"), s.asString().c_str());
1361 MIL << description << endl;
1362 problemSolution->addDescription (description);
1364 } else if ( p == SOLVER_SOLUTION_BLACK ) {
1365 // Allow to install a blacklisted package (PTF, retracted,...).
1366 // For not-installed items only
1367 s = mapSolvable (rp);
1368 PoolItem poolItem = _pool.find (s);
1370 problemSolution->addSingleAction (poolItem, INSTALL);
1372 if ( s.isRetracted() ) {
1373 // translator: %1% is a package name
1374 description = str::Format(_("install %1% although it has been retracted")) % s.asString();
1375 } else if ( s.isPtf() ) {
1376 // translator: %1% is a package name
1377 description = str::Format(_("allow to install the PTF %1%")) % s.asString();
1379 // translator: %1% is a package name
1380 description = str::Format(_("install %1% although it is blacklisted")) % s.asString();
1382 MIL << description << endl;
1383 problemSolution->addDescription( description );
1384 } else if ( p > 0 ) {
1385 /* policy, replace p with rp */
1386 s = mapSolvable (p);
1387 PoolItem itemFrom = _pool.find (s);
1392 sd = mapSolvable (rp);
1393 PoolItem itemTo = _pool.find (sd);
1394 if (itemFrom && itemTo) {
1395 problemSolution->addSingleAction (itemTo, INSTALL);
1396 int illegal = policy_is_illegal(_satSolver, s.get(), sd.get(), 0);
1398 if ((illegal & POLICY_ILLEGAL_DOWNGRADE) != 0)
1400 string description = str::form (_("downgrade of %s to %s"), s.asString().c_str(), sd.asString().c_str());
1401 MIL << description << endl;
1402 problemSolution->addDescription (description);
1405 if ((illegal & POLICY_ILLEGAL_ARCHCHANGE) != 0)
1407 string description = str::form (_("architecture change of %s to %s"), s.asString().c_str(), sd.asString().c_str());
1408 MIL << description << endl;
1409 problemSolution->addDescription (description);
1412 if ((illegal & POLICY_ILLEGAL_VENDORCHANGE) != 0)
1414 IdString s_vendor( s.vendor() );
1415 IdString sd_vendor( sd.vendor() );
1416 string description = str::form (_("install %s (with vendor change)\n %s --> %s") ,
1417 sd.asString().c_str(),
1418 ( s_vendor ? s_vendor.c_str() : " (no vendor) " ),
1419 ( sd_vendor ? sd_vendor.c_str() : " (no vendor) " ) );
1420 MIL << description << endl;
1421 problemSolution->addDescription (description);
1425 string description = str::form (_("replacement of %s with %s"), s.asString().c_str(), sd.asString().c_str());
1426 MIL << description << endl;
1427 problemSolution->addDescription (description);
1430 ERR << s.asString() << " or " << sd.asString() << " not found" << endl;
1436 string description = str::form (_("deinstallation of %s"), s.asString().c_str());
1437 MIL << description << endl;
1438 problemSolution->addDescription (description);
1439 problemSolution->addSingleAction (itemFrom, REMOVE);
1445 INT << "Unknown solution " << p << endl;
1449 resolverProblem->addSolution (problemSolution,
1450 problemSolution->actionCount() > 1 ? true : false); // Solutions with more than 1 action will be shown first.
1451 MIL << "------------------------------------" << endl;
1455 // There is a possibility to ignore this error by setting weak dependencies
1456 PoolItem item = _pool.find (sat::Solvable(ignoreId));
1457 ProblemSolutionIgnore *problemSolution = new ProblemSolutionIgnore(item);
1458 resolverProblem->addSolution (problemSolution,
1459 false); // Solutions will be shown at the end
1460 MIL << "ignore some dependencies of " << item << endl;
1461 MIL << "------------------------------------" << endl;
1465 resolverProblems.push_back (resolverProblem);
1468 return resolverProblems;
1471 void SATResolver::applySolutions( const ProblemSolutionList & solutions )
1472 { Resolver( _pool ).applySolutions( solutions ); }
1474 void SATResolver::setLocks()
1479 for (PoolItemList::const_iterator iter = _items_to_lock.begin(); iter != _items_to_lock.end(); ++iter) {
1480 sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
1481 if (iter->status().isInstalled()) {
1483 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
1484 queue_push( &(_jobQueue), ident );
1487 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE | MAYBE_CLEANDEPS );
1488 queue_push( &(_jobQueue), ident );
1491 MIL << "Locked " << icnt << " installed items and " << acnt << " NOT installed items." << endl;
1493 ///////////////////////////////////////////////////////////////////
1494 // Weak locks: Ignore if an item with this name is already installed.
1495 // If it's not installed try to keep it this way using a weak delete
1496 ///////////////////////////////////////////////////////////////////
1497 std::set<IdString> unifiedByName;
1498 for (PoolItemList::const_iterator iter = _items_to_keep.begin(); iter != _items_to_keep.end(); ++iter) {
1499 IdString ident( (*iter)->satSolvable().ident() );
1500 if ( unifiedByName.insert( ident ).second )
1502 if ( ! ui::Selectable::get( *iter )->hasInstalledObj() )
1504 MIL << "Keep NOT installed name " << ident << " (" << *iter << ")" << endl;
1505 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_NAME | SOLVER_WEAK | MAYBE_CLEANDEPS );
1506 queue_push( &(_jobQueue), ident.id() );
1512 void SATResolver::setSystemRequirements()
1514 CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1515 CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1517 for (CapabilitySet::const_iterator iter = system_requires.begin(); iter != system_requires.end(); ++iter) {
1518 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES );
1519 queue_push( &(_jobQueue), iter->id() );
1520 MIL << "SYSTEM Requires " << *iter << endl;
1523 for (CapabilitySet::const_iterator iter = system_conflicts.begin(); iter != system_conflicts.end(); ++iter) {
1524 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES | MAYBE_CLEANDEPS );
1525 queue_push( &(_jobQueue), iter->id() );
1526 MIL << "SYSTEM Conflicts " << *iter << endl;
1529 // Lock the architecture of the running systems rpm
1530 // package on distupgrade.
1531 if ( _distupgrade && ZConfig::instance().systemRoot() == "/" )
1533 ResPool pool( ResPool::instance() );
1534 IdString rpm( "rpm" );
1535 for_( it, pool.byIdentBegin(rpm), pool.byIdentEnd(rpm) )
1537 if ( (*it)->isSystem() )
1539 Capability archrule( (*it)->arch(), rpm.c_str(), Capability::PARSED );
1540 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_NAME | SOLVER_ESSENTIAL );
1541 queue_push( &(_jobQueue), archrule.id() );
1548 sat::StringQueue SATResolver::autoInstalled() const
1550 sat::StringQueue ret;
1552 ::solver_get_userinstalled( _satSolver, ret, GET_USERINSTALLED_NAMES|GET_USERINSTALLED_INVERTED );
1556 sat::StringQueue SATResolver::userInstalled() const
1558 sat::StringQueue ret;
1560 ::solver_get_userinstalled( _satSolver, ret, GET_USERINSTALLED_NAMES );
1565 ///////////////////////////////////////////////////////////////////
1566 };// namespace detail
1567 /////////////////////////////////////////////////////////////////////
1568 /////////////////////////////////////////////////////////////////////
1569 };// namespace solver
1570 ///////////////////////////////////////////////////////////////////////
1571 ///////////////////////////////////////////////////////////////////////
1573 /////////////////////////////////////////////////////////////////////////