1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
4 * Copyright (C) 2000-2002 Ximian, Inc.
5 * Copyright (C) 2005 SUSE Linux Products GmbH
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License,
9 * version 2, as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 #include <solv/repo_solv.h>
24 #include <solv/poolarch.h>
26 #include <solv/poolvendor.h>
27 #include <solv/policy.h>
28 #include <solv/bitmap.h>
29 #include <solv/queue.h>
32 #include "zypp/solver/detail/Helper.h"
33 #include "zypp/base/String.h"
34 #include "zypp/Product.h"
35 #include "zypp/Capability.h"
36 #include "zypp/ResStatus.h"
37 #include "zypp/VendorAttr.h"
38 #include "zypp/base/LogTools.h"
39 #include "zypp/base/String.h"
40 #include "zypp/base/Gettext.h"
41 #include "zypp/base/Algorithm.h"
42 #include "zypp/ResPool.h"
43 #include "zypp/ResFilters.h"
44 #include "zypp/ZConfig.h"
45 #include "zypp/sat/Pool.h"
46 #include "zypp/sat/WhatProvides.h"
47 #include "zypp/sat/WhatObsoletes.h"
48 #include "zypp/solver/detail/SATResolver.h"
49 #include "zypp/solver/detail/ProblemSolutionCombi.h"
50 #include "zypp/solver/detail/ProblemSolutionIgnore.h"
51 #include "zypp/solver/detail/SolverQueueItemInstall.h"
52 #include "zypp/solver/detail/SolverQueueItemDelete.h"
53 #include "zypp/solver/detail/SystemCheck.h"
54 #include "zypp/sat/Transaction.h"
55 #include "zypp/sat/Queue.h"
57 /////////////////////////////////////////////////////////////////////////
59 { ///////////////////////////////////////////////////////////////////////
61 /////////////////////////////////////////////////////////////////////////
64 inline bool HACKENV( const char * var_r, bool default_r )
67 const char * val = ::getenv( var_r );
70 ret = str::strToBool( val, default_r );
71 if ( ret != default_r )
72 INT << "HACKENV " << var_r << " = " << ret << endl;
77 /////////////////////////////////////////////////////////////////////////
79 ///////////////////////////////////////////////////////////////////////
81 { /////////////////////////////////////////////////////////////////////
82 /////////////////////////////////////////////////////////////////////
84 { ///////////////////////////////////////////////////////////////////
88 IMPL_PTR_TYPE(SATResolver);
90 #define MAYBE_CLEANDEPS (cleandepsOnRemove()?SOLVER_CLEANDEPS:0)
92 //---------------------------------------------------------------------------
93 // Callbacks for SAT policies
94 //---------------------------------------------------------------------------
96 int vendorCheck( sat::detail::CPool *pool, Solvable *solvable1, Solvable *solvable2 )
98 return VendorAttr::instance().equivalent( IdString(solvable1->vendor),
99 IdString(solvable2->vendor) ) ? 0 : 1;
103 inline std::string itemToString( const PoolItem & item )
106 return std::string();
108 sat::Solvable slv( item.satSolvable() );
109 std::string ret( slv.asString() ); // n-v-r.a
110 if ( ! slv.isSystem() )
113 ret += slv.repository().alias();
119 inline PoolItem getPoolItem( Id id_r )
121 PoolItem ret( (sat::Solvable( id_r )) );
123 INT << "id " << id_r << " not found in ZYPP pool." << endl;
127 //---------------------------------------------------------------------------
130 SATResolver::dumpOn( std::ostream & os ) const
132 os << "<resolver>" << endl;
134 #define OUTS(X) os << " " << #X << "\t= " << solver_get_flag(_satSolver, SOLVER_FLAG_##X) << endl
135 OUTS( ALLOW_DOWNGRADE );
136 OUTS( ALLOW_ARCHCHANGE );
137 OUTS( ALLOW_VENDORCHANGE );
138 OUTS( ALLOW_UNINSTALL );
139 OUTS( NO_UPDATEPROVIDE );
140 OUTS( SPLITPROVIDES );
141 OUTS( IGNORE_RECOMMENDED );
142 OUTS( ADD_ALREADY_RECOMMENDED );
143 OUTS( NO_INFARCHCHECK );
144 OUTS( ALLOW_NAMECHANGE );
145 OUTS( KEEP_EXPLICIT_OBSOLETES );
146 OUTS( BEST_OBEY_POLICY );
147 OUTS( NO_AUTOTARGET );
148 OUTS( DUP_ALLOW_DOWNGRADE );
149 OUTS( DUP_ALLOW_ARCHCHANGE );
150 OUTS( DUP_ALLOW_VENDORCHANGE );
151 OUTS( DUP_ALLOW_NAMECHANGE );
152 OUTS( KEEP_ORPHANS );
153 OUTS( BREAK_ORPHANS );
154 OUTS( FOCUS_INSTALLED );
155 OUTS( YUM_OBSOLETES );
157 os << " distupgrade = " << _distupgrade << endl;
158 os << " distupgrade_removeunsupported = " << _distupgrade_removeunsupported << endl;
159 os << " solveSrcPackages = " << _solveSrcPackages << endl;
160 os << " cleandepsOnRemove = " << _cleandepsOnRemove << endl;
161 os << " fixsystem = " << _fixsystem << endl;
165 return os << "<resolver/>" << endl;
168 //---------------------------------------------------------------------------
170 SATResolver::SATResolver (const ResPool & pool, sat::detail::CPool *satPool)
175 , _allowdowngrade(false)
176 , _allowarchchange(false)
177 , _allowvendorchange(ZConfig::instance().solver_allowVendorChange())
178 , _allowuninstall(false)
179 , _dup_allowdowngrade( true )
180 , _dup_allownamechange( true )
181 , _dup_allowarchchange( true )
182 , _dup_allowvendorchange( true )
183 , _updatesystem(false)
184 , _noupdateprovide(false)
185 , _dosplitprovides(true)
186 , _onlyRequires(ZConfig::instance().solver_onlyRequires())
187 , _ignorealreadyrecommended(true)
188 , _distupgrade(false)
189 , _distupgrade_removeunsupported(false)
190 , _solveSrcPackages(false)
191 , _cleandepsOnRemove(ZConfig::instance().solver_cleandepsOnRemove())
196 SATResolver::~SATResolver()
201 //---------------------------------------------------------------------------
204 SATResolver::pool (void) const
210 SATResolver::resetItemTransaction (PoolItem item)
213 for (PoolItemList::const_iterator iter = _items_to_remove.begin();
214 iter != _items_to_remove.end(); ++iter) {
216 _items_to_remove.remove(*iter);
222 for (PoolItemList::const_iterator iter = _items_to_install.begin();
223 iter != _items_to_install.end(); ++iter) {
225 _items_to_install.remove(*iter);
232 for (PoolItemList::const_iterator iter = _items_to_keep.begin();
233 iter != _items_to_keep.end(); ++iter) {
235 _items_to_keep.remove(*iter);
242 for (PoolItemList::const_iterator iter = _items_to_lock.begin();
243 iter != _items_to_lock.end(); ++iter) {
245 _items_to_lock.remove(*iter);
255 SATResolver::addPoolItemToInstall (PoolItem item)
257 resetItemTransaction (item);
258 _items_to_install.push_back (item);
259 _items_to_install.unique ();
264 SATResolver::addPoolItemsToInstallFromList (PoolItemList & rl)
266 for (PoolItemList::const_iterator iter = rl.begin(); iter != rl.end(); iter++) {
267 addPoolItemToInstall (*iter);
273 SATResolver::addPoolItemToRemove (PoolItem item)
275 resetItemTransaction (item);
276 _items_to_remove.push_back (item);
277 _items_to_remove.unique ();
282 SATResolver::addPoolItemsToRemoveFromList (PoolItemList & rl)
284 for (PoolItemList::const_iterator iter = rl.begin(); iter != rl.end(); iter++) {
285 addPoolItemToRemove (*iter);
290 SATResolver::addPoolItemToLock (PoolItem item)
292 resetItemTransaction (item);
293 _items_to_lock.push_back (item);
294 _items_to_lock.unique ();
298 SATResolver::addPoolItemToKeep (PoolItem item)
300 resetItemTransaction (item);
301 _items_to_keep.push_back (item);
302 _items_to_keep.unique ();
305 //---------------------------------------------------------------------------
307 // copy marked item from solution back to pool
308 // if data != NULL, set as APPL_LOW (from establishPool())
311 SATSolutionToPool (PoolItem item, const ResStatus & status, const ResStatus::TransactByValue causer)
314 item.status().resetTransact (causer);
315 item.status().resetWeak ();
319 // installation/deletion
320 if (status.isToBeInstalled()) {
321 r = item.status().setToBeInstalled (causer);
322 _XDEBUG("SATSolutionToPool install returns " << item << ", " << r);
324 else if (status.isToBeUninstalledDueToUpgrade()) {
325 r = item.status().setToBeUninstalledDueToUpgrade (causer);
326 _XDEBUG("SATSolutionToPool upgrade returns " << item << ", " << r);
328 else if (status.isToBeUninstalled()) {
329 r = item.status().setToBeUninstalled (causer);
330 _XDEBUG("SATSolutionToPool remove returns " << item << ", " << r);
336 //----------------------------------------------------------------------------
337 //----------------------------------------------------------------------------
339 //----------------------------------------------------------------------------
340 //----------------------------------------------------------------------------
342 //----------------------------------------------------------------------------
343 // Helper functions for the ZYPP-Pool
344 //----------------------------------------------------------------------------
347 //------------------------------------------------------------------------------------------------------------
348 // This function loops over the pool and grabs all items
349 // It clears all previous bySolver() states also
351 // Every toBeInstalled is passed to zypp::solver:detail::Resolver.addPoolItemToInstall()
352 // Every toBeUninstalled is passed to zypp::solver:detail::Resolver.addPoolItemToRemove()
354 // Solver results must be written back to the pool.
355 //------------------------------------------------------------------------------------------------------------
358 struct SATCollectTransact : public resfilter::PoolItemFilterFunctor
360 SATResolver & resolver;
362 SATCollectTransact (SATResolver & r)
366 bool operator()( PoolItem item ) // only transacts() items go here
368 ResStatus status = item.status();
369 bool by_solver = (status.isBySolver() || status.isByApplLow());
372 item.status().resetTransact( ResStatus::APPL_LOW );// clear any solver/establish transactions
373 return true; // back out here, dont re-queue former solver result
376 if ( item.satSolvable().isKind<SrcPackage>() && ! resolver.solveSrcPackages() )
378 // Later we may continue on a per source package base.
379 return true; // dont process this source package.
382 if (status.isToBeInstalled()) {
383 resolver.addPoolItemToInstall(item); // -> install!
385 else if (status.isToBeUninstalled()) {
386 resolver.addPoolItemToRemove(item); // -> remove !
388 else if (status.isLocked()
390 resolver.addPoolItemToLock (item);
392 else if (status.isKept()
394 resolver.addPoolItemToKeep (item);
402 //----------------------------------------------------------------------------
403 //----------------------------------------------------------------------------
405 //----------------------------------------------------------------------------
406 //----------------------------------------------------------------------------
409 class CheckIfUpdate : public resfilter::PoolItemFilterFunctor
414 sat::Solvable _installed;
416 CheckIfUpdate( sat::Solvable installed_r )
417 : is_updated( false )
418 , multiversion( installed_r.multiversionInstall() )
419 , _installed( installed_r )
422 // check this item will be updated
424 bool operator()( PoolItem item )
426 if ( item.status().isToBeInstalled() )
428 if ( ! multiversion || sameNVRA( _installed, item ) )
439 class CollectPseudoInstalled : public resfilter::PoolItemFilterFunctor
442 Queue *solvableQueue;
444 CollectPseudoInstalled( Queue *queue )
445 :solvableQueue (queue)
448 // collecting PseudoInstalled items
449 bool operator()( PoolItem item )
451 if ( traits::isPseudoInstalled( item.satSolvable().kind() ) )
452 queue_push( solvableQueue, item.satSolvable().id() );
458 SATResolver::solving(const CapabilitySet & requires_caps,
459 const CapabilitySet & conflict_caps)
461 _satSolver = solver_create( _satPool );
462 ::pool_set_custom_vendorcheck( _satPool, &vendorCheck );
464 queue_push( &(_jobQueue), SOLVER_VERIFY|SOLVER_SOLVABLE_ALL);
465 queue_push( &(_jobQueue), 0 );
468 queue_push( &(_jobQueue), SOLVER_UPDATE|SOLVER_SOLVABLE_ALL);
469 queue_push( &(_jobQueue), 0 );
472 queue_push( &(_jobQueue), SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_ALL);
473 queue_push( &(_jobQueue), 0 );
475 if (_distupgrade_removeunsupported) {
476 queue_push( &(_jobQueue), SOLVER_DROP_ORPHANED|SOLVER_SOLVABLE_ALL);
477 queue_push( &(_jobQueue), 0 );
479 solver_set_flag(_satSolver, SOLVER_FLAG_ADD_ALREADY_RECOMMENDED, !_ignorealreadyrecommended);
480 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_DOWNGRADE, _allowdowngrade);
481 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_UNINSTALL, _allowuninstall);
482 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_ARCHCHANGE, _allowarchchange);
483 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_VENDORCHANGE, _allowvendorchange);
484 solver_set_flag(_satSolver, SOLVER_FLAG_SPLITPROVIDES, _dosplitprovides);
485 solver_set_flag(_satSolver, SOLVER_FLAG_NO_UPDATEPROVIDE, _noupdateprovide);
486 solver_set_flag(_satSolver, SOLVER_FLAG_IGNORE_RECOMMENDED, _onlyRequires);
487 solver_set_flag(_satSolver, SOLVER_FLAG_DUP_ALLOW_DOWNGRADE, _dup_allowdowngrade );
488 solver_set_flag(_satSolver, SOLVER_FLAG_DUP_ALLOW_NAMECHANGE, _dup_allownamechange );
489 solver_set_flag(_satSolver, SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE, _dup_allowarchchange );
490 solver_set_flag(_satSolver, SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE, _dup_allowvendorchange );
492 #define HACKENV(X,D) solver_set_flag(_satSolver, X, env::HACKENV( #X, D ) );
493 HACKENV( SOLVER_FLAG_DUP_ALLOW_DOWNGRADE, _dup_allowdowngrade );
494 HACKENV( SOLVER_FLAG_DUP_ALLOW_NAMECHANGE, _dup_allownamechange );
495 HACKENV( SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE, _dup_allowarchchange );
496 HACKENV( SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE,_dup_allowvendorchange );
499 sat::Pool::instance().prepareForSolving();
502 MIL << "Starting solving...." << endl;
504 solver_solve( _satSolver, &(_jobQueue) );
505 MIL << "....Solver end" << endl;
507 // copying solution back to zypp pool
508 //-----------------------------------------
509 _result_items_to_install.clear();
510 _result_items_to_remove.clear();
512 /* solvables to be installed */
514 queue_init(&decisionq);
515 solver_get_decisionqueue(_satSolver, &decisionq);
516 for ( int i = 0; i < decisionq.count; ++i )
518 sat::Solvable slv( decisionq.elements[i] );
519 if ( !slv || slv.isSystem() )
522 PoolItem poolItem( slv );
523 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
524 _result_items_to_install.push_back (poolItem);
526 queue_free(&decisionq);
528 /* solvables to be erased */
529 Repository systemRepo( sat::Pool::instance().findSystemRepo() ); // don't create if it does not exist
530 if ( systemRepo && ! systemRepo.solvablesEmpty() )
532 bool mustCheckObsoletes = false;
533 for_( it, systemRepo.solvablesBegin(), systemRepo.solvablesEnd() )
535 if (solver_get_decisionlevel(_satSolver, it->id()) > 0)
538 // Check if this is an update
539 CheckIfUpdate info( *it );
540 PoolItem poolItem( *it );
541 invokeOnEach( _pool.byIdentBegin( poolItem ),
542 _pool.byIdentEnd( poolItem ),
543 resfilter::ByUninstalled(), // ByUninstalled
544 functor::functorRef<bool,PoolItem> (info) );
546 if (info.is_updated) {
547 SATSolutionToPool( poolItem, ResStatus::toBeUninstalledDueToUpgrade, ResStatus::SOLVER );
549 SATSolutionToPool( poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER );
550 if ( ! mustCheckObsoletes )
551 mustCheckObsoletes = true; // lazy check for UninstalledDueToObsolete
553 _result_items_to_remove.push_back (poolItem);
555 if ( mustCheckObsoletes )
557 sat::WhatObsoletes obsoleted( _result_items_to_install.begin(), _result_items_to_install.end() );
558 for_( it, obsoleted.poolItemBegin(), obsoleted.poolItemEnd() )
560 ResStatus & status( it->status() );
561 // WhatObsoletes contains installed items only!
562 if ( status.transacts() && ! status.isToBeUninstalledDueToUpgrade() )
563 status.setToBeUninstalledDueToObsolete();
568 Queue recommendations;
572 queue_init(&recommendations);
573 queue_init(&suggestions);
574 queue_init(&orphaned);
575 queue_init(&unneeded);
576 solver_get_recommendations(_satSolver, &recommendations, &suggestions, 0);
577 solver_get_orphaned(_satSolver, &orphaned);
578 solver_get_unneeded(_satSolver, &unneeded, 1);
579 /* solvables which are recommended */
580 for ( int i = 0; i < recommendations.count; ++i )
582 PoolItem poolItem( getPoolItem( recommendations.elements[i] ) );
583 poolItem.status().setRecommended( true );
586 /* solvables which are suggested */
587 for ( int i = 0; i < suggestions.count; ++i )
589 PoolItem poolItem( getPoolItem( suggestions.elements[i] ) );
590 poolItem.status().setSuggested( true );
593 _problem_items.clear();
594 /* solvables which are orphaned */
595 for ( int i = 0; i < orphaned.count; ++i )
597 PoolItem poolItem( getPoolItem( orphaned.elements[i] ) );
598 poolItem.status().setOrphaned( true );
599 _problem_items.push_back( poolItem );
602 /* solvables which are unneeded */
603 for ( int i = 0; i < unneeded.count; ++i )
605 PoolItem poolItem( getPoolItem( unneeded.elements[i] ) );
606 poolItem.status().setUnneeded( true );
609 queue_free(&recommendations);
610 queue_free(&suggestions);
611 queue_free(&orphaned);
612 queue_free(&unneeded);
614 /* Write validation state back to pool */
615 Queue flags, solvableQueue;
618 queue_init(&solvableQueue);
620 CollectPseudoInstalled collectPseudoInstalled(&solvableQueue);
621 invokeOnEach( _pool.begin(),
623 functor::functorRef<bool,PoolItem> (collectPseudoInstalled) );
624 solver_trivial_installable(_satSolver, &solvableQueue, &flags );
625 for (int i = 0; i < solvableQueue.count; i++) {
626 PoolItem item = _pool.find (sat::Solvable(solvableQueue.elements[i]));
627 item.status().setUndetermined();
629 if (flags.elements[i] == -1) {
630 item.status().setNonRelevant();
631 _XDEBUG("SATSolutionToPool(" << item << " ) nonRelevant !");
632 } else if (flags.elements[i] == 1) {
633 item.status().setSatisfied();
634 _XDEBUG("SATSolutionToPool(" << item << " ) satisfied !");
635 } else if (flags.elements[i] == 0) {
636 item.status().setBroken();
637 _XDEBUG("SATSolutionToPool(" << item << " ) broken !");
640 queue_free(&(solvableQueue));
644 // Solvables which were selected due requirements which have been made by the user will
645 // be selected by APPL_LOW. We can't use any higher level, because this setting must
646 // not serve as a request for the next solver run. APPL_LOW is reset before solving.
647 for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
648 sat::WhatProvides rpmProviders(*iter);
649 for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
650 PoolItem poolItem(*iter2);
651 if (poolItem.status().isToBeInstalled()) {
652 MIL << "User requirement " << *iter << " sets " << poolItem << endl;
653 poolItem.status().setTransactByValue (ResStatus::APPL_LOW);
657 for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
658 sat::WhatProvides rpmProviders(*iter);
659 for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
660 PoolItem poolItem(*iter2);
661 if (poolItem.status().isToBeUninstalled()) {
662 MIL << "User conflict " << *iter << " sets " << poolItem << endl;
663 poolItem.status().setTransactByValue (ResStatus::APPL_LOW);
668 if (solver_problem_count(_satSolver) > 0 )
670 ERR << "Solverrun finished with an ERROR" << endl;
679 SATResolver::solverInit(const PoolItemList & weakItems)
681 SATCollectTransact info (*this);
683 MIL << "SATResolver::solverInit()" << endl;
688 queue_init( &_jobQueue );
689 _items_to_install.clear();
690 _items_to_remove.clear();
691 _items_to_lock.clear();
692 _items_to_keep.clear();
694 invokeOnEach ( _pool.begin(), _pool.end(),
695 functor::functorRef<bool,PoolItem>(info) );
697 for (PoolItemList::const_iterator iter = weakItems.begin(); iter != weakItems.end(); iter++) {
698 Id id = (*iter)->satSolvable().id();
700 ERR << "Weaken: " << *iter << " not found" << endl;
702 MIL << "Weaken dependencies of " << *iter << endl;
703 queue_push( &(_jobQueue), SOLVER_WEAKENDEPS | SOLVER_SOLVABLE );
704 queue_push( &(_jobQueue), id );
707 // Add rules for parallel installable resolvables with different versions
708 for_( it, sat::Pool::instance().multiversionBegin(), sat::Pool::instance().multiversionEnd() )
710 queue_push( &(_jobQueue), SOLVER_NOOBSOLETES | SOLVER_SOLVABLE_NAME );
711 queue_push( &(_jobQueue), it->id() );
714 ::pool_add_userinstalled_jobs(_satPool, sat::Pool::instance().autoInstalled(), &(_jobQueue), GET_USERINSTALLED_NAMES|GET_USERINSTALLED_INVERTED);
718 if ( ZConfig::instance().solverUpgradeRemoveDroppedPackages() )
720 MIL << "Checking droplists ..." << endl;
721 // Dropped packages: look for 'weakremover()' provides
722 // in dup candidates of installed products.
723 ResPoolProxy proxy( ResPool::instance().proxy() );
724 for_( it, proxy.byKindBegin<Product>(), proxy.byKindEnd<Product>() )
726 if ( (*it)->onSystem() ) // (to install) or (not to delete)
728 Product::constPtr prodCand( (*it)->candidateAsKind<Product>() );
730 continue; // product no longer available
732 CapabilitySet droplist( prodCand->droplist() );
733 dumpRangeLine( MIL << "Droplist for " << (*it)->candidateObj() << ": " << droplist.size() << " ", droplist.begin(), droplist.end() ) << endl;
734 for_( cap, droplist.begin(), droplist.end() )
736 queue_push( &_jobQueue, SOLVER_DROP_ORPHANED | SOLVER_SOLVABLE_NAME );
737 queue_push( &_jobQueue, cap->id() );
744 MIL << "Droplist processing is disabled." << endl;
750 SATResolver::solverEnd()
755 solver_free(_satSolver);
757 queue_free( &(_jobQueue) );
763 SATResolver::resolvePool(const CapabilitySet & requires_caps,
764 const CapabilitySet & conflict_caps,
765 const PoolItemList & weakItems,
766 const std::set<Repository> & upgradeRepos)
768 MIL << "SATResolver::resolvePool()" << endl;
771 solverInit(weakItems);
773 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
774 Id id = (*iter)->satSolvable().id();
776 ERR << "Install: " << *iter << " not found" << endl;
778 MIL << "Install " << *iter << endl;
779 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
780 queue_push( &(_jobQueue), id );
784 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
785 Id id = (*iter)->satSolvable().id();
787 ERR << "Delete: " << *iter << " not found" << endl;
789 MIL << "Delete " << *iter << endl;
790 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE | MAYBE_CLEANDEPS );
791 queue_push( &(_jobQueue), id);
795 for_( iter, upgradeRepos.begin(), upgradeRepos.end() )
797 queue_push( &(_jobQueue), SOLVER_DISTUPGRADE | SOLVER_SOLVABLE_REPO );
798 queue_push( &(_jobQueue), iter->get()->repoid );
799 MIL << "Upgrade repo " << *iter << endl;
802 for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
803 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES );
804 queue_push( &(_jobQueue), iter->id() );
805 MIL << "Requires " << *iter << endl;
808 for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
809 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES | MAYBE_CLEANDEPS );
810 queue_push( &(_jobQueue), iter->id() );
811 MIL << "Conflicts " << *iter << endl;
814 // set requirements for a running system
815 setSystemRequirements();
817 // set locks for the solver
821 bool ret = solving(requires_caps, conflict_caps);
823 (ret?MIL:WAR) << "SATResolver::resolvePool() done. Ret:" << ret << endl;
829 SATResolver::resolveQueue(const SolverQueueItemList &requestQueue,
830 const PoolItemList & weakItems)
832 MIL << "SATResolver::resolvQueue()" << endl;
835 solverInit(weakItems);
837 // generate solver queue
838 for (SolverQueueItemList::const_iterator iter = requestQueue.begin(); iter != requestQueue.end(); iter++) {
839 (*iter)->addRule(_jobQueue);
842 // Add addition item status to the resolve-queue cause these can be set by problem resolutions
843 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
844 Id id = (*iter)->satSolvable().id();
846 ERR << "Install: " << *iter << " not found" << endl;
848 MIL << "Install " << *iter << endl;
849 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
850 queue_push( &(_jobQueue), id );
853 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
854 sat::detail::IdType ident( (*iter)->satSolvable().ident().id() );
855 MIL << "Delete " << *iter << ident << endl;
856 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_NAME | MAYBE_CLEANDEPS );
857 queue_push( &(_jobQueue), ident);
860 // set requirements for a running system
861 setSystemRequirements();
863 // set locks for the solver
867 bool ret = solving();
869 MIL << "SATResolver::resolveQueue() done. Ret:" << ret << endl;
873 /** \todo duplicate code to be joined with \ref solving. */
874 void SATResolver::doUpdate()
876 MIL << "SATResolver::doUpdate()" << endl;
879 solverInit(PoolItemList());
881 // set requirements for a running system
882 setSystemRequirements();
884 // set locks for the solver
887 _satSolver = solver_create( _satPool );
888 ::pool_set_custom_vendorcheck( _satPool, &vendorCheck );
890 queue_push( &(_jobQueue), SOLVER_VERIFY|SOLVER_SOLVABLE_ALL);
891 queue_push( &(_jobQueue), 0 );
894 queue_push( &(_jobQueue), SOLVER_UPDATE|SOLVER_SOLVABLE_ALL);
895 queue_push( &(_jobQueue), 0 );
898 queue_push( &(_jobQueue), SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_ALL);
899 queue_push( &(_jobQueue), 0 );
901 if (_distupgrade_removeunsupported) {
902 queue_push( &(_jobQueue), SOLVER_DROP_ORPHANED|SOLVER_SOLVABLE_ALL);
903 queue_push( &(_jobQueue), 0 );
905 solver_set_flag(_satSolver, SOLVER_FLAG_ADD_ALREADY_RECOMMENDED, !_ignorealreadyrecommended);
906 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_DOWNGRADE, _allowdowngrade);
907 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_UNINSTALL, _allowuninstall);
908 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_ARCHCHANGE, _allowarchchange);
909 solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_VENDORCHANGE, _allowvendorchange);
910 solver_set_flag(_satSolver, SOLVER_FLAG_SPLITPROVIDES, _dosplitprovides);
911 solver_set_flag(_satSolver, SOLVER_FLAG_NO_UPDATEPROVIDE, _noupdateprovide);
912 solver_set_flag(_satSolver, SOLVER_FLAG_IGNORE_RECOMMENDED, _onlyRequires);
914 sat::Pool::instance().prepareForSolving();
917 MIL << "Starting solving for update...." << endl;
919 solver_solve( _satSolver, &(_jobQueue) );
920 MIL << "....Solver end" << endl;
922 // copying solution back to zypp pool
923 //-----------------------------------------
925 /* solvables to be installed */
927 queue_init(&decisionq);
928 solver_get_decisionqueue(_satSolver, &decisionq);
929 for (int i = 0; i < decisionq.count; i++)
932 p = decisionq.elements[i];
933 if (p < 0 || !sat::Solvable(p))
935 if (sat::Solvable(p).repository().get() == _satSolver->pool->installed)
938 PoolItem poolItem = _pool.find (sat::Solvable(p));
940 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
942 ERR << "id " << p << " not found in ZYPP pool." << endl;
945 queue_free(&decisionq);
947 /* solvables to be erased */
948 for (int i = _satSolver->pool->installed->start; i < _satSolver->pool->installed->start + _satSolver->pool->installed->nsolvables; i++)
950 if (solver_get_decisionlevel(_satSolver, i) > 0)
953 PoolItem poolItem( _pool.find( sat::Solvable(i) ) );
955 // Check if this is an update
956 CheckIfUpdate info( (sat::Solvable(i)) );
957 invokeOnEach( _pool.byIdentBegin( poolItem ),
958 _pool.byIdentEnd( poolItem ),
959 resfilter::ByUninstalled(), // ByUninstalled
960 functor::functorRef<bool,PoolItem> (info) );
962 if (info.is_updated) {
963 SATSolutionToPool (poolItem, ResStatus::toBeUninstalledDueToUpgrade , ResStatus::SOLVER);
965 SATSolutionToPool (poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER);
968 ERR << "id " << i << " not found in ZYPP pool." << endl;
971 MIL << "SATResolver::doUpdate() done" << endl;
976 //----------------------------------------------------------------------------
977 //----------------------------------------------------------------------------
979 //----------------------------------------------------------------------------
980 //----------------------------------------------------------------------------
982 //----------------------------------------------------------------------------
984 //----------------------------------------------------------------------------
986 struct FindPackage : public resfilter::ResObjectFilterFunctor
988 ProblemSolutionCombi *problemSolution;
989 TransactionKind action;
990 FindPackage (ProblemSolutionCombi *p, const TransactionKind act)
991 : problemSolution (p)
996 bool operator()( PoolItem p)
998 problemSolution->addSingleAction (p, action);
1004 //----------------------------------------------------------------------------
1005 // Checking if this solvable/item has a buddy which reflect the real
1006 // user visible description of an item
1007 // e.g. The release package has a buddy to the concerning product item.
1008 // This user want's the message "Product foo conflicts with product bar" and
1009 // NOT "package release-foo conflicts with package release-bar"
1010 // (ma: that's why we should map just packages to buddies, not vice versa)
1011 //----------------------------------------------------------------------------
1012 inline sat::Solvable mapBuddy( const PoolItem & item_r )
1014 if ( item_r.satSolvable().isKind<Package>() )
1016 sat::Solvable buddy = item_r.buddy();
1020 return item_r.satSolvable();
1022 inline sat::Solvable mapBuddy( sat::Solvable item_r )
1023 { return mapBuddy( PoolItem( item_r ) ); }
1025 PoolItem SATResolver::mapItem ( const PoolItem & item )
1026 { return PoolItem( mapBuddy( item ) ); }
1028 sat::Solvable SATResolver::mapSolvable ( const Id & id )
1029 { return mapBuddy( sat::Solvable(id) ); }
1031 string SATResolver::SATprobleminfoString(Id problem, string &detail, Id &ignoreId)
1034 sat::detail::CPool *pool = _satSolver->pool;
1036 Id dep, source, target;
1037 sat::Solvable s, s2;
1041 // FIXME: solver_findallproblemrules to get all rules for this problem
1042 // (the 'most relevabt' one returned by solver_findproblemrule is embedded
1043 probr = solver_findproblemrule(_satSolver, problem);
1044 switch (solver_ruleinfo(_satSolver, probr, &source, &target, &dep))
1046 case SOLVER_RULE_DISTUPGRADE:
1047 s = mapSolvable (source);
1048 ret = str::form (_("%s does not belong to a distupgrade repository"), s.asString().c_str());
1050 case SOLVER_RULE_INFARCH:
1051 s = mapSolvable (source);
1052 ret = str::form (_("%s has inferior architecture"), s.asString().c_str());
1054 case SOLVER_RULE_UPDATE:
1055 s = mapSolvable (source);
1056 ret = str::form (_("problem with installed package %s"), s.asString().c_str());
1058 case SOLVER_RULE_JOB:
1059 ret = _("conflicting requests");
1061 case SOLVER_RULE_RPM:
1062 ret = _("some dependency problem");
1064 case SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP:
1065 ret = str::form (_("nothing provides requested %s"), pool_dep2str(pool, dep));
1066 detail += _("Have you enabled all requested repositories?");
1068 case SOLVER_RULE_JOB_UNKNOWN_PACKAGE:
1069 ret = str::form (_("package %s does not exist"), pool_dep2str(pool, dep));
1070 detail += _("Have you enabled all requested repositories?");
1072 case SOLVER_RULE_JOB_UNSUPPORTED:
1073 ret = _("unsupported request");
1075 case SOLVER_RULE_JOB_PROVIDED_BY_SYSTEM:
1076 ret = str::form (_("%s is provided by the system and cannot be erased"), pool_dep2str(pool, dep));
1078 case SOLVER_RULE_RPM_NOT_INSTALLABLE:
1079 s = mapSolvable (source);
1080 ret = str::form (_("%s is not installable"), s.asString().c_str());
1082 case SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP:
1083 ignoreId = source; // for setting weak dependencies
1084 s = mapSolvable (source);
1085 ret = str::form (_("nothing provides %s needed by %s"), pool_dep2str(pool, dep), s.asString().c_str());
1087 case SOLVER_RULE_RPM_SAME_NAME:
1088 s = mapSolvable (source);
1089 s2 = mapSolvable (target);
1090 ret = str::form (_("cannot install both %s and %s"), s.asString().c_str(), s2.asString().c_str());
1092 case SOLVER_RULE_RPM_PACKAGE_CONFLICT:
1093 s = mapSolvable (source);
1094 s2 = mapSolvable (target);
1095 ret = str::form (_("%s conflicts with %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1097 case SOLVER_RULE_RPM_PACKAGE_OBSOLETES:
1098 s = mapSolvable (source);
1099 s2 = mapSolvable (target);
1100 ret = str::form (_("%s obsoletes %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1102 case SOLVER_RULE_RPM_INSTALLEDPKG_OBSOLETES:
1103 s = mapSolvable (source);
1104 s2 = mapSolvable (target);
1105 ret = str::form (_("installed %s obsoletes %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1107 case SOLVER_RULE_RPM_SELF_CONFLICT:
1108 s = mapSolvable (source);
1109 ret = str::form (_("solvable %s conflicts with %s provided by itself"), s.asString().c_str(), pool_dep2str(pool, dep));
1111 case SOLVER_RULE_RPM_PACKAGE_REQUIRES:
1112 ignoreId = source; // for setting weak dependencies
1113 s = mapSolvable (source);
1114 Capability cap(dep);
1115 sat::WhatProvides possibleProviders(cap);
1117 // check, if a provider will be deleted
1118 typedef list<PoolItem> ProviderList;
1119 ProviderList providerlistInstalled, providerlistUninstalled;
1120 for_( iter1, possibleProviders.begin(), possibleProviders.end() ) {
1121 PoolItem provider1 = ResPool::instance().find( *iter1 );
1122 // find pair of an installed/uninstalled item with the same NVR
1124 for_( iter2, possibleProviders.begin(), possibleProviders.end() ) {
1125 PoolItem provider2 = ResPool::instance().find( *iter2 );
1126 if (compareByNVR (provider1.resolvable(),provider2.resolvable()) == 0
1127 && ( (provider1.status().isInstalled() && provider2.status().isUninstalled())
1128 || (provider2.status().isInstalled() && provider1.status().isUninstalled()) )) {
1134 if (provider1.status().isInstalled())
1135 providerlistInstalled.push_back(provider1);
1137 providerlistUninstalled.push_back(provider1);
1141 ret = str::form (_("%s requires %s, but this requirement cannot be provided"), s.asString().c_str(), pool_dep2str(pool, dep));
1142 if (providerlistInstalled.size() > 0) {
1143 detail += _("deleted providers: ");
1144 for (ProviderList::const_iterator iter = providerlistInstalled.begin(); iter != providerlistInstalled.end(); iter++) {
1145 if (iter == providerlistInstalled.begin())
1146 detail += itemToString( *iter );
1148 detail += "\n " + itemToString( mapItem(*iter) );
1151 if (providerlistUninstalled.size() > 0) {
1152 if (detail.size() > 0)
1153 detail += _("\nuninstallable providers: ");
1155 detail = _("uninstallable providers: ");
1156 for (ProviderList::const_iterator iter = providerlistUninstalled.begin(); iter != providerlistUninstalled.end(); iter++) {
1157 if (iter == providerlistUninstalled.begin())
1158 detail += itemToString( *iter );
1160 detail += "\n " + itemToString( mapItem(*iter) );
1170 SATResolver::problems ()
1172 ResolverProblemList resolverProblems;
1173 if (_satSolver && solver_problem_count(_satSolver)) {
1174 sat::detail::CPool *pool = _satSolver->pool;
1177 Id problem, solution, element;
1178 sat::Solvable s, sd;
1180 CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1181 CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1183 MIL << "Encountered problems! Here are the solutions:\n" << endl;
1186 while ((problem = solver_next_problem(_satSolver, problem)) != 0) {
1187 MIL << "Problem " << pcnt++ << ":" << endl;
1188 MIL << "====================================" << endl;
1191 string whatString = SATprobleminfoString (problem,detail,ignoreId);
1192 MIL << whatString << endl;
1193 MIL << "------------------------------------" << endl;
1194 ResolverProblem_Ptr resolverProblem = new ResolverProblem (whatString, detail);
1197 while ((solution = solver_next_solution(_satSolver, problem, solution)) != 0) {
1199 ProblemSolutionCombi *problemSolution = new ProblemSolutionCombi(resolverProblem);
1200 while ((element = solver_next_solutionelement(_satSolver, problem, solution, element, &p, &rp)) != 0) {
1201 if (p == SOLVER_SOLUTION_JOB) {
1202 /* job, rp is index into job queue */
1203 what = _jobQueue.elements[rp];
1204 switch (_jobQueue.elements[rp-1]&(SOLVER_SELECTMASK|SOLVER_JOBMASK))
1206 case SOLVER_INSTALL | SOLVER_SOLVABLE: {
1207 s = mapSolvable (what);
1208 PoolItem poolItem = _pool.find (s);
1210 if (pool->installed && s.get()->repo == pool->installed) {
1211 problemSolution->addSingleAction (poolItem, REMOVE);
1212 string description = str::form (_("remove lock to allow removal of %s"), s.asString().c_str() );
1213 MIL << description << endl;
1214 problemSolution->addDescription (description);
1216 problemSolution->addSingleAction (poolItem, KEEP);
1217 string description = str::form (_("do not install %s"), s.asString().c_str());
1218 MIL << description << endl;
1219 problemSolution->addDescription (description);
1222 ERR << "SOLVER_INSTALL_SOLVABLE: No item found for " << s.asString() << endl;
1226 case SOLVER_ERASE | SOLVER_SOLVABLE: {
1227 s = mapSolvable (what);
1228 PoolItem poolItem = _pool.find (s);
1230 if (pool->installed && s.get()->repo == pool->installed) {
1231 problemSolution->addSingleAction (poolItem, KEEP);
1232 string description = str::form (_("keep %s"), s.asString().c_str());
1233 MIL << description << endl;
1234 problemSolution->addDescription (description);
1236 problemSolution->addSingleAction (poolItem, UNLOCK);
1237 string description = str::form (_("remove lock to allow installation of %s"), itemToString( poolItem ).c_str());
1238 MIL << description << endl;
1239 problemSolution->addDescription (description);
1242 ERR << "SOLVER_ERASE_SOLVABLE: No item found for " << s.asString() << endl;
1246 case SOLVER_INSTALL | SOLVER_SOLVABLE_NAME:
1248 IdString ident( what );
1249 SolverQueueItemInstall_Ptr install =
1250 new SolverQueueItemInstall(_pool, ident.asString(), false );
1251 problemSolution->addSingleAction (install, REMOVE_SOLVE_QUEUE_ITEM);
1253 string description = str::form (_("do not install %s"), ident.c_str() );
1254 MIL << description << endl;
1255 problemSolution->addDescription (description);
1258 case SOLVER_ERASE | SOLVER_SOLVABLE_NAME:
1260 // As we do not know, if this request has come from resolvePool or
1261 // resolveQueue we will have to take care for both cases.
1262 IdString ident( what );
1263 FindPackage info (problemSolution, KEEP);
1264 invokeOnEach( _pool.byIdentBegin( ident ),
1265 _pool.byIdentEnd( ident ),
1266 functor::chain (resfilter::ByInstalled (), // ByInstalled
1267 resfilter::ByTransact ()), // will be deinstalled
1268 functor::functorRef<bool,PoolItem> (info) );
1270 SolverQueueItemDelete_Ptr del =
1271 new SolverQueueItemDelete(_pool, ident.asString(), false );
1272 problemSolution->addSingleAction (del, REMOVE_SOLVE_QUEUE_ITEM);
1274 string description = str::form (_("keep %s"), ident.c_str());
1275 MIL << description << endl;
1276 problemSolution->addDescription (description);
1279 case SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES:
1281 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_REQUIRE);
1282 string description = "";
1284 // Checking if this problem solution would break your system
1285 if (system_requires.find(Capability(what)) != system_requires.end()) {
1286 // Show a better warning
1287 resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1288 resolverProblem->setDescription(_("This request will break your system!"));
1289 description = _("ignore the warning of a broken system");
1290 description += string(" (requires:")+pool_dep2str(pool, what)+")";
1291 MIL << description << endl;
1292 problemSolution->addFrontDescription (description);
1294 description = str::form (_("do not ask to install a solvable providing %s"), pool_dep2str(pool, what));
1295 MIL << description << endl;
1296 problemSolution->addDescription (description);
1300 case SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES:
1302 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_CONFLICT);
1303 string description = "";
1305 // Checking if this problem solution would break your system
1306 if (system_conflicts.find(Capability(what)) != system_conflicts.end()) {
1307 // Show a better warning
1308 resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1309 resolverProblem->setDescription(_("This request will break your system!"));
1310 description = _("ignore the warning of a broken system");
1311 description += string(" (conflicts:")+pool_dep2str(pool, what)+")";
1312 MIL << description << endl;
1313 problemSolution->addFrontDescription (description);
1316 description = str::form (_("do not ask to delete all solvables providing %s"), pool_dep2str(pool, what));
1317 MIL << description << endl;
1318 problemSolution->addDescription (description);
1322 case SOLVER_UPDATE | SOLVER_SOLVABLE:
1324 s = mapSolvable (what);
1325 PoolItem poolItem = _pool.find (s);
1327 if (pool->installed && s.get()->repo == pool->installed) {
1328 problemSolution->addSingleAction (poolItem, KEEP);
1329 string description = str::form (_("do not install most recent version of %s"), s.asString().c_str());
1330 MIL << description << endl;
1331 problemSolution->addDescription (description);
1333 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE " << poolItem << " is not selected for installation" << endl;
1336 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE: No item found for " << s.asString() << endl;
1341 MIL << "- do something different" << endl;
1342 ERR << "No valid solution available" << endl;
1345 } else if (p == SOLVER_SOLUTION_INFARCH) {
1346 s = mapSolvable (rp);
1347 PoolItem poolItem = _pool.find (s);
1348 if (pool->installed && s.get()->repo == pool->installed) {
1349 problemSolution->addSingleAction (poolItem, LOCK);
1350 string description = str::form (_("keep %s despite the inferior architecture"), s.asString().c_str());
1351 MIL << description << endl;
1352 problemSolution->addDescription (description);
1354 problemSolution->addSingleAction (poolItem, INSTALL);
1355 string description = str::form (_("install %s despite the inferior architecture"), s.asString().c_str());
1356 MIL << description << endl;
1357 problemSolution->addDescription (description);
1359 } else if (p == SOLVER_SOLUTION_DISTUPGRADE) {
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 obsolete %s"), s.asString().c_str());
1365 MIL << description << endl;
1366 problemSolution->addDescription (description);
1368 problemSolution->addSingleAction (poolItem, INSTALL);
1369 string description = str::form (_("install %s from excluded repository"), s.asString().c_str());
1370 MIL << description << endl;
1371 problemSolution->addDescription (description);
1374 /* policy, replace p with rp */
1375 s = mapSolvable (p);
1376 PoolItem itemFrom = _pool.find (s);
1381 sd = mapSolvable (rp);
1382 PoolItem itemTo = _pool.find (sd);
1383 if (itemFrom && itemTo) {
1384 problemSolution->addSingleAction (itemTo, INSTALL);
1385 int illegal = policy_is_illegal(_satSolver, s.get(), sd.get(), 0);
1387 if ((illegal & POLICY_ILLEGAL_DOWNGRADE) != 0)
1389 string description = str::form (_("downgrade of %s to %s"), s.asString().c_str(), sd.asString().c_str());
1390 MIL << description << endl;
1391 problemSolution->addDescription (description);
1394 if ((illegal & POLICY_ILLEGAL_ARCHCHANGE) != 0)
1396 string description = str::form (_("architecture change of %s to %s"), s.asString().c_str(), sd.asString().c_str());
1397 MIL << description << endl;
1398 problemSolution->addDescription (description);
1401 if ((illegal & POLICY_ILLEGAL_VENDORCHANGE) != 0)
1403 IdString s_vendor( s.vendor() );
1404 IdString sd_vendor( sd.vendor() );
1405 string description = str::form (_("install %s (with vendor change)\n %s --> %s") ,
1406 sd.asString().c_str(),
1407 ( s_vendor ? s_vendor.c_str() : " (no vendor) " ),
1408 ( sd_vendor ? sd_vendor.c_str() : " (no vendor) " ) );
1409 MIL << description << endl;
1410 problemSolution->addDescription (description);
1414 string description = str::form (_("replacement of %s with %s"), s.asString().c_str(), sd.asString().c_str());
1415 MIL << description << endl;
1416 problemSolution->addDescription (description);
1419 ERR << s.asString() << " or " << sd.asString() << " not found" << endl;
1425 string description = str::form (_("deinstallation of %s"), s.asString().c_str());
1426 MIL << description << endl;
1427 problemSolution->addDescription (description);
1428 problemSolution->addSingleAction (itemFrom, REMOVE);
1433 resolverProblem->addSolution (problemSolution,
1434 problemSolution->actionCount() > 1 ? true : false); // Solutions with more than 1 action will be shown first.
1435 MIL << "------------------------------------" << endl;
1439 // There is a possibility to ignore this error by setting weak dependencies
1440 PoolItem item = _pool.find (sat::Solvable(ignoreId));
1441 ProblemSolutionIgnore *problemSolution = new ProblemSolutionIgnore(resolverProblem, item);
1442 resolverProblem->addSolution (problemSolution,
1443 false); // Solutions will be shown at the end
1444 MIL << "ignore some dependencies of " << item << endl;
1445 MIL << "------------------------------------" << endl;
1449 resolverProblems.push_back (resolverProblem);
1452 return resolverProblems;
1456 SATResolver::applySolutions (const ProblemSolutionList & solutions)
1458 for (ProblemSolutionList::const_iterator iter = solutions.begin();
1459 iter != solutions.end(); ++iter) {
1460 ProblemSolution_Ptr solution = *iter;
1461 Resolver dummyResolver(_pool);
1462 if (!solution->apply (dummyResolver))
1467 void SATResolver::setLocks()
1469 for (PoolItemList::const_iterator iter = _items_to_lock.begin(); iter != _items_to_lock.end(); ++iter) {
1470 sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
1471 if (iter->status().isInstalled()) {
1472 MIL << "Lock installed item " << *iter << endl;
1473 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
1474 queue_push( &(_jobQueue), ident );
1476 MIL << "Lock NOT installed item " << *iter << endl;
1477 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE | MAYBE_CLEANDEPS );
1478 queue_push( &(_jobQueue), ident );
1482 ///////////////////////////////////////////////////////////////////
1483 // Weak locks: Ignore if an item with this name is already installed.
1484 // If it's not installed try to keep it this way using a weak delete
1485 ///////////////////////////////////////////////////////////////////
1486 std::set<IdString> unifiedByName;
1487 for (PoolItemList::const_iterator iter = _items_to_keep.begin(); iter != _items_to_keep.end(); ++iter) {
1488 IdString ident( (*iter)->satSolvable().ident() );
1489 if ( unifiedByName.insert( ident ).second )
1491 if ( ! ui::Selectable::get( *iter )->hasInstalledObj() )
1493 MIL << "Keep NOT installed name " << ident << " (" << *iter << ")" << endl;
1494 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_NAME | SOLVER_WEAK | MAYBE_CLEANDEPS );
1495 queue_push( &(_jobQueue), ident.id() );
1501 void SATResolver::setSystemRequirements()
1503 CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1504 CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1506 for (CapabilitySet::const_iterator iter = system_requires.begin(); iter != system_requires.end(); ++iter) {
1507 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES );
1508 queue_push( &(_jobQueue), iter->id() );
1509 MIL << "SYSTEM Requires " << *iter << endl;
1512 for (CapabilitySet::const_iterator iter = system_conflicts.begin(); iter != system_conflicts.end(); ++iter) {
1513 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES | MAYBE_CLEANDEPS );
1514 queue_push( &(_jobQueue), iter->id() );
1515 MIL << "SYSTEM Conflicts " << *iter << endl;
1518 // Lock the architecture of the running systems rpm
1519 // package on distupgrade.
1520 if ( _distupgrade && ZConfig::instance().systemRoot() == "/" )
1522 ResPool pool( ResPool::instance() );
1523 IdString rpm( "rpm" );
1524 for_( it, pool.byIdentBegin(rpm), pool.byIdentEnd(rpm) )
1526 if ( (*it)->isSystem() )
1528 Capability archrule( (*it)->arch(), rpm.c_str(), Capability::PARSED );
1529 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_NAME | SOLVER_ESSENTIAL );
1530 queue_push( &(_jobQueue), archrule.id() );
1537 sat::StringQueue SATResolver::autoInstalled() const
1539 sat::StringQueue ret;
1541 ::solver_get_userinstalled( _satSolver, ret, GET_USERINSTALLED_NAMES|GET_USERINSTALLED_INVERTED );
1545 sat::StringQueue SATResolver::userInstalled() const
1547 sat::StringQueue ret;
1549 ::solver_get_userinstalled( _satSolver, ret, GET_USERINSTALLED_NAMES );
1554 ///////////////////////////////////////////////////////////////////
1555 };// namespace detail
1556 /////////////////////////////////////////////////////////////////////
1557 /////////////////////////////////////////////////////////////////////
1558 };// namespace solver
1559 ///////////////////////////////////////////////////////////////////////
1560 ///////////////////////////////////////////////////////////////////////
1562 /////////////////////////////////////////////////////////////////////////