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( Pool *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(_solv, 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, Pool *SATPool)
175 , _allowdowngrade(false)
176 , _allowarchchange(false)
177 , _allowvendorchange(ZConfig::instance().solver_allowVendorChange())
178 , _allowuninstall(false)
179 , _updatesystem(false)
180 , _noupdateprovide(false)
181 , _dosplitprovides(false)
182 , _onlyRequires(ZConfig::instance().solver_onlyRequires())
183 , _ignorealreadyrecommended(true)
184 , _distupgrade(false)
185 , _distupgrade_removeunsupported(false)
186 , _solveSrcPackages(false)
187 , _cleandepsOnRemove(ZConfig::instance().solver_cleandepsOnRemove())
192 SATResolver::~SATResolver()
197 //---------------------------------------------------------------------------
200 SATResolver::pool (void) const
206 SATResolver::resetItemTransaction (PoolItem item)
209 for (PoolItemList::const_iterator iter = _items_to_remove.begin();
210 iter != _items_to_remove.end(); ++iter) {
212 _items_to_remove.remove(*iter);
218 for (PoolItemList::const_iterator iter = _items_to_install.begin();
219 iter != _items_to_install.end(); ++iter) {
221 _items_to_install.remove(*iter);
228 for (PoolItemList::const_iterator iter = _items_to_keep.begin();
229 iter != _items_to_keep.end(); ++iter) {
231 _items_to_keep.remove(*iter);
238 for (PoolItemList::const_iterator iter = _items_to_lock.begin();
239 iter != _items_to_lock.end(); ++iter) {
241 _items_to_lock.remove(*iter);
251 SATResolver::addPoolItemToInstall (PoolItem item)
253 resetItemTransaction (item);
254 _items_to_install.push_back (item);
255 _items_to_install.unique ();
260 SATResolver::addPoolItemsToInstallFromList (PoolItemList & rl)
262 for (PoolItemList::const_iterator iter = rl.begin(); iter != rl.end(); iter++) {
263 addPoolItemToInstall (*iter);
269 SATResolver::addPoolItemToRemove (PoolItem item)
271 resetItemTransaction (item);
272 _items_to_remove.push_back (item);
273 _items_to_remove.unique ();
278 SATResolver::addPoolItemsToRemoveFromList (PoolItemList & rl)
280 for (PoolItemList::const_iterator iter = rl.begin(); iter != rl.end(); iter++) {
281 addPoolItemToRemove (*iter);
286 SATResolver::addPoolItemToLock (PoolItem item)
288 resetItemTransaction (item);
289 _items_to_lock.push_back (item);
290 _items_to_lock.unique ();
294 SATResolver::addPoolItemToKeep (PoolItem item)
296 resetItemTransaction (item);
297 _items_to_keep.push_back (item);
298 _items_to_keep.unique ();
301 //---------------------------------------------------------------------------
303 // copy marked item from solution back to pool
304 // if data != NULL, set as APPL_LOW (from establishPool())
307 SATSolutionToPool (PoolItem item, const ResStatus & status, const ResStatus::TransactByValue causer)
310 item.status().resetTransact (causer);
311 item.status().resetWeak ();
315 // installation/deletion
316 if (status.isToBeInstalled()) {
317 r = item.status().setToBeInstalled (causer);
318 _XDEBUG("SATSolutionToPool install returns " << item << ", " << r);
320 else if (status.isToBeUninstalledDueToUpgrade()) {
321 r = item.status().setToBeUninstalledDueToUpgrade (causer);
322 _XDEBUG("SATSolutionToPool upgrade returns " << item << ", " << r);
324 else if (status.isToBeUninstalled()) {
325 r = item.status().setToBeUninstalled (causer);
326 _XDEBUG("SATSolutionToPool remove returns " << item << ", " << r);
332 //----------------------------------------------------------------------------
333 //----------------------------------------------------------------------------
335 //----------------------------------------------------------------------------
336 //----------------------------------------------------------------------------
338 //----------------------------------------------------------------------------
339 // Helper functions for the ZYPP-Pool
340 //----------------------------------------------------------------------------
343 //------------------------------------------------------------------------------------------------------------
344 // This function loops over the pool and grabs all items
345 // It clears all previous bySolver() states also
347 // Every toBeInstalled is passed to zypp::solver:detail::Resolver.addPoolItemToInstall()
348 // Every toBeUninstalled is passed to zypp::solver:detail::Resolver.addPoolItemToRemove()
350 // Solver results must be written back to the pool.
351 //------------------------------------------------------------------------------------------------------------
354 struct SATCollectTransact : public resfilter::PoolItemFilterFunctor
356 SATResolver & resolver;
358 SATCollectTransact (SATResolver & r)
362 bool operator()( PoolItem item ) // only transacts() items go here
364 ResStatus status = item.status();
365 bool by_solver = (status.isBySolver() || status.isByApplLow());
368 item.status().resetTransact( ResStatus::APPL_LOW );// clear any solver/establish transactions
369 return true; // back out here, dont re-queue former solver result
372 if ( item.satSolvable().isKind<SrcPackage>() && ! resolver.solveSrcPackages() )
374 // Later we may continue on a per source package base.
375 return true; // dont process this source package.
378 if (status.isToBeInstalled()) {
379 resolver.addPoolItemToInstall(item); // -> install!
381 else if (status.isToBeUninstalled()) {
382 resolver.addPoolItemToRemove(item); // -> remove !
384 else if (status.isLocked()
386 resolver.addPoolItemToLock (item);
388 else if (status.isKept()
390 resolver.addPoolItemToKeep (item);
398 //----------------------------------------------------------------------------
399 //----------------------------------------------------------------------------
401 //----------------------------------------------------------------------------
402 //----------------------------------------------------------------------------
405 class CheckIfUpdate : public resfilter::PoolItemFilterFunctor
410 sat::Solvable _installed;
412 CheckIfUpdate( sat::Solvable installed_r )
413 : is_updated( false )
414 , multiversion( installed_r.multiversionInstall() )
415 , _installed( installed_r )
418 // check this item will be updated
420 bool operator()( PoolItem item )
422 if ( item.status().isToBeInstalled() )
424 if ( ! multiversion || sameNVRA( _installed, item ) )
435 class CollectPseudoInstalled : public resfilter::PoolItemFilterFunctor
438 Queue *solvableQueue;
440 CollectPseudoInstalled( Queue *queue )
441 :solvableQueue (queue)
444 // collecting PseudoInstalled items
445 bool operator()( PoolItem item )
447 if ( traits::isPseudoInstalled( item.satSolvable().kind() ) )
448 queue_push( solvableQueue, item.satSolvable().id() );
454 SATResolver::solving(const CapabilitySet & requires_caps,
455 const CapabilitySet & conflict_caps)
457 _solv = solver_create( _SATPool );
458 ::pool_set_custom_vendorcheck( _SATPool, &vendorCheck );
460 queue_push( &(_jobQueue), SOLVER_VERIFY|SOLVER_SOLVABLE_ALL);
461 queue_push( &(_jobQueue), 0 );
464 queue_push( &(_jobQueue), SOLVER_UPDATE|SOLVER_SOLVABLE_ALL);
465 queue_push( &(_jobQueue), 0 );
468 queue_push( &(_jobQueue), SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_ALL);
469 queue_push( &(_jobQueue), 0 );
471 if (_distupgrade_removeunsupported) {
472 queue_push( &(_jobQueue), SOLVER_DROP_ORPHANED|SOLVER_SOLVABLE_ALL);
473 queue_push( &(_jobQueue), 0 );
475 solver_set_flag(_solv, SOLVER_FLAG_ADD_ALREADY_RECOMMENDED, !_ignorealreadyrecommended);
476 solver_set_flag(_solv, SOLVER_FLAG_ALLOW_DOWNGRADE, _allowdowngrade);
477 solver_set_flag(_solv, SOLVER_FLAG_ALLOW_UNINSTALL, _allowuninstall);
478 solver_set_flag(_solv, SOLVER_FLAG_ALLOW_ARCHCHANGE, _allowarchchange);
479 solver_set_flag(_solv, SOLVER_FLAG_ALLOW_VENDORCHANGE, _allowvendorchange);
480 solver_set_flag(_solv, SOLVER_FLAG_SPLITPROVIDES, _dosplitprovides);
481 solver_set_flag(_solv, SOLVER_FLAG_NO_UPDATEPROVIDE, _noupdateprovide);
482 solver_set_flag(_solv, SOLVER_FLAG_IGNORE_RECOMMENDED, _onlyRequires);
484 #define HACKENV(X,D) solver_set_flag(_solv, X, env::HACKENV( #X, D ) );
485 HACKENV( SOLVER_FLAG_DUP_ALLOW_DOWNGRADE, true );
486 HACKENV( SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE, true );
487 HACKENV( SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE,true );
488 HACKENV( SOLVER_FLAG_DUP_ALLOW_NAMECHANGE, true );
491 sat::Pool::instance().prepareForSolving();
494 MIL << "Starting solving...." << endl;
496 solver_solve( _solv, &(_jobQueue) );
497 MIL << "....Solver end" << endl;
499 // copying solution back to zypp pool
500 //-----------------------------------------
501 _result_items_to_install.clear();
502 _result_items_to_remove.clear();
504 /* solvables to be installed */
506 queue_init(&decisionq);
507 solver_get_decisionqueue(_solv, &decisionq);
508 for ( int i = 0; i < decisionq.count; ++i )
510 sat::Solvable slv( decisionq.elements[i] );
511 if ( !slv || slv.isSystem() )
514 PoolItem poolItem( slv );
515 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
516 _result_items_to_install.push_back (poolItem);
518 queue_free(&decisionq);
520 /* solvables to be erased */
521 Repository systemRepo( sat::Pool::instance().findSystemRepo() ); // don't create if it does not exist
522 if ( systemRepo && ! systemRepo.solvablesEmpty() )
524 bool mustCheckObsoletes = false;
525 for_( it, systemRepo.solvablesBegin(), systemRepo.solvablesEnd() )
527 if (solver_get_decisionlevel(_solv, it->id()) > 0)
530 // Check if this is an update
531 CheckIfUpdate info( *it );
532 PoolItem poolItem( *it );
533 invokeOnEach( _pool.byIdentBegin( poolItem ),
534 _pool.byIdentEnd( poolItem ),
535 resfilter::ByUninstalled(), // ByUninstalled
536 functor::functorRef<bool,PoolItem> (info) );
538 if (info.is_updated) {
539 SATSolutionToPool( poolItem, ResStatus::toBeUninstalledDueToUpgrade, ResStatus::SOLVER );
541 SATSolutionToPool( poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER );
542 if ( ! mustCheckObsoletes )
543 mustCheckObsoletes = true; // lazy check for UninstalledDueToObsolete
545 _result_items_to_remove.push_back (poolItem);
547 if ( mustCheckObsoletes )
549 sat::WhatObsoletes obsoleted( _result_items_to_install.begin(), _result_items_to_install.end() );
550 for_( it, obsoleted.poolItemBegin(), obsoleted.poolItemEnd() )
552 ResStatus & status( it->status() );
553 // WhatObsoletes contains installed items only!
554 if ( status.transacts() && ! status.isToBeUninstalledDueToUpgrade() )
555 status.setToBeUninstalledDueToObsolete();
560 Queue recommendations;
564 queue_init(&recommendations);
565 queue_init(&suggestions);
566 queue_init(&orphaned);
567 queue_init(&unneeded);
568 solver_get_recommendations(_solv, &recommendations, &suggestions, 0);
569 solver_get_orphaned(_solv, &orphaned);
570 solver_get_unneeded(_solv, &unneeded, 1);
571 /* solvables which are recommended */
572 for ( int i = 0; i < recommendations.count; ++i )
574 PoolItem poolItem( getPoolItem( recommendations.elements[i] ) );
575 poolItem.status().setRecommended( true );
578 /* solvables which are suggested */
579 for ( int i = 0; i < suggestions.count; ++i )
581 PoolItem poolItem( getPoolItem( suggestions.elements[i] ) );
582 poolItem.status().setSuggested( true );
585 _problem_items.clear();
586 /* solvables which are orphaned */
587 for ( int i = 0; i < orphaned.count; ++i )
589 PoolItem poolItem( getPoolItem( orphaned.elements[i] ) );
590 poolItem.status().setOrphaned( true );
591 _problem_items.push_back( poolItem );
594 /* solvables which are unneeded */
595 for ( int i = 0; i < unneeded.count; ++i )
597 PoolItem poolItem( getPoolItem( unneeded.elements[i] ) );
598 poolItem.status().setUnneeded( true );
601 queue_free(&recommendations);
602 queue_free(&suggestions);
603 queue_free(&orphaned);
604 queue_free(&unneeded);
606 /* Write validation state back to pool */
607 Queue flags, solvableQueue;
610 queue_init(&solvableQueue);
612 CollectPseudoInstalled collectPseudoInstalled(&solvableQueue);
613 invokeOnEach( _pool.begin(),
615 functor::functorRef<bool,PoolItem> (collectPseudoInstalled) );
616 solver_trivial_installable(_solv, &solvableQueue, &flags );
617 for (int i = 0; i < solvableQueue.count; i++) {
618 PoolItem item = _pool.find (sat::Solvable(solvableQueue.elements[i]));
619 item.status().setUndetermined();
621 if (flags.elements[i] == -1) {
622 item.status().setNonRelevant();
623 _XDEBUG("SATSolutionToPool(" << item << " ) nonRelevant !");
624 } else if (flags.elements[i] == 1) {
625 item.status().setSatisfied();
626 _XDEBUG("SATSolutionToPool(" << item << " ) satisfied !");
627 } else if (flags.elements[i] == 0) {
628 item.status().setBroken();
629 _XDEBUG("SATSolutionToPool(" << item << " ) broken !");
632 queue_free(&(solvableQueue));
636 // Solvables which were selected due requirements which have been made by the user will
637 // be selected by APPL_LOW. We can't use any higher level, because this setting must
638 // not serve as a request for the next solver run. APPL_LOW is reset before solving.
639 for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
640 sat::WhatProvides rpmProviders(*iter);
641 for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
642 PoolItem poolItem(*iter2);
643 if (poolItem.status().isToBeInstalled()) {
644 MIL << "User requirement " << *iter << " sets " << poolItem << endl;
645 poolItem.status().setTransactByValue (ResStatus::APPL_LOW);
649 for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
650 sat::WhatProvides rpmProviders(*iter);
651 for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
652 PoolItem poolItem(*iter2);
653 if (poolItem.status().isToBeUninstalled()) {
654 MIL << "User conflict " << *iter << " sets " << poolItem << endl;
655 poolItem.status().setTransactByValue (ResStatus::APPL_LOW);
660 if (solver_problem_count(_solv) > 0 )
662 ERR << "Solverrun finished with an ERROR" << endl;
671 SATResolver::solverInit(const PoolItemList & weakItems)
673 SATCollectTransact info (*this);
675 MIL << "SATResolver::solverInit()" << endl;
680 queue_init( &_jobQueue );
681 _items_to_install.clear();
682 _items_to_remove.clear();
683 _items_to_lock.clear();
684 _items_to_keep.clear();
686 invokeOnEach ( _pool.begin(), _pool.end(),
687 functor::functorRef<bool,PoolItem>(info) );
689 for (PoolItemList::const_iterator iter = weakItems.begin(); iter != weakItems.end(); iter++) {
690 Id id = (*iter)->satSolvable().id();
692 ERR << "Weaken: " << *iter << " not found" << endl;
694 MIL << "Weaken dependencies of " << *iter << endl;
695 queue_push( &(_jobQueue), SOLVER_WEAKENDEPS | SOLVER_SOLVABLE );
696 queue_push( &(_jobQueue), id );
699 // Add rules for parallel installable resolvables with different versions
700 for_( it, sat::Pool::instance().multiversionBegin(), sat::Pool::instance().multiversionEnd() )
702 queue_push( &(_jobQueue), SOLVER_NOOBSOLETES | SOLVER_SOLVABLE_NAME );
703 queue_push( &(_jobQueue), it->id() );
706 ::pool_add_userinstalled_jobs(_SATPool, sat::Pool::instance().autoInstalled(), &(_jobQueue), GET_USERINSTALLED_NAMES|GET_USERINSTALLED_INVERTED);
710 if ( ZConfig::instance().solverUpgradeRemoveDroppedPackages() )
712 MIL << "Checking droplists ..." << endl;
713 // Dropped packages: look for 'weakremover()' provides
714 // in dup candidates of installed products.
715 ResPoolProxy proxy( ResPool::instance().proxy() );
716 for_( it, proxy.byKindBegin<Product>(), proxy.byKindEnd<Product>() )
718 if ( (*it)->onSystem() ) // (to install) or (not to delete)
720 Product::constPtr prodCand( (*it)->candidateAsKind<Product>() );
722 continue; // product no longer available
724 CapabilitySet droplist( prodCand->droplist() );
725 dumpRangeLine( MIL << "Droplist for " << (*it)->candidateObj() << ": " << droplist.size() << " ", droplist.begin(), droplist.end() ) << endl;
726 for_( cap, droplist.begin(), droplist.end() )
728 queue_push( &_jobQueue, SOLVER_DROP_ORPHANED | SOLVER_SOLVABLE_NAME );
729 queue_push( &_jobQueue, cap->id() );
736 MIL << "Droplist processing is disabled." << endl;
742 SATResolver::solverEnd()
749 queue_free( &(_jobQueue) );
755 SATResolver::resolvePool(const CapabilitySet & requires_caps,
756 const CapabilitySet & conflict_caps,
757 const PoolItemList & weakItems,
758 const std::set<Repository> & upgradeRepos)
760 MIL << "SATResolver::resolvePool()" << endl;
763 solverInit(weakItems);
765 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
766 Id id = (*iter)->satSolvable().id();
768 ERR << "Install: " << *iter << " not found" << endl;
770 MIL << "Install " << *iter << endl;
771 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
772 queue_push( &(_jobQueue), id );
776 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
777 Id id = (*iter)->satSolvable().id();
779 ERR << "Delete: " << *iter << " not found" << endl;
781 MIL << "Delete " << *iter << endl;
782 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE | MAYBE_CLEANDEPS );
783 queue_push( &(_jobQueue), id);
787 for_( iter, upgradeRepos.begin(), upgradeRepos.end() )
789 queue_push( &(_jobQueue), SOLVER_DISTUPGRADE | SOLVER_SOLVABLE_REPO );
790 queue_push( &(_jobQueue), iter->get()->repoid );
791 MIL << "Upgrade repo " << *iter << endl;
794 for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
795 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES );
796 queue_push( &(_jobQueue), iter->id() );
797 MIL << "Requires " << *iter << endl;
800 for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
801 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES | MAYBE_CLEANDEPS );
802 queue_push( &(_jobQueue), iter->id() );
803 MIL << "Conflicts " << *iter << endl;
806 // set requirements for a running system
807 setSystemRequirements();
809 // set locks for the solver
813 bool ret = solving(requires_caps, conflict_caps);
815 (ret?MIL:WAR) << "SATResolver::resolvePool() done. Ret:" << ret << endl;
821 SATResolver::resolveQueue(const SolverQueueItemList &requestQueue,
822 const PoolItemList & weakItems)
824 MIL << "SATResolver::resolvQueue()" << endl;
827 solverInit(weakItems);
829 // generate solver queue
830 for (SolverQueueItemList::const_iterator iter = requestQueue.begin(); iter != requestQueue.end(); iter++) {
831 (*iter)->addRule(_jobQueue);
834 // Add addition item status to the resolve-queue cause these can be set by problem resolutions
835 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
836 Id id = (*iter)->satSolvable().id();
838 ERR << "Install: " << *iter << " not found" << endl;
840 MIL << "Install " << *iter << endl;
841 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
842 queue_push( &(_jobQueue), id );
845 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
846 sat::detail::IdType ident( (*iter)->satSolvable().ident().id() );
847 MIL << "Delete " << *iter << ident << endl;
848 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_NAME | MAYBE_CLEANDEPS );
849 queue_push( &(_jobQueue), ident);
852 // set requirements for a running system
853 setSystemRequirements();
855 // set locks for the solver
859 bool ret = solving();
861 MIL << "SATResolver::resolveQueue() done. Ret:" << ret << endl;
865 /** \todo duplicate code to be joined with \ref solving. */
866 void SATResolver::doUpdate()
868 MIL << "SATResolver::doUpdate()" << endl;
871 solverInit(PoolItemList());
873 // set requirements for a running system
874 setSystemRequirements();
876 // set locks for the solver
879 _solv = solver_create( _SATPool );
880 ::pool_set_custom_vendorcheck( _SATPool, &vendorCheck );
882 queue_push( &(_jobQueue), SOLVER_VERIFY|SOLVER_SOLVABLE_ALL);
883 queue_push( &(_jobQueue), 0 );
886 queue_push( &(_jobQueue), SOLVER_UPDATE|SOLVER_SOLVABLE_ALL);
887 queue_push( &(_jobQueue), 0 );
890 queue_push( &(_jobQueue), SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_ALL);
891 queue_push( &(_jobQueue), 0 );
893 if (_distupgrade_removeunsupported) {
894 queue_push( &(_jobQueue), SOLVER_DROP_ORPHANED|SOLVER_SOLVABLE_ALL);
895 queue_push( &(_jobQueue), 0 );
897 solver_set_flag(_solv, SOLVER_FLAG_ADD_ALREADY_RECOMMENDED, !_ignorealreadyrecommended);
898 solver_set_flag(_solv, SOLVER_FLAG_ALLOW_DOWNGRADE, _allowdowngrade);
899 solver_set_flag(_solv, SOLVER_FLAG_ALLOW_UNINSTALL, _allowuninstall);
900 solver_set_flag(_solv, SOLVER_FLAG_ALLOW_ARCHCHANGE, _allowarchchange);
901 solver_set_flag(_solv, SOLVER_FLAG_ALLOW_VENDORCHANGE, _allowvendorchange);
902 solver_set_flag(_solv, SOLVER_FLAG_SPLITPROVIDES, _dosplitprovides);
903 solver_set_flag(_solv, SOLVER_FLAG_NO_UPDATEPROVIDE, _noupdateprovide);
904 solver_set_flag(_solv, SOLVER_FLAG_IGNORE_RECOMMENDED, _onlyRequires);
906 sat::Pool::instance().prepareForSolving();
909 MIL << "Starting solving for update...." << endl;
911 solver_solve( _solv, &(_jobQueue) );
912 MIL << "....Solver end" << endl;
914 // copying solution back to zypp pool
915 //-----------------------------------------
917 /* solvables to be installed */
919 queue_init(&decisionq);
920 solver_get_decisionqueue(_solv, &decisionq);
921 for (int i = 0; i < decisionq.count; i++)
924 p = decisionq.elements[i];
925 if (p < 0 || !sat::Solvable(p))
927 if (sat::Solvable(p).repository().get() == _solv->pool->installed)
930 PoolItem poolItem = _pool.find (sat::Solvable(p));
932 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
934 ERR << "id " << p << " not found in ZYPP pool." << endl;
937 queue_free(&decisionq);
939 /* solvables to be erased */
940 for (int i = _solv->pool->installed->start; i < _solv->pool->installed->start + _solv->pool->installed->nsolvables; i++)
942 if (solver_get_decisionlevel(_solv, i) > 0)
945 PoolItem poolItem( _pool.find( sat::Solvable(i) ) );
947 // Check if this is an update
948 CheckIfUpdate info( (sat::Solvable(i)) );
949 invokeOnEach( _pool.byIdentBegin( poolItem ),
950 _pool.byIdentEnd( poolItem ),
951 resfilter::ByUninstalled(), // ByUninstalled
952 functor::functorRef<bool,PoolItem> (info) );
954 if (info.is_updated) {
955 SATSolutionToPool (poolItem, ResStatus::toBeUninstalledDueToUpgrade , ResStatus::SOLVER);
957 SATSolutionToPool (poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER);
960 ERR << "id " << i << " not found in ZYPP pool." << endl;
963 MIL << "SATResolver::doUpdate() done" << endl;
968 //----------------------------------------------------------------------------
969 //----------------------------------------------------------------------------
971 //----------------------------------------------------------------------------
972 //----------------------------------------------------------------------------
974 //----------------------------------------------------------------------------
976 //----------------------------------------------------------------------------
978 struct FindPackage : public resfilter::ResObjectFilterFunctor
980 ProblemSolutionCombi *problemSolution;
981 TransactionKind action;
982 FindPackage (ProblemSolutionCombi *p, const TransactionKind act)
983 : problemSolution (p)
988 bool operator()( PoolItem p)
990 problemSolution->addSingleAction (p, action);
996 //----------------------------------------------------------------------------
997 // Checking if this solvable/item has a buddy which reflect the real
998 // user visible description of an item
999 // e.g. The release package has a buddy to the concerning product item.
1000 // This user want's the message "Product foo conflicts with product bar" and
1001 // NOT "package release-foo conflicts with package release-bar"
1002 // (ma: that's why we should map just packages to buddies, not vice versa)
1003 //----------------------------------------------------------------------------
1004 inline sat::Solvable mapBuddy( const PoolItem & item_r )
1006 if ( item_r.satSolvable().isKind<Package>() )
1008 sat::Solvable buddy = item_r.buddy();
1012 return item_r.satSolvable();
1014 inline sat::Solvable mapBuddy( sat::Solvable item_r )
1015 { return mapBuddy( PoolItem( item_r ) ); }
1017 PoolItem SATResolver::mapItem ( const PoolItem & item )
1018 { return PoolItem( mapBuddy( item ) ); }
1020 sat::Solvable SATResolver::mapSolvable ( const Id & id )
1021 { return mapBuddy( sat::Solvable(id) ); }
1023 string SATResolver::SATprobleminfoString(Id problem, string &detail, Id &ignoreId)
1026 Pool *pool = _solv->pool;
1028 Id dep, source, target;
1029 sat::Solvable s, s2;
1033 // FIXME: solver_findallproblemrules to get all rules for this problem
1034 // (the 'most relevabt' one returned by solver_findproblemrule is embedded
1035 probr = solver_findproblemrule(_solv, problem);
1036 switch (solver_ruleinfo(_solv, probr, &source, &target, &dep))
1038 case SOLVER_RULE_DISTUPGRADE:
1039 s = mapSolvable (source);
1040 ret = str::form (_("%s does not belong to a distupgrade repository"), s.asString().c_str());
1042 case SOLVER_RULE_INFARCH:
1043 s = mapSolvable (source);
1044 ret = str::form (_("%s has inferior architecture"), s.asString().c_str());
1046 case SOLVER_RULE_UPDATE:
1047 s = mapSolvable (source);
1048 ret = str::form (_("problem with installed package %s"), s.asString().c_str());
1050 case SOLVER_RULE_JOB:
1051 ret = _("conflicting requests");
1053 case SOLVER_RULE_RPM:
1054 ret = _("some dependency problem");
1056 case SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP:
1057 ret = str::form (_("nothing provides requested %s"), pool_dep2str(pool, dep));
1058 detail += _("Have you enabled all requested repositories?");
1060 case SOLVER_RULE_JOB_UNKNOWN_PACKAGE:
1061 ret = str::form (_("package %s does not exist"), pool_dep2str(pool, dep));
1062 detail += _("Have you enabled all requested repositories?");
1064 case SOLVER_RULE_JOB_UNSUPPORTED:
1065 ret = _("unsupported request");
1067 case SOLVER_RULE_JOB_PROVIDED_BY_SYSTEM:
1068 ret = str::form (_("%s is provided by the system and cannot be erased"), pool_dep2str(pool, dep));
1070 case SOLVER_RULE_RPM_NOT_INSTALLABLE:
1071 s = mapSolvable (source);
1072 ret = str::form (_("%s is not installable"), s.asString().c_str());
1074 case SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP:
1075 ignoreId = source; // for setting weak dependencies
1076 s = mapSolvable (source);
1077 ret = str::form (_("nothing provides %s needed by %s"), pool_dep2str(pool, dep), s.asString().c_str());
1079 case SOLVER_RULE_RPM_SAME_NAME:
1080 s = mapSolvable (source);
1081 s2 = mapSolvable (target);
1082 ret = str::form (_("cannot install both %s and %s"), s.asString().c_str(), s2.asString().c_str());
1084 case SOLVER_RULE_RPM_PACKAGE_CONFLICT:
1085 s = mapSolvable (source);
1086 s2 = mapSolvable (target);
1087 ret = str::form (_("%s conflicts with %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1089 case SOLVER_RULE_RPM_PACKAGE_OBSOLETES:
1090 s = mapSolvable (source);
1091 s2 = mapSolvable (target);
1092 ret = str::form (_("%s obsoletes %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1094 case SOLVER_RULE_RPM_INSTALLEDPKG_OBSOLETES:
1095 s = mapSolvable (source);
1096 s2 = mapSolvable (target);
1097 ret = str::form (_("installed %s obsoletes %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1099 case SOLVER_RULE_RPM_SELF_CONFLICT:
1100 s = mapSolvable (source);
1101 ret = str::form (_("solvable %s conflicts with %s provided by itself"), s.asString().c_str(), pool_dep2str(pool, dep));
1103 case SOLVER_RULE_RPM_PACKAGE_REQUIRES:
1104 ignoreId = source; // for setting weak dependencies
1105 s = mapSolvable (source);
1106 Capability cap(dep);
1107 sat::WhatProvides possibleProviders(cap);
1109 // check, if a provider will be deleted
1110 typedef list<PoolItem> ProviderList;
1111 ProviderList providerlistInstalled, providerlistUninstalled;
1112 for_( iter1, possibleProviders.begin(), possibleProviders.end() ) {
1113 PoolItem provider1 = ResPool::instance().find( *iter1 );
1114 // find pair of an installed/uninstalled item with the same NVR
1116 for_( iter2, possibleProviders.begin(), possibleProviders.end() ) {
1117 PoolItem provider2 = ResPool::instance().find( *iter2 );
1118 if (compareByNVR (provider1.resolvable(),provider2.resolvable()) == 0
1119 && ( (provider1.status().isInstalled() && provider2.status().isUninstalled())
1120 || (provider2.status().isInstalled() && provider1.status().isUninstalled()) )) {
1126 if (provider1.status().isInstalled())
1127 providerlistInstalled.push_back(provider1);
1129 providerlistUninstalled.push_back(provider1);
1133 ret = str::form (_("%s requires %s, but this requirement cannot be provided"), s.asString().c_str(), pool_dep2str(pool, dep));
1134 if (providerlistInstalled.size() > 0) {
1135 detail += _("deleted providers: ");
1136 for (ProviderList::const_iterator iter = providerlistInstalled.begin(); iter != providerlistInstalled.end(); iter++) {
1137 if (iter == providerlistInstalled.begin())
1138 detail += itemToString( *iter );
1140 detail += "\n " + itemToString( mapItem(*iter) );
1143 if (providerlistUninstalled.size() > 0) {
1144 if (detail.size() > 0)
1145 detail += _("\nuninstallable providers: ");
1147 detail = _("uninstallable providers: ");
1148 for (ProviderList::const_iterator iter = providerlistUninstalled.begin(); iter != providerlistUninstalled.end(); iter++) {
1149 if (iter == providerlistUninstalled.begin())
1150 detail += itemToString( *iter );
1152 detail += "\n " + itemToString( mapItem(*iter) );
1162 SATResolver::problems ()
1164 ResolverProblemList resolverProblems;
1165 if (_solv && solver_problem_count(_solv)) {
1166 Pool *pool = _solv->pool;
1169 Id problem, solution, element;
1170 sat::Solvable s, sd;
1172 CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1173 CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1175 MIL << "Encountered problems! Here are the solutions:\n" << endl;
1178 while ((problem = solver_next_problem(_solv, problem)) != 0) {
1179 MIL << "Problem " << pcnt++ << ":" << endl;
1180 MIL << "====================================" << endl;
1183 string whatString = SATprobleminfoString (problem,detail,ignoreId);
1184 MIL << whatString << endl;
1185 MIL << "------------------------------------" << endl;
1186 ResolverProblem_Ptr resolverProblem = new ResolverProblem (whatString, detail);
1189 while ((solution = solver_next_solution(_solv, problem, solution)) != 0) {
1191 ProblemSolutionCombi *problemSolution = new ProblemSolutionCombi(resolverProblem);
1192 while ((element = solver_next_solutionelement(_solv, problem, solution, element, &p, &rp)) != 0) {
1193 if (p == SOLVER_SOLUTION_JOB) {
1194 /* job, rp is index into job queue */
1195 what = _jobQueue.elements[rp];
1196 switch (_jobQueue.elements[rp-1]&(SOLVER_SELECTMASK|SOLVER_JOBMASK))
1198 case SOLVER_INSTALL | SOLVER_SOLVABLE: {
1199 s = mapSolvable (what);
1200 PoolItem poolItem = _pool.find (s);
1202 if (pool->installed && s.get()->repo == pool->installed) {
1203 problemSolution->addSingleAction (poolItem, REMOVE);
1204 string description = str::form (_("do not keep %s installed"), s.asString().c_str() );
1205 MIL << description << endl;
1206 problemSolution->addDescription (description);
1208 problemSolution->addSingleAction (poolItem, KEEP);
1209 string description = str::form (_("do not install %s"), s.asString().c_str());
1210 MIL << description << endl;
1211 problemSolution->addDescription (description);
1214 ERR << "SOLVER_INSTALL_SOLVABLE: No item found for " << s.asString() << endl;
1218 case SOLVER_ERASE | SOLVER_SOLVABLE: {
1219 s = mapSolvable (what);
1220 PoolItem poolItem = _pool.find (s);
1222 if (pool->installed && s.get()->repo == pool->installed) {
1223 problemSolution->addSingleAction (poolItem, KEEP);
1224 string description = str::form (_("keep %s"), s.asString().c_str());
1225 MIL << description << endl;
1226 problemSolution->addDescription (description);
1228 problemSolution->addSingleAction (poolItem, UNLOCK);
1229 string description = str::form (_("do not forbid installation of %s"), itemToString( poolItem ).c_str());
1230 MIL << description << endl;
1231 problemSolution->addDescription (description);
1234 ERR << "SOLVER_ERASE_SOLVABLE: No item found for " << s.asString() << endl;
1238 case SOLVER_INSTALL | SOLVER_SOLVABLE_NAME:
1240 IdString ident( what );
1241 SolverQueueItemInstall_Ptr install =
1242 new SolverQueueItemInstall(_pool, ident.asString(), false );
1243 problemSolution->addSingleAction (install, REMOVE_SOLVE_QUEUE_ITEM);
1245 string description = str::form (_("do not install %s"), ident.c_str() );
1246 MIL << description << endl;
1247 problemSolution->addDescription (description);
1250 case SOLVER_ERASE | SOLVER_SOLVABLE_NAME:
1252 // As we do not know, if this request has come from resolvePool or
1253 // resolveQueue we will have to take care for both cases.
1254 IdString ident( what );
1255 FindPackage info (problemSolution, KEEP);
1256 invokeOnEach( _pool.byIdentBegin( ident ),
1257 _pool.byIdentEnd( ident ),
1258 functor::chain (resfilter::ByInstalled (), // ByInstalled
1259 resfilter::ByTransact ()), // will be deinstalled
1260 functor::functorRef<bool,PoolItem> (info) );
1262 SolverQueueItemDelete_Ptr del =
1263 new SolverQueueItemDelete(_pool, ident.asString(), false );
1264 problemSolution->addSingleAction (del, REMOVE_SOLVE_QUEUE_ITEM);
1266 string description = str::form (_("keep %s"), ident.c_str());
1267 MIL << description << endl;
1268 problemSolution->addDescription (description);
1271 case SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES:
1273 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_REQUIRE);
1274 string description = "";
1276 // Checking if this problem solution would break your system
1277 if (system_requires.find(Capability(what)) != system_requires.end()) {
1278 // Show a better warning
1279 resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1280 resolverProblem->setDescription(_("This request will break your system!"));
1281 description = _("ignore the warning of a broken system");
1282 description += string(" (requires:")+pool_dep2str(pool, what)+")";
1283 MIL << description << endl;
1284 problemSolution->addFrontDescription (description);
1286 description = str::form (_("do not ask to install a solvable providing %s"), pool_dep2str(pool, what));
1287 MIL << description << endl;
1288 problemSolution->addDescription (description);
1292 case SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES:
1294 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_CONFLICT);
1295 string description = "";
1297 // Checking if this problem solution would break your system
1298 if (system_conflicts.find(Capability(what)) != system_conflicts.end()) {
1299 // Show a better warning
1300 resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1301 resolverProblem->setDescription(_("This request will break your system!"));
1302 description = _("ignore the warning of a broken system");
1303 description += string(" (conflicts:")+pool_dep2str(pool, what)+")";
1304 MIL << description << endl;
1305 problemSolution->addFrontDescription (description);
1308 description = str::form (_("do not ask to delete all solvables providing %s"), pool_dep2str(pool, what));
1309 MIL << description << endl;
1310 problemSolution->addDescription (description);
1314 case SOLVER_UPDATE | SOLVER_SOLVABLE:
1316 s = mapSolvable (what);
1317 PoolItem poolItem = _pool.find (s);
1319 if (pool->installed && s.get()->repo == pool->installed) {
1320 problemSolution->addSingleAction (poolItem, KEEP);
1321 string description = str::form (_("do not install most recent version of %s"), s.asString().c_str());
1322 MIL << description << endl;
1323 problemSolution->addDescription (description);
1325 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE " << poolItem << " is not selected for installation" << endl;
1328 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE: No item found for " << s.asString() << endl;
1333 MIL << "- do something different" << endl;
1334 ERR << "No valid solution available" << endl;
1337 } else if (p == SOLVER_SOLUTION_INFARCH) {
1338 s = mapSolvable (rp);
1339 PoolItem poolItem = _pool.find (s);
1340 if (pool->installed && s.get()->repo == pool->installed) {
1341 problemSolution->addSingleAction (poolItem, LOCK);
1342 string description = str::form (_("keep %s despite the inferior architecture"), s.asString().c_str());
1343 MIL << description << endl;
1344 problemSolution->addDescription (description);
1346 problemSolution->addSingleAction (poolItem, INSTALL);
1347 string description = str::form (_("install %s despite the inferior architecture"), s.asString().c_str());
1348 MIL << description << endl;
1349 problemSolution->addDescription (description);
1351 } else if (p == SOLVER_SOLUTION_DISTUPGRADE) {
1352 s = mapSolvable (rp);
1353 PoolItem poolItem = _pool.find (s);
1354 if (pool->installed && s.get()->repo == pool->installed) {
1355 problemSolution->addSingleAction (poolItem, LOCK);
1356 string description = str::form (_("keep obsolete %s"), s.asString().c_str());
1357 MIL << description << endl;
1358 problemSolution->addDescription (description);
1360 problemSolution->addSingleAction (poolItem, INSTALL);
1361 string description = str::form (_("install %s from excluded repository"), s.asString().c_str());
1362 MIL << description << endl;
1363 problemSolution->addDescription (description);
1366 /* policy, replace p with rp */
1367 s = mapSolvable (p);
1368 PoolItem itemFrom = _pool.find (s);
1373 sd = mapSolvable (rp);
1374 PoolItem itemTo = _pool.find (sd);
1375 if (itemFrom && itemTo) {
1376 problemSolution->addSingleAction (itemTo, INSTALL);
1377 int illegal = policy_is_illegal(_solv, s.get(), sd.get(), 0);
1379 if ((illegal & POLICY_ILLEGAL_DOWNGRADE) != 0)
1381 string description = str::form (_("downgrade of %s to %s"), s.asString().c_str(), sd.asString().c_str());
1382 MIL << description << endl;
1383 problemSolution->addDescription (description);
1386 if ((illegal & POLICY_ILLEGAL_ARCHCHANGE) != 0)
1388 string description = str::form (_("architecture change of %s to %s"), s.asString().c_str(), sd.asString().c_str());
1389 MIL << description << endl;
1390 problemSolution->addDescription (description);
1393 if ((illegal & POLICY_ILLEGAL_VENDORCHANGE) != 0)
1395 IdString s_vendor( s.vendor() );
1396 IdString sd_vendor( sd.vendor() );
1397 string description = str::form (_("install %s (with vendor change)\n %s --> %s") ,
1398 sd.asString().c_str(),
1399 ( s_vendor ? s_vendor.c_str() : " (no vendor) " ),
1400 ( sd_vendor ? sd_vendor.c_str() : " (no vendor) " ) );
1401 MIL << description << endl;
1402 problemSolution->addDescription (description);
1406 string description = str::form (_("replacement of %s with %s"), s.asString().c_str(), sd.asString().c_str());
1407 MIL << description << endl;
1408 problemSolution->addDescription (description);
1411 ERR << s.asString() << " or " << sd.asString() << " not found" << endl;
1417 string description = str::form (_("deinstallation of %s"), s.asString().c_str());
1418 MIL << description << endl;
1419 problemSolution->addDescription (description);
1420 problemSolution->addSingleAction (itemFrom, REMOVE);
1425 resolverProblem->addSolution (problemSolution,
1426 problemSolution->actionCount() > 1 ? true : false); // Solutions with more than 1 action will be shown first.
1427 MIL << "------------------------------------" << endl;
1431 // There is a possibility to ignore this error by setting weak dependencies
1432 PoolItem item = _pool.find (sat::Solvable(ignoreId));
1433 ProblemSolutionIgnore *problemSolution = new ProblemSolutionIgnore(resolverProblem, item);
1434 resolverProblem->addSolution (problemSolution,
1435 false); // Solutions will be shown at the end
1436 MIL << "ignore some dependencies of " << item << endl;
1437 MIL << "------------------------------------" << endl;
1441 resolverProblems.push_back (resolverProblem);
1444 return resolverProblems;
1448 SATResolver::applySolutions (const ProblemSolutionList & solutions)
1450 for (ProblemSolutionList::const_iterator iter = solutions.begin();
1451 iter != solutions.end(); ++iter) {
1452 ProblemSolution_Ptr solution = *iter;
1453 Resolver dummyResolver(_pool);
1454 if (!solution->apply (dummyResolver))
1459 void SATResolver::setLocks()
1461 for (PoolItemList::const_iterator iter = _items_to_lock.begin(); iter != _items_to_lock.end(); ++iter) {
1462 sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
1463 if (iter->status().isInstalled()) {
1464 MIL << "Lock installed item " << *iter << endl;
1465 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
1466 queue_push( &(_jobQueue), ident );
1468 MIL << "Lock NOT installed item " << *iter << endl;
1469 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE | MAYBE_CLEANDEPS );
1470 queue_push( &(_jobQueue), ident );
1474 ///////////////////////////////////////////////////////////////////
1475 // Weak locks: Ignore if an item with this name is already installed.
1476 // If it's not installed try to keep it this way using a weak delete
1477 ///////////////////////////////////////////////////////////////////
1478 std::set<IdString> unifiedByName;
1479 for (PoolItemList::const_iterator iter = _items_to_keep.begin(); iter != _items_to_keep.end(); ++iter) {
1480 IdString ident( (*iter)->satSolvable().ident() );
1481 if ( unifiedByName.insert( ident ).second )
1483 if ( ! ui::Selectable::get( *iter )->hasInstalledObj() )
1485 MIL << "Keep NOT installed name " << ident << " (" << *iter << ")" << endl;
1486 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_NAME | SOLVER_WEAK | MAYBE_CLEANDEPS );
1487 queue_push( &(_jobQueue), ident.id() );
1493 void SATResolver::setSystemRequirements()
1495 CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1496 CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1498 for (CapabilitySet::const_iterator iter = system_requires.begin(); iter != system_requires.end(); ++iter) {
1499 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES );
1500 queue_push( &(_jobQueue), iter->id() );
1501 MIL << "SYSTEM Requires " << *iter << endl;
1504 for (CapabilitySet::const_iterator iter = system_conflicts.begin(); iter != system_conflicts.end(); ++iter) {
1505 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES | MAYBE_CLEANDEPS );
1506 queue_push( &(_jobQueue), iter->id() );
1507 MIL << "SYSTEM Conflicts " << *iter << endl;
1510 // Lock the architecture of the running systems rpm
1511 // package on distupgrade.
1512 if ( _distupgrade && ZConfig::instance().systemRoot() == "/" )
1514 ResPool pool( ResPool::instance() );
1515 IdString rpm( "rpm" );
1516 for_( it, pool.byIdentBegin(rpm), pool.byIdentEnd(rpm) )
1518 if ( (*it)->isSystem() )
1520 Capability archrule( (*it)->arch(), rpm.c_str(), Capability::PARSED );
1521 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_NAME | SOLVER_ESSENTIAL );
1522 queue_push( &(_jobQueue), archrule.id() );
1529 sat::StringQueue SATResolver::autoInstalled() const
1531 sat::StringQueue ret;
1533 ::solver_get_userinstalled( _solv, ret, GET_USERINSTALLED_NAMES|GET_USERINSTALLED_INVERTED );
1537 sat::StringQueue SATResolver::userInstalled() const
1539 sat::StringQueue ret;
1541 ::solver_get_userinstalled( _solv, ret, GET_USERINSTALLED_NAMES );
1546 ///////////////////////////////////////////////////////////////////
1547 };// namespace detail
1548 /////////////////////////////////////////////////////////////////////
1549 /////////////////////////////////////////////////////////////////////
1550 };// namespace solver
1551 ///////////////////////////////////////////////////////////////////////
1552 ///////////////////////////////////////////////////////////////////////
1554 /////////////////////////////////////////////////////////////////////////