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::detail::IdType id : decisionq )
444 sat::Solvable slv { id };
445 // get product buddies (they carry the weakremover)...
446 static const Capability productCap { "product()" };
447 if ( slv && slv.provides().matches( productCap ) )
449 CapabilitySet droplist { slv.valuesOfNamespace( "weakremover" ) };
450 MIL << "Droplist for " << slv << ": size " << droplist.size() << endl;
451 if ( !droplist.empty() )
453 for ( const auto & cap : droplist )
455 queue_push( &_jobQueue, SOLVER_DROP_ORPHANED | SOLVER_SOLVABLE_NAME );
456 queue_push( &_jobQueue, cap.id() );
458 // PIN product - a safety net to prevent cleanup from changing the decision for this product
459 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
460 queue_push( &(_jobQueue), id );
466 solver_solve( _satSolver, &(_jobQueue) );
470 MIL << "....Solver end" << endl;
472 // copying solution back to zypp pool
473 //-----------------------------------------
474 _result_items_to_install.clear();
475 _result_items_to_remove.clear();
477 /* solvables to be installed */
479 queue_init(&decisionq);
480 solver_get_decisionqueue(_satSolver, &decisionq);
481 for ( int i = 0; i < decisionq.count; ++i )
483 Id p = decisionq.elements[i];
487 sat::Solvable slv { p };
488 if ( ! slv || slv.isSystem() )
491 PoolItem poolItem( slv );
492 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
493 _result_items_to_install.push_back( poolItem );
495 queue_free(&decisionq);
497 /* solvables to be erased */
498 Repository systemRepo( sat::Pool::instance().findSystemRepo() ); // don't create if it does not exist
499 if ( systemRepo && ! systemRepo.solvablesEmpty() )
501 bool mustCheckObsoletes = false;
502 for_( it, systemRepo.solvablesBegin(), systemRepo.solvablesEnd() )
504 if (solver_get_decisionlevel(_satSolver, it->id()) > 0)
507 // Check if this is an update
508 CheckIfUpdate info( *it );
509 PoolItem poolItem( *it );
510 invokeOnEach( _pool.byIdentBegin( poolItem ),
511 _pool.byIdentEnd( poolItem ),
512 resfilter::ByUninstalled(), // ByUninstalled
513 functor::functorRef<bool,PoolItem> (info) );
515 if (info.is_updated) {
516 SATSolutionToPool( poolItem, ResStatus::toBeUninstalledDueToUpgrade, ResStatus::SOLVER );
518 SATSolutionToPool( poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER );
519 if ( ! mustCheckObsoletes )
520 mustCheckObsoletes = true; // lazy check for UninstalledDueToObsolete
522 _result_items_to_remove.push_back (poolItem);
524 if ( mustCheckObsoletes )
526 sat::WhatObsoletes obsoleted( _result_items_to_install.begin(), _result_items_to_install.end() );
527 for_( it, obsoleted.poolItemBegin(), obsoleted.poolItemEnd() )
529 ResStatus & status( it->status() );
530 // WhatObsoletes contains installed items only!
531 if ( status.transacts() && ! status.isToBeUninstalledDueToUpgrade() )
532 status.setToBeUninstalledDueToObsolete();
537 Queue recommendations;
541 queue_init(&recommendations);
542 queue_init(&suggestions);
543 queue_init(&orphaned);
544 queue_init(&unneeded);
545 solver_get_recommendations(_satSolver, &recommendations, &suggestions, 0);
546 solver_get_orphaned(_satSolver, &orphaned);
547 solver_get_unneeded(_satSolver, &unneeded, 1);
548 /* solvables which are recommended */
549 for ( int i = 0; i < recommendations.count; ++i )
551 PoolItem poolItem( getPoolItem( recommendations.elements[i] ) );
552 poolItem.status().setRecommended( true );
555 /* solvables which are suggested */
556 for ( int i = 0; i < suggestions.count; ++i )
558 PoolItem poolItem( getPoolItem( suggestions.elements[i] ) );
559 poolItem.status().setSuggested( true );
562 _problem_items.clear();
563 /* solvables which are orphaned */
564 for ( int i = 0; i < orphaned.count; ++i )
566 PoolItem poolItem( getPoolItem( orphaned.elements[i] ) );
567 poolItem.status().setOrphaned( true );
568 _problem_items.push_back( poolItem );
571 /* solvables which are unneeded */
572 for ( int i = 0; i < unneeded.count; ++i )
574 PoolItem poolItem( getPoolItem( unneeded.elements[i] ) );
575 poolItem.status().setUnneeded( true );
578 queue_free(&recommendations);
579 queue_free(&suggestions);
580 queue_free(&orphaned);
581 queue_free(&unneeded);
583 /* Write validation state back to pool */
584 Queue flags, solvableQueue;
587 queue_init(&solvableQueue);
589 CollectPseudoInstalled collectPseudoInstalled(&solvableQueue);
590 invokeOnEach( _pool.begin(),
592 functor::functorRef<bool,PoolItem> (collectPseudoInstalled) );
593 solver_trivial_installable(_satSolver, &solvableQueue, &flags );
594 for (int i = 0; i < solvableQueue.count; i++) {
595 PoolItem item = _pool.find (sat::Solvable(solvableQueue.elements[i]));
596 item.status().setUndetermined();
598 if (flags.elements[i] == -1) {
599 item.status().setNonRelevant();
600 XDEBUG("SATSolutionToPool(" << item << " ) nonRelevant !");
601 } else if (flags.elements[i] == 1) {
602 item.status().setSatisfied();
603 XDEBUG("SATSolutionToPool(" << item << " ) satisfied !");
604 } else if (flags.elements[i] == 0) {
605 item.status().setBroken();
606 XDEBUG("SATSolutionToPool(" << item << " ) broken !");
609 queue_free(&(solvableQueue));
613 // Solvables which were selected due requirements which have been made by the user will
614 // be selected by APPL_LOW. We can't use any higher level, because this setting must
615 // not serve as a request for the next solver run. APPL_LOW is reset before solving.
616 for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
617 sat::WhatProvides rpmProviders(*iter);
618 for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
619 PoolItem poolItem(*iter2);
620 if (poolItem.status().isToBeInstalled()) {
621 MIL << "User requirement " << *iter << " sets " << poolItem << endl;
622 poolItem.status().setTransactByValue (ResStatus::APPL_LOW);
626 for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
627 sat::WhatProvides rpmProviders(*iter);
628 for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
629 PoolItem poolItem(*iter2);
630 if (poolItem.status().isToBeUninstalled()) {
631 MIL << "User conflict " << *iter << " sets " << poolItem << endl;
632 poolItem.status().setTransactByValue (ResStatus::APPL_LOW);
637 if (solver_problem_count(_satSolver) > 0 )
639 ERR << "Solverrun finished with an ERROR" << endl;
648 SATResolver::solverInit(const PoolItemList & weakItems)
651 MIL << "SATResolver::solverInit()" << endl;
655 queue_init( &_jobQueue );
657 // clear and rebuild: _items_to_install, _items_to_remove, _items_to_lock, _items_to_keep
659 SATCollectTransact collector( _items_to_install, _items_to_remove, _items_to_lock, _items_to_keep, solveSrcPackages() );
660 invokeOnEach ( _pool.begin(), _pool.end(), functor::functorRef<bool,PoolItem>( collector ) );
663 for (PoolItemList::const_iterator iter = weakItems.begin(); iter != weakItems.end(); iter++) {
664 Id id = (*iter)->satSolvable().id();
666 ERR << "Weaken: " << *iter << " not found" << endl;
668 MIL << "Weaken dependencies of " << *iter << endl;
669 queue_push( &(_jobQueue), SOLVER_WEAKENDEPS | SOLVER_SOLVABLE );
670 queue_push( &(_jobQueue), id );
673 // Ad rules for retracted patches and packages
675 queue_push( &(_jobQueue), SOLVER_BLACKLIST|SOLVER_SOLVABLE_PROVIDES );
676 queue_push( &(_jobQueue), sat::Solvable::retractedToken.id() );
677 queue_push( &(_jobQueue), SOLVER_BLACKLIST|SOLVER_SOLVABLE_PROVIDES );
678 queue_push( &(_jobQueue), sat::Solvable::ptfToken.id() );
681 // Ad rules for changed requestedLocales
683 const auto & trackedLocaleIds( myPool().trackedLocaleIds() );
685 // just track changed locakes
686 for ( const auto & locale : trackedLocaleIds.added() )
688 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES );
689 queue_push( &(_jobQueue), Capability( ResolverNamespace::language, IdString(locale) ).id() );
692 for ( const auto & locale : trackedLocaleIds.removed() )
694 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES | SOLVER_CLEANDEPS ); // needs uncond. SOLVER_CLEANDEPS!
695 queue_push( &(_jobQueue), Capability( ResolverNamespace::language, IdString(locale) ).id() );
699 // Add rules for parallel installable resolvables with different versions
700 for ( const sat::Solvable & solv : myPool().multiversionList() )
702 queue_push( &(_jobQueue), SOLVER_NOOBSOLETES | SOLVER_SOLVABLE );
703 queue_push( &(_jobQueue), solv.id() );
706 ::pool_add_userinstalled_jobs(_satPool, sat::Pool::instance().autoInstalled(), &(_jobQueue), GET_USERINSTALLED_NAMES|GET_USERINSTALLED_INVERTED);
710 SATResolver::solverEnd()
715 solver_free(_satSolver);
717 queue_free( &(_jobQueue) );
723 SATResolver::resolvePool(const CapabilitySet & requires_caps,
724 const CapabilitySet & conflict_caps,
725 const PoolItemList & weakItems,
726 const std::set<Repository> & upgradeRepos)
728 MIL << "SATResolver::resolvePool()" << endl;
731 solverInit(weakItems);
733 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
734 Id id = (*iter)->satSolvable().id();
736 ERR << "Install: " << *iter << " not found" << endl;
738 MIL << "Install " << *iter << endl;
739 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
740 queue_push( &(_jobQueue), id );
744 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
745 Id id = (*iter)->satSolvable().id();
747 ERR << "Delete: " << *iter << " not found" << endl;
749 MIL << "Delete " << *iter << endl;
750 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE | MAYBE_CLEANDEPS );
751 queue_push( &(_jobQueue), id);
755 for_( iter, upgradeRepos.begin(), upgradeRepos.end() )
757 queue_push( &(_jobQueue), SOLVER_DISTUPGRADE | SOLVER_SOLVABLE_REPO );
758 queue_push( &(_jobQueue), iter->get()->repoid );
759 MIL << "Upgrade repo " << *iter << endl;
762 for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
763 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES );
764 queue_push( &(_jobQueue), iter->id() );
765 MIL << "Requires " << *iter << endl;
768 for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
769 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES | MAYBE_CLEANDEPS );
770 queue_push( &(_jobQueue), iter->id() );
771 MIL << "Conflicts " << *iter << endl;
774 // set requirements for a running system
775 setSystemRequirements();
777 // set locks for the solver
781 bool ret = solving(requires_caps, conflict_caps);
783 (ret?MIL:WAR) << "SATResolver::resolvePool() done. Ret:" << ret << endl;
789 SATResolver::resolveQueue(const SolverQueueItemList &requestQueue,
790 const PoolItemList & weakItems)
792 MIL << "SATResolver::resolvQueue()" << endl;
795 solverInit(weakItems);
797 // generate solver queue
798 for (SolverQueueItemList::const_iterator iter = requestQueue.begin(); iter != requestQueue.end(); iter++) {
799 (*iter)->addRule(_jobQueue);
802 // Add addition item status to the resolve-queue cause these can be set by problem resolutions
803 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
804 Id id = (*iter)->satSolvable().id();
806 ERR << "Install: " << *iter << " not found" << endl;
808 MIL << "Install " << *iter << endl;
809 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
810 queue_push( &(_jobQueue), id );
813 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
814 sat::detail::IdType ident( (*iter)->satSolvable().ident().id() );
815 MIL << "Delete " << *iter << ident << endl;
816 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_NAME | MAYBE_CLEANDEPS );
817 queue_push( &(_jobQueue), ident);
820 // set requirements for a running system
821 setSystemRequirements();
823 // set locks for the solver
827 bool ret = solving();
829 MIL << "SATResolver::resolveQueue() done. Ret:" << ret << endl;
833 /** \todo duplicate code to be joined with \ref solving. */
834 void SATResolver::doUpdate()
836 MIL << "SATResolver::doUpdate()" << endl;
839 solverInit(PoolItemList());
841 // set requirements for a running system
842 setSystemRequirements();
844 // set locks for the solver
847 _satSolver = solver_create( _satPool );
848 ::pool_set_custom_vendorcheck( _satPool, &vendorCheck );
850 queue_push( &(_jobQueue), SOLVER_VERIFY|SOLVER_SOLVABLE_ALL);
851 queue_push( &(_jobQueue), 0 );
854 queue_push( &(_jobQueue), SOLVER_UPDATE|SOLVER_SOLVABLE_ALL);
855 queue_push( &(_jobQueue), 0 );
858 queue_push( &(_jobQueue), SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_ALL);
859 queue_push( &(_jobQueue), 0 );
861 if (_distupgrade_removeunsupported) {
862 queue_push( &(_jobQueue), SOLVER_DROP_ORPHANED|SOLVER_SOLVABLE_ALL);
863 queue_push( &(_jobQueue), 0 );
865 solverSetFocus( *_satSolver, _focus );
866 solver_set_flag(_satSolver, SOLVER_FLAG_ADD_ALREADY_RECOMMENDED, !_ignorealreadyrecommended);
867 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_DOWNGRADE, _allowdowngrade);
868 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_NAMECHANGE, _allownamechange);
869 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_ARCHCHANGE, _allowarchchange);
870 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_VENDORCHANGE, _allowvendorchange);
871 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_UNINSTALL, _allowuninstall);
872 solver_set_flag(_satSolver, SOLVER_FLAG_NO_UPDATEPROVIDE, _noupdateprovide);
873 solver_set_flag(_satSolver, SOLVER_FLAG_SPLITPROVIDES, _dosplitprovides);
874 solver_set_flag(_satSolver, SOLVER_FLAG_IGNORE_RECOMMENDED, false); // resolve recommended namespaces
875 solver_set_flag(_satSolver, SOLVER_FLAG_ONLY_NAMESPACE_RECOMMENDED, _onlyRequires); //
877 sat::Pool::instance().prepare();
880 MIL << "Starting solving for update...." << endl;
882 solver_solve( _satSolver, &(_jobQueue) );
883 MIL << "....Solver end" << endl;
885 // copying solution back to zypp pool
886 //-----------------------------------------
888 /* solvables to be installed */
890 queue_init(&decisionq);
891 solver_get_decisionqueue(_satSolver, &decisionq);
892 for (int i = 0; i < decisionq.count; i++)
894 Id p = decisionq.elements[i];
898 sat::Solvable solv { p };
899 if ( ! solv || solv.isSystem() )
902 SATSolutionToPool( PoolItem(solv), ResStatus::toBeInstalled, ResStatus::SOLVER );
904 queue_free(&decisionq);
906 /* solvables to be erased */
907 for (int i = _satSolver->pool->installed->start; i < _satSolver->pool->installed->start + _satSolver->pool->installed->nsolvables; i++)
909 if (solver_get_decisionlevel(_satSolver, i) > 0)
912 PoolItem poolItem( _pool.find( sat::Solvable(i) ) );
914 // Check if this is an update
915 CheckIfUpdate info( (sat::Solvable(i)) );
916 invokeOnEach( _pool.byIdentBegin( poolItem ),
917 _pool.byIdentEnd( poolItem ),
918 resfilter::ByUninstalled(), // ByUninstalled
919 functor::functorRef<bool,PoolItem> (info) );
921 if (info.is_updated) {
922 SATSolutionToPool (poolItem, ResStatus::toBeUninstalledDueToUpgrade , ResStatus::SOLVER);
924 SATSolutionToPool (poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER);
927 ERR << "id " << i << " not found in ZYPP pool." << endl;
930 MIL << "SATResolver::doUpdate() done" << endl;
935 //----------------------------------------------------------------------------
936 //----------------------------------------------------------------------------
938 //----------------------------------------------------------------------------
939 //----------------------------------------------------------------------------
941 //----------------------------------------------------------------------------
943 //----------------------------------------------------------------------------
945 struct FindPackage : public resfilter::ResObjectFilterFunctor
947 ProblemSolutionCombi *problemSolution;
948 TransactionKind action;
949 FindPackage (ProblemSolutionCombi *p, const TransactionKind act)
950 : problemSolution (p)
955 bool operator()( PoolItem p)
957 problemSolution->addSingleAction (p, action);
963 //----------------------------------------------------------------------------
964 // Checking if this solvable/item has a buddy which reflect the real
965 // user visible description of an item
966 // e.g. The release package has a buddy to the concerning product item.
967 // This user want's the message "Product foo conflicts with product bar" and
968 // NOT "package release-foo conflicts with package release-bar"
969 // (ma: that's why we should map just packages to buddies, not vice versa)
970 //----------------------------------------------------------------------------
971 inline sat::Solvable mapBuddy( const PoolItem & item_r )
973 if ( item_r.satSolvable().isKind<Package>() )
975 sat::Solvable buddy = item_r.buddy();
979 return item_r.satSolvable();
981 inline sat::Solvable mapBuddy( sat::Solvable item_r )
982 { return mapBuddy( PoolItem( item_r ) ); }
984 PoolItem SATResolver::mapItem ( const PoolItem & item )
985 { return PoolItem( mapBuddy( item ) ); }
987 sat::Solvable SATResolver::mapSolvable ( const Id & id )
988 { return mapBuddy( sat::Solvable(id) ); }
990 std::vector<std::string> SATResolver::SATgetCompleteProblemInfoStrings ( Id problem )
992 std::vector<std::string> ret;
994 solver_findallproblemrules( _satSolver, problem, problems );
998 //filter out generic rule information if more explicit ones are available
999 for ( sat::Queue::size_type i = 0; i < problems.size(); i++ ) {
1000 SolverRuleinfo ruleClass = solver_ruleclass( _satSolver, problems[i]);
1001 if ( ruleClass != SolverRuleinfo::SOLVER_RULE_UPDATE && ruleClass != SolverRuleinfo::SOLVER_RULE_JOB ) {
1006 for ( sat::Queue::size_type i = 0; i < problems.size(); i++ ) {
1007 SolverRuleinfo ruleClass = solver_ruleclass( _satSolver, problems[i]);
1008 if ( nobad && ( ruleClass == SolverRuleinfo::SOLVER_RULE_UPDATE || ruleClass == SolverRuleinfo::SOLVER_RULE_JOB ) ) {
1014 std::string pInfo = SATproblemRuleInfoString( problems[i], detail, ignore );
1016 //we get the same string multiple times, reduce the noise
1017 if ( std::find( ret.begin(), ret.end(), pInfo ) == ret.end() )
1018 ret.push_back( pInfo );
1023 string SATResolver::SATprobleminfoString(Id problem, string &detail, Id &ignoreId)
1025 // FIXME: solver_findallproblemrules to get all rules for this problem
1026 // (the 'most relevabt' one returned by solver_findproblemrule is embedded
1027 Id probr = solver_findproblemrule(_satSolver, problem);
1028 return SATproblemRuleInfoString( probr, detail, ignoreId );
1031 std::string SATResolver::SATproblemRuleInfoString (Id probr, std::string &detail, Id &ignoreId)
1034 sat::detail::CPool *pool = _satSolver->pool;
1035 Id dep, source, target;
1036 SolverRuleinfo type = solver_ruleinfo(_satSolver, probr, &source, &target, &dep);
1040 sat::Solvable s = mapSolvable( source );
1041 sat::Solvable s2 = mapSolvable( target );
1043 // @FIXME, these strings are a duplicate copied from the libsolv library
1044 // to provide translations. Instead of having duplicate code we should
1045 // translate those strings directly in libsolv
1048 case SOLVER_RULE_DISTUPGRADE:
1049 ret = str::form (_("%s does not belong to a distupgrade repository"), s.asString().c_str());
1051 case SOLVER_RULE_INFARCH:
1052 ret = str::form (_("%s has inferior architecture"), s.asString().c_str());
1054 case SOLVER_RULE_UPDATE:
1055 ret = str::form (_("problem with installed package %s"), s.asString().c_str());
1057 case SOLVER_RULE_JOB:
1058 ret = _("conflicting requests");
1060 case SOLVER_RULE_PKG:
1061 ret = _("some dependency problem");
1063 case SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP:
1064 ret = str::form (_("nothing provides requested %s"), pool_dep2str(pool, dep));
1065 detail += _("Have you enabled all requested repositories?");
1067 case SOLVER_RULE_JOB_UNKNOWN_PACKAGE:
1068 ret = str::form (_("package %s does not exist"), pool_dep2str(pool, dep));
1069 detail += _("Have you enabled all requested repositories?");
1071 case SOLVER_RULE_JOB_UNSUPPORTED:
1072 ret = _("unsupported request");
1074 case SOLVER_RULE_JOB_PROVIDED_BY_SYSTEM:
1075 ret = str::form (_("%s is provided by the system and cannot be erased"), pool_dep2str(pool, dep));
1077 case SOLVER_RULE_PKG_NOT_INSTALLABLE:
1078 ret = str::form (_("%s is not installable"), s.asString().c_str());
1080 case SOLVER_RULE_PKG_NOTHING_PROVIDES_DEP:
1081 ignoreId = source; // for setting weak dependencies
1082 ret = str::form (_("nothing provides %s needed by %s"), pool_dep2str(pool, dep), s.asString().c_str());
1084 case SOLVER_RULE_PKG_SAME_NAME:
1085 ret = str::form (_("cannot install both %s and %s"), s.asString().c_str(), s2.asString().c_str());
1087 case SOLVER_RULE_PKG_CONFLICTS:
1088 ret = str::form (_("%s conflicts with %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1090 case SOLVER_RULE_PKG_OBSOLETES:
1091 ret = str::form (_("%s obsoletes %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1093 case SOLVER_RULE_PKG_INSTALLED_OBSOLETES:
1094 ret = str::form (_("installed %s obsoletes %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1096 case SOLVER_RULE_PKG_SELF_CONFLICT:
1097 ret = str::form (_("solvable %s conflicts with %s provided by itself"), s.asString().c_str(), pool_dep2str(pool, dep));
1099 case SOLVER_RULE_PKG_REQUIRES: {
1100 ignoreId = source; // for setting weak dependencies
1101 Capability cap(dep);
1102 sat::WhatProvides possibleProviders(cap);
1104 // check, if a provider will be deleted
1105 typedef list<PoolItem> ProviderList;
1106 ProviderList providerlistInstalled, providerlistUninstalled;
1107 for_( iter1, possibleProviders.begin(), possibleProviders.end() ) {
1108 PoolItem provider1 = ResPool::instance().find( *iter1 );
1109 // find pair of an installed/uninstalled item with the same NVR
1111 for_( iter2, possibleProviders.begin(), possibleProviders.end() ) {
1112 PoolItem provider2 = ResPool::instance().find( *iter2 );
1113 if (compareByNVR (provider1,provider2) == 0
1114 && ( (provider1.status().isInstalled() && provider2.status().isUninstalled())
1115 || (provider2.status().isInstalled() && provider1.status().isUninstalled()) )) {
1121 if (provider1.status().isInstalled())
1122 providerlistInstalled.push_back(provider1);
1124 providerlistUninstalled.push_back(provider1);
1128 ret = str::form (_("%s requires %s, but this requirement cannot be provided"), s.asString().c_str(), pool_dep2str(pool, dep));
1129 if (providerlistInstalled.size() > 0) {
1130 detail += _("deleted providers: ");
1131 for (ProviderList::const_iterator iter = providerlistInstalled.begin(); iter != providerlistInstalled.end(); iter++) {
1132 if (iter == providerlistInstalled.begin())
1133 detail += itemToString( *iter );
1135 detail += "\n " + itemToString( mapItem(*iter) );
1138 if (providerlistUninstalled.size() > 0) {
1139 if (detail.size() > 0)
1140 detail += _("\nnot installable providers: ");
1142 detail = _("not installable providers: ");
1143 for (ProviderList::const_iterator iter = providerlistUninstalled.begin(); iter != providerlistUninstalled.end(); iter++) {
1144 if (iter == providerlistUninstalled.begin())
1145 detail += itemToString( *iter );
1147 detail += "\n " + itemToString( mapItem(*iter) );
1153 DBG << "Unknown rule type(" << type << ") going to query libsolv for rule information." << endl;
1154 ret = str::asString( ::solver_problemruleinfo2str( _satSolver, type, static_cast<Id>(s.id()), static_cast<Id>(s2.id()), dep ) );
1162 SATResolver::problems ()
1164 ResolverProblemList resolverProblems;
1165 if (_satSolver && solver_problem_count(_satSolver)) {
1166 sat::detail::CPool *pool = _satSolver->pool;
1169 Id problem, solution, element;
1170 sat::Solvable s, sd;
1172 CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1173 CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1175 MIL << "Encountered problems! Here are the solutions:\n" << endl;
1178 while ((problem = solver_next_problem(_satSolver, problem)) != 0) {
1179 MIL << "Problem " << pcnt++ << ":" << endl;
1180 MIL << "====================================" << endl;
1183 string whatString = SATprobleminfoString (problem,detail,ignoreId);
1184 MIL << whatString << endl;
1185 MIL << "------------------------------------" << endl;
1186 ResolverProblem_Ptr resolverProblem = new ResolverProblem (whatString, detail, SATgetCompleteProblemInfoStrings( problem ));
1189 while ((solution = solver_next_solution(_satSolver, problem, solution)) != 0) {
1191 ProblemSolutionCombi *problemSolution = new ProblemSolutionCombi;
1192 while ((element = solver_next_solutionelement(_satSolver, problem, solution, element, &p, &rp)) != 0) {
1193 if (p == SOLVER_SOLUTION_JOB) {
1194 /* job, rp is index into job queue */
1195 what = _jobQueue.elements[rp];
1196 switch (_jobQueue.elements[rp-1]&(SOLVER_SELECTMASK|SOLVER_JOBMASK))
1198 case SOLVER_INSTALL | SOLVER_SOLVABLE: {
1199 s = mapSolvable (what);
1200 PoolItem poolItem = _pool.find (s);
1202 if (pool->installed && s.get()->repo == pool->installed) {
1203 problemSolution->addSingleAction (poolItem, REMOVE);
1204 string description = str::form (_("remove lock to allow removal of %s"), s.asString().c_str() );
1205 MIL << description << endl;
1206 problemSolution->addDescription (description);
1208 problemSolution->addSingleAction (poolItem, KEEP);
1209 string description = str::form (_("do not install %s"), s.asString().c_str());
1210 MIL << description << endl;
1211 problemSolution->addDescription (description);
1214 ERR << "SOLVER_INSTALL_SOLVABLE: No item found for " << s.asString() << endl;
1218 case SOLVER_ERASE | SOLVER_SOLVABLE: {
1219 s = mapSolvable (what);
1220 PoolItem poolItem = _pool.find (s);
1222 if (pool->installed && s.get()->repo == pool->installed) {
1223 problemSolution->addSingleAction (poolItem, KEEP);
1224 string description = str::form (_("keep %s"), s.asString().c_str());
1225 MIL << description << endl;
1226 problemSolution->addDescription (description);
1228 problemSolution->addSingleAction (poolItem, UNLOCK);
1229 string description = str::form (_("remove lock to allow installation of %s"), itemToString( poolItem ).c_str());
1230 MIL << description << endl;
1231 problemSolution->addDescription (description);
1234 ERR << "SOLVER_ERASE_SOLVABLE: No item found for " << s.asString() << endl;
1238 case SOLVER_INSTALL | SOLVER_SOLVABLE_NAME:
1240 IdString ident( what );
1241 SolverQueueItemInstall_Ptr install =
1242 new SolverQueueItemInstall(_pool, ident.asString(), false );
1243 problemSolution->addSingleAction (install, REMOVE_SOLVE_QUEUE_ITEM);
1245 string description = str::form (_("do not install %s"), ident.c_str() );
1246 MIL << description << endl;
1247 problemSolution->addDescription (description);
1250 case SOLVER_ERASE | SOLVER_SOLVABLE_NAME:
1252 // As we do not know, if this request has come from resolvePool or
1253 // resolveQueue we will have to take care for both cases.
1254 IdString ident( what );
1255 FindPackage info (problemSolution, KEEP);
1256 invokeOnEach( _pool.byIdentBegin( ident ),
1257 _pool.byIdentEnd( ident ),
1258 functor::chain (resfilter::ByInstalled (), // ByInstalled
1259 resfilter::ByTransact ()), // will be deinstalled
1260 functor::functorRef<bool,PoolItem> (info) );
1262 SolverQueueItemDelete_Ptr del =
1263 new SolverQueueItemDelete(_pool, ident.asString(), false );
1264 problemSolution->addSingleAction (del, REMOVE_SOLVE_QUEUE_ITEM);
1266 string description = str::form (_("keep %s"), ident.c_str());
1267 MIL << description << endl;
1268 problemSolution->addDescription (description);
1271 case SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES:
1273 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_REQUIRE);
1274 string description = "";
1276 // Checking if this problem solution would break your system
1277 if (system_requires.find(Capability(what)) != system_requires.end()) {
1278 // Show a better warning
1279 resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1280 resolverProblem->setDescription(_("This request will break your system!"));
1281 description = _("ignore the warning of a broken system");
1282 description += string(" (requires:")+pool_dep2str(pool, what)+")";
1283 MIL << description << endl;
1284 problemSolution->addFrontDescription (description);
1286 description = str::form (_("do not ask to install a solvable providing %s"), pool_dep2str(pool, what));
1287 MIL << description << endl;
1288 problemSolution->addDescription (description);
1292 case SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES:
1294 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_CONFLICT);
1295 string description = "";
1297 // Checking if this problem solution would break your system
1298 if (system_conflicts.find(Capability(what)) != system_conflicts.end()) {
1299 // Show a better warning
1300 resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1301 resolverProblem->setDescription(_("This request will break your system!"));
1302 description = _("ignore the warning of a broken system");
1303 description += string(" (conflicts:")+pool_dep2str(pool, what)+")";
1304 MIL << description << endl;
1305 problemSolution->addFrontDescription (description);
1308 description = str::form (_("do not ask to delete all solvables providing %s"), pool_dep2str(pool, what));
1309 MIL << description << endl;
1310 problemSolution->addDescription (description);
1314 case SOLVER_UPDATE | SOLVER_SOLVABLE:
1316 s = mapSolvable (what);
1317 PoolItem poolItem = _pool.find (s);
1319 if (pool->installed && s.get()->repo == pool->installed) {
1320 problemSolution->addSingleAction (poolItem, KEEP);
1321 string description = str::form (_("do not install most recent version of %s"), s.asString().c_str());
1322 MIL << description << endl;
1323 problemSolution->addDescription (description);
1325 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE " << poolItem << " is not selected for installation" << endl;
1328 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE: No item found for " << s.asString() << endl;
1333 MIL << "- do something different" << endl;
1334 ERR << "No valid solution available" << endl;
1337 } else if (p == SOLVER_SOLUTION_INFARCH) {
1338 s = mapSolvable (rp);
1339 PoolItem poolItem = _pool.find (s);
1340 if (pool->installed && s.get()->repo == pool->installed) {
1341 problemSolution->addSingleAction (poolItem, LOCK);
1342 string description = str::form (_("keep %s despite the inferior architecture"), s.asString().c_str());
1343 MIL << description << endl;
1344 problemSolution->addDescription (description);
1346 problemSolution->addSingleAction (poolItem, INSTALL);
1347 string description = str::form (_("install %s despite the inferior architecture"), s.asString().c_str());
1348 MIL << description << endl;
1349 problemSolution->addDescription (description);
1351 } else if (p == SOLVER_SOLUTION_DISTUPGRADE) {
1352 s = mapSolvable (rp);
1353 PoolItem poolItem = _pool.find (s);
1354 if (pool->installed && s.get()->repo == pool->installed) {
1355 problemSolution->addSingleAction (poolItem, LOCK);
1356 string description = str::form (_("keep obsolete %s"), s.asString().c_str());
1357 MIL << description << endl;
1358 problemSolution->addDescription (description);
1360 problemSolution->addSingleAction (poolItem, INSTALL);
1361 string description = str::form (_("install %s from excluded repository"), s.asString().c_str());
1362 MIL << description << endl;
1363 problemSolution->addDescription (description);
1365 } else if ( p == SOLVER_SOLUTION_BLACK ) {
1366 // Allow to install a blacklisted package (PTF, retracted,...).
1367 // For not-installed items only
1368 s = mapSolvable (rp);
1369 PoolItem poolItem = _pool.find (s);
1371 problemSolution->addSingleAction (poolItem, INSTALL);
1373 if ( s.isRetracted() ) {
1374 // translator: %1% is a package name
1375 description = str::Format(_("install %1% although it has been retracted")) % s.asString();
1376 } else if ( s.isPtf() ) {
1377 // translator: %1% is a package name
1378 description = str::Format(_("allow to install the PTF %1%")) % s.asString();
1380 // translator: %1% is a package name
1381 description = str::Format(_("install %1% although it is blacklisted")) % s.asString();
1383 MIL << description << endl;
1384 problemSolution->addDescription( description );
1385 } else if ( p > 0 ) {
1386 /* policy, replace p with rp */
1387 s = mapSolvable (p);
1388 PoolItem itemFrom = _pool.find (s);
1393 sd = mapSolvable (rp);
1394 PoolItem itemTo = _pool.find (sd);
1395 if (itemFrom && itemTo) {
1396 problemSolution->addSingleAction (itemTo, INSTALL);
1397 int illegal = policy_is_illegal(_satSolver, s.get(), sd.get(), 0);
1399 if ((illegal & POLICY_ILLEGAL_DOWNGRADE) != 0)
1401 string description = str::form (_("downgrade of %s to %s"), s.asString().c_str(), sd.asString().c_str());
1402 MIL << description << endl;
1403 problemSolution->addDescription (description);
1406 if ((illegal & POLICY_ILLEGAL_ARCHCHANGE) != 0)
1408 string description = str::form (_("architecture change of %s to %s"), s.asString().c_str(), sd.asString().c_str());
1409 MIL << description << endl;
1410 problemSolution->addDescription (description);
1413 if ((illegal & POLICY_ILLEGAL_VENDORCHANGE) != 0)
1415 IdString s_vendor( s.vendor() );
1416 IdString sd_vendor( sd.vendor() );
1417 string description = str::form (_("install %s (with vendor change)\n %s --> %s") ,
1418 sd.asString().c_str(),
1419 ( s_vendor ? s_vendor.c_str() : " (no vendor) " ),
1420 ( sd_vendor ? sd_vendor.c_str() : " (no vendor) " ) );
1421 MIL << description << endl;
1422 problemSolution->addDescription (description);
1426 string description = str::form (_("replacement of %s with %s"), s.asString().c_str(), sd.asString().c_str());
1427 MIL << description << endl;
1428 problemSolution->addDescription (description);
1431 ERR << s.asString() << " or " << sd.asString() << " not found" << endl;
1437 string description = str::form (_("deinstallation of %s"), s.asString().c_str());
1438 MIL << description << endl;
1439 problemSolution->addDescription (description);
1440 problemSolution->addSingleAction (itemFrom, REMOVE);
1446 INT << "Unknown solution " << p << endl;
1450 resolverProblem->addSolution (problemSolution,
1451 problemSolution->actionCount() > 1 ? true : false); // Solutions with more than 1 action will be shown first.
1452 MIL << "------------------------------------" << endl;
1456 // There is a possibility to ignore this error by setting weak dependencies
1457 PoolItem item = _pool.find (sat::Solvable(ignoreId));
1458 ProblemSolutionIgnore *problemSolution = new ProblemSolutionIgnore(item);
1459 resolverProblem->addSolution (problemSolution,
1460 false); // Solutions will be shown at the end
1461 MIL << "ignore some dependencies of " << item << endl;
1462 MIL << "------------------------------------" << endl;
1466 resolverProblems.push_back (resolverProblem);
1469 return resolverProblems;
1472 void SATResolver::applySolutions( const ProblemSolutionList & solutions )
1473 { Resolver( _pool ).applySolutions( solutions ); }
1475 void SATResolver::setLocks()
1480 for (PoolItemList::const_iterator iter = _items_to_lock.begin(); iter != _items_to_lock.end(); ++iter) {
1481 sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
1482 if (iter->status().isInstalled()) {
1484 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
1485 queue_push( &(_jobQueue), ident );
1488 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE | MAYBE_CLEANDEPS );
1489 queue_push( &(_jobQueue), ident );
1492 MIL << "Locked " << icnt << " installed items and " << acnt << " NOT installed items." << endl;
1494 ///////////////////////////////////////////////////////////////////
1495 // Weak locks: Ignore if an item with this name is already installed.
1496 // If it's not installed try to keep it this way using a weak delete
1497 ///////////////////////////////////////////////////////////////////
1498 std::set<IdString> unifiedByName;
1499 for (PoolItemList::const_iterator iter = _items_to_keep.begin(); iter != _items_to_keep.end(); ++iter) {
1500 IdString ident( (*iter)->satSolvable().ident() );
1501 if ( unifiedByName.insert( ident ).second )
1503 if ( ! ui::Selectable::get( *iter )->hasInstalledObj() )
1505 MIL << "Keep NOT installed name " << ident << " (" << *iter << ")" << endl;
1506 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_NAME | SOLVER_WEAK | MAYBE_CLEANDEPS );
1507 queue_push( &(_jobQueue), ident.id() );
1513 void SATResolver::setSystemRequirements()
1515 CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1516 CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1518 for (CapabilitySet::const_iterator iter = system_requires.begin(); iter != system_requires.end(); ++iter) {
1519 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES );
1520 queue_push( &(_jobQueue), iter->id() );
1521 MIL << "SYSTEM Requires " << *iter << endl;
1524 for (CapabilitySet::const_iterator iter = system_conflicts.begin(); iter != system_conflicts.end(); ++iter) {
1525 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES | MAYBE_CLEANDEPS );
1526 queue_push( &(_jobQueue), iter->id() );
1527 MIL << "SYSTEM Conflicts " << *iter << endl;
1530 // Lock the architecture of the running systems rpm
1531 // package on distupgrade.
1532 if ( _distupgrade && ZConfig::instance().systemRoot() == "/" )
1534 ResPool pool( ResPool::instance() );
1535 IdString rpm( "rpm" );
1536 for_( it, pool.byIdentBegin(rpm), pool.byIdentEnd(rpm) )
1538 if ( (*it)->isSystem() )
1540 Capability archrule( (*it)->arch(), rpm.c_str(), Capability::PARSED );
1541 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_NAME | SOLVER_ESSENTIAL );
1542 queue_push( &(_jobQueue), archrule.id() );
1549 sat::StringQueue SATResolver::autoInstalled() const
1551 sat::StringQueue ret;
1553 ::solver_get_userinstalled( _satSolver, ret, GET_USERINSTALLED_NAMES|GET_USERINSTALLED_INVERTED );
1557 sat::StringQueue SATResolver::userInstalled() const
1559 sat::StringQueue ret;
1561 ::solver_get_userinstalled( _satSolver, ret, GET_USERINSTALLED_NAMES );
1566 ///////////////////////////////////////////////////////////////////
1567 };// namespace detail
1568 /////////////////////////////////////////////////////////////////////
1569 /////////////////////////////////////////////////////////////////////
1570 };// namespace solver
1571 ///////////////////////////////////////////////////////////////////////
1572 ///////////////////////////////////////////////////////////////////////
1574 /////////////////////////////////////////////////////////////////////////