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/AutoDispose.h"
41 #include "zypp/sat/WhatProvides.h"
42 #include "zypp/sat/WhatObsoletes.h"
43 #include "zypp/sat/detail/PoolImpl.h"
45 #include "zypp/solver/detail/Resolver.h"
46 #include "zypp/solver/detail/SATResolver.h"
48 #include "zypp/solver/detail/ProblemSolutionCombi.h"
49 #include "zypp/solver/detail/ProblemSolutionIgnore.h"
50 #include "zypp/solver/detail/SolverQueueItemInstall.h"
51 #include "zypp/solver/detail/SolverQueueItemDelete.h"
52 #include "zypp/solver/detail/SystemCheck.h"
53 #include "zypp/solver/detail/SolutionAction.h"
54 #include "zypp/solver/detail/SolverQueueItem.h"
56 #define XDEBUG(x) do { if (base::logger::isExcessive()) XXX << x << std::endl;} while (0)
58 #undef ZYPP_BASE_LOGGER_LOGGROUP
59 #define ZYPP_BASE_LOGGER_LOGGROUP "zypp::solver"
61 /////////////////////////////////////////////////////////////////////////
63 { ///////////////////////////////////////////////////////////////////////
64 ///////////////////////////////////////////////////////////////////////
66 { /////////////////////////////////////////////////////////////////////
67 /////////////////////////////////////////////////////////////////////
69 { ///////////////////////////////////////////////////////////////////
71 ///////////////////////////////////////////////////////////////////////
74 inline void solverSetFocus( sat::detail::CSolver & satSolver_r, const ResolverFocus & focus_r )
78 case ResolverFocus::Default: // fallthrough to Job
79 case ResolverFocus::Job:
80 solver_set_flag( &satSolver_r, SOLVER_FLAG_FOCUS_INSTALLED, 0 );
81 solver_set_flag( &satSolver_r, SOLVER_FLAG_FOCUS_BEST, 0 );
83 case ResolverFocus::Installed:
84 solver_set_flag( &satSolver_r, SOLVER_FLAG_FOCUS_INSTALLED, 1 );
85 solver_set_flag( &satSolver_r, SOLVER_FLAG_FOCUS_BEST, 0 );
87 case ResolverFocus::Update:
88 solver_set_flag( &satSolver_r, SOLVER_FLAG_FOCUS_INSTALLED, 0 );
89 solver_set_flag( &satSolver_r, SOLVER_FLAG_FOCUS_BEST, 1 );
94 /** Helper collecting pseudo installed items from the pool.
95 * \todo: pseudoItems are cachable as long as pool content does not change
97 inline sat::Queue collectPseudoInstalled( const ResPool & pool_r )
100 for ( const PoolItem & pi : pool_r )
101 if ( traits::isPseudoInstalled( pi.kind() ) ) ret.push( pi.id() );
105 /** Copy back new \ref WeakValue to \ref PoolItem after solving.
106 * On the fly collect orphaned items (cached by the solver for the UI)
108 inline void solverCopyBackWeak( sat::detail::CSolver & satSolver_r, PoolItemList & orphanedItems_r )
110 // NOTE: assert all items weak stati are reset (resetWeak was called)
112 sat::Queue recommendations;
113 sat::Queue suggestions;
114 ::solver_get_recommendations( &satSolver_r, recommendations, suggestions, 0 );
115 for ( sat::Queue::size_type i = 0; i < recommendations.size(); ++i )
116 PoolItem(sat::Solvable(i)).status().setRecommended( true );
117 for ( sat::Queue::size_type i = 0; i < suggestions.size(); ++i )
118 PoolItem(sat::Solvable(i)).status().setSuggested( true );
121 orphanedItems_r.clear(); // cached on the fly
123 ::solver_get_orphaned( &satSolver_r, orphaned );
124 for ( sat::Queue::size_type i = 0; i < orphaned.size(); ++i )
126 PoolItem pi { sat::Solvable(i) };
127 pi.status().setOrphaned( true );
128 orphanedItems_r.push_back( pi );
133 ::solver_get_unneeded( &satSolver_r, unneeded, 1 );
134 for ( sat::Queue::size_type i = 0; i < unneeded.size(); ++i )
135 PoolItem(sat::Solvable(i)).status().setUnneeded( true );
139 /** Copy back new \ref ValidateValue to \ref PoolItem after solving. */
140 inline void solverCopyBackValidate( sat::detail::CSolver & satSolver_r, const ResPool & pool_r )
142 sat::Queue pseudoItems { collectPseudoInstalled( pool_r ) };
143 if ( ! pseudoItems.empty() )
145 sat::Queue pseudoFlags;
146 ::solver_trivial_installable( &satSolver_r, pseudoItems, pseudoFlags );
148 for ( sat::Queue::size_type i = 0; i < pseudoItems.size(); ++i )
150 PoolItem pi { sat::Solvable(pseudoItems[i]) };
151 switch ( pseudoFlags[i] )
153 case 0: pi.status().setBroken(); break;
154 case 1: pi.status().setSatisfied(); break;
155 case -1: pi.status().setNonRelevant(); break;
156 default: pi.status().setUndetermined(); break;
163 ///////////////////////////////////////////////////////////////////////
168 IMPL_PTR_TYPE(SATResolver);
170 #define MAYBE_CLEANDEPS (cleandepsOnRemove()?SOLVER_CLEANDEPS:0)
172 //---------------------------------------------------------------------------
173 // Callbacks for SAT policies
174 //---------------------------------------------------------------------------
176 int vendorCheck( sat::detail::CPool *pool, Solvable *solvable1, Solvable *solvable2 )
178 return VendorAttr::instance().equivalent( IdString(solvable1->vendor),
179 IdString(solvable2->vendor) ) ? 0 : 1;
182 /** ResPool helper to compute the initial status of Patches etc.
183 * An empty solver run (no jobs) just to compute the initial status
184 * of pseudo installed items (patches).
186 void establish( sat::Queue & pseudoItems_r, sat::Queue & pseudoFlags_r )
188 pseudoItems_r = collectPseudoInstalled( ResPool::instance() );
189 if ( ! pseudoItems_r.empty() )
191 MIL << "Establish..." << endl;
192 sat::detail::CPool * cPool { sat::Pool::instance().get() };
193 ::pool_set_custom_vendorcheck( cPool, &vendorCheck );
196 // Add rules for parallel installable resolvables with different versions
197 for ( const sat::Solvable & solv : sat::Pool::instance().multiversion() )
199 jobQueue.push( SOLVER_NOOBSOLETES | SOLVER_SOLVABLE );
200 jobQueue.push( solv.id() );
203 AutoDispose<sat::detail::CSolver*> cSolver { ::solver_create( cPool ), ::solver_free };
204 sat::Pool::instance().prepare();
205 if ( ::solver_solve( cSolver, jobQueue ) != 0 )
206 INT << "How can establish fail?" << endl;
208 ::solver_trivial_installable( cSolver, pseudoItems_r, pseudoFlags_r );
210 for ( sat::Queue::size_type i = 0; i < pseudoItems_r.size(); ++i )
212 PoolItem pi { sat::Solvable(pseudoItems_r[i]) };
213 switch ( pseudoFlags_r[i] )
215 case 0: pi.status().setBroken(); break;
216 case 1: pi.status().setSatisfied(); break;
217 case -1: pi.status().setNonRelevant(); break;
218 default: pi.status().setUndetermined(); break;
221 MIL << "Establish DONE" << endl;
224 MIL << "Establish not needed." << endl;
227 inline std::string itemToString( const PoolItem & item )
230 return std::string();
232 sat::Solvable slv( item.satSolvable() );
233 std::string ret( slv.asString() ); // n-v-r.a
234 if ( ! slv.isSystem() )
237 ret += slv.repository().alias();
243 //---------------------------------------------------------------------------
246 SATResolver::dumpOn( std::ostream & os ) const
248 os << "<resolver>" << endl;
250 #define OUTS(X) os << " " << #X << "\t= " << solver_get_flag(_satSolver, SOLVER_FLAG_##X) << endl
251 OUTS( ALLOW_DOWNGRADE );
252 OUTS( ALLOW_ARCHCHANGE );
253 OUTS( ALLOW_VENDORCHANGE );
254 OUTS( ALLOW_NAMECHANGE );
255 OUTS( ALLOW_UNINSTALL );
256 OUTS( NO_UPDATEPROVIDE );
257 OUTS( SPLITPROVIDES );
258 OUTS( IGNORE_RECOMMENDED );
259 OUTS( ADD_ALREADY_RECOMMENDED );
260 OUTS( NO_INFARCHCHECK );
261 OUTS( KEEP_EXPLICIT_OBSOLETES );
262 OUTS( BEST_OBEY_POLICY );
263 OUTS( NO_AUTOTARGET );
264 OUTS( DUP_ALLOW_DOWNGRADE );
265 OUTS( DUP_ALLOW_ARCHCHANGE );
266 OUTS( DUP_ALLOW_VENDORCHANGE );
267 OUTS( DUP_ALLOW_NAMECHANGE );
268 OUTS( KEEP_ORPHANS );
269 OUTS( BREAK_ORPHANS );
270 OUTS( YUM_OBSOLETES );
272 os << " focus = " << _focus << endl;
273 os << " distupgrade = " << _distupgrade << endl;
274 os << " distupgrade_removeunsupported = " << _distupgrade_removeunsupported << endl;
275 os << " solveSrcPackages = " << _solveSrcPackages << endl;
276 os << " cleandepsOnRemove = " << _cleandepsOnRemove << endl;
277 os << " fixsystem = " << _fixsystem << endl;
281 return os << "<resolver/>" << endl;
284 //---------------------------------------------------------------------------
286 // NOTE: flag defaults must be in sync with ZVARDEFAULT in Resolver.cc
287 SATResolver::SATResolver (const ResPool & pool, sat::detail::CPool *satPool)
291 , _focus ( ZConfig::instance().solver_focus() )
293 , _allowdowngrade ( false )
294 , _allownamechange ( true ) // bsc#1071466
295 , _allowarchchange ( false )
296 , _allowvendorchange ( ZConfig::instance().solver_allowVendorChange() )
297 , _allowuninstall ( false )
298 , _updatesystem(false)
299 , _noupdateprovide ( false )
300 , _dosplitprovides ( true )
301 , _onlyRequires (ZConfig::instance().solver_onlyRequires())
302 , _ignorealreadyrecommended(true)
303 , _distupgrade(false)
304 , _distupgrade_removeunsupported(false)
305 , _dup_allowdowngrade ( ZConfig::instance().solver_dupAllowDowngrade() )
306 , _dup_allownamechange ( ZConfig::instance().solver_dupAllowNameChange() )
307 , _dup_allowarchchange ( ZConfig::instance().solver_dupAllowArchChange() )
308 , _dup_allowvendorchange ( ZConfig::instance().solver_dupAllowVendorChange() )
309 , _solveSrcPackages(false)
310 , _cleandepsOnRemove(ZConfig::instance().solver_cleandepsOnRemove())
315 SATResolver::~SATResolver()
320 //---------------------------------------------------------------------------
323 SATResolver::pool (void) const
328 //---------------------------------------------------------------------------
330 // copy marked item from solution back to pool
331 // if data != NULL, set as APPL_LOW (from establishPool())
334 SATSolutionToPool (PoolItem item, const ResStatus & status, const ResStatus::TransactByValue causer)
337 item.status().resetTransact (causer);
338 item.status().resetWeak ();
342 // installation/deletion
343 if (status.isToBeInstalled()) {
344 r = item.status().setToBeInstalled (causer);
345 XDEBUG("SATSolutionToPool install returns " << item << ", " << r);
347 else if (status.isToBeUninstalledDueToUpgrade()) {
348 r = item.status().setToBeUninstalledDueToUpgrade (causer);
349 XDEBUG("SATSolutionToPool upgrade returns " << item << ", " << r);
351 else if (status.isToBeUninstalled()) {
352 r = item.status().setToBeUninstalled (causer);
353 XDEBUG("SATSolutionToPool remove returns " << item << ", " << r);
359 //----------------------------------------------------------------------------
360 //----------------------------------------------------------------------------
362 //----------------------------------------------------------------------------
363 //----------------------------------------------------------------------------
364 /////////////////////////////////////////////////////////////////////////
365 /// \class SATCollectTransact
366 /// \brief Commit helper functor distributing PoolItem by status into lists
368 /// On the fly it clears all PoolItem bySolver/ByApplLow status.
369 /// The lists are cleared in the Ctor, populated by \ref operator().
370 /////////////////////////////////////////////////////////////////////////
371 struct SATCollectTransact : public resfilter::PoolItemFilterFunctor
373 SATCollectTransact( PoolItemList & items_to_install_r,
374 PoolItemList & items_to_remove_r,
375 PoolItemList & items_to_lock_r,
376 PoolItemList & items_to_keep_r,
377 bool solveSrcPackages_r )
378 : _items_to_install( items_to_install_r )
379 , _items_to_remove( items_to_remove_r )
380 , _items_to_lock( items_to_lock_r )
381 , _items_to_keep( items_to_keep_r )
382 , _solveSrcPackages( solveSrcPackages_r )
384 _items_to_install.clear();
385 _items_to_remove.clear();
386 _items_to_lock.clear();
387 _items_to_keep.clear();
390 bool operator()( const PoolItem & item_r )
393 ResStatus & itemStatus( item_r.status() );
394 bool by_solver = ( itemStatus.isBySolver() || itemStatus.isByApplLow() );
398 // Clear former solver/establish resultd
399 itemStatus.resetTransact( ResStatus::APPL_LOW );
400 return true; // -> back out here, don't re-queue former results
403 if ( !_solveSrcPackages && item_r.isKind<SrcPackage>() )
405 // Later we may continue on a per source package base.
406 return true; // dont process this source package.
409 switch ( itemStatus.getTransactValue() )
411 case ResStatus::TRANSACT:
412 itemStatus.isUninstalled() ? _items_to_install.push_back( item_r )
413 : _items_to_remove.push_back( item_r ); break;
414 case ResStatus::LOCKED: _items_to_lock.push_back( item_r ); break;
415 case ResStatus::KEEP_STATE: _items_to_keep.push_back( item_r ); break;
421 PoolItemList & _items_to_install;
422 PoolItemList & _items_to_remove;
423 PoolItemList & _items_to_lock;
424 PoolItemList & _items_to_keep;
425 bool _solveSrcPackages;
428 /////////////////////////////////////////////////////////////////////////
431 //----------------------------------------------------------------------------
432 //----------------------------------------------------------------------------
434 //----------------------------------------------------------------------------
435 //----------------------------------------------------------------------------
438 class CheckIfUpdate : public resfilter::PoolItemFilterFunctor
442 sat::Solvable _installed;
444 CheckIfUpdate( const sat::Solvable & installed_r )
445 : is_updated( false )
446 , _installed( installed_r )
449 // check this item will be updated
451 bool operator()( const PoolItem & item )
453 if ( item.status().isToBeInstalled() )
455 if ( ! item.multiversionInstall() || sameNVRA( _installed, item ) )
467 SATResolver::solving(const CapabilitySet & requires_caps,
468 const CapabilitySet & conflict_caps)
470 _satSolver = solver_create( _satPool );
471 ::pool_set_custom_vendorcheck( _satPool, &vendorCheck );
473 queue_push( &(_jobQueue), SOLVER_VERIFY|SOLVER_SOLVABLE_ALL);
474 queue_push( &(_jobQueue), 0 );
477 queue_push( &(_jobQueue), SOLVER_UPDATE|SOLVER_SOLVABLE_ALL);
478 queue_push( &(_jobQueue), 0 );
481 queue_push( &(_jobQueue), SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_ALL);
482 queue_push( &(_jobQueue), 0 );
484 if (_distupgrade_removeunsupported) {
485 queue_push( &(_jobQueue), SOLVER_DROP_ORPHANED|SOLVER_SOLVABLE_ALL);
486 queue_push( &(_jobQueue), 0 );
488 solverSetFocus( *_satSolver, _focus );
489 solver_set_flag(_satSolver, SOLVER_FLAG_ADD_ALREADY_RECOMMENDED, !_ignorealreadyrecommended);
490 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_DOWNGRADE, _allowdowngrade);
491 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_NAMECHANGE, _allownamechange);
492 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_ARCHCHANGE, _allowarchchange);
493 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_VENDORCHANGE, _allowvendorchange);
494 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_UNINSTALL, _allowuninstall);
495 solver_set_flag(_satSolver, SOLVER_FLAG_NO_UPDATEPROVIDE, _noupdateprovide);
496 solver_set_flag(_satSolver, SOLVER_FLAG_SPLITPROVIDES, _dosplitprovides);
497 solver_set_flag(_satSolver, SOLVER_FLAG_IGNORE_RECOMMENDED, false); // resolve recommended namespaces
498 solver_set_flag(_satSolver, SOLVER_FLAG_ONLY_NAMESPACE_RECOMMENDED, _onlyRequires); //
499 solver_set_flag(_satSolver, SOLVER_FLAG_DUP_ALLOW_DOWNGRADE, _dup_allowdowngrade );
500 solver_set_flag(_satSolver, SOLVER_FLAG_DUP_ALLOW_NAMECHANGE, _dup_allownamechange );
501 solver_set_flag(_satSolver, SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE, _dup_allowarchchange );
502 solver_set_flag(_satSolver, SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE, _dup_allowvendorchange );
504 sat::Pool::instance().prepare();
507 MIL << "Starting solving...." << endl;
509 if ( solver_solve( _satSolver, &(_jobQueue) ) == 0 )
511 // bsc#1155819: Weakremovers of future product not evaluated.
512 // Do a 2nd run to cleanup weakremovers() of to be installed
513 // Produtcs unless removeunsupported is active (cleans up all).
516 if ( _distupgrade_removeunsupported )
517 MIL << "Droplist processing not needed. RemoveUnsupported is On." << endl;
518 else if ( ! ZConfig::instance().solverUpgradeRemoveDroppedPackages() )
519 MIL << "Droplist processing is disabled in ZConfig." << endl;
522 bool resolve = false;
523 MIL << "Checking droplists ..." << endl;
524 // get Solvables to be installed...
525 sat::SolvableQueue decisionq;
526 solver_get_decisionqueue( _satSolver, decisionq );
527 for ( sat::detail::IdType id : decisionq )
531 sat::Solvable slv { (sat::detail::SolvableIdType)id };
532 // get product buddies (they carry the weakremover)...
533 static const Capability productCap { "product()" };
534 if ( slv && slv.provides().matches( productCap ) )
536 CapabilitySet droplist { slv.valuesOfNamespace( "weakremover" ) };
537 MIL << "Droplist for " << slv << ": size " << droplist.size() << endl;
538 if ( !droplist.empty() )
540 for ( const auto & cap : droplist )
542 queue_push( &_jobQueue, SOLVER_DROP_ORPHANED | SOLVER_SOLVABLE_NAME );
543 queue_push( &_jobQueue, cap.id() );
545 // PIN product - a safety net to prevent cleanup from changing the decision for this product
546 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
547 queue_push( &(_jobQueue), id );
553 solver_solve( _satSolver, &(_jobQueue) );
557 MIL << "....Solver end" << endl;
559 // copying solution back to zypp pool
560 //-----------------------------------------
561 _result_items_to_install.clear();
562 _result_items_to_remove.clear();
564 /* solvables to be installed */
566 queue_init(&decisionq);
567 solver_get_decisionqueue(_satSolver, &decisionq);
568 for ( int i = 0; i < decisionq.count; ++i )
570 Id p = decisionq.elements[i];
574 sat::Solvable slv { (sat::detail::SolvableIdType)p };
575 if ( ! slv || slv.isSystem() )
578 PoolItem poolItem( slv );
579 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
580 _result_items_to_install.push_back( poolItem );
582 queue_free(&decisionq);
584 /* solvables to be erased */
585 Repository systemRepo( sat::Pool::instance().findSystemRepo() ); // don't create if it does not exist
586 if ( systemRepo && ! systemRepo.solvablesEmpty() )
588 bool mustCheckObsoletes = false;
589 for_( it, systemRepo.solvablesBegin(), systemRepo.solvablesEnd() )
591 if (solver_get_decisionlevel(_satSolver, it->id()) > 0)
594 // Check if this is an update
595 CheckIfUpdate info( *it );
596 PoolItem poolItem( *it );
597 invokeOnEach( _pool.byIdentBegin( poolItem ),
598 _pool.byIdentEnd( poolItem ),
599 resfilter::ByUninstalled(), // ByUninstalled
600 functor::functorRef<bool,PoolItem> (info) );
602 if (info.is_updated) {
603 SATSolutionToPool( poolItem, ResStatus::toBeUninstalledDueToUpgrade, ResStatus::SOLVER );
605 SATSolutionToPool( poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER );
606 if ( ! mustCheckObsoletes )
607 mustCheckObsoletes = true; // lazy check for UninstalledDueToObsolete
609 _result_items_to_remove.push_back (poolItem);
611 if ( mustCheckObsoletes )
613 sat::WhatObsoletes obsoleted( _result_items_to_install.begin(), _result_items_to_install.end() );
614 for_( it, obsoleted.poolItemBegin(), obsoleted.poolItemEnd() )
616 ResStatus & status( it->status() );
617 // WhatObsoletes contains installed items only!
618 if ( status.transacts() && ! status.isToBeUninstalledDueToUpgrade() )
619 status.setToBeUninstalledDueToObsolete();
624 // copy back computed status values to pool
625 // (on the fly cache orphaned items for the UI)
626 solverCopyBackWeak( *_satSolver, _problem_items );
627 solverCopyBackValidate( *_satSolver, _pool );
629 // Solvables which were selected due requirements which have been made by the user will
630 // be selected by APPL_LOW. We can't use any higher level, because this setting must
631 // not serve as a request for the next solver run. APPL_LOW is reset before solving.
632 for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
633 sat::WhatProvides rpmProviders(*iter);
634 for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
635 PoolItem poolItem(*iter2);
636 if (poolItem.status().isToBeInstalled()) {
637 MIL << "User requirement " << *iter << " sets " << poolItem << endl;
638 poolItem.status().setTransactByValue (ResStatus::APPL_LOW);
642 for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
643 sat::WhatProvides rpmProviders(*iter);
644 for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
645 PoolItem poolItem(*iter2);
646 if (poolItem.status().isToBeUninstalled()) {
647 MIL << "User conflict " << *iter << " sets " << poolItem << endl;
648 poolItem.status().setTransactByValue (ResStatus::APPL_LOW);
653 if (solver_problem_count(_satSolver) > 0 )
655 ERR << "Solverrun finished with an ERROR" << endl;
664 SATResolver::solverInit(const PoolItemList & weakItems)
667 MIL << "SATResolver::solverInit()" << endl;
671 queue_init( &_jobQueue );
673 // clear and rebuild: _items_to_install, _items_to_remove, _items_to_lock, _items_to_keep
675 SATCollectTransact collector( _items_to_install, _items_to_remove, _items_to_lock, _items_to_keep, solveSrcPackages() );
676 invokeOnEach ( _pool.begin(), _pool.end(), functor::functorRef<bool,PoolItem>( collector ) );
679 for (PoolItemList::const_iterator iter = weakItems.begin(); iter != weakItems.end(); iter++) {
680 Id id = (*iter)->satSolvable().id();
682 ERR << "Weaken: " << *iter << " not found" << endl;
684 MIL << "Weaken dependencies of " << *iter << endl;
685 queue_push( &(_jobQueue), SOLVER_WEAKENDEPS | SOLVER_SOLVABLE );
686 queue_push( &(_jobQueue), id );
689 // Ad rules for retracted patches and packages
691 queue_push( &(_jobQueue), SOLVER_BLACKLIST|SOLVER_SOLVABLE_PROVIDES );
692 queue_push( &(_jobQueue), sat::Solvable::retractedToken.id() );
693 queue_push( &(_jobQueue), SOLVER_BLACKLIST|SOLVER_SOLVABLE_PROVIDES );
694 queue_push( &(_jobQueue), sat::Solvable::ptfToken.id() );
697 // Ad rules for changed requestedLocales
699 const auto & trackedLocaleIds( myPool().trackedLocaleIds() );
701 // just track changed locakes
702 for ( const auto & locale : trackedLocaleIds.added() )
704 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES );
705 queue_push( &(_jobQueue), Capability( ResolverNamespace::language, IdString(locale) ).id() );
708 for ( const auto & locale : trackedLocaleIds.removed() )
710 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES | SOLVER_CLEANDEPS ); // needs uncond. SOLVER_CLEANDEPS!
711 queue_push( &(_jobQueue), Capability( ResolverNamespace::language, IdString(locale) ).id() );
715 // Add rules for parallel installable resolvables with different versions
716 for ( const sat::Solvable & solv : myPool().multiversionList() )
718 queue_push( &(_jobQueue), SOLVER_NOOBSOLETES | SOLVER_SOLVABLE );
719 queue_push( &(_jobQueue), solv.id() );
722 ::pool_add_userinstalled_jobs(_satPool, sat::Pool::instance().autoInstalled(), &(_jobQueue), GET_USERINSTALLED_NAMES|GET_USERINSTALLED_INVERTED);
726 SATResolver::solverEnd()
731 solver_free(_satSolver);
733 queue_free( &(_jobQueue) );
739 SATResolver::resolvePool(const CapabilitySet & requires_caps,
740 const CapabilitySet & conflict_caps,
741 const PoolItemList & weakItems,
742 const std::set<Repository> & upgradeRepos)
744 MIL << "SATResolver::resolvePool()" << endl;
747 solverInit(weakItems);
749 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
750 Id id = (*iter)->satSolvable().id();
752 ERR << "Install: " << *iter << " not found" << endl;
754 MIL << "Install " << *iter << endl;
755 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
756 queue_push( &(_jobQueue), id );
760 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
761 Id id = (*iter)->satSolvable().id();
763 ERR << "Delete: " << *iter << " not found" << endl;
765 MIL << "Delete " << *iter << endl;
766 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE | MAYBE_CLEANDEPS );
767 queue_push( &(_jobQueue), id);
771 for_( iter, upgradeRepos.begin(), upgradeRepos.end() )
773 queue_push( &(_jobQueue), SOLVER_DISTUPGRADE | SOLVER_SOLVABLE_REPO );
774 queue_push( &(_jobQueue), iter->get()->repoid );
775 MIL << "Upgrade repo " << *iter << endl;
778 for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
779 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES );
780 queue_push( &(_jobQueue), iter->id() );
781 MIL << "Requires " << *iter << endl;
784 for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
785 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES | MAYBE_CLEANDEPS );
786 queue_push( &(_jobQueue), iter->id() );
787 MIL << "Conflicts " << *iter << endl;
790 // set requirements for a running system
791 setSystemRequirements();
793 // set locks for the solver
797 bool ret = solving(requires_caps, conflict_caps);
799 (ret?MIL:WAR) << "SATResolver::resolvePool() done. Ret:" << ret << endl;
805 SATResolver::resolveQueue(const SolverQueueItemList &requestQueue,
806 const PoolItemList & weakItems)
808 MIL << "SATResolver::resolvQueue()" << endl;
811 solverInit(weakItems);
813 // generate solver queue
814 for (SolverQueueItemList::const_iterator iter = requestQueue.begin(); iter != requestQueue.end(); iter++) {
815 (*iter)->addRule(_jobQueue);
818 // Add addition item status to the resolve-queue cause these can be set by problem resolutions
819 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
820 Id id = (*iter)->satSolvable().id();
822 ERR << "Install: " << *iter << " not found" << endl;
824 MIL << "Install " << *iter << endl;
825 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
826 queue_push( &(_jobQueue), id );
829 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
830 sat::detail::IdType ident( (*iter)->satSolvable().ident().id() );
831 MIL << "Delete " << *iter << ident << endl;
832 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_NAME | MAYBE_CLEANDEPS );
833 queue_push( &(_jobQueue), ident);
836 // set requirements for a running system
837 setSystemRequirements();
839 // set locks for the solver
843 bool ret = solving();
845 MIL << "SATResolver::resolveQueue() done. Ret:" << ret << endl;
849 /** \todo duplicate code to be joined with \ref solving. */
850 void SATResolver::doUpdate()
852 MIL << "SATResolver::doUpdate()" << endl;
855 solverInit(PoolItemList());
857 // set requirements for a running system
858 setSystemRequirements();
860 // set locks for the solver
863 _satSolver = solver_create( _satPool );
864 ::pool_set_custom_vendorcheck( _satPool, &vendorCheck );
866 queue_push( &(_jobQueue), SOLVER_VERIFY|SOLVER_SOLVABLE_ALL);
867 queue_push( &(_jobQueue), 0 );
870 queue_push( &(_jobQueue), SOLVER_UPDATE|SOLVER_SOLVABLE_ALL);
871 queue_push( &(_jobQueue), 0 );
874 queue_push( &(_jobQueue), SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_ALL);
875 queue_push( &(_jobQueue), 0 );
877 if (_distupgrade_removeunsupported) {
878 queue_push( &(_jobQueue), SOLVER_DROP_ORPHANED|SOLVER_SOLVABLE_ALL);
879 queue_push( &(_jobQueue), 0 );
881 solverSetFocus( *_satSolver, _focus );
882 solver_set_flag(_satSolver, SOLVER_FLAG_ADD_ALREADY_RECOMMENDED, !_ignorealreadyrecommended);
883 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_DOWNGRADE, _allowdowngrade);
884 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_NAMECHANGE, _allownamechange);
885 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_ARCHCHANGE, _allowarchchange);
886 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_VENDORCHANGE, _allowvendorchange);
887 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_UNINSTALL, _allowuninstall);
888 solver_set_flag(_satSolver, SOLVER_FLAG_NO_UPDATEPROVIDE, _noupdateprovide);
889 solver_set_flag(_satSolver, SOLVER_FLAG_SPLITPROVIDES, _dosplitprovides);
890 solver_set_flag(_satSolver, SOLVER_FLAG_IGNORE_RECOMMENDED, false); // resolve recommended namespaces
891 solver_set_flag(_satSolver, SOLVER_FLAG_ONLY_NAMESPACE_RECOMMENDED, _onlyRequires); //
893 sat::Pool::instance().prepare();
896 MIL << "Starting solving for update...." << endl;
898 solver_solve( _satSolver, &(_jobQueue) );
899 MIL << "....Solver end" << endl;
901 // copying solution back to zypp pool
902 //-----------------------------------------
904 /* solvables to be installed */
906 queue_init(&decisionq);
907 solver_get_decisionqueue(_satSolver, &decisionq);
908 for (int i = 0; i < decisionq.count; i++)
910 Id p = decisionq.elements[i];
914 sat::Solvable solv { (sat::detail::SolvableIdType)p };
915 if ( ! solv || solv.isSystem() )
918 SATSolutionToPool( PoolItem(solv), ResStatus::toBeInstalled, ResStatus::SOLVER );
920 queue_free(&decisionq);
922 /* solvables to be erased */
923 for (int i = _satSolver->pool->installed->start; i < _satSolver->pool->installed->start + _satSolver->pool->installed->nsolvables; i++)
925 if (solver_get_decisionlevel(_satSolver, i) > 0)
928 PoolItem poolItem( _pool.find( sat::Solvable(i) ) );
930 // Check if this is an update
931 CheckIfUpdate info( (sat::Solvable(i)) );
932 invokeOnEach( _pool.byIdentBegin( poolItem ),
933 _pool.byIdentEnd( poolItem ),
934 resfilter::ByUninstalled(), // ByUninstalled
935 functor::functorRef<bool,PoolItem> (info) );
937 if (info.is_updated) {
938 SATSolutionToPool (poolItem, ResStatus::toBeUninstalledDueToUpgrade , ResStatus::SOLVER);
940 SATSolutionToPool (poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER);
943 ERR << "id " << i << " not found in ZYPP pool." << endl;
947 // copy back computed status values to pool
948 // (on the fly cache orphaned items for the UI)
949 solverCopyBackWeak( *_satSolver, _problem_items );
950 solverCopyBackValidate( *_satSolver, _pool );
952 MIL << "SATResolver::doUpdate() done" << endl;
957 //----------------------------------------------------------------------------
958 //----------------------------------------------------------------------------
960 //----------------------------------------------------------------------------
961 //----------------------------------------------------------------------------
963 //----------------------------------------------------------------------------
965 //----------------------------------------------------------------------------
967 struct FindPackage : public resfilter::ResObjectFilterFunctor
969 ProblemSolutionCombi *problemSolution;
970 TransactionKind action;
971 FindPackage (ProblemSolutionCombi *p, const TransactionKind act)
972 : problemSolution (p)
977 bool operator()( PoolItem p)
979 problemSolution->addSingleAction (p, action);
985 //----------------------------------------------------------------------------
986 // Checking if this solvable/item has a buddy which reflect the real
987 // user visible description of an item
988 // e.g. The release package has a buddy to the concerning product item.
989 // This user want's the message "Product foo conflicts with product bar" and
990 // NOT "package release-foo conflicts with package release-bar"
991 // (ma: that's why we should map just packages to buddies, not vice versa)
992 //----------------------------------------------------------------------------
993 inline sat::Solvable mapBuddy( const PoolItem & item_r )
995 if ( item_r.satSolvable().isKind<Package>() )
997 sat::Solvable buddy = item_r.buddy();
1001 return item_r.satSolvable();
1003 inline sat::Solvable mapBuddy( sat::Solvable item_r )
1004 { return mapBuddy( PoolItem( item_r ) ); }
1006 PoolItem SATResolver::mapItem ( const PoolItem & item )
1007 { return PoolItem( mapBuddy( item ) ); }
1009 sat::Solvable SATResolver::mapSolvable ( const Id & id )
1010 { return mapBuddy( sat::Solvable(id) ); }
1012 std::vector<std::string> SATResolver::SATgetCompleteProblemInfoStrings ( Id problem )
1014 std::vector<std::string> ret;
1015 sat::Queue problems;
1016 solver_findallproblemrules( _satSolver, problem, problems );
1020 //filter out generic rule information if more explicit ones are available
1021 for ( sat::Queue::size_type i = 0; i < problems.size(); i++ ) {
1022 SolverRuleinfo ruleClass = solver_ruleclass( _satSolver, problems[i]);
1023 if ( ruleClass != SolverRuleinfo::SOLVER_RULE_UPDATE && ruleClass != SolverRuleinfo::SOLVER_RULE_JOB ) {
1028 for ( sat::Queue::size_type i = 0; i < problems.size(); i++ ) {
1029 SolverRuleinfo ruleClass = solver_ruleclass( _satSolver, problems[i]);
1030 if ( nobad && ( ruleClass == SolverRuleinfo::SOLVER_RULE_UPDATE || ruleClass == SolverRuleinfo::SOLVER_RULE_JOB ) ) {
1036 std::string pInfo = SATproblemRuleInfoString( problems[i], detail, ignore );
1038 //we get the same string multiple times, reduce the noise
1039 if ( std::find( ret.begin(), ret.end(), pInfo ) == ret.end() )
1040 ret.push_back( pInfo );
1045 string SATResolver::SATprobleminfoString(Id problem, string &detail, Id &ignoreId)
1047 // FIXME: solver_findallproblemrules to get all rules for this problem
1048 // (the 'most relevabt' one returned by solver_findproblemrule is embedded
1049 Id probr = solver_findproblemrule(_satSolver, problem);
1050 return SATproblemRuleInfoString( probr, detail, ignoreId );
1053 std::string SATResolver::SATproblemRuleInfoString (Id probr, std::string &detail, Id &ignoreId)
1056 sat::detail::CPool *pool = _satSolver->pool;
1057 Id dep, source, target;
1058 SolverRuleinfo type = solver_ruleinfo(_satSolver, probr, &source, &target, &dep);
1062 sat::Solvable s = mapSolvable( source );
1063 sat::Solvable s2 = mapSolvable( target );
1065 // @FIXME, these strings are a duplicate copied from the libsolv library
1066 // to provide translations. Instead of having duplicate code we should
1067 // translate those strings directly in libsolv
1070 case SOLVER_RULE_DISTUPGRADE:
1071 ret = str::form (_("%s does not belong to a distupgrade repository"), s.asString().c_str());
1073 case SOLVER_RULE_INFARCH:
1074 ret = str::form (_("%s has inferior architecture"), s.asString().c_str());
1076 case SOLVER_RULE_UPDATE:
1077 ret = str::form (_("problem with installed package %s"), s.asString().c_str());
1079 case SOLVER_RULE_JOB:
1080 ret = _("conflicting requests");
1082 case SOLVER_RULE_PKG:
1083 ret = _("some dependency problem");
1085 case SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP:
1086 ret = str::form (_("nothing provides requested %s"), pool_dep2str(pool, dep));
1087 detail += _("Have you enabled all requested repositories?");
1089 case SOLVER_RULE_JOB_UNKNOWN_PACKAGE:
1090 ret = str::form (_("package %s does not exist"), pool_dep2str(pool, dep));
1091 detail += _("Have you enabled all requested repositories?");
1093 case SOLVER_RULE_JOB_UNSUPPORTED:
1094 ret = _("unsupported request");
1096 case SOLVER_RULE_JOB_PROVIDED_BY_SYSTEM:
1097 ret = str::form (_("%s is provided by the system and cannot be erased"), pool_dep2str(pool, dep));
1099 case SOLVER_RULE_PKG_NOT_INSTALLABLE:
1100 ret = str::form (_("%s is not installable"), s.asString().c_str());
1102 case SOLVER_RULE_PKG_NOTHING_PROVIDES_DEP:
1103 ignoreId = source; // for setting weak dependencies
1104 ret = str::form (_("nothing provides %s needed by %s"), pool_dep2str(pool, dep), s.asString().c_str());
1106 case SOLVER_RULE_PKG_SAME_NAME:
1107 ret = str::form (_("cannot install both %s and %s"), s.asString().c_str(), s2.asString().c_str());
1109 case SOLVER_RULE_PKG_CONFLICTS:
1110 ret = str::form (_("%s conflicts with %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1112 case SOLVER_RULE_PKG_OBSOLETES:
1113 ret = str::form (_("%s obsoletes %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1115 case SOLVER_RULE_PKG_INSTALLED_OBSOLETES:
1116 ret = str::form (_("installed %s obsoletes %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1118 case SOLVER_RULE_PKG_SELF_CONFLICT:
1119 ret = str::form (_("solvable %s conflicts with %s provided by itself"), s.asString().c_str(), pool_dep2str(pool, dep));
1121 case SOLVER_RULE_PKG_REQUIRES: {
1122 ignoreId = source; // for setting weak dependencies
1123 Capability cap(dep);
1124 sat::WhatProvides possibleProviders(cap);
1126 // check, if a provider will be deleted
1127 typedef list<PoolItem> ProviderList;
1128 ProviderList providerlistInstalled, providerlistUninstalled;
1129 for_( iter1, possibleProviders.begin(), possibleProviders.end() ) {
1130 PoolItem provider1 = ResPool::instance().find( *iter1 );
1131 // find pair of an installed/uninstalled item with the same NVR
1133 for_( iter2, possibleProviders.begin(), possibleProviders.end() ) {
1134 PoolItem provider2 = ResPool::instance().find( *iter2 );
1135 if (compareByNVR (provider1,provider2) == 0
1136 && ( (provider1.status().isInstalled() && provider2.status().isUninstalled())
1137 || (provider2.status().isInstalled() && provider1.status().isUninstalled()) )) {
1143 if (provider1.status().isInstalled())
1144 providerlistInstalled.push_back(provider1);
1146 providerlistUninstalled.push_back(provider1);
1150 ret = str::form (_("%s requires %s, but this requirement cannot be provided"), s.asString().c_str(), pool_dep2str(pool, dep));
1151 if (providerlistInstalled.size() > 0) {
1152 detail += _("deleted providers: ");
1153 for (ProviderList::const_iterator iter = providerlistInstalled.begin(); iter != providerlistInstalled.end(); iter++) {
1154 if (iter == providerlistInstalled.begin())
1155 detail += itemToString( *iter );
1157 detail += "\n " + itemToString( mapItem(*iter) );
1160 if (providerlistUninstalled.size() > 0) {
1161 if (detail.size() > 0)
1162 detail += _("\nnot installable providers: ");
1164 detail = _("not installable providers: ");
1165 for (ProviderList::const_iterator iter = providerlistUninstalled.begin(); iter != providerlistUninstalled.end(); iter++) {
1166 if (iter == providerlistUninstalled.begin())
1167 detail += itemToString( *iter );
1169 detail += "\n " + itemToString( mapItem(*iter) );
1175 DBG << "Unknown rule type(" << type << ") going to query libsolv for rule information." << endl;
1176 ret = str::asString( ::solver_problemruleinfo2str( _satSolver, type, static_cast<Id>(s.id()), static_cast<Id>(s2.id()), dep ) );
1184 SATResolver::problems ()
1186 ResolverProblemList resolverProblems;
1187 if (_satSolver && solver_problem_count(_satSolver)) {
1188 sat::detail::CPool *pool = _satSolver->pool;
1191 Id problem, solution, element;
1192 sat::Solvable s, sd;
1194 CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1195 CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1197 MIL << "Encountered problems! Here are the solutions:\n" << endl;
1200 while ((problem = solver_next_problem(_satSolver, problem)) != 0) {
1201 MIL << "Problem " << pcnt++ << ":" << endl;
1202 MIL << "====================================" << endl;
1205 string whatString = SATprobleminfoString (problem,detail,ignoreId);
1206 MIL << whatString << endl;
1207 MIL << "------------------------------------" << endl;
1208 ResolverProblem_Ptr resolverProblem = new ResolverProblem (whatString, detail, SATgetCompleteProblemInfoStrings( problem ));
1211 while ((solution = solver_next_solution(_satSolver, problem, solution)) != 0) {
1213 ProblemSolutionCombi *problemSolution = new ProblemSolutionCombi;
1214 while ((element = solver_next_solutionelement(_satSolver, problem, solution, element, &p, &rp)) != 0) {
1215 if (p == SOLVER_SOLUTION_JOB) {
1216 /* job, rp is index into job queue */
1217 what = _jobQueue.elements[rp];
1218 switch (_jobQueue.elements[rp-1]&(SOLVER_SELECTMASK|SOLVER_JOBMASK))
1220 case SOLVER_INSTALL | SOLVER_SOLVABLE: {
1221 s = mapSolvable (what);
1222 PoolItem poolItem = _pool.find (s);
1224 if (pool->installed && s.get()->repo == pool->installed) {
1225 problemSolution->addSingleAction (poolItem, REMOVE);
1226 string description = str::form (_("remove lock to allow removal of %s"), s.asString().c_str() );
1227 MIL << description << endl;
1228 problemSolution->addDescription (description);
1230 problemSolution->addSingleAction (poolItem, KEEP);
1231 string description = str::form (_("do not install %s"), s.asString().c_str());
1232 MIL << description << endl;
1233 problemSolution->addDescription (description);
1236 ERR << "SOLVER_INSTALL_SOLVABLE: No item found for " << s.asString() << endl;
1240 case SOLVER_ERASE | SOLVER_SOLVABLE: {
1241 s = mapSolvable (what);
1242 PoolItem poolItem = _pool.find (s);
1244 if (pool->installed && s.get()->repo == pool->installed) {
1245 problemSolution->addSingleAction (poolItem, KEEP);
1246 string description = str::form (_("keep %s"), s.asString().c_str());
1247 MIL << description << endl;
1248 problemSolution->addDescription (description);
1250 problemSolution->addSingleAction (poolItem, UNLOCK);
1251 string description = str::form (_("remove lock to allow installation of %s"), itemToString( poolItem ).c_str());
1252 MIL << description << endl;
1253 problemSolution->addDescription (description);
1256 ERR << "SOLVER_ERASE_SOLVABLE: No item found for " << s.asString() << endl;
1260 case SOLVER_INSTALL | SOLVER_SOLVABLE_NAME:
1262 IdString ident( what );
1263 SolverQueueItemInstall_Ptr install =
1264 new SolverQueueItemInstall(_pool, ident.asString(), false );
1265 problemSolution->addSingleAction (install, REMOVE_SOLVE_QUEUE_ITEM);
1267 string description = str::form (_("do not install %s"), ident.c_str() );
1268 MIL << description << endl;
1269 problemSolution->addDescription (description);
1272 case SOLVER_ERASE | SOLVER_SOLVABLE_NAME:
1274 // As we do not know, if this request has come from resolvePool or
1275 // resolveQueue we will have to take care for both cases.
1276 IdString ident( what );
1277 FindPackage info (problemSolution, KEEP);
1278 invokeOnEach( _pool.byIdentBegin( ident ),
1279 _pool.byIdentEnd( ident ),
1280 functor::chain (resfilter::ByInstalled (), // ByInstalled
1281 resfilter::ByTransact ()), // will be deinstalled
1282 functor::functorRef<bool,PoolItem> (info) );
1284 SolverQueueItemDelete_Ptr del =
1285 new SolverQueueItemDelete(_pool, ident.asString(), false );
1286 problemSolution->addSingleAction (del, REMOVE_SOLVE_QUEUE_ITEM);
1288 string description = str::form (_("keep %s"), ident.c_str());
1289 MIL << description << endl;
1290 problemSolution->addDescription (description);
1293 case SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES:
1295 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_REQUIRE);
1296 string description = "";
1298 // Checking if this problem solution would break your system
1299 if (system_requires.find(Capability(what)) != system_requires.end()) {
1300 // Show a better warning
1301 resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1302 resolverProblem->setDescription(_("This request will break your system!"));
1303 description = _("ignore the warning of a broken system");
1304 description += string(" (requires:")+pool_dep2str(pool, what)+")";
1305 MIL << description << endl;
1306 problemSolution->addFrontDescription (description);
1308 description = str::form (_("do not ask to install a solvable providing %s"), pool_dep2str(pool, what));
1309 MIL << description << endl;
1310 problemSolution->addDescription (description);
1314 case SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES:
1316 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_CONFLICT);
1317 string description = "";
1319 // Checking if this problem solution would break your system
1320 if (system_conflicts.find(Capability(what)) != system_conflicts.end()) {
1321 // Show a better warning
1322 resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1323 resolverProblem->setDescription(_("This request will break your system!"));
1324 description = _("ignore the warning of a broken system");
1325 description += string(" (conflicts:")+pool_dep2str(pool, what)+")";
1326 MIL << description << endl;
1327 problemSolution->addFrontDescription (description);
1330 description = str::form (_("do not ask to delete all solvables providing %s"), pool_dep2str(pool, what));
1331 MIL << description << endl;
1332 problemSolution->addDescription (description);
1336 case SOLVER_UPDATE | SOLVER_SOLVABLE:
1338 s = mapSolvable (what);
1339 PoolItem poolItem = _pool.find (s);
1341 if (pool->installed && s.get()->repo == pool->installed) {
1342 problemSolution->addSingleAction (poolItem, KEEP);
1343 string description = str::form (_("do not install most recent version of %s"), s.asString().c_str());
1344 MIL << description << endl;
1345 problemSolution->addDescription (description);
1347 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE " << poolItem << " is not selected for installation" << endl;
1350 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE: No item found for " << s.asString() << endl;
1355 MIL << "- do something different" << endl;
1356 ERR << "No valid solution available" << endl;
1359 } else if (p == SOLVER_SOLUTION_INFARCH) {
1360 s = mapSolvable (rp);
1361 PoolItem poolItem = _pool.find (s);
1362 if (pool->installed && s.get()->repo == pool->installed) {
1363 problemSolution->addSingleAction (poolItem, LOCK);
1364 string description = str::form (_("keep %s despite the inferior architecture"), s.asString().c_str());
1365 MIL << description << endl;
1366 problemSolution->addDescription (description);
1368 problemSolution->addSingleAction (poolItem, INSTALL);
1369 string description = str::form (_("install %s despite the inferior architecture"), s.asString().c_str());
1370 MIL << description << endl;
1371 problemSolution->addDescription (description);
1373 } else if (p == SOLVER_SOLUTION_DISTUPGRADE) {
1374 s = mapSolvable (rp);
1375 PoolItem poolItem = _pool.find (s);
1376 if (pool->installed && s.get()->repo == pool->installed) {
1377 problemSolution->addSingleAction (poolItem, LOCK);
1378 string description = str::form (_("keep obsolete %s"), s.asString().c_str());
1379 MIL << description << endl;
1380 problemSolution->addDescription (description);
1382 problemSolution->addSingleAction (poolItem, INSTALL);
1383 string description = str::form (_("install %s from excluded repository"), s.asString().c_str());
1384 MIL << description << endl;
1385 problemSolution->addDescription (description);
1387 } else if ( p == SOLVER_SOLUTION_BLACK ) {
1388 // Allow to install a blacklisted package (PTF, retracted,...).
1389 // For not-installed items only
1390 s = mapSolvable (rp);
1391 PoolItem poolItem = _pool.find (s);
1393 problemSolution->addSingleAction (poolItem, INSTALL);
1395 if ( s.isRetracted() ) {
1396 // translator: %1% is a package name
1397 description = str::Format(_("install %1% although it has been retracted")) % s.asString();
1398 } else if ( s.isPtf() ) {
1399 // translator: %1% is a package name
1400 description = str::Format(_("allow to install the PTF %1%")) % s.asString();
1402 // translator: %1% is a package name
1403 description = str::Format(_("install %1% although it is blacklisted")) % s.asString();
1405 MIL << description << endl;
1406 problemSolution->addDescription( description );
1407 } else if ( p > 0 ) {
1408 /* policy, replace p with rp */
1409 s = mapSolvable (p);
1410 PoolItem itemFrom = _pool.find (s);
1415 sd = mapSolvable (rp);
1416 PoolItem itemTo = _pool.find (sd);
1417 if (itemFrom && itemTo) {
1418 problemSolution->addSingleAction (itemTo, INSTALL);
1419 int illegal = policy_is_illegal(_satSolver, s.get(), sd.get(), 0);
1421 if ((illegal & POLICY_ILLEGAL_DOWNGRADE) != 0)
1423 string description = str::form (_("downgrade of %s to %s"), s.asString().c_str(), sd.asString().c_str());
1424 MIL << description << endl;
1425 problemSolution->addDescription (description);
1428 if ((illegal & POLICY_ILLEGAL_ARCHCHANGE) != 0)
1430 string description = str::form (_("architecture change of %s to %s"), s.asString().c_str(), sd.asString().c_str());
1431 MIL << description << endl;
1432 problemSolution->addDescription (description);
1435 if ((illegal & POLICY_ILLEGAL_VENDORCHANGE) != 0)
1437 IdString s_vendor( s.vendor() );
1438 IdString sd_vendor( sd.vendor() );
1439 string description = str::form (_("install %s (with vendor change)\n %s --> %s") ,
1440 sd.asString().c_str(),
1441 ( s_vendor ? s_vendor.c_str() : " (no vendor) " ),
1442 ( sd_vendor ? sd_vendor.c_str() : " (no vendor) " ) );
1443 MIL << description << endl;
1444 problemSolution->addDescription (description);
1448 string description = str::form (_("replacement of %s with %s"), s.asString().c_str(), sd.asString().c_str());
1449 MIL << description << endl;
1450 problemSolution->addDescription (description);
1453 ERR << s.asString() << " or " << sd.asString() << " not found" << endl;
1459 string description = str::form (_("deinstallation of %s"), s.asString().c_str());
1460 MIL << description << endl;
1461 problemSolution->addDescription (description);
1462 problemSolution->addSingleAction (itemFrom, REMOVE);
1468 INT << "Unknown solution " << p << endl;
1472 resolverProblem->addSolution (problemSolution,
1473 problemSolution->actionCount() > 1 ? true : false); // Solutions with more than 1 action will be shown first.
1474 MIL << "------------------------------------" << endl;
1478 // There is a possibility to ignore this error by setting weak dependencies
1479 PoolItem item = _pool.find (sat::Solvable(ignoreId));
1480 ProblemSolutionIgnore *problemSolution = new ProblemSolutionIgnore(item);
1481 resolverProblem->addSolution (problemSolution,
1482 false); // Solutions will be shown at the end
1483 MIL << "ignore some dependencies of " << item << endl;
1484 MIL << "------------------------------------" << endl;
1488 resolverProblems.push_back (resolverProblem);
1491 return resolverProblems;
1494 void SATResolver::applySolutions( const ProblemSolutionList & solutions )
1495 { Resolver( _pool ).applySolutions( solutions ); }
1497 void SATResolver::setLocks()
1502 for (PoolItemList::const_iterator iter = _items_to_lock.begin(); iter != _items_to_lock.end(); ++iter) {
1503 sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
1504 if (iter->status().isInstalled()) {
1506 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
1507 queue_push( &(_jobQueue), ident );
1510 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE | MAYBE_CLEANDEPS );
1511 queue_push( &(_jobQueue), ident );
1514 MIL << "Locked " << icnt << " installed items and " << acnt << " NOT installed items." << endl;
1516 ///////////////////////////////////////////////////////////////////
1517 // Weak locks: Ignore if an item with this name is already installed.
1518 // If it's not installed try to keep it this way using a weak delete
1519 ///////////////////////////////////////////////////////////////////
1520 std::set<IdString> unifiedByName;
1521 for (PoolItemList::const_iterator iter = _items_to_keep.begin(); iter != _items_to_keep.end(); ++iter) {
1522 IdString ident( (*iter)->satSolvable().ident() );
1523 if ( unifiedByName.insert( ident ).second )
1525 if ( ! ui::Selectable::get( *iter )->hasInstalledObj() )
1527 MIL << "Keep NOT installed name " << ident << " (" << *iter << ")" << endl;
1528 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_NAME | SOLVER_WEAK | MAYBE_CLEANDEPS );
1529 queue_push( &(_jobQueue), ident.id() );
1535 void SATResolver::setSystemRequirements()
1537 CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1538 CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1540 for (CapabilitySet::const_iterator iter = system_requires.begin(); iter != system_requires.end(); ++iter) {
1541 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES );
1542 queue_push( &(_jobQueue), iter->id() );
1543 MIL << "SYSTEM Requires " << *iter << endl;
1546 for (CapabilitySet::const_iterator iter = system_conflicts.begin(); iter != system_conflicts.end(); ++iter) {
1547 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES | MAYBE_CLEANDEPS );
1548 queue_push( &(_jobQueue), iter->id() );
1549 MIL << "SYSTEM Conflicts " << *iter << endl;
1552 // Lock the architecture of the running systems rpm
1553 // package on distupgrade.
1554 if ( _distupgrade && ZConfig::instance().systemRoot() == "/" )
1556 ResPool pool( ResPool::instance() );
1557 IdString rpm( "rpm" );
1558 for_( it, pool.byIdentBegin(rpm), pool.byIdentEnd(rpm) )
1560 if ( (*it)->isSystem() )
1562 Capability archrule( (*it)->arch(), rpm.c_str(), Capability::PARSED );
1563 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_NAME | SOLVER_ESSENTIAL );
1564 queue_push( &(_jobQueue), archrule.id() );
1571 sat::StringQueue SATResolver::autoInstalled() const
1573 sat::StringQueue ret;
1575 ::solver_get_userinstalled( _satSolver, ret, GET_USERINSTALLED_NAMES|GET_USERINSTALLED_INVERTED );
1579 sat::StringQueue SATResolver::userInstalled() const
1581 sat::StringQueue ret;
1583 ::solver_get_userinstalled( _satSolver, ret, GET_USERINSTALLED_NAMES );
1588 ///////////////////////////////////////////////////////////////////
1589 };// namespace detail
1590 /////////////////////////////////////////////////////////////////////
1591 /////////////////////////////////////////////////////////////////////
1592 };// namespace solver
1593 ///////////////////////////////////////////////////////////////////////
1594 ///////////////////////////////////////////////////////////////////////
1596 /////////////////////////////////////////////////////////////////////////