libzypp  17.11.3
SATResolver.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* SATResolver.cc
3  *
4  * Copyright (C) 2000-2002 Ximian, Inc.
5  * Copyright (C) 2005 SUSE Linux Products GmbH
6  *
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.
10  *
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.
15  *
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
19  * 02111-1307, USA.
20  */
21 extern "C"
22 {
23 #include <solv/repo_solv.h>
24 #include <solv/poolarch.h>
25 #include <solv/evr.h>
26 #include <solv/poolvendor.h>
27 #include <solv/policy.h>
28 #include <solv/bitmap.h>
29 #include <solv/queue.h>
30 }
31 
32 #define ZYPP_USE_RESOLVER_INTERNALS
33 
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"
58 #include "zypp/sat/Transaction.h"
59 #include "zypp/sat/Queue.h"
60 
62 
63 #define XDEBUG(x) do { if (base::logger::isExcessive()) XXX << x << std::endl;} while (0)
64 
65 #undef ZYPP_BASE_LOGGER_LOGGROUP
66 #define ZYPP_BASE_LOGGER_LOGGROUP "zypp::solver"
67 
69 namespace zypp
70 {
71 
73  namespace env
74  {
75  inline bool HACKENV( const char * var_r, bool default_r )
76  {
77  bool ret = default_r;
78  const char * val = ::getenv( var_r );
79  if ( val )
80  {
81  ret = str::strToBool( val, default_r );
82  if ( ret != default_r )
83  INT << "HACKENV " << var_r << " = " << ret << endl;
84  }
85  return ret;
86  }
87  } // namespace env
89 
91  namespace solver
92  {
93  namespace detail
95  {
96 
97 using namespace std;
98 
99 IMPL_PTR_TYPE(SATResolver);
100 
101 #define MAYBE_CLEANDEPS (cleandepsOnRemove()?SOLVER_CLEANDEPS:0)
102 
103 //---------------------------------------------------------------------------
104 // Callbacks for SAT policies
105 //---------------------------------------------------------------------------
106 
107 int vendorCheck( sat::detail::CPool *pool, Solvable *solvable1, Solvable *solvable2 )
108 {
109  return VendorAttr::instance().equivalent( IdString(solvable1->vendor),
110  IdString(solvable2->vendor) ) ? 0 : 1;
111 }
112 
113 
114 inline std::string itemToString( const PoolItem & item )
115 {
116  if ( !item )
117  return std::string();
118 
119  sat::Solvable slv( item.satSolvable() );
120  std::string ret( slv.asString() ); // n-v-r.a
121  if ( ! slv.isSystem() )
122  {
123  ret += "[";
124  ret += slv.repository().alias();
125  ret += "]";
126  }
127  return ret;
128 }
129 
130 inline PoolItem getPoolItem( Id id_r )
131 {
132  PoolItem ret( (sat::Solvable( id_r )) );
133  if ( !ret && id_r )
134  INT << "id " << id_r << " not found in ZYPP pool." << endl;
135  return ret;
136 }
137 
138 //---------------------------------------------------------------------------
139 
140 std::ostream &
141 SATResolver::dumpOn( std::ostream & os ) const
142 {
143  os << "<resolver>" << endl;
144  if (_satSolver) {
145 #define OUTS(X) os << " " << #X << "\t= " << solver_get_flag(_satSolver, SOLVER_FLAG_##X) << endl
146  OUTS( ALLOW_DOWNGRADE );
147  OUTS( ALLOW_ARCHCHANGE );
148  OUTS( ALLOW_VENDORCHANGE );
149  OUTS( ALLOW_NAMECHANGE );
150  OUTS( ALLOW_UNINSTALL );
151  OUTS( NO_UPDATEPROVIDE );
152  OUTS( SPLITPROVIDES );
153  OUTS( IGNORE_RECOMMENDED );
154  OUTS( ADD_ALREADY_RECOMMENDED );
155  OUTS( NO_INFARCHCHECK );
156  OUTS( KEEP_EXPLICIT_OBSOLETES );
157  OUTS( BEST_OBEY_POLICY );
158  OUTS( NO_AUTOTARGET );
159  OUTS( DUP_ALLOW_DOWNGRADE );
160  OUTS( DUP_ALLOW_ARCHCHANGE );
161  OUTS( DUP_ALLOW_VENDORCHANGE );
162  OUTS( DUP_ALLOW_NAMECHANGE );
163  OUTS( KEEP_ORPHANS );
164  OUTS( BREAK_ORPHANS );
165  OUTS( FOCUS_INSTALLED );
166  OUTS( YUM_OBSOLETES );
167 #undef OUTS
168  os << " distupgrade = " << _distupgrade << endl;
169  os << " distupgrade_removeunsupported = " << _distupgrade_removeunsupported << endl;
170  os << " solveSrcPackages = " << _solveSrcPackages << endl;
171  os << " cleandepsOnRemove = " << _cleandepsOnRemove << endl;
172  os << " fixsystem = " << _fixsystem << endl;
173  } else {
174  os << "<NULL>";
175  }
176  return os << "<resolver/>" << endl;
177 }
178 
179 //---------------------------------------------------------------------------
180 
181 // NOTE: flag defaults must be in sync with ZVARDEFAULT in Resolver.cc
182 SATResolver::SATResolver (const ResPool & pool, sat::detail::CPool *satPool)
183  : _pool(pool)
184  , _satPool(satPool)
185  , _satSolver(NULL)
186  , _fixsystem(false)
187  , _allowdowngrade ( false )
188  , _allownamechange ( true ) // bsc#1071466
189  , _allowarchchange ( false )
190  , _allowvendorchange ( ZConfig::instance().solver_allowVendorChange() )
191  , _allowuninstall ( false )
192  , _updatesystem(false)
193  , _noupdateprovide ( false )
194  , _dosplitprovides ( true )
195  , _onlyRequires (ZConfig::instance().solver_onlyRequires())
196  , _ignorealreadyrecommended(true)
197  , _distupgrade(false)
198  , _distupgrade_removeunsupported(false)
199  , _dup_allowdowngrade ( ZConfig::instance().solver_dupAllowDowngrade() )
200  , _dup_allownamechange ( ZConfig::instance().solver_dupAllowNameChange() )
201  , _dup_allowarchchange ( ZConfig::instance().solver_dupAllowArchChange() )
202  , _dup_allowvendorchange ( ZConfig::instance().solver_dupAllowVendorChange() )
203  , _solveSrcPackages(false)
204  , _cleandepsOnRemove(ZConfig::instance().solver_cleandepsOnRemove())
205 {
206 }
207 
208 
209 SATResolver::~SATResolver()
210 {
211  solverEnd();
212 }
213 
214 //---------------------------------------------------------------------------
215 
216 ResPool
217 SATResolver::pool (void) const
218 {
219  return _pool;
220 }
221 
222 //---------------------------------------------------------------------------
223 
224 // copy marked item from solution back to pool
225 // if data != NULL, set as APPL_LOW (from establishPool())
226 
227 static void
229 {
230  // resetting
231  item.status().resetTransact (causer);
232  item.status().resetWeak ();
233 
234  bool r;
235 
236  // installation/deletion
237  if (status.isToBeInstalled()) {
238  r = item.status().setToBeInstalled (causer);
239  XDEBUG("SATSolutionToPool install returns " << item << ", " << r);
240  }
241  else if (status.isToBeUninstalledDueToUpgrade()) {
242  r = item.status().setToBeUninstalledDueToUpgrade (causer);
243  XDEBUG("SATSolutionToPool upgrade returns " << item << ", " << r);
244  }
245  else if (status.isToBeUninstalled()) {
246  r = item.status().setToBeUninstalled (causer);
247  XDEBUG("SATSolutionToPool remove returns " << item << ", " << r);
248  }
249 
250  return;
251 }
252 
253 //----------------------------------------------------------------------------
254 //----------------------------------------------------------------------------
255 // resolvePool
256 //----------------------------------------------------------------------------
257 //----------------------------------------------------------------------------
266 {
267  SATCollectTransact( PoolItemList & items_to_install_r,
268  PoolItemList & items_to_remove_r,
269  PoolItemList & items_to_lock_r,
270  PoolItemList & items_to_keep_r,
271  bool solveSrcPackages_r )
272  : _items_to_install( items_to_install_r )
273  , _items_to_remove( items_to_remove_r )
274  , _items_to_lock( items_to_lock_r )
275  , _items_to_keep( items_to_keep_r )
276  , _solveSrcPackages( solveSrcPackages_r )
277  {
278  _items_to_install.clear();
279  _items_to_remove.clear();
280  _items_to_lock.clear();
281  _items_to_keep.clear();
282  }
283 
284  bool operator()( const PoolItem & item_r )
285  {
286 
287  ResStatus & itemStatus( item_r.status() );
288  bool by_solver = ( itemStatus.isBySolver() || itemStatus.isByApplLow() );
289 
290  if ( by_solver )
291  {
292  // Clear former solver/establish resultd
293  itemStatus.resetTransact( ResStatus::APPL_LOW );
294  return true; // -> back out here, don't re-queue former results
295  }
296 
297  if ( !_solveSrcPackages && item_r.isKind<SrcPackage>() )
298  {
299  // Later we may continue on a per source package base.
300  return true; // dont process this source package.
301  }
302 
303  switch ( itemStatus.getTransactValue() )
304  {
305  case ResStatus::TRANSACT:
306  itemStatus.isUninstalled() ? _items_to_install.push_back( item_r )
307  : _items_to_remove.push_back( item_r ); break;
308  case ResStatus::LOCKED: _items_to_lock.push_back( item_r ); break;
309  case ResStatus::KEEP_STATE: _items_to_keep.push_back( item_r ); break;
310  }
311  return true;
312  }
313 
314 private:
315  PoolItemList & _items_to_install;
316  PoolItemList & _items_to_remove;
317  PoolItemList & _items_to_lock;
318  PoolItemList & _items_to_keep;
320 
321 };
323 
324 
325 //----------------------------------------------------------------------------
326 //----------------------------------------------------------------------------
327 // solving.....
328 //----------------------------------------------------------------------------
329 //----------------------------------------------------------------------------
330 
331 
333 {
334  public:
337 
338  CheckIfUpdate( const sat::Solvable & installed_r )
339  : is_updated( false )
340  , _installed( installed_r )
341  {}
342 
343  // check this item will be updated
344 
345  bool operator()( const PoolItem & item )
346  {
347  if ( item.status().isToBeInstalled() )
348  {
349  if ( ! item.multiversionInstall() || sameNVRA( _installed, item ) )
350  {
351  is_updated = true;
352  return false;
353  }
354  }
355  return true;
356  }
357 };
358 
359 
361 {
362  public:
364 
365  CollectPseudoInstalled( Queue *queue )
366  :solvableQueue (queue)
367  {}
368 
369  // collecting PseudoInstalled items
370  bool operator()( PoolItem item )
371  {
372  if ( traits::isPseudoInstalled( item.satSolvable().kind() ) )
373  queue_push( solvableQueue, item.satSolvable().id() );
374  return true;
375  }
376 };
377 
378 bool
379 SATResolver::solving(const CapabilitySet & requires_caps,
380  const CapabilitySet & conflict_caps)
381 {
382  _satSolver = solver_create( _satPool );
383  ::pool_set_custom_vendorcheck( _satPool, &vendorCheck );
384  if (_fixsystem) {
385  queue_push( &(_jobQueue), SOLVER_VERIFY|SOLVER_SOLVABLE_ALL);
386  queue_push( &(_jobQueue), 0 );
387  }
388  if (_updatesystem) {
389  queue_push( &(_jobQueue), SOLVER_UPDATE|SOLVER_SOLVABLE_ALL);
390  queue_push( &(_jobQueue), 0 );
391  }
392  if (_distupgrade) {
393  queue_push( &(_jobQueue), SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_ALL);
394  queue_push( &(_jobQueue), 0 );
395  }
396  if (_distupgrade_removeunsupported) {
397  queue_push( &(_jobQueue), SOLVER_DROP_ORPHANED|SOLVER_SOLVABLE_ALL);
398  queue_push( &(_jobQueue), 0 );
399  }
400  solver_set_flag(_satSolver, SOLVER_FLAG_ADD_ALREADY_RECOMMENDED, !_ignorealreadyrecommended);
401  solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_DOWNGRADE, _allowdowngrade);
402  solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_NAMECHANGE, _allownamechange);
403  solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_ARCHCHANGE, _allowarchchange);
404  solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_VENDORCHANGE, _allowvendorchange);
405  solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_UNINSTALL, _allowuninstall);
406  solver_set_flag(_satSolver, SOLVER_FLAG_NO_UPDATEPROVIDE, _noupdateprovide);
407  solver_set_flag(_satSolver, SOLVER_FLAG_SPLITPROVIDES, _dosplitprovides);
408  solver_set_flag(_satSolver, SOLVER_FLAG_IGNORE_RECOMMENDED, false); // resolve recommended namespaces
409  solver_set_flag(_satSolver, SOLVER_FLAG_ONLY_NAMESPACE_RECOMMENDED, _onlyRequires); //
410  solver_set_flag(_satSolver, SOLVER_FLAG_DUP_ALLOW_DOWNGRADE, _dup_allowdowngrade );
411  solver_set_flag(_satSolver, SOLVER_FLAG_DUP_ALLOW_NAMECHANGE, _dup_allownamechange );
412  solver_set_flag(_satSolver, SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE, _dup_allowarchchange );
413  solver_set_flag(_satSolver, SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE, _dup_allowvendorchange );
414 #if 1
415 #define HACKENV(X,D) solver_set_flag(_satSolver, X, env::HACKENV( #X, D ) );
416  HACKENV( SOLVER_FLAG_DUP_ALLOW_DOWNGRADE, _dup_allowdowngrade );
417  HACKENV( SOLVER_FLAG_DUP_ALLOW_NAMECHANGE, _dup_allownamechange );
418  HACKENV( SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE, _dup_allowarchchange );
419  HACKENV( SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE,_dup_allowvendorchange );
420 #undef HACKENV
421 #endif
423 
424  // Solve !
425  MIL << "Starting solving...." << endl;
426  MIL << *this;
427  solver_solve( _satSolver, &(_jobQueue) );
428  MIL << "....Solver end" << endl;
429 
430  // copying solution back to zypp pool
431  //-----------------------------------------
432  _result_items_to_install.clear();
433  _result_items_to_remove.clear();
434 
435  /* solvables to be installed */
436  Queue decisionq;
437  queue_init(&decisionq);
438  solver_get_decisionqueue(_satSolver, &decisionq);
439  for ( int i = 0; i < decisionq.count; ++i )
440  {
441  sat::Solvable slv( decisionq.elements[i] );
442  if ( !slv || slv.isSystem() )
443  continue;
444 
445  PoolItem poolItem( slv );
447  _result_items_to_install.push_back( poolItem );
448  }
449  queue_free(&decisionq);
450 
451  /* solvables to be erased */
452  Repository systemRepo( sat::Pool::instance().findSystemRepo() ); // don't create if it does not exist
453  if ( systemRepo && ! systemRepo.solvablesEmpty() )
454  {
455  bool mustCheckObsoletes = false;
456  for_( it, systemRepo.solvablesBegin(), systemRepo.solvablesEnd() )
457  {
458  if (solver_get_decisionlevel(_satSolver, it->id()) > 0)
459  continue;
460 
461  // Check if this is an update
462  CheckIfUpdate info( *it );
463  PoolItem poolItem( *it );
464  invokeOnEach( _pool.byIdentBegin( poolItem ),
465  _pool.byIdentEnd( poolItem ),
466  resfilter::ByUninstalled(), // ByUninstalled
467  functor::functorRef<bool,PoolItem> (info) );
468 
469  if (info.is_updated) {
471  } else {
473  if ( ! mustCheckObsoletes )
474  mustCheckObsoletes = true; // lazy check for UninstalledDueToObsolete
475  }
476  _result_items_to_remove.push_back (poolItem);
477  }
478  if ( mustCheckObsoletes )
479  {
480  sat::WhatObsoletes obsoleted( _result_items_to_install.begin(), _result_items_to_install.end() );
481  for_( it, obsoleted.poolItemBegin(), obsoleted.poolItemEnd() )
482  {
483  ResStatus & status( it->status() );
484  // WhatObsoletes contains installed items only!
485  if ( status.transacts() && ! status.isToBeUninstalledDueToUpgrade() )
486  status.setToBeUninstalledDueToObsolete();
487  }
488  }
489  }
490 
491  Queue recommendations;
492  Queue suggestions;
493  Queue orphaned;
494  Queue unneeded;
495  queue_init(&recommendations);
496  queue_init(&suggestions);
497  queue_init(&orphaned);
498  queue_init(&unneeded);
499  solver_get_recommendations(_satSolver, &recommendations, &suggestions, 0);
500  solver_get_orphaned(_satSolver, &orphaned);
501  solver_get_unneeded(_satSolver, &unneeded, 1);
502  /* solvables which are recommended */
503  for ( int i = 0; i < recommendations.count; ++i )
504  {
505  PoolItem poolItem( getPoolItem( recommendations.elements[i] ) );
506  poolItem.status().setRecommended( true );
507  }
508 
509  /* solvables which are suggested */
510  for ( int i = 0; i < suggestions.count; ++i )
511  {
512  PoolItem poolItem( getPoolItem( suggestions.elements[i] ) );
513  poolItem.status().setSuggested( true );
514  }
515 
516  _problem_items.clear();
517  /* solvables which are orphaned */
518  for ( int i = 0; i < orphaned.count; ++i )
519  {
520  PoolItem poolItem( getPoolItem( orphaned.elements[i] ) );
521  poolItem.status().setOrphaned( true );
522  _problem_items.push_back( poolItem );
523  }
524 
525  /* solvables which are unneeded */
526  for ( int i = 0; i < unneeded.count; ++i )
527  {
528  PoolItem poolItem( getPoolItem( unneeded.elements[i] ) );
529  poolItem.status().setUnneeded( true );
530  }
531 
532  queue_free(&recommendations);
533  queue_free(&suggestions);
534  queue_free(&orphaned);
535  queue_free(&unneeded);
536 
537  /* Write validation state back to pool */
538  Queue flags, solvableQueue;
539 
540  queue_init(&flags);
541  queue_init(&solvableQueue);
542 
543  CollectPseudoInstalled collectPseudoInstalled(&solvableQueue);
544  invokeOnEach( _pool.begin(),
545  _pool.end(),
546  functor::functorRef<bool,PoolItem> (collectPseudoInstalled) );
547  solver_trivial_installable(_satSolver, &solvableQueue, &flags );
548  for (int i = 0; i < solvableQueue.count; i++) {
549  PoolItem item = _pool.find (sat::Solvable(solvableQueue.elements[i]));
550  item.status().setUndetermined();
551 
552  if (flags.elements[i] == -1) {
553  item.status().setNonRelevant();
554  XDEBUG("SATSolutionToPool(" << item << " ) nonRelevant !");
555  } else if (flags.elements[i] == 1) {
556  item.status().setSatisfied();
557  XDEBUG("SATSolutionToPool(" << item << " ) satisfied !");
558  } else if (flags.elements[i] == 0) {
559  item.status().setBroken();
560  XDEBUG("SATSolutionToPool(" << item << " ) broken !");
561  }
562  }
563  queue_free(&(solvableQueue));
564  queue_free(&flags);
565 
566 
567  // Solvables which were selected due requirements which have been made by the user will
568  // be selected by APPL_LOW. We can't use any higher level, because this setting must
569  // not serve as a request for the next solver run. APPL_LOW is reset before solving.
570  for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
571  sat::WhatProvides rpmProviders(*iter);
572  for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
573  PoolItem poolItem(*iter2);
574  if (poolItem.status().isToBeInstalled()) {
575  MIL << "User requirement " << *iter << " sets " << poolItem << endl;
576  poolItem.status().setTransactByValue (ResStatus::APPL_LOW);
577  }
578  }
579  }
580  for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
581  sat::WhatProvides rpmProviders(*iter);
582  for_( iter2, rpmProviders.begin(), rpmProviders.end() ) {
583  PoolItem poolItem(*iter2);
584  if (poolItem.status().isToBeUninstalled()) {
585  MIL << "User conflict " << *iter << " sets " << poolItem << endl;
586  poolItem.status().setTransactByValue (ResStatus::APPL_LOW);
587  }
588  }
589  }
590 
591  if (solver_problem_count(_satSolver) > 0 )
592  {
593  ERR << "Solverrun finished with an ERROR" << endl;
594  return false;
595  }
596 
597  return true;
598 }
599 
600 
601 void
602 SATResolver::solverInit(const PoolItemList & weakItems)
603 {
604 
605  MIL << "SATResolver::solverInit()" << endl;
606 
607  // remove old stuff
608  solverEnd();
609  queue_init( &_jobQueue );
610 
611  // clear and rebuild: _items_to_install, _items_to_remove, _items_to_lock, _items_to_keep
612  {
613  SATCollectTransact collector( _items_to_install, _items_to_remove, _items_to_lock, _items_to_keep, solveSrcPackages() );
614  invokeOnEach ( _pool.begin(), _pool.end(), functor::functorRef<bool,PoolItem>( collector ) );
615  }
616 
617  for (PoolItemList::const_iterator iter = weakItems.begin(); iter != weakItems.end(); iter++) {
618  Id id = (*iter)->satSolvable().id();
619  if (id == ID_NULL) {
620  ERR << "Weaken: " << *iter << " not found" << endl;
621  }
622  MIL << "Weaken dependencies of " << *iter << endl;
623  queue_push( &(_jobQueue), SOLVER_WEAKENDEPS | SOLVER_SOLVABLE );
624  queue_push( &(_jobQueue), id );
625  }
626 
627  // Ad rules for changed requestedLocales
628  {
629  const auto & trackedLocaleIds( myPool().trackedLocaleIds() );
630 
631  // just track changed locakes
632  for ( const auto & locale : trackedLocaleIds.added() )
633  {
634  queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES );
635  queue_push( &(_jobQueue), Capability( ResolverNamespace::language, IdString(locale) ).id() );
636  }
637 
638  for ( const auto & locale : trackedLocaleIds.removed() )
639  {
640  queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES | SOLVER_CLEANDEPS ); // needs uncond. SOLVER_CLEANDEPS!
641  queue_push( &(_jobQueue), Capability( ResolverNamespace::language, IdString(locale) ).id() );
642  }
643  }
644 
645  // Add rules for parallel installable resolvables with different versions
646  for ( const sat::Solvable & solv : myPool().multiversionList() )
647  {
648  queue_push( &(_jobQueue), SOLVER_NOOBSOLETES | SOLVER_SOLVABLE );
649  queue_push( &(_jobQueue), solv.id() );
650  }
651 
652  ::pool_add_userinstalled_jobs(_satPool, sat::Pool::instance().autoInstalled(), &(_jobQueue), GET_USERINSTALLED_NAMES|GET_USERINSTALLED_INVERTED);
653 
654  if ( _distupgrade )
655  {
656  if ( ZConfig::instance().solverUpgradeRemoveDroppedPackages() )
657  {
658  MIL << "Checking droplists ..." << endl;
659  // Dropped packages: look for 'weakremover()' provides
660  // in dup candidates of installed products.
661  ResPoolProxy proxy( ResPool::instance().proxy() );
662  for_( it, proxy.byKindBegin<Product>(), proxy.byKindEnd<Product>() )
663  {
664  if ( (*it)->onSystem() ) // (to install) or (not to delete)
665  {
666  Product::constPtr prodCand( (*it)->candidateAsKind<Product>() );
667  if ( ! prodCand )
668  continue; // product no longer available
669 
670  CapabilitySet droplist( prodCand->droplist() );
671  dumpRangeLine( MIL << "Droplist for " << (*it)->candidateObj() << ": " << droplist.size() << " ", droplist.begin(), droplist.end() ) << endl;
672  for_( cap, droplist.begin(), droplist.end() )
673  {
674  queue_push( &_jobQueue, SOLVER_DROP_ORPHANED | SOLVER_SOLVABLE_NAME );
675  queue_push( &_jobQueue, cap->id() );
676  }
677  }
678  }
679  }
680  else
681  {
682  MIL << "Droplist processing is disabled." << endl;
683  }
684  }
685 }
686 
687 void
688 SATResolver::solverEnd()
689 {
690  // cleanup
691  if ( _satSolver )
692  {
693  solver_free(_satSolver);
694  _satSolver = NULL;
695  queue_free( &(_jobQueue) );
696  }
697 }
698 
699 
700 bool
701 SATResolver::resolvePool(const CapabilitySet & requires_caps,
702  const CapabilitySet & conflict_caps,
703  const PoolItemList & weakItems,
704  const std::set<Repository> & upgradeRepos)
705 {
706  MIL << "SATResolver::resolvePool()" << endl;
707 
708  // initialize
709  solverInit(weakItems);
710 
711  for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
712  Id id = (*iter)->satSolvable().id();
713  if (id == ID_NULL) {
714  ERR << "Install: " << *iter << " not found" << endl;
715  } else {
716  MIL << "Install " << *iter << endl;
717  queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
718  queue_push( &(_jobQueue), id );
719  }
720  }
721 
722  for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
723  Id id = (*iter)->satSolvable().id();
724  if (id == ID_NULL) {
725  ERR << "Delete: " << *iter << " not found" << endl;
726  } else {
727  MIL << "Delete " << *iter << endl;
728  queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE | MAYBE_CLEANDEPS );
729  queue_push( &(_jobQueue), id);
730  }
731  }
732 
733  for_( iter, upgradeRepos.begin(), upgradeRepos.end() )
734  {
735  queue_push( &(_jobQueue), SOLVER_DISTUPGRADE | SOLVER_SOLVABLE_REPO );
736  queue_push( &(_jobQueue), iter->get()->repoid );
737  MIL << "Upgrade repo " << *iter << endl;
738  }
739 
740  for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
741  queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES );
742  queue_push( &(_jobQueue), iter->id() );
743  MIL << "Requires " << *iter << endl;
744  }
745 
746  for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
747  queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES | MAYBE_CLEANDEPS );
748  queue_push( &(_jobQueue), iter->id() );
749  MIL << "Conflicts " << *iter << endl;
750  }
751 
752  // set requirements for a running system
753  setSystemRequirements();
754 
755  // set locks for the solver
756  setLocks();
757 
758  // solving
759  bool ret = solving(requires_caps, conflict_caps);
760 
761  (ret?MIL:WAR) << "SATResolver::resolvePool() done. Ret:" << ret << endl;
762  return ret;
763 }
764 
765 
766 bool
767 SATResolver::resolveQueue(const SolverQueueItemList &requestQueue,
768  const PoolItemList & weakItems)
769 {
770  MIL << "SATResolver::resolvQueue()" << endl;
771 
772  // initialize
773  solverInit(weakItems);
774 
775  // generate solver queue
776  for (SolverQueueItemList::const_iterator iter = requestQueue.begin(); iter != requestQueue.end(); iter++) {
777  (*iter)->addRule(_jobQueue);
778  }
779 
780  // Add addition item status to the resolve-queue cause these can be set by problem resolutions
781  for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
782  Id id = (*iter)->satSolvable().id();
783  if (id == ID_NULL) {
784  ERR << "Install: " << *iter << " not found" << endl;
785  } else {
786  MIL << "Install " << *iter << endl;
787  queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
788  queue_push( &(_jobQueue), id );
789  }
790  }
791  for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
792  sat::detail::IdType ident( (*iter)->satSolvable().ident().id() );
793  MIL << "Delete " << *iter << ident << endl;
794  queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_NAME | MAYBE_CLEANDEPS );
795  queue_push( &(_jobQueue), ident);
796  }
797 
798  // set requirements for a running system
799  setSystemRequirements();
800 
801  // set locks for the solver
802  setLocks();
803 
804  // solving
805  bool ret = solving();
806 
807  MIL << "SATResolver::resolveQueue() done. Ret:" << ret << endl;
808  return ret;
809 }
810 
812 void SATResolver::doUpdate()
813 {
814  MIL << "SATResolver::doUpdate()" << endl;
815 
816  // initialize
817  solverInit(PoolItemList());
818 
819  // set requirements for a running system
820  setSystemRequirements();
821 
822  // set locks for the solver
823  setLocks();
824 
825  _satSolver = solver_create( _satPool );
826  ::pool_set_custom_vendorcheck( _satPool, &vendorCheck );
827  if (_fixsystem) {
828  queue_push( &(_jobQueue), SOLVER_VERIFY|SOLVER_SOLVABLE_ALL);
829  queue_push( &(_jobQueue), 0 );
830  }
831  if (1) {
832  queue_push( &(_jobQueue), SOLVER_UPDATE|SOLVER_SOLVABLE_ALL);
833  queue_push( &(_jobQueue), 0 );
834  }
835  if (_distupgrade) {
836  queue_push( &(_jobQueue), SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_ALL);
837  queue_push( &(_jobQueue), 0 );
838  }
839  if (_distupgrade_removeunsupported) {
840  queue_push( &(_jobQueue), SOLVER_DROP_ORPHANED|SOLVER_SOLVABLE_ALL);
841  queue_push( &(_jobQueue), 0 );
842  }
843  solver_set_flag(_satSolver, SOLVER_FLAG_ADD_ALREADY_RECOMMENDED, !_ignorealreadyrecommended);
844  solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_DOWNGRADE, _allowdowngrade);
845  solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_NAMECHANGE, _allownamechange);
846  solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_ARCHCHANGE, _allowarchchange);
847  solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_VENDORCHANGE, _allowvendorchange);
848  solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_UNINSTALL, _allowuninstall);
849  solver_set_flag(_satSolver, SOLVER_FLAG_NO_UPDATEPROVIDE, _noupdateprovide);
850  solver_set_flag(_satSolver, SOLVER_FLAG_SPLITPROVIDES, _dosplitprovides);
851  solver_set_flag(_satSolver, SOLVER_FLAG_IGNORE_RECOMMENDED, false); // resolve recommended namespaces
852  solver_set_flag(_satSolver, SOLVER_FLAG_ONLY_NAMESPACE_RECOMMENDED, _onlyRequires); //
853 
855 
856  // Solve !
857  MIL << "Starting solving for update...." << endl;
858  MIL << *this;
859  solver_solve( _satSolver, &(_jobQueue) );
860  MIL << "....Solver end" << endl;
861 
862  // copying solution back to zypp pool
863  //-----------------------------------------
864 
865  /* solvables to be installed */
866  Queue decisionq;
867  queue_init(&decisionq);
868  solver_get_decisionqueue(_satSolver, &decisionq);
869  for (int i = 0; i < decisionq.count; i++)
870  {
871  Id p;
872  p = decisionq.elements[i];
873  if (p < 0 || !sat::Solvable(p))
874  continue;
875  if (sat::Solvable(p).repository().get() == _satSolver->pool->installed)
876  continue;
877 
878  PoolItem poolItem = _pool.find (sat::Solvable(p));
879  if (poolItem) {
881  } else {
882  ERR << "id " << p << " not found in ZYPP pool." << endl;
883  }
884  }
885  queue_free(&decisionq);
886 
887  /* solvables to be erased */
888  for (int i = _satSolver->pool->installed->start; i < _satSolver->pool->installed->start + _satSolver->pool->installed->nsolvables; i++)
889  {
890  if (solver_get_decisionlevel(_satSolver, i) > 0)
891  continue;
892 
893  PoolItem poolItem( _pool.find( sat::Solvable(i) ) );
894  if (poolItem) {
895  // Check if this is an update
896  CheckIfUpdate info( (sat::Solvable(i)) );
897  invokeOnEach( _pool.byIdentBegin( poolItem ),
898  _pool.byIdentEnd( poolItem ),
899  resfilter::ByUninstalled(), // ByUninstalled
900  functor::functorRef<bool,PoolItem> (info) );
901 
902  if (info.is_updated) {
904  } else {
906  }
907  } else {
908  ERR << "id " << i << " not found in ZYPP pool." << endl;
909  }
910  }
911  MIL << "SATResolver::doUpdate() done" << endl;
912 }
913 
914 
915 
916 //----------------------------------------------------------------------------
917 //----------------------------------------------------------------------------
918 // error handling
919 //----------------------------------------------------------------------------
920 //----------------------------------------------------------------------------
921 
922 //----------------------------------------------------------------------------
923 // helper function
924 //----------------------------------------------------------------------------
925 
927 {
928  ProblemSolutionCombi *problemSolution;
929  TransactionKind action;
930  FindPackage (ProblemSolutionCombi *p, const TransactionKind act)
931  : problemSolution (p)
932  , action (act)
933  {
934  }
935 
937  {
938  problemSolution->addSingleAction (p, action);
939  return true;
940  }
941 };
942 
943 
944 //----------------------------------------------------------------------------
945 // Checking if this solvable/item has a buddy which reflect the real
946 // user visible description of an item
947 // e.g. The release package has a buddy to the concerning product item.
948 // This user want's the message "Product foo conflicts with product bar" and
949 // NOT "package release-foo conflicts with package release-bar"
950 // (ma: that's why we should map just packages to buddies, not vice versa)
951 //----------------------------------------------------------------------------
952 inline sat::Solvable mapBuddy( const PoolItem & item_r )
953 {
954  if ( item_r.satSolvable().isKind<Package>() )
955  {
956  sat::Solvable buddy = item_r.buddy();
957  if ( buddy )
958  return buddy;
959  }
960  return item_r.satSolvable();
961 }
963 { return mapBuddy( PoolItem( item_r ) ); }
964 
965 PoolItem SATResolver::mapItem ( const PoolItem & item )
966 { return PoolItem( mapBuddy( item ) ); }
967 
968 sat::Solvable SATResolver::mapSolvable ( const Id & id )
969 { return mapBuddy( sat::Solvable(id) ); }
970 
971 string SATResolver::SATprobleminfoString(Id problem, string &detail, Id &ignoreId)
972 {
973  string ret;
974  sat::detail::CPool *pool = _satSolver->pool;
975  Id probr;
976  Id dep, source, target;
977  sat::Solvable s, s2;
978 
979  ignoreId = 0;
980 
981  // FIXME: solver_findallproblemrules to get all rules for this problem
982  // (the 'most relevabt' one returned by solver_findproblemrule is embedded
983  probr = solver_findproblemrule(_satSolver, problem);
984  switch (solver_ruleinfo(_satSolver, probr, &source, &target, &dep))
985  {
986  case SOLVER_RULE_DISTUPGRADE:
987  s = mapSolvable (source);
988  ret = str::form (_("%s does not belong to a distupgrade repository"), s.asString().c_str());
989  break;
990  case SOLVER_RULE_INFARCH:
991  s = mapSolvable (source);
992  ret = str::form (_("%s has inferior architecture"), s.asString().c_str());
993  break;
994  case SOLVER_RULE_UPDATE:
995  s = mapSolvable (source);
996  ret = str::form (_("problem with installed package %s"), s.asString().c_str());
997  break;
998  case SOLVER_RULE_JOB:
999  ret = _("conflicting requests");
1000  break;
1001  case SOLVER_RULE_RPM:
1002  ret = _("some dependency problem");
1003  break;
1004  case SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP:
1005  ret = str::form (_("nothing provides requested %s"), pool_dep2str(pool, dep));
1006  detail += _("Have you enabled all requested repositories?");
1007  break;
1008  case SOLVER_RULE_JOB_UNKNOWN_PACKAGE:
1009  ret = str::form (_("package %s does not exist"), pool_dep2str(pool, dep));
1010  detail += _("Have you enabled all requested repositories?");
1011  break;
1012  case SOLVER_RULE_JOB_UNSUPPORTED:
1013  ret = _("unsupported request");
1014  break;
1015  case SOLVER_RULE_JOB_PROVIDED_BY_SYSTEM:
1016  ret = str::form (_("%s is provided by the system and cannot be erased"), pool_dep2str(pool, dep));
1017  break;
1018  case SOLVER_RULE_RPM_NOT_INSTALLABLE:
1019  s = mapSolvable (source);
1020  ret = str::form (_("%s is not installable"), s.asString().c_str());
1021  break;
1022  case SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP:
1023  ignoreId = source; // for setting weak dependencies
1024  s = mapSolvable (source);
1025  ret = str::form (_("nothing provides %s needed by %s"), pool_dep2str(pool, dep), s.asString().c_str());
1026  break;
1027  case SOLVER_RULE_RPM_SAME_NAME:
1028  s = mapSolvable (source);
1029  s2 = mapSolvable (target);
1030  ret = str::form (_("cannot install both %s and %s"), s.asString().c_str(), s2.asString().c_str());
1031  break;
1032  case SOLVER_RULE_RPM_PACKAGE_CONFLICT:
1033  s = mapSolvable (source);
1034  s2 = mapSolvable (target);
1035  ret = str::form (_("%s conflicts with %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1036  break;
1037  case SOLVER_RULE_RPM_PACKAGE_OBSOLETES:
1038  s = mapSolvable (source);
1039  s2 = mapSolvable (target);
1040  ret = str::form (_("%s obsoletes %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1041  break;
1042  case SOLVER_RULE_RPM_INSTALLEDPKG_OBSOLETES:
1043  s = mapSolvable (source);
1044  s2 = mapSolvable (target);
1045  ret = str::form (_("installed %s obsoletes %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1046  break;
1047  case SOLVER_RULE_RPM_SELF_CONFLICT:
1048  s = mapSolvable (source);
1049  ret = str::form (_("solvable %s conflicts with %s provided by itself"), s.asString().c_str(), pool_dep2str(pool, dep));
1050  break;
1051  case SOLVER_RULE_RPM_PACKAGE_REQUIRES:
1052  ignoreId = source; // for setting weak dependencies
1053  s = mapSolvable (source);
1054  Capability cap(dep);
1055  sat::WhatProvides possibleProviders(cap);
1056 
1057  // check, if a provider will be deleted
1058  typedef list<PoolItem> ProviderList;
1059  ProviderList providerlistInstalled, providerlistUninstalled;
1060  for_( iter1, possibleProviders.begin(), possibleProviders.end() ) {
1061  PoolItem provider1 = ResPool::instance().find( *iter1 );
1062  // find pair of an installed/uninstalled item with the same NVR
1063  bool found = false;
1064  for_( iter2, possibleProviders.begin(), possibleProviders.end() ) {
1065  PoolItem provider2 = ResPool::instance().find( *iter2 );
1066  if (compareByNVR (provider1,provider2) == 0
1067  && ( (provider1.status().isInstalled() && provider2.status().isUninstalled())
1068  || (provider2.status().isInstalled() && provider1.status().isUninstalled()) )) {
1069  found = true;
1070  break;
1071  }
1072  }
1073  if (!found) {
1074  if (provider1.status().isInstalled())
1075  providerlistInstalled.push_back(provider1);
1076  else
1077  providerlistUninstalled.push_back(provider1);
1078  }
1079  }
1080 
1081  ret = str::form (_("%s requires %s, but this requirement cannot be provided"), s.asString().c_str(), pool_dep2str(pool, dep));
1082  if (providerlistInstalled.size() > 0) {
1083  detail += _("deleted providers: ");
1084  for (ProviderList::const_iterator iter = providerlistInstalled.begin(); iter != providerlistInstalled.end(); iter++) {
1085  if (iter == providerlistInstalled.begin())
1086  detail += itemToString( *iter );
1087  else
1088  detail += "\n " + itemToString( mapItem(*iter) );
1089  }
1090  }
1091  if (providerlistUninstalled.size() > 0) {
1092  if (detail.size() > 0)
1093  detail += _("\nnot installable providers: ");
1094  else
1095  detail = _("not installable providers: ");
1096  for (ProviderList::const_iterator iter = providerlistUninstalled.begin(); iter != providerlistUninstalled.end(); iter++) {
1097  if (iter == providerlistUninstalled.begin())
1098  detail += itemToString( *iter );
1099  else
1100  detail += "\n " + itemToString( mapItem(*iter) );
1101  }
1102  }
1103  break;
1104  }
1105 
1106  return ret;
1107 }
1108 
1110 SATResolver::problems ()
1111 {
1112  ResolverProblemList resolverProblems;
1113  if (_satSolver && solver_problem_count(_satSolver)) {
1114  sat::detail::CPool *pool = _satSolver->pool;
1115  int pcnt;
1116  Id p, rp, what;
1117  Id problem, solution, element;
1118  sat::Solvable s, sd;
1119 
1120  CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1121  CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1122 
1123  MIL << "Encountered problems! Here are the solutions:\n" << endl;
1124  pcnt = 1;
1125  problem = 0;
1126  while ((problem = solver_next_problem(_satSolver, problem)) != 0) {
1127  MIL << "Problem " << pcnt++ << ":" << endl;
1128  MIL << "====================================" << endl;
1129  string detail;
1130  Id ignoreId;
1131  string whatString = SATprobleminfoString (problem,detail,ignoreId);
1132  MIL << whatString << endl;
1133  MIL << "------------------------------------" << endl;
1134  ResolverProblem_Ptr resolverProblem = new ResolverProblem (whatString, detail);
1135 
1136  solution = 0;
1137  while ((solution = solver_next_solution(_satSolver, problem, solution)) != 0) {
1138  element = 0;
1139  ProblemSolutionCombi *problemSolution = new ProblemSolutionCombi;
1140  while ((element = solver_next_solutionelement(_satSolver, problem, solution, element, &p, &rp)) != 0) {
1141  if (p == SOLVER_SOLUTION_JOB) {
1142  /* job, rp is index into job queue */
1143  what = _jobQueue.elements[rp];
1144  switch (_jobQueue.elements[rp-1]&(SOLVER_SELECTMASK|SOLVER_JOBMASK))
1145  {
1146  case SOLVER_INSTALL | SOLVER_SOLVABLE: {
1147  s = mapSolvable (what);
1148  PoolItem poolItem = _pool.find (s);
1149  if (poolItem) {
1150  if (pool->installed && s.get()->repo == pool->installed) {
1151  problemSolution->addSingleAction (poolItem, REMOVE);
1152  string description = str::form (_("remove lock to allow removal of %s"), s.asString().c_str() );
1153  MIL << description << endl;
1154  problemSolution->addDescription (description);
1155  } else {
1156  problemSolution->addSingleAction (poolItem, KEEP);
1157  string description = str::form (_("do not install %s"), s.asString().c_str());
1158  MIL << description << endl;
1159  problemSolution->addDescription (description);
1160  }
1161  } else {
1162  ERR << "SOLVER_INSTALL_SOLVABLE: No item found for " << s.asString() << endl;
1163  }
1164  }
1165  break;
1166  case SOLVER_ERASE | SOLVER_SOLVABLE: {
1167  s = mapSolvable (what);
1168  PoolItem poolItem = _pool.find (s);
1169  if (poolItem) {
1170  if (pool->installed && s.get()->repo == pool->installed) {
1171  problemSolution->addSingleAction (poolItem, KEEP);
1172  string description = str::form (_("keep %s"), s.asString().c_str());
1173  MIL << description << endl;
1174  problemSolution->addDescription (description);
1175  } else {
1176  problemSolution->addSingleAction (poolItem, UNLOCK);
1177  string description = str::form (_("remove lock to allow installation of %s"), itemToString( poolItem ).c_str());
1178  MIL << description << endl;
1179  problemSolution->addDescription (description);
1180  }
1181  } else {
1182  ERR << "SOLVER_ERASE_SOLVABLE: No item found for " << s.asString() << endl;
1183  }
1184  }
1185  break;
1186  case SOLVER_INSTALL | SOLVER_SOLVABLE_NAME:
1187  {
1188  IdString ident( what );
1189  SolverQueueItemInstall_Ptr install =
1190  new SolverQueueItemInstall(_pool, ident.asString(), false );
1191  problemSolution->addSingleAction (install, REMOVE_SOLVE_QUEUE_ITEM);
1192 
1193  string description = str::form (_("do not install %s"), ident.c_str() );
1194  MIL << description << endl;
1195  problemSolution->addDescription (description);
1196  }
1197  break;
1198  case SOLVER_ERASE | SOLVER_SOLVABLE_NAME:
1199  {
1200  // As we do not know, if this request has come from resolvePool or
1201  // resolveQueue we will have to take care for both cases.
1202  IdString ident( what );
1203  FindPackage info (problemSolution, KEEP);
1204  invokeOnEach( _pool.byIdentBegin( ident ),
1205  _pool.byIdentEnd( ident ),
1206  functor::chain (resfilter::ByInstalled (), // ByInstalled
1207  resfilter::ByTransact ()), // will be deinstalled
1208  functor::functorRef<bool,PoolItem> (info) );
1209 
1210  SolverQueueItemDelete_Ptr del =
1211  new SolverQueueItemDelete(_pool, ident.asString(), false );
1212  problemSolution->addSingleAction (del, REMOVE_SOLVE_QUEUE_ITEM);
1213 
1214  string description = str::form (_("keep %s"), ident.c_str());
1215  MIL << description << endl;
1216  problemSolution->addDescription (description);
1217  }
1218  break;
1219  case SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES:
1220  {
1221  problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_REQUIRE);
1222  string description = "";
1223 
1224  // Checking if this problem solution would break your system
1225  if (system_requires.find(Capability(what)) != system_requires.end()) {
1226  // Show a better warning
1227  resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1228  resolverProblem->setDescription(_("This request will break your system!"));
1229  description = _("ignore the warning of a broken system");
1230  description += string(" (requires:")+pool_dep2str(pool, what)+")";
1231  MIL << description << endl;
1232  problemSolution->addFrontDescription (description);
1233  } else {
1234  description = str::form (_("do not ask to install a solvable providing %s"), pool_dep2str(pool, what));
1235  MIL << description << endl;
1236  problemSolution->addDescription (description);
1237  }
1238  }
1239  break;
1240  case SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES:
1241  {
1242  problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_CONFLICT);
1243  string description = "";
1244 
1245  // Checking if this problem solution would break your system
1246  if (system_conflicts.find(Capability(what)) != system_conflicts.end()) {
1247  // Show a better warning
1248  resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1249  resolverProblem->setDescription(_("This request will break your system!"));
1250  description = _("ignore the warning of a broken system");
1251  description += string(" (conflicts:")+pool_dep2str(pool, what)+")";
1252  MIL << description << endl;
1253  problemSolution->addFrontDescription (description);
1254 
1255  } else {
1256  description = str::form (_("do not ask to delete all solvables providing %s"), pool_dep2str(pool, what));
1257  MIL << description << endl;
1258  problemSolution->addDescription (description);
1259  }
1260  }
1261  break;
1262  case SOLVER_UPDATE | SOLVER_SOLVABLE:
1263  {
1264  s = mapSolvable (what);
1265  PoolItem poolItem = _pool.find (s);
1266  if (poolItem) {
1267  if (pool->installed && s.get()->repo == pool->installed) {
1268  problemSolution->addSingleAction (poolItem, KEEP);
1269  string description = str::form (_("do not install most recent version of %s"), s.asString().c_str());
1270  MIL << description << endl;
1271  problemSolution->addDescription (description);
1272  } else {
1273  ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE " << poolItem << " is not selected for installation" << endl;
1274  }
1275  } else {
1276  ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE: No item found for " << s.asString() << endl;
1277  }
1278  }
1279  break;
1280  default:
1281  MIL << "- do something different" << endl;
1282  ERR << "No valid solution available" << endl;
1283  break;
1284  }
1285  } else if (p == SOLVER_SOLUTION_INFARCH) {
1286  s = mapSolvable (rp);
1287  PoolItem poolItem = _pool.find (s);
1288  if (pool->installed && s.get()->repo == pool->installed) {
1289  problemSolution->addSingleAction (poolItem, LOCK);
1290  string description = str::form (_("keep %s despite the inferior architecture"), s.asString().c_str());
1291  MIL << description << endl;
1292  problemSolution->addDescription (description);
1293  } else {
1294  problemSolution->addSingleAction (poolItem, INSTALL);
1295  string description = str::form (_("install %s despite the inferior architecture"), s.asString().c_str());
1296  MIL << description << endl;
1297  problemSolution->addDescription (description);
1298  }
1299  } else if (p == SOLVER_SOLUTION_DISTUPGRADE) {
1300  s = mapSolvable (rp);
1301  PoolItem poolItem = _pool.find (s);
1302  if (pool->installed && s.get()->repo == pool->installed) {
1303  problemSolution->addSingleAction (poolItem, LOCK);
1304  string description = str::form (_("keep obsolete %s"), s.asString().c_str());
1305  MIL << description << endl;
1306  problemSolution->addDescription (description);
1307  } else {
1308  problemSolution->addSingleAction (poolItem, INSTALL);
1309  string description = str::form (_("install %s from excluded repository"), s.asString().c_str());
1310  MIL << description << endl;
1311  problemSolution->addDescription (description);
1312  }
1313  } else {
1314  /* policy, replace p with rp */
1315  s = mapSolvable (p);
1316  PoolItem itemFrom = _pool.find (s);
1317  if (rp)
1318  {
1319  int gotone = 0;
1320 
1321  sd = mapSolvable (rp);
1322  PoolItem itemTo = _pool.find (sd);
1323  if (itemFrom && itemTo) {
1324  problemSolution->addSingleAction (itemTo, INSTALL);
1325  int illegal = policy_is_illegal(_satSolver, s.get(), sd.get(), 0);
1326 
1327  if ((illegal & POLICY_ILLEGAL_DOWNGRADE) != 0)
1328  {
1329  string description = str::form (_("downgrade of %s to %s"), s.asString().c_str(), sd.asString().c_str());
1330  MIL << description << endl;
1331  problemSolution->addDescription (description);
1332  gotone = 1;
1333  }
1334  if ((illegal & POLICY_ILLEGAL_ARCHCHANGE) != 0)
1335  {
1336  string description = str::form (_("architecture change of %s to %s"), s.asString().c_str(), sd.asString().c_str());
1337  MIL << description << endl;
1338  problemSolution->addDescription (description);
1339  gotone = 1;
1340  }
1341  if ((illegal & POLICY_ILLEGAL_VENDORCHANGE) != 0)
1342  {
1343  IdString s_vendor( s.vendor() );
1344  IdString sd_vendor( sd.vendor() );
1345  string description = str::form (_("install %s (with vendor change)\n %s --> %s") ,
1346  sd.asString().c_str(),
1347  ( s_vendor ? s_vendor.c_str() : " (no vendor) " ),
1348  ( sd_vendor ? sd_vendor.c_str() : " (no vendor) " ) );
1349  MIL << description << endl;
1350  problemSolution->addDescription (description);
1351  gotone = 1;
1352  }
1353  if (!gotone) {
1354  string description = str::form (_("replacement of %s with %s"), s.asString().c_str(), sd.asString().c_str());
1355  MIL << description << endl;
1356  problemSolution->addDescription (description);
1357  }
1358  } else {
1359  ERR << s.asString() << " or " << sd.asString() << " not found" << endl;
1360  }
1361  }
1362  else
1363  {
1364  if (itemFrom) {
1365  string description = str::form (_("deinstallation of %s"), s.asString().c_str());
1366  MIL << description << endl;
1367  problemSolution->addDescription (description);
1368  problemSolution->addSingleAction (itemFrom, REMOVE);
1369  }
1370  }
1371  }
1372  }
1373  resolverProblem->addSolution (problemSolution,
1374  problemSolution->actionCount() > 1 ? true : false); // Solutions with more than 1 action will be shown first.
1375  MIL << "------------------------------------" << endl;
1376  }
1377 
1378  if (ignoreId > 0) {
1379  // There is a possibility to ignore this error by setting weak dependencies
1380  PoolItem item = _pool.find (sat::Solvable(ignoreId));
1381  ProblemSolutionIgnore *problemSolution = new ProblemSolutionIgnore(item);
1382  resolverProblem->addSolution (problemSolution,
1383  false); // Solutions will be shown at the end
1384  MIL << "ignore some dependencies of " << item << endl;
1385  MIL << "------------------------------------" << endl;
1386  }
1387 
1388  // save problem
1389  resolverProblems.push_back (resolverProblem);
1390  }
1391  }
1392  return resolverProblems;
1393 }
1394 
1395 void SATResolver::applySolutions( const ProblemSolutionList & solutions )
1396 { Resolver( _pool ).applySolutions( solutions ); }
1397 
1398 void SATResolver::setLocks()
1399 {
1400  unsigned icnt = 0;
1401  unsigned acnt = 0;
1402 
1403  for (PoolItemList::const_iterator iter = _items_to_lock.begin(); iter != _items_to_lock.end(); ++iter) {
1404  sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
1405  if (iter->status().isInstalled()) {
1406  ++icnt;
1407  queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
1408  queue_push( &(_jobQueue), ident );
1409  } else {
1410  ++acnt;
1411  queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE | MAYBE_CLEANDEPS );
1412  queue_push( &(_jobQueue), ident );
1413  }
1414  }
1415  MIL << "Locked " << icnt << " installed items and " << acnt << " NOT installed items." << endl;
1416 
1418  // Weak locks: Ignore if an item with this name is already installed.
1419  // If it's not installed try to keep it this way using a weak delete
1421  std::set<IdString> unifiedByName;
1422  for (PoolItemList::const_iterator iter = _items_to_keep.begin(); iter != _items_to_keep.end(); ++iter) {
1423  IdString ident( (*iter)->satSolvable().ident() );
1424  if ( unifiedByName.insert( ident ).second )
1425  {
1426  if ( ! ui::Selectable::get( *iter )->hasInstalledObj() )
1427  {
1428  MIL << "Keep NOT installed name " << ident << " (" << *iter << ")" << endl;
1429  queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_NAME | SOLVER_WEAK | MAYBE_CLEANDEPS );
1430  queue_push( &(_jobQueue), ident.id() );
1431  }
1432  }
1433  }
1434 }
1435 
1436 void SATResolver::setSystemRequirements()
1437 {
1438  CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1439  CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1440 
1441  for (CapabilitySet::const_iterator iter = system_requires.begin(); iter != system_requires.end(); ++iter) {
1442  queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES );
1443  queue_push( &(_jobQueue), iter->id() );
1444  MIL << "SYSTEM Requires " << *iter << endl;
1445  }
1446 
1447  for (CapabilitySet::const_iterator iter = system_conflicts.begin(); iter != system_conflicts.end(); ++iter) {
1448  queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES | MAYBE_CLEANDEPS );
1449  queue_push( &(_jobQueue), iter->id() );
1450  MIL << "SYSTEM Conflicts " << *iter << endl;
1451  }
1452 
1453  // Lock the architecture of the running systems rpm
1454  // package on distupgrade.
1455  if ( _distupgrade && ZConfig::instance().systemRoot() == "/" )
1456  {
1457  ResPool pool( ResPool::instance() );
1458  IdString rpm( "rpm" );
1459  for_( it, pool.byIdentBegin(rpm), pool.byIdentEnd(rpm) )
1460  {
1461  if ( (*it)->isSystem() )
1462  {
1463  Capability archrule( (*it)->arch(), rpm.c_str(), Capability::PARSED );
1464  queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_NAME | SOLVER_ESSENTIAL );
1465  queue_push( &(_jobQueue), archrule.id() );
1466 
1467  }
1468  }
1469  }
1470 }
1471 
1472 sat::StringQueue SATResolver::autoInstalled() const
1473 {
1474  sat::StringQueue ret;
1475  if ( _satSolver )
1476  ::solver_get_userinstalled( _satSolver, ret, GET_USERINSTALLED_NAMES|GET_USERINSTALLED_INVERTED );
1477  return ret;
1478 }
1479 
1480 sat::StringQueue SATResolver::userInstalled() const
1481 {
1482  sat::StringQueue ret;
1483  if ( _satSolver )
1484  ::solver_get_userinstalled( _satSolver, ret, GET_USERINSTALLED_NAMES );
1485  return ret;
1486 }
1487 
1488 
1490 };// namespace detail
1493  };// namespace solver
1496 };// namespace zypp
1498 
Interface to gettext.
std::list< ProblemSolution_Ptr > ProblemSolutionList
Definition: ProblemTypes.h:43
#define MIL
Definition: Logger.h:79
int IdType
Generic Id type.
Definition: PoolMember.h:104
A Solvable object within the sat Pool.
Definition: Solvable.h:53
IdType id() const
Expert backdoor.
Definition: Solvable.h:388
ResKind kind() const
The Solvables ResKind.
Definition: Solvable.cc:271
static ZConfig & instance()
Singleton ctor.
Definition: Resolver.cc:127
bool isToBeInstalled() const
Definition: ResStatus.h:244
bool equivalent(const Vendor &lVendor, const Vendor &rVendor) const
Return whether two vendor strings should be treated as the same vendor.
Definition: VendorAttr.cc:264
ProblemSolutionCombi * problemSolution
Definition: SATResolver.cc:928
PoolItem find(const sat::Solvable &slv_r) const
Return the corresponding PoolItem.
Definition: ResPool.cc:70
#define INT
Definition: Logger.h:83
ResStatus & status() const
Returns the current status.
Definition: PoolItem.cc:204
static const ResStatus toBeInstalled
Definition: ResStatus.h:653
std::ostream & dumpOn(std::ostream &str, const zypp::shared_ptr< void > &obj)
Definition: PtrTypes.h:151
unsigned SolvableIdType
Id type to connect Solvable and sat-solvable.
Definition: PoolMember.h:125
bool isKind(const ResKind &kind_r) const
Test whether a Solvable is of a certain ResKind.
Definition: Solvable.cc:298
sat::Solvable buddy() const
Return the buddy we share our status object with.
Definition: PoolItem.cc:206
#define OUTS(X)
Definition: Arch.h:344
Access to the sat-pools string space.
Definition: IdString.h:41
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:27
bool sameNVRA(const SolvableType< Derived > &lhs, const Solvable &rhs)
Definition: SolvableType.h:228
bool resetTransact(TransactByValue causer_r)
Not the same as setTransact( false ).
Definition: ResStatus.h:476
TraitsType::constPtrType constPtr
Definition: Product.h:38
std::list< SolverQueueItem_Ptr > SolverQueueItemList
Definition: Types.h:45
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition: String.cc:36
static void SATSolutionToPool(PoolItem item, const ResStatus &status, const ResStatus::TransactByValue causer)
Definition: SATResolver.cc:228
#define ERR
Definition: Logger.h:81
bool setToBeUninstalledDueToUpgrade(TransactByValue causer)
Definition: ResStatus.h:560
#define MAYBE_CLEANDEPS
Definition: SATResolver.cc:101
static const ResStatus toBeUninstalledDueToUpgrade
Definition: ResStatus.h:655
std::unary_function< ResObject::constPtr, bool > ResObjectFilterFunctor
Definition: ResFilters.h:151
void prepare() const
Update housekeeping data if necessary (e.g.
Definition: Pool.cc:61
CheckIfUpdate(const sat::Solvable &installed_r)
Definition: SATResolver.cc:338
Repository repository() const
The Repository this Solvable belongs to.
Definition: Solvable.cc:359
Queue StringQueue
Queue with String ids.
Definition: Queue.h:27
std::list< ResolverProblem_Ptr > ResolverProblemList
Definition: ProblemTypes.h:46
static Pool instance()
Singleton ctor.
Definition: Pool.h:55
Commit helper functor distributing PoolItem by status into lists.
Definition: SATResolver.cc:265
bool operator()(const PoolItem &item)
Definition: SATResolver.cc:345
int vendorCheck(sat::detail::CPool *pool, Solvable *solvable1, Solvable *solvable2)
Definition: SATResolver.cc:107
Package interface.
Definition: Package.h:32
std::unary_function< PoolItem, bool > PoolItemFilterFunctor
Definition: ResFilters.h:285
#define WAR
Definition: Logger.h:80
bool HACKENV(const char *var_r, bool default_r)
Definition: SATResolver.cc:75
#define HACKENV(X, D)
bool multiversionInstall() const
Definition: SolvableType.h:82
#define _(MSG)
Definition: Gettext.h:37
SATCollectTransact(PoolItemList &items_to_install_r, PoolItemList &items_to_remove_r, PoolItemList &items_to_lock_r, PoolItemList &items_to_keep_r, bool solveSrcPackages_r)
Definition: SATResolver.cc:267
bool isPseudoInstalled(ResKind kind_r)
Those are denoted to be installed, if the solver verifies them as being satisfied.
Definition: ResTraits.h:28
::s_Pool CPool
Wrapped libsolv C data type exposed as backdoor.
Definition: PoolMember.h:61
bool operator()(const PoolItem &item_r)
Definition: SATResolver.cc:284
bool setToBeUninstalled(TransactByValue causer)
Definition: ResStatus.h:536
FindPackage(ProblemSolutionCombi *p, const TransactionKind act)
Definition: SATResolver.cc:930
bool compareByNVR(const SolvableType< Derived > &lhs, const Solvable &rhs)
Definition: SolvableType.h:256
std::unordered_set< Capability > CapabilitySet
Definition: Capability.h:33
static Ptr get(const pool::ByIdent &ident_r)
Get the Selctable.
Definition: Selectable.cc:28
SrcPackage interface.
Definition: SrcPackage.h:29
sat::Solvable mapBuddy(sat::Solvable item_r)
Definition: SATResolver.cc:962
std::string alias() const
Short unique string to identify a repo.
Definition: Repository.cc:59
PoolItem getPoolItem(Id id_r)
Definition: SATResolver.cc:130
bool isToBeUninstalled() const
Definition: ResStatus.h:252
bool strToBool(const C_Str &str, bool default_r)
Parse str into a bool depending on the default value.
Definition: String.h:428
Chain< TACondition, TBCondition > chain(TACondition conda_r, TBCondition condb_r)
Convenience function for creating a Chain from two conditions conda_r and condb_r.
Definition: Functional.h:346
bool setToBeInstalled(TransactByValue causer)
Definition: ResStatus.h:522
std::ostream & dumpRangeLine(std::ostream &str, TIterator begin, TIterator end)
Print range defined by iterators (single line style).
Definition: LogTools.h:114
Status bitfield.
Definition: ResStatus.h:53
IMPL_PTR_TYPE(SATResolver)
Combining sat::Solvable and ResStatus.
Definition: PoolItem.h:50
Pathname systemRoot() const
The target root directory.
Definition: ZConfig.cc:819
bool isKind(const ResKind &kind_r) const
Definition: SolvableType.h:64
void resetWeak()
Definition: ResStatus.h:197
static const VendorAttr & instance()
Singleton.
Definition: VendorAttr.cc:121
int invokeOnEach(TIterator begin_r, TIterator end_r, TFilter filter_r, TFunction fnc_r)
Iterate through [begin_r,end_r) and invoke fnc_r on each item that passes filter_r.
Definition: Algorithm.h:30
std::string itemToString(const PoolItem &item)
Definition: SATResolver.cc:114
#define XDEBUG(x)
Definition: SATResolver.cc:63
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
Solvable satSolvable() const
Return the corresponding sat::Solvable.
Definition: SolvableType.h:57
static const ResStatus toBeUninstalled
Definition: ResStatus.h:654
bool isToBeUninstalledDueToUpgrade() const
Definition: ResStatus.h:309
static ResPool instance()
Singleton ctor.
Definition: ResPool.cc:33