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 <satsolver/repo_solv.h>
24 #include <satsolver/poolarch.h>
25 #include <satsolver/evr.h>
26 #include <satsolver/poolvendor.h>
27 #include <satsolver/policy.h>
28 #include <satsolver/bitmap.h>
29 #include <satsolver/queue.h>
32 #include "zypp/solver/detail/Helper.h"
33 #include "zypp/base/String.h"
34 #include "zypp/Capability.h"
35 #include "zypp/ResStatus.h"
36 #include "zypp/VendorAttr.h"
37 #include "zypp/base/Logger.h"
38 #include "zypp/base/String.h"
39 #include "zypp/base/Gettext.h"
40 #include "zypp/base/Algorithm.h"
41 #include "zypp/ResPool.h"
42 #include "zypp/ResFilters.h"
43 #include "zypp/ZConfig.h"
44 #include "zypp/sat/Pool.h"
45 #include "zypp/sat/WhatProvides.h"
46 #include "zypp/sat/WhatObsoletes.h"
47 #include "zypp/solver/detail/SATResolver.h"
48 #include "zypp/solver/detail/ProblemSolutionCombi.h"
49 #include "zypp/solver/detail/ProblemSolutionIgnore.h"
50 #include "zypp/solver/detail/SolverQueueItemInstall.h"
51 #include "zypp/solver/detail/SolverQueueItemDelete.h"
52 #include "zypp/solver/detail/SystemCheck.h"
54 /////////////////////////////////////////////////////////////////////////
56 { ///////////////////////////////////////////////////////////////////////
57 ///////////////////////////////////////////////////////////////////////
59 { /////////////////////////////////////////////////////////////////////
60 /////////////////////////////////////////////////////////////////////
62 { ///////////////////////////////////////////////////////////////////
66 IMPL_PTR_TYPE(SATResolver);
68 //---------------------------------------------------------------------------
69 // Callbacks for SAT policies
70 //---------------------------------------------------------------------------
72 int vendorCheck( Pool *pool, Solvable *solvable1, Solvable *solvable2 )
74 return VendorAttr::instance().equivalent( IdString(solvable1->vendor),
75 IdString(solvable2->vendor) ) ? 0 : 1;
79 inline std::string itemToString( const PoolItem & item )
84 sat::Solvable slv( item.satSolvable() );
85 std::string ret( slv.asString() ); // n-v-r.a
86 if ( ! slv.isSystem() )
89 ret += slv.repository().alias();
96 //---------------------------------------------------------------------------
99 SATResolver::dumpOn( std::ostream & os ) const
101 os << "<resolver>" << endl;
103 os << " fixsystem = " << _solv->fixsystem << endl;
104 os << " allowdowngrade = " << _solv->allowdowngrade << endl;
105 os << " allowarchchange = " << _solv->allowarchchange << endl;
106 os << " allowvendorchange = " << _solv->allowvendorchange << endl;
107 os << " allowuninstall = " << _solv->allowuninstall << endl;
108 os << " updatesystem = " << _solv->updatesystem << endl;
109 os << " noupdateprovide = " << _solv->noupdateprovide << endl;
110 os << " dosplitprovides = " << _solv->dosplitprovides << endl;
111 os << " onlyRequires = " << _solv->dontinstallrecommended << endl;
112 os << " ignorealreadyrecommended = " << _solv->ignorealreadyrecommended << endl;
113 os << " distupgrade = " << _distupgrade << endl;
114 os << " distupgrade_removeunsupported = " << _distupgrade_removeunsupported << endl;
115 os << " solveSrcPackages = " << _solveSrcPackages << endl;
119 return os << "<resolver/>" << endl;
122 //---------------------------------------------------------------------------
124 SATResolver::SATResolver (const ResPool & pool, Pool *SATPool)
129 , _allowdowngrade(false)
130 , _allowarchchange(false)
131 , _allowvendorchange(false)
132 , _allowuninstall(false)
133 , _updatesystem(false)
134 , _noupdateprovide(false)
135 , _dosplitprovides(false)
136 , _onlyRequires(ZConfig::instance().solver_onlyRequires())
137 , _ignorealreadyrecommended(false)
138 , _distupgrade(false)
139 , _distupgrade_removeunsupported(false)
145 SATResolver::~SATResolver()
149 //---------------------------------------------------------------------------
153 SATResolver::pool (void) const
160 SATResolver::resetItemTransaction (PoolItem item)
163 for (PoolItemList::const_iterator iter = _items_to_remove.begin();
164 iter != _items_to_remove.end(); ++iter) {
166 _items_to_remove.remove(*iter);
172 for (PoolItemList::const_iterator iter = _items_to_install.begin();
173 iter != _items_to_install.end(); ++iter) {
175 _items_to_install.remove(*iter);
182 for (PoolItemList::const_iterator iter = _items_to_keep.begin();
183 iter != _items_to_keep.end(); ++iter) {
185 _items_to_keep.remove(*iter);
192 for (PoolItemList::const_iterator iter = _items_to_lock.begin();
193 iter != _items_to_lock.end(); ++iter) {
195 _items_to_lock.remove(*iter);
205 SATResolver::addPoolItemToInstall (PoolItem item)
207 resetItemTransaction (item);
208 _items_to_install.push_back (item);
209 _items_to_install.unique ();
214 SATResolver::addPoolItemsToInstallFromList (PoolItemList & rl)
216 for (PoolItemList::const_iterator iter = rl.begin(); iter != rl.end(); iter++) {
217 addPoolItemToInstall (*iter);
223 SATResolver::addPoolItemToRemove (PoolItem item)
225 resetItemTransaction (item);
226 _items_to_remove.push_back (item);
227 _items_to_remove.unique ();
232 SATResolver::addPoolItemsToRemoveFromList (PoolItemList & rl)
234 for (PoolItemList::const_iterator iter = rl.begin(); iter != rl.end(); iter++) {
235 addPoolItemToRemove (*iter);
240 SATResolver::addPoolItemToLock (PoolItem item)
242 resetItemTransaction (item);
243 _items_to_lock.push_back (item);
244 _items_to_lock.unique ();
248 SATResolver::addPoolItemToKeep (PoolItem item)
250 resetItemTransaction (item);
251 _items_to_keep.push_back (item);
252 _items_to_keep.unique ();
255 //---------------------------------------------------------------------------
257 // copy marked item from solution back to pool
258 // if data != NULL, set as APPL_LOW (from establishPool())
261 SATSolutionToPool (PoolItem item, const ResStatus & status, const ResStatus::TransactByValue causer)
264 item.status().resetTransact (causer);
265 item.status().resetWeak ();
269 // installation/deletion
270 if (status.isToBeInstalled()) {
271 r = item.status().setToBeInstalled (causer);
272 _XDEBUG("SATSolutionToPool install returns " << item << ", " << r);
274 else if (status.isToBeUninstalledDueToUpgrade()) {
275 r = item.status().setToBeUninstalledDueToUpgrade (causer);
276 _XDEBUG("SATSolutionToPool upgrade returns " << item << ", " << r);
278 else if (status.isToBeUninstalled()) {
279 r = item.status().setToBeUninstalled (causer);
280 _XDEBUG("SATSolutionToPool remove returns " << item << ", " << r);
286 //----------------------------------------------------------------------------
287 //----------------------------------------------------------------------------
289 //----------------------------------------------------------------------------
290 //----------------------------------------------------------------------------
292 //----------------------------------------------------------------------------
293 // Helper functions for the ZYPP-Pool
294 //----------------------------------------------------------------------------
297 //------------------------------------------------------------------------------------------------------------
298 // This function loops over the pool and grabs all items
299 // It clears all previous bySolver() states also
301 // Every toBeInstalled is passed to zypp::solver:detail::Resolver.addPoolItemToInstall()
302 // Every toBeUninstalled is passed to zypp::solver:detail::Resolver.addPoolItemToRemove()
304 // Solver results must be written back to the pool.
305 //------------------------------------------------------------------------------------------------------------
308 struct SATCollectTransact : public resfilter::PoolItemFilterFunctor
310 SATResolver & resolver;
312 SATCollectTransact (SATResolver & r)
316 bool operator()( PoolItem item ) // only transacts() items go here
318 ResStatus status = item.status();
319 bool by_solver = (status.isBySolver() || status.isByApplLow());
322 item.status().resetTransact( ResStatus::APPL_LOW );// clear any solver/establish transactions
323 return true; // back out here, dont re-queue former solver result
326 if ( item.satSolvable().isKind<SrcPackage>() && ! resolver.solveSrcPackages() )
328 // Later we may continue on a per source package base.
329 return true; // dont process this source package.
332 if (status.isToBeInstalled()) {
333 resolver.addPoolItemToInstall(item); // -> install!
335 else if (status.isToBeUninstalled()) {
336 resolver.addPoolItemToRemove(item); // -> remove !
338 else if (status.isLocked()
340 resolver.addPoolItemToLock (item);
342 else if (status.isKept()
344 resolver.addPoolItemToKeep (item);
352 //----------------------------------------------------------------------------
353 //----------------------------------------------------------------------------
355 //----------------------------------------------------------------------------
356 //----------------------------------------------------------------------------
359 class CheckIfUpdate : public resfilter::PoolItemFilterFunctor
365 : is_updated( false )
368 // check this item will be installed
370 bool operator()( PoolItem item )
372 if (item.status().isToBeInstalled())
382 class CollectNonePackages : public resfilter::PoolItemFilterFunctor
385 Queue *solvableQueue;
387 CollectNonePackages( Queue *queue )
388 :solvableQueue (queue)
391 // collecting none packges
393 bool operator()( PoolItem item )
395 queue_push(solvableQueue, item.satSolvable().id());
401 SATResolver::solving(const CapabilitySet & requires_caps,
402 const CapabilitySet & conflict_caps)
404 _solv = solver_create( _SATPool );
405 _solv->vendorCheckCb = &vendorCheck;
406 _solv->fixsystem = _fixsystem;
407 _solv->ignorealreadyrecommended = _ignorealreadyrecommended;
408 _solv->updatesystem = _updatesystem;
409 _solv->allowdowngrade = _allowdowngrade;
410 _solv->allowuninstall = _allowuninstall;
411 _solv->allowarchchange = _allowarchchange;
412 _solv->allowvendorchange = _allowvendorchange;
413 _solv->dosplitprovides = _dosplitprovides;
414 _solv->noupdateprovide = _noupdateprovide;
415 _solv->dontinstallrecommended = _onlyRequires;
416 _solv->distupgrade = _distupgrade;
417 _solv->distupgrade_removeunsupported = _distupgrade_removeunsupported;
419 sat::Pool::instance().prepare();
422 MIL << "Starting solving...." << endl;
424 solver_solve( _solv, &(_jobQueue) );
425 MIL << "....Solver end" << endl;
427 // copying solution back to zypp pool
428 //-----------------------------------------
429 _result_items_to_install.clear();
430 _result_items_to_remove.clear();
432 /* solvables to be installed */
433 for (int i = 0; i < _solv->decisionq.count; i++)
436 p = _solv->decisionq.elements[i];
437 if (p < 0 || !sat::Solvable(p) || sat::Solvable(p).isSystem())
440 PoolItem poolItem((sat::Solvable(p)));
442 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
443 _result_items_to_install.push_back (poolItem);
445 ERR << "id " << p << " not found in ZYPP pool." << endl;
449 /* solvables to be erased */
450 Repository systemRepo( sat::Pool::instance().findSystemRepo() ); // don't create if it does not exist
451 if ( systemRepo && ! systemRepo.solvablesEmpty() )
453 bool mustCheckObsoletes = false;
454 for_( it, systemRepo.solvablesBegin(), systemRepo.solvablesEnd() )
456 if (_solv->decisionmap[it->id()] > 0)
459 PoolItem poolItem( *it );
460 // Check if this is an update
462 invokeOnEach( _pool.byIdentBegin( poolItem ),
463 _pool.byIdentEnd( poolItem ),
464 resfilter::ByUninstalled(), // ByUninstalled
465 functor::functorRef<bool,PoolItem> (info) );
467 if (info.is_updated) {
468 SATSolutionToPool( poolItem, ResStatus::toBeUninstalledDueToUpgrade, ResStatus::SOLVER );
470 SATSolutionToPool( poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER );
471 if ( ! mustCheckObsoletes )
472 mustCheckObsoletes = true; // lazy check for UninstalledDueToObsolete
474 _result_items_to_remove.push_back (poolItem);
476 if ( mustCheckObsoletes )
478 sat::WhatObsoletes obsoleted( _result_items_to_install.begin(), _result_items_to_install.end() );
479 for_( it, obsoleted.poolItemBegin(), obsoleted.poolItemEnd() )
481 ResStatus & status( it->status() );
482 // WhatObsoletes contains installed items only!
483 if ( status.transacts() && ! status.isToBeUninstalledDueToUpgrade() )
484 status.setToBeUninstalledDueToObsolete();
488 /* solvables which are recommended */
489 for (int i = 0; i < _solv->recommendations.count; i++)
492 p = _solv->recommendations.elements[i];
493 if (p < 0 || !sat::Solvable(p))
496 PoolItem poolItem = _pool.find (sat::Solvable(p));
498 poolItem.status().setRecommended(true);
499 _XDEBUG("SATSolutionToPool(" << poolItem << ") recommended !");
501 ERR << "id " << p << " not found in ZYPP pool." << endl;
505 /* solvables which are suggested */
506 for (int i = 0; i < _solv->suggestions.count; i++)
509 p = _solv->suggestions.elements[i];
510 if (p < 0 || !sat::Solvable(p))
513 PoolItem poolItem = _pool.find (sat::Solvable(p));
515 poolItem.status().setSuggested(true);
516 _XDEBUG("SATSolutionToPool(" << poolItem << ") suggested !");
518 ERR << "id " << p << " not found in ZYPP pool." << endl;
522 _problem_items.clear();
523 /* solvables which are no longer supported */
524 for (int i = 0; i < _solv->orphaned.count; i++)
527 p = _solv->orphaned.elements[i];
528 if (p < 0 || !sat::Solvable(p))
531 PoolItem poolItem = _pool.find (sat::Solvable(p));
533 _problem_items.push_back(poolItem);
534 _XDEBUG( poolItem << " orphaned !");
536 ERR << "id " << p << " not found in ZYPP pool." << endl;
540 /* Write validation state back to pool */
541 Queue flags, solvableQueue;
544 queue_init(&solvableQueue);
546 CollectNonePackages collectNonePackages(&solvableQueue);
547 invokeOnEach( _pool.begin(),
549 functor::not_c(resfilter::byKind<Package>()), // every solvable BUT packages
550 functor::functorRef<bool,PoolItem> (collectNonePackages) );
551 solver_trivial_installable(_solv, &solvableQueue, &flags );
552 for (int i = 0; i < solvableQueue.count; i++) {
553 PoolItem item = _pool.find (sat::Solvable(solvableQueue.elements[i]));
554 item.status().setUndetermined();
556 if (flags.elements[i] == -1) {
557 item.status().setNonRelevant();
558 _XDEBUG("SATSolutionToPool(" << item << " ) nonRelevant !");
559 } else if (flags.elements[i] == 1) {
560 item.status().setSatisfied();
561 _XDEBUG("SATSolutionToPool(" << item << " ) satisfied !");
562 } else if (flags.elements[i] == 0) {
563 item.status().setBroken();
564 _XDEBUG("SATSolutionToPool(" << item << " ) broken !");
568 // Solvables which were selected due requirements which have been made by the user will
569 // be selected by APPL_LOW. We can't use any higher level, because this setting must
570 // not serve as a request for the next solver run. APPL_LOW is reset before solving.
571 for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
572 sat::WhatProvides rpmProviders(*iter);
573 for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
574 PoolItem poolItem(*iter2);
575 if (poolItem.status().isToBeInstalled()) {
576 MIL << "User requirement " << *iter << " sets " << poolItem << endl;
577 poolItem.status().setTransactByValue (ResStatus::APPL_LOW);
581 for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
582 sat::WhatProvides rpmProviders(*iter);
583 for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
584 PoolItem poolItem(*iter2);
585 if (poolItem.status().isToBeUninstalled()) {
586 MIL << "User conflict " << *iter << " sets " << poolItem << endl;
587 poolItem.status().setTransactByValue (ResStatus::APPL_LOW);
592 if (_solv->problems.count > 0 )
594 ERR << "Solverrun finished with an ERROR" << endl;
598 queue_free(&(solvableQueue));
606 SATResolver::solverInit(const PoolItemList & weakItems)
608 SATCollectTransact info (*this);
610 MIL << "SATResolver::solverInit()" << endl;
616 queue_free( &(_jobQueue) );
619 queue_init( &_jobQueue );
620 _items_to_install.clear();
621 _items_to_remove.clear();
622 _items_to_lock.clear();
623 _items_to_keep.clear();
625 invokeOnEach ( _pool.begin(), _pool.end(),
626 functor::functorRef<bool,PoolItem>(info) );
628 for (PoolItemList::const_iterator iter = weakItems.begin(); iter != weakItems.end(); iter++) {
629 Id id = (*iter)->satSolvable().id();
631 ERR << "Weaken: " << *iter << " not found" << endl;
633 MIL << "Weaken dependencies of " << *iter << endl;
634 queue_push( &(_jobQueue), SOLVER_WEAKEN_SOLVABLE_DEPS );
635 queue_push( &(_jobQueue), id );
638 // Add rules for parallel installable resolvables with different versions
639 std::set<IdString> parallel = ZConfig::instance().multiversion();
640 for (std::set<IdString>::const_iterator it = parallel.begin(); it != parallel.end(); ++it) {
641 queue_push( &(_jobQueue), SOLVER_NOOBSOLETES_SOLVABLE_NAME );
642 queue_push( &(_jobQueue), it->id() );
647 SATResolver::solverEnd()
652 queue_free( &(_jobQueue) );
657 SATResolver::resolvePool(const CapabilitySet & requires_caps,
658 const CapabilitySet & conflict_caps,
659 const PoolItemList & weakItems)
661 MIL << "SATResolver::resolvePool()" << endl;
664 solverInit(weakItems);
666 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
667 Id id = (*iter)->satSolvable().id();
669 ERR << "Install: " << *iter << " not found" << endl;
671 MIL << "Install " << *iter << endl;
672 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE );
673 queue_push( &(_jobQueue), id );
677 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
678 Id id = (*iter)->satSolvable().id();
680 ERR << "Delete: " << *iter << " not found" << endl;
682 MIL << "Delete " << *iter << endl;
683 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE );
684 queue_push( &(_jobQueue), id);
688 for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
689 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE_PROVIDES );
690 queue_push( &(_jobQueue), iter->id() );
691 MIL << "Requires " << *iter << endl;
694 for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
695 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_PROVIDES);
696 queue_push( &(_jobQueue), iter->id() );
697 MIL << "Conflicts " << *iter << endl;
700 // set requirements for a running system
701 setSystemRequirements();
703 // set locks for the solver
707 bool ret = solving(requires_caps, conflict_caps);
710 solverEnd(); // remove solver only if no errors happend. Need it for solving problems
712 (ret?MIL:WAR) << "SATResolver::resolvePool() done. Ret:" << ret << endl;
718 SATResolver::resolveQueue(const SolverQueueItemList &requestQueue,
719 const PoolItemList & weakItems)
721 MIL << "SATResolver::resolvQueue()" << endl;
724 solverInit(weakItems);
726 // generate solver queue
727 for (SolverQueueItemList::const_iterator iter = requestQueue.begin(); iter != requestQueue.end(); iter++) {
728 (*iter)->addRule(_jobQueue);
731 // Add addition item status to the resolve-queue cause these can be set by problem resolutions
732 for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
733 Id id = (*iter)->satSolvable().id();
735 ERR << "Install: " << *iter << " not found" << endl;
737 MIL << "Install " << *iter << endl;
738 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE );
739 queue_push( &(_jobQueue), id );
742 for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
743 sat::detail::IdType ident( (*iter)->satSolvable().ident().id() );
744 MIL << "Delete " << *iter << ident << endl;
745 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_NAME );
746 queue_push( &(_jobQueue), ident);
749 // set requirements for a running system
750 setSystemRequirements();
752 // set locks for the solver
756 bool ret = solving();
760 solverEnd(); // remove solver only if no errors happend. Need it for solving problems
762 MIL << "SATResolver::resolveQueue() done. Ret:" << ret << endl;
767 void SATResolver::doUpdate()
769 MIL << "SATResolver::doUpdate()" << endl;
772 solverInit(PoolItemList());
774 // set requirements for a running system
775 setSystemRequirements();
777 // set locks for the solver
780 _solv = solver_create( _SATPool );
781 _solv->vendorCheckCb = &vendorCheck;
783 _solv->updatesystem = true;
784 _solv->dontinstallrecommended = true; // #FIXME dontinstallrecommended maybe set to false if it works correctly
786 sat::Pool::instance().prepare();
789 MIL << "Starting solving for update...." << endl;
791 solver_solve( _solv, &(_jobQueue) );
792 MIL << "....Solver end" << endl;
794 // copying solution back to zypp pool
795 //-----------------------------------------
797 /* solvables to be installed */
798 for (int i = 0; i < _solv->decisionq.count; i++)
801 p = _solv->decisionq.elements[i];
802 if (p < 0 || !sat::Solvable(p))
804 if (sat::Solvable(p).repository().get() == _solv->installed)
807 PoolItem poolItem = _pool.find (sat::Solvable(p));
809 SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER);
811 ERR << "id " << p << " not found in ZYPP pool." << endl;
815 /* solvables to be erased */
816 for (int i = _solv->installed->start; i < _solv->installed->start + _solv->installed->nsolvables; i++)
818 if (_solv->decisionmap[i] > 0)
821 PoolItem poolItem = _pool.find (sat::Solvable(i));
823 // Check if this is an update
825 invokeOnEach( _pool.byIdentBegin( poolItem ),
826 _pool.byIdentEnd( poolItem ),
827 resfilter::ByUninstalled(), // ByUninstalled
828 functor::functorRef<bool,PoolItem> (info) );
830 if (info.is_updated) {
831 SATSolutionToPool (poolItem, ResStatus::toBeUninstalledDueToUpgrade , ResStatus::SOLVER);
833 SATSolutionToPool (poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER);
836 ERR << "id " << i << " not found in ZYPP pool." << endl;
843 MIL << "SATResolver::doUpdate() done" << endl;
848 //----------------------------------------------------------------------------
849 //----------------------------------------------------------------------------
851 //----------------------------------------------------------------------------
852 //----------------------------------------------------------------------------
854 //----------------------------------------------------------------------------
856 //----------------------------------------------------------------------------
858 struct FindPackage : public resfilter::ResObjectFilterFunctor
860 ProblemSolutionCombi *problemSolution;
861 TransactionKind action;
862 FindPackage (ProblemSolutionCombi *p, const TransactionKind act)
863 : problemSolution (p)
868 bool operator()( PoolItem p)
870 problemSolution->addSingleAction (p, action);
876 //----------------------------------------------------------------------------
877 // Checking if this solvable/item has a buddy which reflect the real
878 // user visible description of an item
879 // e.g. The release package has a buddy to the concerning product item.
880 // This user want's the message "Product foo conflicts with product bar" and
881 // NOT "package release-foo conflicts with package release-bar"
882 //----------------------------------------------------------------------------
885 PoolItem SATResolver::mapItem (const PoolItem &item)
887 sat::Solvable buddy = item.buddy();
888 if (buddy != sat::Solvable())
890 return _pool.find (buddy);
898 sat::Solvable SATResolver::mapSolvable (const Id &id)
900 PoolItem item = _pool.find (sat::Solvable(id));
901 return mapItem(item).satSolvable();
904 string SATResolver::SATprobleminfoString(Id problem, string &detail, Id &ignoreId)
907 Pool *pool = _solv->pool;
909 Id dep, source, target;
913 probr = solver_findproblemrule(_solv, problem);
914 switch (solver_problemruleinfo(_solv, &(_jobQueue), probr, &dep, &source, &target))
916 case SOLVER_PROBLEM_DISTUPGRADE_RULE:
917 s = mapSolvable (source);
918 ret = str::form (_("%s does not belong to a distupgrade repository"), s.asString().c_str());
920 case SOLVER_PROBLEM_INFARCH_RULE:
921 s = mapSolvable (source);
922 ret = str::form (_("%s has inferior architecture"), s.asString().c_str());
924 case SOLVER_PROBLEM_UPDATE_RULE:
925 s = mapSolvable (source);
926 ret = str::form (_("problem with installed package %s"), s.asString().c_str());
928 case SOLVER_PROBLEM_JOB_RULE:
929 ret = _("conflicting requests");
931 case SOLVER_PROBLEM_RPM_RULE:
932 ret = _("some dependency problem");
934 case SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP:
935 ret = str::form (_("nothing provides requested %s"), dep2str(pool, dep));
936 detail += _("Have you enabled all requested repositories?");
938 case SOLVER_PROBLEM_NOT_INSTALLABLE:
939 s = mapSolvable (source);
940 ret = str::form (_("%s is not installable"), s.asString().c_str());
942 case SOLVER_PROBLEM_NOTHING_PROVIDES_DEP:
943 s = mapSolvable (source);
944 ret = str::form (_("nothing provides %s needed by %s"), dep2str(pool, dep), s.asString().c_str());
946 case SOLVER_PROBLEM_SAME_NAME:
947 s = mapSolvable (source);
948 s2 = mapSolvable (target);
949 ret = str::form (_("cannot install both %s and %s"), s.asString().c_str(), s2.asString().c_str());
951 case SOLVER_PROBLEM_PACKAGE_CONFLICT:
952 s = mapSolvable (source);
953 s2 = mapSolvable (target);
954 ret = str::form (_("%s conflicts with %s provided by %s"), s.asString().c_str(), dep2str(pool, dep), s2.asString().c_str());
956 case SOLVER_PROBLEM_PACKAGE_OBSOLETES:
957 s = mapSolvable (source);
958 s2 = mapSolvable (target);
959 ret = str::form (_("%s obsoletes %s provided by %s"), s.asString().c_str(), dep2str(pool, dep), s2.asString().c_str());
961 case SOLVER_PROBLEM_SELF_CONFLICT:
962 s = mapSolvable (source);
963 ret = str::form (_("solvable %s conflicts with %s provided by itself"), s.asString().c_str(), dep2str(pool, dep));
965 case SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE:
966 ignoreId = source; // for setting weak dependencies
967 s = mapSolvable (source);
969 sat::WhatProvides possibleProviders(cap);
971 // check, if a provider will be deleted
972 typedef list<PoolItem> ProviderList;
973 ProviderList providerlistInstalled, providerlistUninstalled;
974 for_( iter1, possibleProviders.begin(), possibleProviders.end() ) {
975 PoolItem provider1 = ResPool::instance().find( *iter1 );
976 // find pair of an installed/uninstalled item with the same NVR
978 for_( iter2, possibleProviders.begin(), possibleProviders.end() ) {
979 PoolItem provider2 = ResPool::instance().find( *iter2 );
980 if (compareByNVR (provider1.resolvable(),provider2.resolvable()) == 0
981 && ( (provider1.status().isInstalled() && provider2.status().isUninstalled())
982 || (provider2.status().isInstalled() && provider1.status().isUninstalled()) )) {
988 if (provider1.status().isInstalled())
989 providerlistInstalled.push_back(provider1);
991 providerlistUninstalled.push_back(provider1);
995 ret = str::form (_("%s requires %s, but this requirement cannot be provided"), s.asString().c_str(), dep2str(pool, dep));
996 if (providerlistInstalled.size() > 0) {
997 detail += _("deleted providers: ");
998 for (ProviderList::const_iterator iter = providerlistInstalled.begin(); iter != providerlistInstalled.end(); iter++) {
999 if (iter == providerlistInstalled.begin())
1000 detail += itemToString( *iter );
1002 detail += "\n " + itemToString( mapItem(*iter) );
1005 if (providerlistUninstalled.size() > 0) {
1006 if (detail.size() > 0)
1007 detail += _("\nuninstallable providers: ");
1009 detail = _("uninstallable providers: ");
1010 for (ProviderList::const_iterator iter = providerlistUninstalled.begin(); iter != providerlistUninstalled.end(); iter++) {
1011 if (iter == providerlistUninstalled.begin())
1012 detail += itemToString( *iter );
1014 detail += "\n " + itemToString( mapItem(*iter) );
1024 SATResolver::problems ()
1026 ResolverProblemList resolverProblems;
1027 if (_solv && _solv->problems.count) {
1028 Pool *pool = _solv->pool;
1031 Id problem, solution, element;
1032 sat::Solvable s, sd;
1034 CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1035 CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1037 MIL << "Encountered problems! Here are the solutions:\n" << endl;
1040 while ((problem = solver_next_problem(_solv, problem)) != 0) {
1041 MIL << "Problem " << pcnt++ << ":" << endl;
1042 MIL << "====================================" << endl;
1045 string whatString = SATprobleminfoString (problem,detail,ignoreId);
1046 MIL << whatString << endl;
1047 MIL << "------------------------------------" << endl;
1048 ResolverProblem_Ptr resolverProblem = new ResolverProblem (whatString, detail);
1051 while ((solution = solver_next_solution(_solv, problem, solution)) != 0) {
1053 ProblemSolutionCombi *problemSolution = new ProblemSolutionCombi(resolverProblem);
1054 while ((element = solver_next_solutionelement(_solv, problem, solution, element, &p, &rp)) != 0) {
1055 if (p == SOLVER_SOLUTION_JOB) {
1056 /* job, rp is index into job queue */
1057 what = _jobQueue.elements[rp];
1058 switch (_jobQueue.elements[rp-1])
1060 case SOLVER_INSTALL_SOLVABLE: {
1061 s = mapSolvable (what);
1062 PoolItem poolItem = _pool.find (s);
1064 if (_solv->installed && s.get()->repo == _solv->installed) {
1065 problemSolution->addSingleAction (poolItem, REMOVE);
1066 string description = str::form (_("do not keep %s installed"), s.asString().c_str() );
1067 MIL << description << endl;
1068 problemSolution->addDescription (description);
1070 problemSolution->addSingleAction (poolItem, KEEP);
1071 string description = str::form (_("do not install %s"), s.asString().c_str());
1072 MIL << description << endl;
1073 problemSolution->addDescription (description);
1076 ERR << "SOLVER_INSTALL_SOLVABLE: No item found for " << s.asString() << endl;
1080 case SOLVER_ERASE_SOLVABLE: {
1081 s = mapSolvable (what);
1082 PoolItem poolItem = _pool.find (s);
1084 if (_solv->installed && s.get()->repo == _solv->installed) {
1085 problemSolution->addSingleAction (poolItem, KEEP);
1086 string description = str::form (_("keep %s"), s.asString().c_str());
1087 MIL << description << endl;
1088 problemSolution->addDescription (description);
1090 problemSolution->addSingleAction (poolItem, UNLOCK);
1091 string description = str::form (_("do not forbid installation of %s"), itemToString( poolItem ).c_str());
1092 MIL << description << endl;
1093 problemSolution->addDescription (description);
1096 ERR << "SOLVER_ERASE_SOLVABLE: No item found for " << s.asString() << endl;
1100 case SOLVER_INSTALL_SOLVABLE_NAME:
1102 IdString ident( what );
1103 SolverQueueItemInstall_Ptr install =
1104 new SolverQueueItemInstall(_pool, ident.asString(), false );
1105 problemSolution->addSingleAction (install, REMOVE_SOLVE_QUEUE_ITEM);
1107 string description = str::form (_("do not install %s"), ident.c_str() );
1108 MIL << description << endl;
1109 problemSolution->addDescription (description);
1112 case SOLVER_ERASE_SOLVABLE_NAME:
1114 // As we do not know, if this request has come from resolvePool or
1115 // resolveQueue we will have to take care for both cases.
1116 IdString ident( what );
1117 FindPackage info (problemSolution, KEEP);
1118 invokeOnEach( _pool.byIdentBegin( ident ),
1119 _pool.byIdentEnd( ident ),
1120 functor::chain (resfilter::ByInstalled (), // ByInstalled
1121 resfilter::ByTransact ()), // will be deinstalled
1122 functor::functorRef<bool,PoolItem> (info) );
1124 SolverQueueItemDelete_Ptr del =
1125 new SolverQueueItemDelete(_pool, ident.asString(), false );
1126 problemSolution->addSingleAction (del, REMOVE_SOLVE_QUEUE_ITEM);
1128 string description = str::form (_("keep %s"), ident.c_str());
1129 MIL << description << endl;
1130 problemSolution->addDescription (description);
1133 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
1135 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_REQUIRE);
1136 string description = "";
1138 // Checking if this problem solution would break your system
1139 if (system_requires.find(Capability(what)) != system_requires.end()) {
1140 // Show a better warning
1141 resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1142 resolverProblem->setDescription(_("This request will break your system!"));
1143 description = _("ignore the warning of a broken system");
1144 description += string(" (requires:")+dep2str(pool, what)+")";
1145 MIL << description << endl;
1146 problemSolution->addFrontDescription (description);
1148 description = str::form (_("do not ask to install a solvable providing %s"), dep2str(pool, what));
1149 MIL << description << endl;
1150 problemSolution->addDescription (description);
1154 case SOLVER_ERASE_SOLVABLE_PROVIDES:
1156 problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_CONFLICT);
1157 string description = "";
1159 // Checking if this problem solution would break your system
1160 if (system_conflicts.find(Capability(what)) != system_conflicts.end()) {
1161 // Show a better warning
1162 resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1163 resolverProblem->setDescription(_("This request will break your system!"));
1164 description = _("ignore the warning of a broken system");
1165 description += string(" (conflicts:")+dep2str(pool, what)+")";
1166 MIL << description << endl;
1167 problemSolution->addFrontDescription (description);
1170 description = str::form (_("do not ask to delete all solvables providing %s"), dep2str(pool, what));
1171 MIL << description << endl;
1172 problemSolution->addDescription (description);
1176 case SOLVER_INSTALL_SOLVABLE_UPDATE:
1178 s = mapSolvable (what);
1179 PoolItem poolItem = _pool.find (s);
1181 if (_solv->installed && s.get()->repo == _solv->installed) {
1182 problemSolution->addSingleAction (poolItem, KEEP);
1183 string description = str::form (_("do not install most recent version of %s"), s.asString().c_str());
1184 MIL << description << endl;
1185 problemSolution->addDescription (description);
1187 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE " << poolItem << " is not selected for installation" << endl;
1190 ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE: No item found for " << s.asString() << endl;
1195 MIL << "- do something different" << endl;
1196 ERR << "No valid solution available" << endl;
1199 } else if (p == SOLVER_SOLUTION_INFARCH) {
1200 s = mapSolvable (rp);
1201 PoolItem poolItem = _pool.find (s);
1202 if (_solv->installed && s.get()->repo == _solv->installed) {
1203 problemSolution->addSingleAction (poolItem, KEEP);
1204 string description = str::form (_("keep %s despite the inferior architecture"), s.asString().c_str());
1205 MIL << description << endl;
1206 problemSolution->addDescription (description);
1208 problemSolution->addSingleAction (poolItem, INSTALL);
1209 string description = str::form (_("install %s despite the inferior architecture"), s.asString().c_str());
1210 MIL << description << endl;
1211 problemSolution->addDescription (description);
1213 } else if (p == SOLVER_SOLUTION_DISTUPGRADE) {
1214 s = mapSolvable (rp);
1215 PoolItem poolItem = _pool.find (s);
1216 if (_solv->installed && s.get()->repo == _solv->installed) {
1217 problemSolution->addSingleAction (poolItem, KEEP);
1218 string description = str::form (_("keep obsolete %s"), s.asString().c_str());
1219 MIL << description << endl;
1220 problemSolution->addDescription (description);
1222 problemSolution->addSingleAction (poolItem, INSTALL);
1223 string description = str::form (_("install %s from excluded repository"), s.asString().c_str());
1224 MIL << description << endl;
1225 problemSolution->addDescription (description);
1228 /* policy, replace p with rp */
1229 s = mapSolvable (p);
1231 sd = mapSolvable (rp);
1233 PoolItem itemFrom = _pool.find (s);
1234 if (s == sd && _solv->distupgrade)
1236 PoolItem poolItem = _pool.find (s);
1238 problemSolution->addSingleAction (poolItem, LOCK); // for solver reason: NOT weak lock.
1239 string description = str::form (_("keep %s"), s.asString().c_str());
1240 MIL << description << endl;
1241 problemSolution->addDescription (description);
1243 ERR << "SOLVER_INSTALL_SOLVABLE: No item found for " << s.asString() << endl;
1250 PoolItem itemTo = _pool.find (sd);
1251 if (itemFrom && itemTo) {
1252 problemSolution->addSingleAction (itemTo, INSTALL);
1254 if (evrcmp(pool, s.get()->evr, sd.get()->evr, EVRCMP_COMPARE ) > 0)
1256 string description = str::form (_("downgrade of %s to %s"), s.asString().c_str(), sd.asString().c_str());
1257 MIL << description << endl;
1258 problemSolution->addDescription (description);
1261 if (!_solv->allowarchchange && s.get()->name == sd.get()->name && s.get()->arch != sd.get()->arch
1262 && policy_illegal_archchange(_solv, s.get(), sd.get()))
1264 string description = str::form (_("architecture change of %s to %s"), s.asString().c_str(), sd.asString().c_str());
1265 MIL << description << endl;
1266 problemSolution->addDescription (description);
1269 if (!_solv->allowvendorchange && s.get()->name == sd.get()->name && s.get()->vendor != sd.get()->vendor
1270 && policy_illegal_vendorchange(_solv, s.get(), sd.get()))
1272 IdString s_vendor( s.vendor() );
1273 IdString sd_vendor( sd.vendor() );
1274 string description = str::form (_("install %s (with vendor change)\n %s --> %s") ,
1275 sd.asString().c_str(),
1276 ( s_vendor ? s_vendor.c_str() : " (no vendor) " ),
1277 ( sd_vendor ? sd_vendor.c_str() : " (no vendor) " ) );
1278 MIL << description << endl;
1279 problemSolution->addDescription (description);
1283 string description = str::form (_("replacement of %s with %s"), s.asString().c_str(), sd.asString().c_str());
1284 MIL << description << endl;
1285 problemSolution->addDescription (description);
1288 ERR << s.asString() << " or " << sd.asString() << " not found" << endl;
1294 string description = str::form (_("deinstallation of %s"), s.asString().c_str());
1295 MIL << description << endl;
1296 problemSolution->addDescription (description);
1297 problemSolution->addSingleAction (itemFrom, REMOVE);
1302 resolverProblem->addSolution (problemSolution,
1303 problemSolution->actionCount() > 1 ? true : false); // Solutions with more than 1 action will be shown first.
1304 MIL << "------------------------------------" << endl;
1308 // There is a possibility to ignore this error by setting weak dependencies
1309 PoolItem item = _pool.find (sat::Solvable(ignoreId));
1310 ProblemSolutionIgnore *problemSolution = new ProblemSolutionIgnore(resolverProblem, item);
1311 resolverProblem->addSolution (problemSolution,
1312 false); // Solutions will be shown at the end
1313 MIL << "ignore some dependencies of " << item << endl;
1314 MIL << "------------------------------------" << endl;
1318 resolverProblems.push_back (resolverProblem);
1321 return resolverProblems;
1325 SATResolver::applySolutions (const ProblemSolutionList & solutions)
1327 for (ProblemSolutionList::const_iterator iter = solutions.begin();
1328 iter != solutions.end(); ++iter) {
1329 ProblemSolution_Ptr solution = *iter;
1330 Resolver dummyResolver(_pool);
1331 if (!solution->apply (dummyResolver))
1336 void SATResolver::setLocks()
1338 for (PoolItemList::const_iterator iter = _items_to_lock.begin(); iter != _items_to_lock.end(); iter++) {
1339 sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
1340 if (iter->status().isInstalled()) {
1341 MIL << "Lock installed item " << *iter << endl;
1342 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE );
1343 queue_push( &(_jobQueue), ident );
1345 MIL << "Lock NOT installed item " << *iter << endl;
1346 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE );
1347 queue_push( &(_jobQueue), ident );
1351 for (PoolItemList::const_iterator iter = _items_to_keep.begin(); iter != _items_to_keep.end(); iter++) {
1352 sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
1353 if (iter->status().isInstalled()) {
1354 MIL << "Keep installed item " << *iter << endl;
1355 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE | SOLVER_WEAK);
1356 queue_push( &(_jobQueue), ident );
1358 MIL << "Keep NOT installed item " << *iter << ident << endl;
1359 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE | SOLVER_WEAK);
1360 queue_push( &(_jobQueue), ident );
1365 void SATResolver::setSystemRequirements()
1367 CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1368 CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1370 for (CapabilitySet::const_iterator iter = system_requires.begin(); iter != system_requires.end(); iter++) {
1371 queue_push( &(_jobQueue), SOLVER_INSTALL_SOLVABLE_PROVIDES);
1372 queue_push( &(_jobQueue), iter->id() );
1373 MIL << "SYSTEM Requires " << *iter << endl;
1376 for (CapabilitySet::const_iterator iter = system_conflicts.begin(); iter != system_conflicts.end(); iter++) {
1377 queue_push( &(_jobQueue), SOLVER_ERASE_SOLVABLE_PROVIDES);
1378 queue_push( &(_jobQueue), iter->id() );
1379 MIL << "SYSTEM Conflicts " << *iter << endl;
1382 // try to prefer none architecture change if possible
1383 // So the architecture of the "rpm" package should be prefered
1385 Capability cap("rpm");
1386 sat::WhatProvides rpmProviders(cap);
1387 for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
1388 if (iter2->isSystem()) {
1389 sat::detail::IdType nid = iter2->ident().id();
1390 nid = rel2id(_SATPool,
1392 iter2->arch().id(), REL_ARCH, true);
1395 bool addRule = false;
1396 Capability cap(nid);
1397 sat::WhatProvides rpmProviders(cap);
1398 for_( iter3, rpmProviders.begin(), rpmProviders.end() ) {
1399 if ( !(iter3->isSystem())) {
1408 queue_push(&(_jobQueue), SOLVER_INSTALL|SOLVABLE_NAME|SOLVER_ESSENTIAL);
1409 queue_push(&(_jobQueue), nid);
1416 ///////////////////////////////////////////////////////////////////
1417 };// namespace detail
1418 /////////////////////////////////////////////////////////////////////
1419 /////////////////////////////////////////////////////////////////////
1420 };// namespace solver
1421 ///////////////////////////////////////////////////////////////////////
1422 ///////////////////////////////////////////////////////////////////////
1424 /////////////////////////////////////////////////////////////////////////