1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
4 * Copyright (C) 2000-2002 Ximian, Inc.
5 * Copyright (C) 2005 SUSE Linux Products GmbH
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License,
9 * version 2, as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 #include <solv/repo_solv.h>
24 #include <solv/poolarch.h>
26 #include <solv/poolvendor.h>
27 #include <solv/policy.h>
28 #include <solv/bitmap.h>
29 #include <solv/queue.h>
32 #define ZYPP_USE_RESOLVER_INTERNALS
34 #include "zypp/base/String.h"
35 #include "zypp/Product.h"
36 #include "zypp/Capability.h"
37 #include "zypp/ResStatus.h"
38 #include "zypp/VendorAttr.h"
39 #include "zypp/base/LogTools.h"
40 #include "zypp/base/String.h"
41 #include "zypp/base/Gettext.h"
42 #include "zypp/base/Algorithm.h"
43 #include "zypp/ResPool.h"
44 #include "zypp/ResFilters.h"
45 #include "zypp/ZConfig.h"
46 #include "zypp/sat/Pool.h"
47 #include "zypp/sat/WhatProvides.h"
48 #include "zypp/sat/WhatObsoletes.h"
49 #include "zypp/solver/detail/Resolver.h"
50 #include "zypp/solver/detail/SATResolver.h"
51 #include "zypp/solver/detail/ProblemSolutionCombi.h"
52 #include "zypp/solver/detail/ProblemSolutionIgnore.h"
53 #include "zypp/solver/detail/SolverQueueItemInstall.h"
54 #include "zypp/solver/detail/SolverQueueItemDelete.h"
55 #include "zypp/solver/detail/SystemCheck.h"
56 #include "zypp/solver/detail/SolutionAction.h"
57 #include "zypp/solver/detail/SolverQueueItem.h"
58 #include "zypp/sat/Transaction.h"
59 #include "zypp/sat/Queue.h"
61 #include "zypp/sat/detail/PoolImpl.h"
63 #define _XDEBUG(x) do { if (base::logger::isExcessive()) XXX << x << std::endl;} while (0)
65 /////////////////////////////////////////////////////////////////////////
67 { ///////////////////////////////////////////////////////////////////////
69 /////////////////////////////////////////////////////////////////////////
72 inline bool HACKENV( const char * var_r, bool default_r )
75 const char * val = ::getenv( var_r );
78 ret = str::strToBool( val, default_r );
79 if ( ret != default_r )
80 INT << "HACKENV " << var_r << " = " << ret << endl;
85 /////////////////////////////////////////////////////////////////////////
87 ///////////////////////////////////////////////////////////////////////
89 { /////////////////////////////////////////////////////////////////////
90 /////////////////////////////////////////////////////////////////////
92 { ///////////////////////////////////////////////////////////////////
96 IMPL_PTR_TYPE(SATResolver);
98 #define MAYBE_CLEANDEPS (cleandepsOnRemove()?SOLVER_CLEANDEPS:0)
100 //---------------------------------------------------------------------------
101 // Callbacks for SAT policies
102 //---------------------------------------------------------------------------
104 int vendorCheck( Pool *pool, Solvable *solvable1, Solvable *solvable2 )
106 return VendorAttr::instance().equivalent( IdString(solvable1->vendor),
107 IdString(solvable2->vendor) ) ? 0 : 1;
111 inline std::string itemToString( const PoolItem & item )
114 return std::string();
116 sat::Solvable slv( item.satSolvable() );
117 std::string ret( slv.asString() ); // n-v-r.a
118 if ( ! slv.isSystem() )
121 ret += slv.repository().alias();
127 inline PoolItem getPoolItem( Id id_r )
129 PoolItem ret( (sat::Solvable( id_r )) );
131 INT << "id " << id_r << " not found in ZYPP pool." << endl;
135 //---------------------------------------------------------------------------
138 SATResolver::dumpOn( std::ostream & os ) const
140 os << "<resolver>" << endl;
142 #define OUTS(X) os << " " << #X << "\t= " << solver_get_flag(_solv, SOLVER_FLAG_##X) << endl
143 OUTS( ALLOW_DOWNGRADE );
144 OUTS( ALLOW_ARCHCHANGE );
145 OUTS( ALLOW_VENDORCHANGE );
146 OUTS( ALLOW_UNINSTALL );
147 OUTS( NO_UPDATEPROVIDE );
148 OUTS( SPLITPROVIDES );
149 OUTS( IGNORE_RECOMMENDED );
150 OUTS( ADD_ALREADY_RECOMMENDED );
151 OUTS( NO_INFARCHCHECK );
152 OUTS( ALLOW_NAMECHANGE );
153 OUTS( KEEP_EXPLICIT_OBSOLETES );
154 OUTS( BEST_OBEY_POLICY );
155 OUTS( NO_AUTOTARGET );
156 OUTS( DUP_ALLOW_DOWNGRADE );
157 OUTS( DUP_ALLOW_ARCHCHANGE );
158 OUTS( DUP_ALLOW_VENDORCHANGE );
159 OUTS( DUP_ALLOW_NAMECHANGE );
160 OUTS( KEEP_ORPHANS );
161 OUTS( BREAK_ORPHANS );
162 OUTS( FOCUS_INSTALLED );
163 OUTS( YUM_OBSOLETES );
165 os << " distupgrade = " << _distupgrade << endl;
166 os << " distupgrade_removeunsupported = " << _distupgrade_removeunsupported << endl;
167 os << " solveSrcPackages = " << _solveSrcPackages << endl;
168 os << " cleandepsOnRemove = " << _cleandepsOnRemove << endl;
169 os << " fixsystem = " << _fixsystem << endl;
173 return os << "<resolver/>" << endl;
176 //---------------------------------------------------------------------------
178 SATResolver::SATResolver (const ResPool & pool, Pool *SATPool)
183 , _allowdowngrade(false)
184 , _allowarchchange(false)
185 , _allowvendorchange(ZConfig::instance().solver_allowVendorChange())
186 , _allowuninstall(false)
187 , _updatesystem(false)
188 , _noupdateprovide(false)
189 , _dosplitprovides(true)
190 , _onlyRequires(ZConfig::instance().solver_onlyRequires())
191 , _ignorealreadyrecommended(true)
192 , _distupgrade(false)
193 , _distupgrade_removeunsupported(false)
194 , _dup_allowdowngrade ( ZConfig::instance().solver_dupAllowDowngrade() )
195 , _dup_allownamechange ( ZConfig::instance().solver_dupAllowNameChange() )
196 , _dup_allowarchchange ( ZConfig::instance().solver_dupAllowArchChange() )
197 , _dup_allowvendorchange ( ZConfig::instance().solver_dupAllowVendorChange() )
198 , _solveSrcPackages(false)
199 , _cleandepsOnRemove(ZConfig::instance().solver_cleandepsOnRemove())
204 SATResolver::~SATResolver()
209 //---------------------------------------------------------------------------
212 SATResolver::pool (void) const
218 SATResolver::resetItemTransaction (PoolItem item)
221 for (PoolItemList::const_iterator iter = _items_to_remove.begin();
222 iter != _items_to_remove.end(); ++iter) {
224 _items_to_remove.remove(*iter);
230 for (PoolItemList::const_iterator iter = _items_to_install.begin();
231 iter != _items_to_install.end(); ++iter) {
233 _items_to_install.remove(*iter);
240 for (PoolItemList::const_iterator iter = _items_to_keep.begin();
241 iter != _items_to_keep.end(); ++iter) {
243 _items_to_keep.remove(*iter);
250 for (PoolItemList::const_iterator iter = _items_to_lock.begin();
251 iter != _items_to_lock.end(); ++iter) {
253 _items_to_lock.remove(*iter);
263 SATResolver::addPoolItemToInstall (PoolItem item)
265 resetItemTransaction (item);
266 _items_to_install.push_back (item);
267 _items_to_install.unique ();
272 SATResolver::addPoolItemsToInstallFromList (PoolItemList & rl)
274 for (PoolItemList::const_iterator iter = rl.begin(); iter != rl.end(); iter++) {
275 addPoolItemToInstall (*iter);
281 SATResolver::addPoolItemToRemove (PoolItem item)
283 resetItemTransaction (item);
284 _items_to_remove.push_back (item);
285 _items_to_remove.unique ();
290 SATResolver::addPoolItemsToRemoveFromList (PoolItemList & rl)
292 for (PoolItemList::const_iterator iter = rl.begin(); iter != rl.end(); iter++) {
293 addPoolItemToRemove (*iter);
298 SATResolver::addPoolItemToLock (PoolItem item)
300 resetItemTransaction (item);
301 _items_to_lock.push_back (item);
302 _items_to_lock.unique ();
306 SATResolver::addPoolItemToKeep (PoolItem item)
308 resetItemTransaction (item);
309 _items_to_keep.push_back (item);
310 _items_to_keep.unique ();
313 //---------------------------------------------------------------------------
315 // copy marked item from solution back to pool
316 // if data != NULL, set as APPL_LOW (from establishPool())
319 SATSolutionToPool (PoolItem item, const ResStatus & status, const ResStatus::TransactByValue causer)
322 item.status().resetTransact (causer);
323 item.status().resetWeak ();
327 // installation/deletion
328 if (status.isToBeInstalled()) {
329 r = item.status().setToBeInstalled (causer);
330 _XDEBUG("SATSolutionToPool install returns " << item << ", " << r);
332 else if (status.isToBeUninstalledDueToUpgrade()) {
333 r = item.status().setToBeUninstalledDueToUpgrade (causer);
334 _XDEBUG("SATSolutionToPool upgrade returns " << item << ", " << r);
336 else if (status.isToBeUninstalled()) {
337 r = item.status().setToBeUninstalled (causer);
338 _XDEBUG("SATSolutionToPool remove returns " << item << ", " << r);
344 //----------------------------------------------------------------------------
345 //----------------------------------------------------------------------------
347 //----------------------------------------------------------------------------
348 //----------------------------------------------------------------------------
350 //----------------------------------------------------------------------------
351 // Helper functions for the ZYPP-Pool
352 //----------------------------------------------------------------------------
355 //------------------------------------------------------------------------------------------------------------
356 // This function loops over the pool and grabs all items
357 // It clears all previous bySolver() states also
359 // Every toBeInstalled is passed to zypp::solver:detail::Resolver.addPoolItemToInstall()
360 // Every toBeUninstalled is passed to zypp::solver:detail::Resolver.addPoolItemToRemove()
362 // Solver results must be written back to the pool.
363 //------------------------------------------------------------------------------------------------------------
366 struct SATCollectTransact : public resfilter::PoolItemFilterFunctor
368 SATResolver & resolver;
370 SATCollectTransact (SATResolver & r)
374 bool operator()( PoolItem item ) // only transacts() items go here
376 ResStatus status = item.status();
377 bool by_solver = (status.isBySolver() || status.isByApplLow());
380 item.status().resetTransact( ResStatus::APPL_LOW );// clear any solver/establish transactions
381 return true; // back out here, dont re-queue former solver result
384 if ( item.satSolvable().isKind<SrcPackage>() && ! resolver.solveSrcPackages() )
386 // Later we may continue on a per source package base.
387 return true; // dont process this source package.
390 if (status.isToBeInstalled()) {
391 resolver.addPoolItemToInstall(item); // -> install!
393 else if (status.isToBeUninstalled()) {
394 resolver.addPoolItemToRemove(item); // -> remove !
396 else if (status.isLocked()
398 resolver.addPoolItemToLock (item);
400 else if (status.isKept()
402 resolver.addPoolItemToKeep (item);
410 //----------------------------------------------------------------------------
411 //----------------------------------------------------------------------------
413 //----------------------------------------------------------------------------
414 //----------------------------------------------------------------------------
417 class CheckIfUpdate : public resfilter::PoolItemFilterFunctor
421 sat::Solvable _installed;
423 CheckIfUpdate( const sat::Solvable & installed_r )
424 : is_updated( false )
425 , _installed( installed_r )
428 // check this item will be updated
430 bool operator()( const PoolItem & item )
432 if ( item.status().isToBeInstalled() )
434 if ( ! item.multiversionInstall() || sameNVRA( _installed, item ) )
445 class CollectPseudoInstalled : public resfilter::PoolItemFilterFunctor
448 Queue *solvableQueue;
450 CollectPseudoInstalled( Queue *queue )
451 :solvableQueue (queue)
454 // collecting PseudoInstalled items
455 bool operator()( PoolItem item )
457 if ( traits::isPseudoInstalled( item.satSolvable().kind() ) )
458 queue_push( solvableQueue, item.satSolvable().id() );
464 SATResolver::solving(const CapabilitySet & requires_caps,
465 const CapabilitySet & conflict_caps)
467 _solv = solver_create( _SATPool );
468 ::pool_set_custom_vendorcheck( _SATPool, &vendorCheck );
470 queue_push( &(_jobQueue), SOLVER_VERIFY|SOLVER_SOLVABLE_ALL);
471 queue_push( &(_jobQueue), 0 );
474 queue_push( &(_jobQueue), SOLVER_UPDATE|SOLVER_SOLVABLE_ALL);
475 queue_push( &(_jobQueue), 0 );
478 queue_push( &(_jobQueue), SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_ALL);
479 queue_push( &(_jobQueue), 0 );
481 if (_distupgrade_removeunsupported) {
482 queue_push( &(_jobQueue), SOLVER_DROP_ORPHANED|SOLVER_SOLVABLE_ALL);
483 queue_push( &(_jobQueue), 0 );
485 solver_set_flag(_solv, SOLVER_FLAG_ADD_ALREADY_RECOMMENDED, !_ignorealreadyrecommended);
486 solver_set_flag(_solv, SOLVER_FLAG_ALLOW_DOWNGRADE, _allowdowngrade);
487 solver_set_flag(_solv, SOLVER_FLAG_ALLOW_UNINSTALL, _allowuninstall);
488 solver_set_flag(_solv, SOLVER_FLAG_ALLOW_ARCHCHANGE, _allowarchchange);
489 solver_set_flag(_solv, SOLVER_FLAG_ALLOW_VENDORCHANGE, _allowvendorchange);
490 solver_set_flag(_solv, SOLVER_FLAG_SPLITPROVIDES, _dosplitprovides);
491 solver_set_flag(_solv, SOLVER_FLAG_NO_UPDATEPROVIDE, _noupdateprovide);
492 solver_set_flag(_solv, SOLVER_FLAG_IGNORE_RECOMMENDED, _onlyRequires);
493 solver_set_flag(_solv, SOLVER_FLAG_DUP_ALLOW_DOWNGRADE, _dup_allowdowngrade );
494 solver_set_flag(_solv, SOLVER_FLAG_DUP_ALLOW_NAMECHANGE, _dup_allownamechange );
495 solver_set_flag(_solv, SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE, _dup_allowarchchange );
496 solver_set_flag(_solv, SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE, _dup_allowvendorchange );
498 #define HACKENV(X,D) solver_set_flag(_solv, X, env::HACKENV( #X, D ) );
499 HACKENV( SOLVER_FLAG_DUP_ALLOW_DOWNGRADE, _dup_allowdowngrade );
500 HACKENV( SOLVER_FLAG_DUP_ALLOW_NAMECHANGE, _dup_allownamechange );
501 HACKENV( SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE, _dup_allowarchchange );
502 HACKENV( SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE,_dup_allowvendorchange );
505 sat::Pool::instance().prepareForSolving();
508 MIL << "Starting solving...." << endl;
510 solver_solve( _solv, &(_jobQueue) );
511 MIL << "....Solver end" << endl;
513 // copying solution back to zypp pool
514 //-----------------------------------------
515 _result_items_to_install.clear();
516 _result_items_to_remove.clear();
518 /* solvables to be installed */
520 queue_init(&decisionq);
521 solver_get_decisionqueue(_solv, &decisionq);
522 for ( int i = 0; i < decisionq.count; ++i )
524 sat::Solvable slv( decisionq.elements[i] );
525 if ( !slv || slv.isSystem() )
528 PoolItem poolItem( slv );
529 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
530 _result_items_to_install.push_back (poolItem);
532 queue_free(&decisionq);
534 /* solvables to be erased */
535 Repository systemRepo( sat::Pool::instance().findSystemRepo() ); // don't create if it does not exist
536 if ( systemRepo && ! systemRepo.solvablesEmpty() )
538 bool mustCheckObsoletes = false;
539 for_( it, systemRepo.solvablesBegin(), systemRepo.solvablesEnd() )
541 if (solver_get_decisionlevel(_solv, it->id()) > 0)
544 // Check if this is an update
545 CheckIfUpdate info( *it );
546 PoolItem poolItem( *it );
547 invokeOnEach( _pool.byIdentBegin( poolItem ),
548 _pool.byIdentEnd( poolItem ),
549 resfilter::ByUninstalled(), // ByUninstalled
550 functor::functorRef<bool,PoolItem> (info) );
552 if (info.is_updated) {
553 SATSolutionToPool( poolItem, ResStatus::toBeUninstalledDueToUpgrade, ResStatus::SOLVER );
555 SATSolutionToPool( poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER );
556 if ( ! mustCheckObsoletes )
557 mustCheckObsoletes = true; // lazy check for UninstalledDueToObsolete
559 _result_items_to_remove.push_back (poolItem);
561 if ( mustCheckObsoletes )
563 sat::WhatObsoletes obsoleted( _result_items_to_install.begin(), _result_items_to_install.end() );
564 for_( it, obsoleted.poolItemBegin(), obsoleted.poolItemEnd() )
566 ResStatus & status( it->status() );
567 // WhatObsoletes contains installed items only!
568 if ( status.transacts() && ! status.isToBeUninstalledDueToUpgrade() )
569 status.setToBeUninstalledDueToObsolete();
574 Queue recommendations;
578 queue_init(&recommendations);
579 queue_init(&suggestions);
580 queue_init(&orphaned);
581 queue_init(&unneeded);
582 solver_get_recommendations(_solv, &recommendations, &suggestions, 0);
583 solver_get_orphaned(_solv, &orphaned);
584 solver_get_unneeded(_solv, &unneeded, 1);
585 /* solvables which are recommended */
586 for ( int i = 0; i < recommendations.count; ++i )
588 PoolItem poolItem( getPoolItem( recommendations.elements[i] ) );
589 poolItem.status().setRecommended( true );
592 /* solvables which are suggested */
593 for ( int i = 0; i < suggestions.count; ++i )
595 PoolItem poolItem( getPoolItem( suggestions.elements[i] ) );
596 poolItem.status().setSuggested( true );
599 _problem_items.clear();
600 /* solvables which are orphaned */
601 for ( int i = 0; i < orphaned.count; ++i )
603 PoolItem poolItem( getPoolItem( orphaned.elements[i] ) );
604 poolItem.status().setOrphaned( true );
605 _problem_items.push_back( poolItem );
608 /* solvables which are unneeded */
609 for ( int i = 0; i < unneeded.count; ++i )
611 PoolItem poolItem( getPoolItem( unneeded.elements[i] ) );
612 poolItem.status().setUnneeded( true );
615 queue_free(&recommendations);
616 queue_free(&suggestions);
617 queue_free(&orphaned);
618 queue_free(&unneeded);
620 /* Write validation state back to pool */
621 Queue flags, solvableQueue;
624 queue_init(&solvableQueue);
626 CollectPseudoInstalled collectPseudoInstalled(&solvableQueue);
627 invokeOnEach( _pool.begin(),
629 functor::functorRef<bool,PoolItem> (collectPseudoInstalled) );
630 solver_trivial_installable(_solv, &solvableQueue, &flags );
631 for (int i = 0; i < solvableQueue.count; i++) {
632 PoolItem item = _pool.find (sat::Solvable(solvableQueue.elements[i]));
633 item.status().setUndetermined();
635 if (flags.elements[i] == -1) {
636 item.status().setNonRelevant();
637 _XDEBUG("SATSolutionToPool(" << item << " ) nonRelevant !");
638 } else if (flags.elements[i] == 1) {
639 item.status().setSatisfied();
640 _XDEBUG("SATSolutionToPool(" << item << " ) satisfied !");
641 } else if (flags.elements[i] == 0) {
642 item.status().setBroken();
643 _XDEBUG("SATSolutionToPool(" << item << " ) broken !");
646 queue_free(&(solvableQueue));
650 // Solvables which were selected due requirements which have been made by the user will
651 // be selected by APPL_LOW. We can't use any higher level, because this setting must
652 // not serve as a request for the next solver run. APPL_LOW is reset before solving.
653 for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
654 sat::WhatProvides rpmProviders(*iter);
655 for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
656 PoolItem poolItem(*iter2);
657 if (poolItem.status().isToBeInstalled()) {
658 MIL << "User requirement " << *iter << " sets " << poolItem << endl;
659 poolItem.status().setTransactByValue (ResStatus::APPL_LOW);
663 for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
664 sat::WhatProvides rpmProviders(*iter);
665 for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
666 PoolItem poolItem(*iter2);
667 if (poolItem.status().isToBeUninstalled()) {
668 MIL << "User conflict " << *iter << " sets " << poolItem << endl;
669 poolItem.status().setTransactByValue (ResStatus::APPL_LOW);
674 if (solver_problem_count(_solv) > 0 )
676 ERR << "Solverrun finished with an ERROR" << endl;
685 SATResolver::solverInit(const PoolItemList & weakItems)
687 SATCollectTransact info (*this);
689 MIL << "SATResolver::solverInit()" << endl;
694 queue_init( &_jobQueue );
695 _items_to_install.clear();
696 _items_to_remove.clear();
697 _items_to_lock.clear();
698 _items_to_keep.clear();
700 invokeOnEach ( _pool.begin(), _pool.end(),
701 functor::functorRef<bool,PoolItem>(info) );
703 for (PoolItemList::const_iterator iter = weakItems.begin(); iter != weakItems.end(); iter++) {
704 Id id = (*iter)->satSolvable().id();
706 ERR << "Weaken: " << *iter << " not found" << endl;
708 MIL << "Weaken dependencies of " << *iter << endl;
709 queue_push( &(_jobQueue), SOLVER_WEAKENDEPS | SOLVER_SOLVABLE );
710 queue_push( &(_jobQueue), id );
713 // Ad rules for changed requestedLocales
714 const auto & trackedLocaleIds( myPool().trackedLocaleIds() );
715 for ( const auto & locale : trackedLocaleIds.added() )
717 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES );
718 queue_push( &(_jobQueue), Capability( ResolverNamespace::language, IdString(locale) ).id() );
721 for ( const auto & locale : trackedLocaleIds.removed() )
723 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES | SOLVER_CLEANDEPS ); // needs uncond. SOLVER_CLEANDEPS!
724 queue_push( &(_jobQueue), Capability( ResolverNamespace::language, IdString(locale) ).id() );
727 // Add rules for parallel installable resolvables with different versions
728 for ( const sat::Solvable & solv : myPool().multiversionList() )
730 queue_push( &(_jobQueue), SOLVER_NOOBSOLETES | SOLVER_SOLVABLE );
731 queue_push( &(_jobQueue), solv.id() );
734 ::pool_add_userinstalled_jobs(_SATPool, sat::Pool::instance().autoInstalled(), &(_jobQueue), GET_USERINSTALLED_NAMES|GET_USERINSTALLED_INVERTED);
738 if ( ZConfig::instance().solverUpgradeRemoveDroppedPackages() )
740 MIL << "Checking droplists ..." << endl;
741 // Dropped packages: look for 'weakremover()' provides
742 // in dup candidates of installed products.
743 ResPoolProxy proxy( ResPool::instance().proxy() );
744 for_( it, proxy.byKindBegin<Product>(), proxy.byKindEnd<Product>() )
746 if ( (*it)->onSystem() ) // (to install) or (not to delete)
748 Product::constPtr prodCand( (*it)->candidateAsKind<Product>() );
750 continue; // product no longer available
752 CapabilitySet droplist( prodCand->droplist() );
753 dumpRangeLine( MIL << "Droplist for " << (*it)->candidateObj() << ": " << droplist.size() << " ", droplist.begin(), droplist.end() ) << endl;
754 for_( cap, droplist.begin(), droplist.end() )
756 queue_push( &_jobQueue, SOLVER_DROP_ORPHANED | SOLVER_SOLVABLE_NAME );
757 queue_push( &_jobQueue, cap->id() );
764 MIL << "Droplist processing is disabled." << endl;
770 SATResolver::solverEnd()
777 queue_free( &(_jobQueue) );
783 SATResolver::resolvePool(const CapabilitySet & requires_caps,
784 const CapabilitySet & conflict_caps,
785 const PoolItemList & weakItems,
786 const std::set<Repository> & upgradeRepos)
788 MIL << "SATResolver::resolvePool()" << endl;
791 solverInit(weakItems);
793 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
794 Id id = (*iter)->satSolvable().id();
796 ERR << "Install: " << *iter << " not found" << endl;
798 MIL << "Install " << *iter << endl;
799 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
800 queue_push( &(_jobQueue), id );
804 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
805 Id id = (*iter)->satSolvable().id();
807 ERR << "Delete: " << *iter << " not found" << endl;
809 MIL << "Delete " << *iter << endl;
810 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE | MAYBE_CLEANDEPS );
811 queue_push( &(_jobQueue), id);
815 for_( iter, upgradeRepos.begin(), upgradeRepos.end() )
817 queue_push( &(_jobQueue), SOLVER_DISTUPGRADE | SOLVER_SOLVABLE_REPO );
818 queue_push( &(_jobQueue), iter->get()->repoid );
819 MIL << "Upgrade repo " << *iter << endl;
822 for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
823 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES );
824 queue_push( &(_jobQueue), iter->id() );
825 MIL << "Requires " << *iter << endl;
828 for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
829 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES | MAYBE_CLEANDEPS );
830 queue_push( &(_jobQueue), iter->id() );
831 MIL << "Conflicts " << *iter << endl;
834 // set requirements for a running system
835 setSystemRequirements();
837 // set locks for the solver
841 bool ret = solving(requires_caps, conflict_caps);
843 (ret?MIL:WAR) << "SATResolver::resolvePool() done. Ret:" << ret << endl;
849 SATResolver::resolveQueue(const SolverQueueItemList &requestQueue,
850 const PoolItemList & weakItems)
852 MIL << "SATResolver::resolvQueue()" << endl;
855 solverInit(weakItems);
857 // generate solver queue
858 for (SolverQueueItemList::const_iterator iter = requestQueue.begin(); iter != requestQueue.end(); iter++) {
859 (*iter)->addRule(_jobQueue);
862 // Add addition item status to the resolve-queue cause these can be set by problem resolutions
863 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
864 Id id = (*iter)->satSolvable().id();
866 ERR << "Install: " << *iter << " not found" << endl;
868 MIL << "Install " << *iter << endl;
869 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
870 queue_push( &(_jobQueue), id );
873 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
874 sat::detail::IdType ident( (*iter)->satSolvable().ident().id() );
875 MIL << "Delete " << *iter << ident << endl;
876 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_NAME | MAYBE_CLEANDEPS );
877 queue_push( &(_jobQueue), ident);
880 // set requirements for a running system
881 setSystemRequirements();
883 // set locks for the solver
887 bool ret = solving();
889 MIL << "SATResolver::resolveQueue() done. Ret:" << ret << endl;
893 /** \todo duplicate code to be joined with \ref solving. */
894 void SATResolver::doUpdate()
896 MIL << "SATResolver::doUpdate()" << endl;
899 solverInit(PoolItemList());
901 // set requirements for a running system
902 setSystemRequirements();
904 // set locks for the solver
907 _solv = solver_create( _SATPool );
908 ::pool_set_custom_vendorcheck( _SATPool, &vendorCheck );
910 queue_push( &(_jobQueue), SOLVER_VERIFY|SOLVER_SOLVABLE_ALL);
911 queue_push( &(_jobQueue), 0 );
914 queue_push( &(_jobQueue), SOLVER_UPDATE|SOLVER_SOLVABLE_ALL);
915 queue_push( &(_jobQueue), 0 );
918 queue_push( &(_jobQueue), SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_ALL);
919 queue_push( &(_jobQueue), 0 );
921 if (_distupgrade_removeunsupported) {
922 queue_push( &(_jobQueue), SOLVER_DROP_ORPHANED|SOLVER_SOLVABLE_ALL);
923 queue_push( &(_jobQueue), 0 );
925 solver_set_flag(_solv, SOLVER_FLAG_ADD_ALREADY_RECOMMENDED, !_ignorealreadyrecommended);
926 solver_set_flag(_solv, SOLVER_FLAG_ALLOW_DOWNGRADE, _allowdowngrade);
927 solver_set_flag(_solv, SOLVER_FLAG_ALLOW_UNINSTALL, _allowuninstall);
928 solver_set_flag(_solv, SOLVER_FLAG_ALLOW_ARCHCHANGE, _allowarchchange);
929 solver_set_flag(_solv, SOLVER_FLAG_ALLOW_VENDORCHANGE, _allowvendorchange);
930 solver_set_flag(_solv, SOLVER_FLAG_SPLITPROVIDES, _dosplitprovides);
931 solver_set_flag(_solv, SOLVER_FLAG_NO_UPDATEPROVIDE, _noupdateprovide);
932 solver_set_flag(_solv, SOLVER_FLAG_IGNORE_RECOMMENDED, _onlyRequires);
934 sat::Pool::instance().prepareForSolving();
937 MIL << "Starting solving for update...." << endl;
939 solver_solve( _solv, &(_jobQueue) );
940 MIL << "....Solver end" << endl;
942 // copying solution back to zypp pool
943 //-----------------------------------------
945 /* solvables to be installed */
947 queue_init(&decisionq);
948 solver_get_decisionqueue(_solv, &decisionq);
949 for (int i = 0; i < decisionq.count; i++)
952 p = decisionq.elements[i];
953 if (p < 0 || !sat::Solvable(p))
955 if (sat::Solvable(p).repository().get() == _solv->pool->installed)
958 PoolItem poolItem = _pool.find (sat::Solvable(p));
960 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
962 ERR << "id " << p << " not found in ZYPP pool." << endl;
965 queue_free(&decisionq);
967 /* solvables to be erased */
968 for (int i = _solv->pool->installed->start; i < _solv->pool->installed->start + _solv->pool->installed->nsolvables; i++)
970 if (solver_get_decisionlevel(_solv, i) > 0)
973 PoolItem poolItem( _pool.find( sat::Solvable(i) ) );
975 // Check if this is an update
976 CheckIfUpdate info( (sat::Solvable(i)) );
977 invokeOnEach( _pool.byIdentBegin( poolItem ),
978 _pool.byIdentEnd( poolItem ),
979 resfilter::ByUninstalled(), // ByUninstalled
980 functor::functorRef<bool,PoolItem> (info) );
982 if (info.is_updated) {
983 SATSolutionToPool (poolItem, ResStatus::toBeUninstalledDueToUpgrade , ResStatus::SOLVER);
985 SATSolutionToPool (poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER);
988 ERR << "id " << i << " not found in ZYPP pool." << endl;
991 MIL << "SATResolver::doUpdate() done" << endl;
996 //----------------------------------------------------------------------------
997 //----------------------------------------------------------------------------
999 //----------------------------------------------------------------------------
1000 //----------------------------------------------------------------------------
1002 //----------------------------------------------------------------------------
1004 //----------------------------------------------------------------------------
1006 struct FindPackage : public resfilter::ResObjectFilterFunctor
1008 ProblemSolutionCombi *problemSolution;
1009 TransactionKind action;
1010 FindPackage (ProblemSolutionCombi *p, const TransactionKind act)
1011 : problemSolution (p)
1016 bool operator()( PoolItem p)
1018 problemSolution->addSingleAction (p, action);
1024 //----------------------------------------------------------------------------
1025 // Checking if this solvable/item has a buddy which reflect the real
1026 // user visible description of an item
1027 // e.g. The release package has a buddy to the concerning product item.
1028 // This user want's the message "Product foo conflicts with product bar" and
1029 // NOT "package release-foo conflicts with package release-bar"
1030 // (ma: that's why we should map just packages to buddies, not vice versa)
1031 //----------------------------------------------------------------------------
1032 inline sat::Solvable mapBuddy( const PoolItem & item_r )
1034 if ( item_r.satSolvable().isKind<Package>() )
1036 sat::Solvable buddy = item_r.buddy();
1040 return item_r.satSolvable();
1042 inline sat::Solvable mapBuddy( sat::Solvable item_r )
1043 { return mapBuddy( PoolItem( item_r ) ); }
1045 PoolItem SATResolver::mapItem ( const PoolItem & item )
1046 { return PoolItem( mapBuddy( item ) ); }
1048 sat::Solvable SATResolver::mapSolvable ( const Id & id )
1049 { return mapBuddy( sat::Solvable(id) ); }
1051 string SATResolver::SATprobleminfoString(Id problem, string &detail, Id &ignoreId)
1054 Pool *pool = _solv->pool;
1056 Id dep, source, target;
1057 sat::Solvable s, s2;
1061 // FIXME: solver_findallproblemrules to get all rules for this problem
1062 // (the 'most relevabt' one returned by solver_findproblemrule is embedded
1063 probr = solver_findproblemrule(_solv, problem);
1064 switch (solver_ruleinfo(_solv, probr, &source, &target, &dep))
1066 case SOLVER_RULE_DISTUPGRADE:
1067 s = mapSolvable (source);
1068 ret = str::form (_("%s does not belong to a distupgrade repository"), s.asString().c_str());
1070 case SOLVER_RULE_INFARCH:
1071 s = mapSolvable (source);
1072 ret = str::form (_("%s has inferior architecture"), s.asString().c_str());
1074 case SOLVER_RULE_UPDATE:
1075 s = mapSolvable (source);
1076 ret = str::form (_("problem with installed package %s"), s.asString().c_str());
1078 case SOLVER_RULE_JOB:
1079 ret = _("conflicting requests");
1081 case SOLVER_RULE_RPM:
1082 ret = _("some dependency problem");
1084 case SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP:
1085 ret = str::form (_("nothing provides requested %s"), pool_dep2str(pool, dep));
1086 detail += _("Have you enabled all requested repositories?");
1088 case SOLVER_RULE_JOB_UNKNOWN_PACKAGE:
1089 ret = str::form (_("package %s does not exist"), pool_dep2str(pool, dep));
1090 detail += _("Have you enabled all requested repositories?");
1092 case SOLVER_RULE_JOB_UNSUPPORTED:
1093 ret = _("unsupported request");
1095 case SOLVER_RULE_JOB_PROVIDED_BY_SYSTEM:
1096 ret = str::form (_("%s is provided by the system and cannot be erased"), pool_dep2str(pool, dep));
1098 case SOLVER_RULE_RPM_NOT_INSTALLABLE:
1099 s = mapSolvable (source);
1100 ret = str::form (_("%s is not installable"), s.asString().c_str());
1102 case SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP:
1103 ignoreId = source; // for setting weak dependencies
1104 s = mapSolvable (source);
1105 ret = str::form (_("nothing provides %s needed by %s"), pool_dep2str(pool, dep), s.asString().c_str());
1107 case SOLVER_RULE_RPM_SAME_NAME:
1108 s = mapSolvable (source);
1109 s2 = mapSolvable (target);
1110 ret = str::form (_("cannot install both %s and %s"), s.asString().c_str(), s2.asString().c_str());
1112 case SOLVER_RULE_RPM_PACKAGE_CONFLICT:
1113 s = mapSolvable (source);
1114 s2 = mapSolvable (target);
1115 ret = str::form (_("%s conflicts with %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1117 case SOLVER_RULE_RPM_PACKAGE_OBSOLETES:
1118 s = mapSolvable (source);
1119 s2 = mapSolvable (target);
1120 ret = str::form (_("%s obsoletes %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1122 case SOLVER_RULE_RPM_INSTALLEDPKG_OBSOLETES:
1123 s = mapSolvable (source);
1124 s2 = mapSolvable (target);
1125 ret = str::form (_("installed %s obsoletes %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1127 case SOLVER_RULE_RPM_SELF_CONFLICT:
1128 s = mapSolvable (source);
1129 ret = str::form (_("solvable %s conflicts with %s provided by itself"), s.asString().c_str(), pool_dep2str(pool, dep));
1131 case SOLVER_RULE_RPM_PACKAGE_REQUIRES:
1132 ignoreId = source; // for setting weak dependencies
1133 s = mapSolvable (source);
1134 Capability cap(dep);
1135 sat::WhatProvides possibleProviders(cap);
1137 // check, if a provider will be deleted
1138 typedef list<PoolItem> ProviderList;
1139 ProviderList providerlistInstalled, providerlistUninstalled;
1140 for_( iter1, possibleProviders.begin(), possibleProviders.end() ) {
1141 PoolItem provider1 = ResPool::instance().find( *iter1 );
1142 // find pair of an installed/uninstalled item with the same NVR
1144 for_( iter2, possibleProviders.begin(), possibleProviders.end() ) {
1145 PoolItem provider2 = ResPool::instance().find( *iter2 );
1146 if (compareByNVR (provider1,provider2) == 0
1147 && ( (provider1.status().isInstalled() && provider2.status().isUninstalled())
1148 || (provider2.status().isInstalled() && provider1.status().isUninstalled()) )) {
1154 if (provider1.status().isInstalled())
1155 providerlistInstalled.push_back(provider1);
1157 providerlistUninstalled.push_back(provider1);
1161 ret = str::form (_("%s requires %s, but this requirement cannot be provided"), s.asString().c_str(), pool_dep2str(pool, dep));
1162 if (providerlistInstalled.size() > 0) {
1163 detail += _("deleted providers: ");
1164 for (ProviderList::const_iterator iter = providerlistInstalled.begin(); iter != providerlistInstalled.end(); iter++) {
1165 if (iter == providerlistInstalled.begin())
1166 detail += itemToString( *iter );
1168 detail += "\n " + itemToString( mapItem(*iter) );
1171 if (providerlistUninstalled.size() > 0) {
1172 if (detail.size() > 0)
1173 detail += _("\nuninstallable providers: ");
1175 detail = _("uninstallable providers: ");
1176 for (ProviderList::const_iterator iter = providerlistUninstalled.begin(); iter != providerlistUninstalled.end(); iter++) {
1177 if (iter == providerlistUninstalled.begin())
1178 detail += itemToString( *iter );
1180 detail += "\n " + itemToString( mapItem(*iter) );
1190 SATResolver::problems ()
1192 ResolverProblemList resolverProblems;
1193 if (_solv && solver_problem_count(_solv)) {
1194 Pool *pool = _solv->pool;
1197 Id problem, solution, element;
1198 sat::Solvable s, sd;
1200 CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1201 CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1203 MIL << "Encountered problems! Here are the solutions:\n" << endl;
1206 while ((problem = solver_next_problem(_solv, problem)) != 0) {
1207 MIL << "Problem " << pcnt++ << ":" << endl;
1208 MIL << "====================================" << endl;
1211 string whatString = SATprobleminfoString (problem,detail,ignoreId);
1212 MIL << whatString << endl;
1213 MIL << "------------------------------------" << endl;
1214 ResolverProblem_Ptr resolverProblem = new ResolverProblem (whatString, detail);
1217 while ((solution = solver_next_solution(_solv, problem, solution)) != 0) {
1219 ProblemSolutionCombi *problemSolution = new ProblemSolutionCombi;
1220 while ((element = solver_next_solutionelement(_solv, problem, solution, element, &p, &rp)) != 0) {
1221 if (p == SOLVER_SOLUTION_JOB) {
1222 /* job, rp is index into job queue */
1223 what = _jobQueue.elements[rp];
1224 switch (_jobQueue.elements[rp-1]&(SOLVER_SELECTMASK|SOLVER_JOBMASK))
1226 case SOLVER_INSTALL | 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, REMOVE);
1232 string description = str::form (_("remove lock to allow removal of %s"), s.asString().c_str() );
1233 MIL << description << endl;
1234 problemSolution->addDescription (description);
1236 problemSolution->addSingleAction (poolItem, KEEP);
1237 string description = str::form (_("do not install %s"), s.asString().c_str());
1238 MIL << description << endl;
1239 problemSolution->addDescription (description);
1242 ERR << "SOLVER_INSTALL_SOLVABLE: No item found for " << s.asString() << endl;
1246 case SOLVER_ERASE | SOLVER_SOLVABLE: {
1247 s = mapSolvable (what);
1248 PoolItem poolItem = _pool.find (s);
1250 if (pool->installed && s.get()->repo == pool->installed) {
1251 problemSolution->addSingleAction (poolItem, KEEP);
1252 string description = str::form (_("keep %s"), s.asString().c_str());
1253 MIL << description << endl;
1254 problemSolution->addDescription (description);
1256 problemSolution->addSingleAction (poolItem, UNLOCK);
1257 string description = str::form (_("remove lock to allow installation of %s"), itemToString( poolItem ).c_str());
1258 MIL << description << endl;
1259 problemSolution->addDescription (description);
1262 ERR << "SOLVER_ERASE_SOLVABLE: No item found for " << s.asString() << endl;
1266 case SOLVER_INSTALL | SOLVER_SOLVABLE_NAME:
1268 IdString ident( what );
1269 SolverQueueItemInstall_Ptr install =
1270 new SolverQueueItemInstall(_pool, ident.asString(), false );
1271 problemSolution->addSingleAction (install, REMOVE_SOLVE_QUEUE_ITEM);
1273 string description = str::form (_("do not install %s"), ident.c_str() );
1274 MIL << description << endl;
1275 problemSolution->addDescription (description);
1278 case SOLVER_ERASE | SOLVER_SOLVABLE_NAME:
1280 // As we do not know, if this request has come from resolvePool or
1281 // resolveQueue we will have to take care for both cases.
1282 IdString ident( what );
1283 FindPackage info (problemSolution, KEEP);
1284 invokeOnEach( _pool.byIdentBegin( ident ),
1285 _pool.byIdentEnd( ident ),
1286 functor::chain (resfilter::ByInstalled (), // ByInstalled
1287 resfilter::ByTransact ()), // will be deinstalled
1288 functor::functorRef<bool,PoolItem> (info) );
1290 SolverQueueItemDelete_Ptr del =
1291 new SolverQueueItemDelete(_pool, ident.asString(), false );
1292 problemSolution->addSingleAction (del, REMOVE_SOLVE_QUEUE_ITEM);
1294 string description = str::form (_("keep %s"), ident.c_str());
1295 MIL << description << endl;
1296 problemSolution->addDescription (description);
1299 case SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES:
1301 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_REQUIRE);
1302 string description = "";
1304 // Checking if this problem solution would break your system
1305 if (system_requires.find(Capability(what)) != system_requires.end()) {
1306 // Show a better warning
1307 resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1308 resolverProblem->setDescription(_("This request will break your system!"));
1309 description = _("ignore the warning of a broken system");
1310 description += string(" (requires:")+pool_dep2str(pool, what)+")";
1311 MIL << description << endl;
1312 problemSolution->addFrontDescription (description);
1314 description = str::form (_("do not ask to install a solvable providing %s"), pool_dep2str(pool, what));
1315 MIL << description << endl;
1316 problemSolution->addDescription (description);
1320 case SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES:
1322 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_CONFLICT);
1323 string description = "";
1325 // Checking if this problem solution would break your system
1326 if (system_conflicts.find(Capability(what)) != system_conflicts.end()) {
1327 // Show a better warning
1328 resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1329 resolverProblem->setDescription(_("This request will break your system!"));
1330 description = _("ignore the warning of a broken system");
1331 description += string(" (conflicts:")+pool_dep2str(pool, what)+")";
1332 MIL << description << endl;
1333 problemSolution->addFrontDescription (description);
1336 description = str::form (_("do not ask to delete all solvables providing %s"), pool_dep2str(pool, what));
1337 MIL << description << endl;
1338 problemSolution->addDescription (description);
1342 case SOLVER_UPDATE | SOLVER_SOLVABLE:
1344 s = mapSolvable (what);
1345 PoolItem poolItem = _pool.find (s);
1347 if (pool->installed && s.get()->repo == pool->installed) {
1348 problemSolution->addSingleAction (poolItem, KEEP);
1349 string description = str::form (_("do not install most recent version of %s"), s.asString().c_str());
1350 MIL << description << endl;
1351 problemSolution->addDescription (description);
1353 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE " << poolItem << " is not selected for installation" << endl;
1356 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE: No item found for " << s.asString() << endl;
1361 MIL << "- do something different" << endl;
1362 ERR << "No valid solution available" << endl;
1365 } else if (p == SOLVER_SOLUTION_INFARCH) {
1366 s = mapSolvable (rp);
1367 PoolItem poolItem = _pool.find (s);
1368 if (pool->installed && s.get()->repo == pool->installed) {
1369 problemSolution->addSingleAction (poolItem, LOCK);
1370 string description = str::form (_("keep %s despite the inferior architecture"), s.asString().c_str());
1371 MIL << description << endl;
1372 problemSolution->addDescription (description);
1374 problemSolution->addSingleAction (poolItem, INSTALL);
1375 string description = str::form (_("install %s despite the inferior architecture"), s.asString().c_str());
1376 MIL << description << endl;
1377 problemSolution->addDescription (description);
1379 } else if (p == SOLVER_SOLUTION_DISTUPGRADE) {
1380 s = mapSolvable (rp);
1381 PoolItem poolItem = _pool.find (s);
1382 if (pool->installed && s.get()->repo == pool->installed) {
1383 problemSolution->addSingleAction (poolItem, LOCK);
1384 string description = str::form (_("keep obsolete %s"), s.asString().c_str());
1385 MIL << description << endl;
1386 problemSolution->addDescription (description);
1388 problemSolution->addSingleAction (poolItem, INSTALL);
1389 string description = str::form (_("install %s from excluded repository"), s.asString().c_str());
1390 MIL << description << endl;
1391 problemSolution->addDescription (description);
1394 /* policy, replace p with rp */
1395 s = mapSolvable (p);
1396 PoolItem itemFrom = _pool.find (s);
1401 sd = mapSolvable (rp);
1402 PoolItem itemTo = _pool.find (sd);
1403 if (itemFrom && itemTo) {
1404 problemSolution->addSingleAction (itemTo, INSTALL);
1405 int illegal = policy_is_illegal(_solv, s.get(), sd.get(), 0);
1407 if ((illegal & POLICY_ILLEGAL_DOWNGRADE) != 0)
1409 string description = str::form (_("downgrade of %s to %s"), s.asString().c_str(), sd.asString().c_str());
1410 MIL << description << endl;
1411 problemSolution->addDescription (description);
1414 if ((illegal & POLICY_ILLEGAL_ARCHCHANGE) != 0)
1416 string description = str::form (_("architecture change of %s to %s"), s.asString().c_str(), sd.asString().c_str());
1417 MIL << description << endl;
1418 problemSolution->addDescription (description);
1421 if ((illegal & POLICY_ILLEGAL_VENDORCHANGE) != 0)
1423 IdString s_vendor( s.vendor() );
1424 IdString sd_vendor( sd.vendor() );
1425 string description = str::form (_("install %s (with vendor change)\n %s --> %s") ,
1426 sd.asString().c_str(),
1427 ( s_vendor ? s_vendor.c_str() : " (no vendor) " ),
1428 ( sd_vendor ? sd_vendor.c_str() : " (no vendor) " ) );
1429 MIL << description << endl;
1430 problemSolution->addDescription (description);
1434 string description = str::form (_("replacement of %s with %s"), s.asString().c_str(), sd.asString().c_str());
1435 MIL << description << endl;
1436 problemSolution->addDescription (description);
1439 ERR << s.asString() << " or " << sd.asString() << " not found" << endl;
1445 string description = str::form (_("deinstallation of %s"), s.asString().c_str());
1446 MIL << description << endl;
1447 problemSolution->addDescription (description);
1448 problemSolution->addSingleAction (itemFrom, REMOVE);
1453 resolverProblem->addSolution (problemSolution,
1454 problemSolution->actionCount() > 1 ? true : false); // Solutions with more than 1 action will be shown first.
1455 MIL << "------------------------------------" << endl;
1459 // There is a possibility to ignore this error by setting weak dependencies
1460 PoolItem item = _pool.find (sat::Solvable(ignoreId));
1461 ProblemSolutionIgnore *problemSolution = new ProblemSolutionIgnore(item);
1462 resolverProblem->addSolution (problemSolution,
1463 false); // Solutions will be shown at the end
1464 MIL << "ignore some dependencies of " << item << endl;
1465 MIL << "------------------------------------" << endl;
1469 resolverProblems.push_back (resolverProblem);
1472 return resolverProblems;
1475 void SATResolver::applySolutions( const ProblemSolutionList & solutions )
1476 { Resolver( _pool ).applySolutions( solutions ); }
1478 void SATResolver::setLocks()
1480 for (PoolItemList::const_iterator iter = _items_to_lock.begin(); iter != _items_to_lock.end(); ++iter) {
1481 sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
1482 if (iter->status().isInstalled()) {
1483 MIL << "Lock installed item " << *iter << endl;
1484 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
1485 queue_push( &(_jobQueue), ident );
1487 MIL << "Lock NOT installed item " << *iter << endl;
1488 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE | MAYBE_CLEANDEPS );
1489 queue_push( &(_jobQueue), ident );
1493 ///////////////////////////////////////////////////////////////////
1494 // Weak locks: Ignore if an item with this name is already installed.
1495 // If it's not installed try to keep it this way using a weak delete
1496 ///////////////////////////////////////////////////////////////////
1497 std::set<IdString> unifiedByName;
1498 for (PoolItemList::const_iterator iter = _items_to_keep.begin(); iter != _items_to_keep.end(); ++iter) {
1499 IdString ident( (*iter)->satSolvable().ident() );
1500 if ( unifiedByName.insert( ident ).second )
1502 if ( ! ui::Selectable::get( *iter )->hasInstalledObj() )
1504 MIL << "Keep NOT installed name " << ident << " (" << *iter << ")" << endl;
1505 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_NAME | SOLVER_WEAK | MAYBE_CLEANDEPS );
1506 queue_push( &(_jobQueue), ident.id() );
1512 void SATResolver::setSystemRequirements()
1514 CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1515 CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1517 for (CapabilitySet::const_iterator iter = system_requires.begin(); iter != system_requires.end(); ++iter) {
1518 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES );
1519 queue_push( &(_jobQueue), iter->id() );
1520 MIL << "SYSTEM Requires " << *iter << endl;
1523 for (CapabilitySet::const_iterator iter = system_conflicts.begin(); iter != system_conflicts.end(); ++iter) {
1524 queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES | MAYBE_CLEANDEPS );
1525 queue_push( &(_jobQueue), iter->id() );
1526 MIL << "SYSTEM Conflicts " << *iter << endl;
1529 // Lock the architecture of the running systems rpm
1530 // package on distupgrade.
1531 if ( _distupgrade && ZConfig::instance().systemRoot() == "/" )
1533 ResPool pool( ResPool::instance() );
1534 IdString rpm( "rpm" );
1535 for_( it, pool.byIdentBegin(rpm), pool.byIdentEnd(rpm) )
1537 if ( (*it)->isSystem() )
1539 Capability archrule( (*it)->arch(), rpm.c_str(), Capability::PARSED );
1540 queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_NAME | SOLVER_ESSENTIAL );
1541 queue_push( &(_jobQueue), archrule.id() );
1548 sat::StringQueue SATResolver::autoInstalled() const
1550 sat::StringQueue ret;
1552 ::solver_get_userinstalled( _solv, ret, GET_USERINSTALLED_NAMES|GET_USERINSTALLED_INVERTED );
1556 sat::StringQueue SATResolver::userInstalled() const
1558 sat::StringQueue ret;
1560 ::solver_get_userinstalled( _solv, ret, GET_USERINSTALLED_NAMES );
1565 ///////////////////////////////////////////////////////////////////
1566 };// namespace detail
1567 /////////////////////////////////////////////////////////////////////
1568 /////////////////////////////////////////////////////////////////////
1569 };// namespace solver
1570 ///////////////////////////////////////////////////////////////////////
1571 ///////////////////////////////////////////////////////////////////////
1573 /////////////////////////////////////////////////////////////////////////