libzypp  17.11.4
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 std::vector<std::string> SATResolver::SATgetCompleteProblemInfoStrings ( Id problem )
972 {
973  std::vector<std::string> ret;
974  sat::Queue problems;
975  solver_findallproblemrules( _satSolver, problem, problems );
976 
977  bool nobad = false;
978 
979  //filter out generic rule information if more explicit ones are available
980  for ( sat::Queue::size_type i = 0; i < problems.size(); i++ ) {
981  SolverRuleinfo ruleClass = solver_ruleclass( _satSolver, problems[i]);
982  if ( ruleClass != SolverRuleinfo::SOLVER_RULE_UPDATE && ruleClass != SolverRuleinfo::SOLVER_RULE_JOB ) {
983  nobad = true;
984  break;
985  }
986  }
987  for ( sat::Queue::size_type i = 0; i < problems.size(); i++ ) {
988  SolverRuleinfo ruleClass = solver_ruleclass( _satSolver, problems[i]);
989  if ( nobad && ( ruleClass == SolverRuleinfo::SOLVER_RULE_UPDATE || ruleClass == SolverRuleinfo::SOLVER_RULE_JOB ) ) {
990  continue;
991  }
992 
993  std::string detail;
994  Id ignore = 0;
995  std::string pInfo = SATproblemRuleInfoString( problems[i], detail, ignore );
996 
997  //we get the same string multiple times, reduce the noise
998  if ( std::find( ret.begin(), ret.end(), pInfo ) == ret.end() )
999  ret.push_back( pInfo );
1000  }
1001  return ret;
1002 }
1003 
1004 string SATResolver::SATprobleminfoString(Id problem, string &detail, Id &ignoreId)
1005 {
1006  // FIXME: solver_findallproblemrules to get all rules for this problem
1007  // (the 'most relevabt' one returned by solver_findproblemrule is embedded
1008  Id probr = solver_findproblemrule(_satSolver, problem);
1009  return SATproblemRuleInfoString( probr, detail, ignoreId );
1010 }
1011 
1012 std::string SATResolver::SATproblemRuleInfoString (Id probr, std::string &detail, Id &ignoreId)
1013 {
1014  string ret;
1015  sat::detail::CPool *pool = _satSolver->pool;
1016  Id dep, source, target;
1017  SolverRuleinfo type = solver_ruleinfo(_satSolver, probr, &source, &target, &dep);
1018 
1019  ignoreId = 0;
1020 
1021  sat::Solvable s = mapSolvable( source );
1022  sat::Solvable s2 = mapSolvable( target );
1023 
1024  // @FIXME, these strings are a duplicate copied from the libsolv library
1025  // to provide translations. Instead of having duplicate code we should
1026  // translate those strings directly in libsolv
1027  switch ( type )
1028  {
1029  case SOLVER_RULE_DISTUPGRADE:
1030  ret = str::form (_("%s does not belong to a distupgrade repository"), s.asString().c_str());
1031  break;
1032  case SOLVER_RULE_INFARCH:
1033  ret = str::form (_("%s has inferior architecture"), s.asString().c_str());
1034  break;
1035  case SOLVER_RULE_UPDATE:
1036  ret = str::form (_("problem with installed package %s"), s.asString().c_str());
1037  break;
1038  case SOLVER_RULE_JOB:
1039  ret = _("conflicting requests");
1040  break;
1041  case SOLVER_RULE_PKG:
1042  ret = _("some dependency problem");
1043  break;
1044  case SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP:
1045  ret = str::form (_("nothing provides requested %s"), pool_dep2str(pool, dep));
1046  detail += _("Have you enabled all requested repositories?");
1047  break;
1048  case SOLVER_RULE_JOB_UNKNOWN_PACKAGE:
1049  ret = str::form (_("package %s does not exist"), pool_dep2str(pool, dep));
1050  detail += _("Have you enabled all requested repositories?");
1051  break;
1052  case SOLVER_RULE_JOB_UNSUPPORTED:
1053  ret = _("unsupported request");
1054  break;
1055  case SOLVER_RULE_JOB_PROVIDED_BY_SYSTEM:
1056  ret = str::form (_("%s is provided by the system and cannot be erased"), pool_dep2str(pool, dep));
1057  break;
1058  case SOLVER_RULE_PKG_NOT_INSTALLABLE:
1059  ret = str::form (_("%s is not installable"), s.asString().c_str());
1060  break;
1061  case SOLVER_RULE_PKG_NOTHING_PROVIDES_DEP:
1062  ignoreId = source; // for setting weak dependencies
1063  ret = str::form (_("nothing provides %s needed by %s"), pool_dep2str(pool, dep), s.asString().c_str());
1064  break;
1065  case SOLVER_RULE_PKG_SAME_NAME:
1066  ret = str::form (_("cannot install both %s and %s"), s.asString().c_str(), s2.asString().c_str());
1067  break;
1068  case SOLVER_RULE_PKG_CONFLICTS:
1069  ret = str::form (_("%s conflicts with %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1070  break;
1071  case SOLVER_RULE_PKG_OBSOLETES:
1072  ret = str::form (_("%s obsoletes %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1073  break;
1074  case SOLVER_RULE_PKG_INSTALLED_OBSOLETES:
1075  ret = str::form (_("installed %s obsoletes %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1076  break;
1077  case SOLVER_RULE_PKG_SELF_CONFLICT:
1078  ret = str::form (_("solvable %s conflicts with %s provided by itself"), s.asString().c_str(), pool_dep2str(pool, dep));
1079  break;
1080  case SOLVER_RULE_PKG_REQUIRES: {
1081  ignoreId = source; // for setting weak dependencies
1082  Capability cap(dep);
1083  sat::WhatProvides possibleProviders(cap);
1084 
1085  // check, if a provider will be deleted
1086  typedef list<PoolItem> ProviderList;
1087  ProviderList providerlistInstalled, providerlistUninstalled;
1088  for_( iter1, possibleProviders.begin(), possibleProviders.end() ) {
1089  PoolItem provider1 = ResPool::instance().find( *iter1 );
1090  // find pair of an installed/uninstalled item with the same NVR
1091  bool found = false;
1092  for_( iter2, possibleProviders.begin(), possibleProviders.end() ) {
1093  PoolItem provider2 = ResPool::instance().find( *iter2 );
1094  if (compareByNVR (provider1,provider2) == 0
1095  && ( (provider1.status().isInstalled() && provider2.status().isUninstalled())
1096  || (provider2.status().isInstalled() && provider1.status().isUninstalled()) )) {
1097  found = true;
1098  break;
1099  }
1100  }
1101  if (!found) {
1102  if (provider1.status().isInstalled())
1103  providerlistInstalled.push_back(provider1);
1104  else
1105  providerlistUninstalled.push_back(provider1);
1106  }
1107  }
1108 
1109  ret = str::form (_("%s requires %s, but this requirement cannot be provided"), s.asString().c_str(), pool_dep2str(pool, dep));
1110  if (providerlistInstalled.size() > 0) {
1111  detail += _("deleted providers: ");
1112  for (ProviderList::const_iterator iter = providerlistInstalled.begin(); iter != providerlistInstalled.end(); iter++) {
1113  if (iter == providerlistInstalled.begin())
1114  detail += itemToString( *iter );
1115  else
1116  detail += "\n " + itemToString( mapItem(*iter) );
1117  }
1118  }
1119  if (providerlistUninstalled.size() > 0) {
1120  if (detail.size() > 0)
1121  detail += _("\nnot installable providers: ");
1122  else
1123  detail = _("not installable providers: ");
1124  for (ProviderList::const_iterator iter = providerlistUninstalled.begin(); iter != providerlistUninstalled.end(); iter++) {
1125  if (iter == providerlistUninstalled.begin())
1126  detail += itemToString( *iter );
1127  else
1128  detail += "\n " + itemToString( mapItem(*iter) );
1129  }
1130  }
1131  break;
1132  }
1133  default: {
1134  DBG << "Unknown rule type(" << type << ") going to query libsolv for rule information." << endl;
1135  ret = str::asString( ::solver_problemruleinfo2str( _satSolver, type, static_cast<Id>(s.id()), static_cast<Id>(s2.id()), dep ) );
1136  break;
1137  }
1138  }
1139  return ret;
1140 }
1141 
1143 SATResolver::problems ()
1144 {
1145  ResolverProblemList resolverProblems;
1146  if (_satSolver && solver_problem_count(_satSolver)) {
1147  sat::detail::CPool *pool = _satSolver->pool;
1148  int pcnt;
1149  Id p, rp, what;
1150  Id problem, solution, element;
1151  sat::Solvable s, sd;
1152 
1153  CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1154  CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1155 
1156  MIL << "Encountered problems! Here are the solutions:\n" << endl;
1157  pcnt = 1;
1158  problem = 0;
1159  while ((problem = solver_next_problem(_satSolver, problem)) != 0) {
1160  MIL << "Problem " << pcnt++ << ":" << endl;
1161  MIL << "====================================" << endl;
1162  string detail;
1163  Id ignoreId;
1164  string whatString = SATprobleminfoString (problem,detail,ignoreId);
1165  MIL << whatString << endl;
1166  MIL << "------------------------------------" << endl;
1167  ResolverProblem_Ptr resolverProblem = new ResolverProblem (whatString, detail, SATgetCompleteProblemInfoStrings( problem ));
1168 
1169  solution = 0;
1170  while ((solution = solver_next_solution(_satSolver, problem, solution)) != 0) {
1171  element = 0;
1172  ProblemSolutionCombi *problemSolution = new ProblemSolutionCombi;
1173  while ((element = solver_next_solutionelement(_satSolver, problem, solution, element, &p, &rp)) != 0) {
1174  if (p == SOLVER_SOLUTION_JOB) {
1175  /* job, rp is index into job queue */
1176  what = _jobQueue.elements[rp];
1177  switch (_jobQueue.elements[rp-1]&(SOLVER_SELECTMASK|SOLVER_JOBMASK))
1178  {
1179  case SOLVER_INSTALL | SOLVER_SOLVABLE: {
1180  s = mapSolvable (what);
1181  PoolItem poolItem = _pool.find (s);
1182  if (poolItem) {
1183  if (pool->installed && s.get()->repo == pool->installed) {
1184  problemSolution->addSingleAction (poolItem, REMOVE);
1185  string description = str::form (_("remove lock to allow removal of %s"), s.asString().c_str() );
1186  MIL << description << endl;
1187  problemSolution->addDescription (description);
1188  } else {
1189  problemSolution->addSingleAction (poolItem, KEEP);
1190  string description = str::form (_("do not install %s"), s.asString().c_str());
1191  MIL << description << endl;
1192  problemSolution->addDescription (description);
1193  }
1194  } else {
1195  ERR << "SOLVER_INSTALL_SOLVABLE: No item found for " << s.asString() << endl;
1196  }
1197  }
1198  break;
1199  case SOLVER_ERASE | SOLVER_SOLVABLE: {
1200  s = mapSolvable (what);
1201  PoolItem poolItem = _pool.find (s);
1202  if (poolItem) {
1203  if (pool->installed && s.get()->repo == pool->installed) {
1204  problemSolution->addSingleAction (poolItem, KEEP);
1205  string description = str::form (_("keep %s"), s.asString().c_str());
1206  MIL << description << endl;
1207  problemSolution->addDescription (description);
1208  } else {
1209  problemSolution->addSingleAction (poolItem, UNLOCK);
1210  string description = str::form (_("remove lock to allow installation of %s"), itemToString( poolItem ).c_str());
1211  MIL << description << endl;
1212  problemSolution->addDescription (description);
1213  }
1214  } else {
1215  ERR << "SOLVER_ERASE_SOLVABLE: No item found for " << s.asString() << endl;
1216  }
1217  }
1218  break;
1219  case SOLVER_INSTALL | SOLVER_SOLVABLE_NAME:
1220  {
1221  IdString ident( what );
1222  SolverQueueItemInstall_Ptr install =
1223  new SolverQueueItemInstall(_pool, ident.asString(), false );
1224  problemSolution->addSingleAction (install, REMOVE_SOLVE_QUEUE_ITEM);
1225 
1226  string description = str::form (_("do not install %s"), ident.c_str() );
1227  MIL << description << endl;
1228  problemSolution->addDescription (description);
1229  }
1230  break;
1231  case SOLVER_ERASE | SOLVER_SOLVABLE_NAME:
1232  {
1233  // As we do not know, if this request has come from resolvePool or
1234  // resolveQueue we will have to take care for both cases.
1235  IdString ident( what );
1236  FindPackage info (problemSolution, KEEP);
1237  invokeOnEach( _pool.byIdentBegin( ident ),
1238  _pool.byIdentEnd( ident ),
1239  functor::chain (resfilter::ByInstalled (), // ByInstalled
1240  resfilter::ByTransact ()), // will be deinstalled
1241  functor::functorRef<bool,PoolItem> (info) );
1242 
1243  SolverQueueItemDelete_Ptr del =
1244  new SolverQueueItemDelete(_pool, ident.asString(), false );
1245  problemSolution->addSingleAction (del, REMOVE_SOLVE_QUEUE_ITEM);
1246 
1247  string description = str::form (_("keep %s"), ident.c_str());
1248  MIL << description << endl;
1249  problemSolution->addDescription (description);
1250  }
1251  break;
1252  case SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES:
1253  {
1254  problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_REQUIRE);
1255  string description = "";
1256 
1257  // Checking if this problem solution would break your system
1258  if (system_requires.find(Capability(what)) != system_requires.end()) {
1259  // Show a better warning
1260  resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1261  resolverProblem->setDescription(_("This request will break your system!"));
1262  description = _("ignore the warning of a broken system");
1263  description += string(" (requires:")+pool_dep2str(pool, what)+")";
1264  MIL << description << endl;
1265  problemSolution->addFrontDescription (description);
1266  } else {
1267  description = str::form (_("do not ask to install a solvable providing %s"), pool_dep2str(pool, what));
1268  MIL << description << endl;
1269  problemSolution->addDescription (description);
1270  }
1271  }
1272  break;
1273  case SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES:
1274  {
1275  problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_CONFLICT);
1276  string description = "";
1277 
1278  // Checking if this problem solution would break your system
1279  if (system_conflicts.find(Capability(what)) != system_conflicts.end()) {
1280  // Show a better warning
1281  resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1282  resolverProblem->setDescription(_("This request will break your system!"));
1283  description = _("ignore the warning of a broken system");
1284  description += string(" (conflicts:")+pool_dep2str(pool, what)+")";
1285  MIL << description << endl;
1286  problemSolution->addFrontDescription (description);
1287 
1288  } else {
1289  description = str::form (_("do not ask to delete all solvables providing %s"), pool_dep2str(pool, what));
1290  MIL << description << endl;
1291  problemSolution->addDescription (description);
1292  }
1293  }
1294  break;
1295  case SOLVER_UPDATE | SOLVER_SOLVABLE:
1296  {
1297  s = mapSolvable (what);
1298  PoolItem poolItem = _pool.find (s);
1299  if (poolItem) {
1300  if (pool->installed && s.get()->repo == pool->installed) {
1301  problemSolution->addSingleAction (poolItem, KEEP);
1302  string description = str::form (_("do not install most recent version of %s"), s.asString().c_str());
1303  MIL << description << endl;
1304  problemSolution->addDescription (description);
1305  } else {
1306  ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE " << poolItem << " is not selected for installation" << endl;
1307  }
1308  } else {
1309  ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE: No item found for " << s.asString() << endl;
1310  }
1311  }
1312  break;
1313  default:
1314  MIL << "- do something different" << endl;
1315  ERR << "No valid solution available" << endl;
1316  break;
1317  }
1318  } else if (p == SOLVER_SOLUTION_INFARCH) {
1319  s = mapSolvable (rp);
1320  PoolItem poolItem = _pool.find (s);
1321  if (pool->installed && s.get()->repo == pool->installed) {
1322  problemSolution->addSingleAction (poolItem, LOCK);
1323  string description = str::form (_("keep %s despite the inferior architecture"), s.asString().c_str());
1324  MIL << description << endl;
1325  problemSolution->addDescription (description);
1326  } else {
1327  problemSolution->addSingleAction (poolItem, INSTALL);
1328  string description = str::form (_("install %s despite the inferior architecture"), s.asString().c_str());
1329  MIL << description << endl;
1330  problemSolution->addDescription (description);
1331  }
1332  } else if (p == SOLVER_SOLUTION_DISTUPGRADE) {
1333  s = mapSolvable (rp);
1334  PoolItem poolItem = _pool.find (s);
1335  if (pool->installed && s.get()->repo == pool->installed) {
1336  problemSolution->addSingleAction (poolItem, LOCK);
1337  string description = str::form (_("keep obsolete %s"), s.asString().c_str());
1338  MIL << description << endl;
1339  problemSolution->addDescription (description);
1340  } else {
1341  problemSolution->addSingleAction (poolItem, INSTALL);
1342  string description = str::form (_("install %s from excluded repository"), s.asString().c_str());
1343  MIL << description << endl;
1344  problemSolution->addDescription (description);
1345  }
1346  } else {
1347  /* policy, replace p with rp */
1348  s = mapSolvable (p);
1349  PoolItem itemFrom = _pool.find (s);
1350  if (rp)
1351  {
1352  int gotone = 0;
1353 
1354  sd = mapSolvable (rp);
1355  PoolItem itemTo = _pool.find (sd);
1356  if (itemFrom && itemTo) {
1357  problemSolution->addSingleAction (itemTo, INSTALL);
1358  int illegal = policy_is_illegal(_satSolver, s.get(), sd.get(), 0);
1359 
1360  if ((illegal & POLICY_ILLEGAL_DOWNGRADE) != 0)
1361  {
1362  string description = str::form (_("downgrade of %s to %s"), s.asString().c_str(), sd.asString().c_str());
1363  MIL << description << endl;
1364  problemSolution->addDescription (description);
1365  gotone = 1;
1366  }
1367  if ((illegal & POLICY_ILLEGAL_ARCHCHANGE) != 0)
1368  {
1369  string description = str::form (_("architecture change of %s to %s"), s.asString().c_str(), sd.asString().c_str());
1370  MIL << description << endl;
1371  problemSolution->addDescription (description);
1372  gotone = 1;
1373  }
1374  if ((illegal & POLICY_ILLEGAL_VENDORCHANGE) != 0)
1375  {
1376  IdString s_vendor( s.vendor() );
1377  IdString sd_vendor( sd.vendor() );
1378  string description = str::form (_("install %s (with vendor change)\n %s --> %s") ,
1379  sd.asString().c_str(),
1380  ( s_vendor ? s_vendor.c_str() : " (no vendor) " ),
1381  ( sd_vendor ? sd_vendor.c_str() : " (no vendor) " ) );
1382  MIL << description << endl;
1383  problemSolution->addDescription (description);
1384  gotone = 1;
1385  }
1386  if (!gotone) {
1387  string description = str::form (_("replacement of %s with %s"), s.asString().c_str(), sd.asString().c_str());
1388  MIL << description << endl;
1389  problemSolution->addDescription (description);
1390  }
1391  } else {
1392  ERR << s.asString() << " or " << sd.asString() << " not found" << endl;
1393  }
1394  }
1395  else
1396  {
1397  if (itemFrom) {
1398  string description = str::form (_("deinstallation of %s"), s.asString().c_str());
1399  MIL << description << endl;
1400  problemSolution->addDescription (description);
1401  problemSolution->addSingleAction (itemFrom, REMOVE);
1402  }
1403  }
1404  }
1405  }
1406  resolverProblem->addSolution (problemSolution,
1407  problemSolution->actionCount() > 1 ? true : false); // Solutions with more than 1 action will be shown first.
1408  MIL << "------------------------------------" << endl;
1409  }
1410 
1411  if (ignoreId > 0) {
1412  // There is a possibility to ignore this error by setting weak dependencies
1413  PoolItem item = _pool.find (sat::Solvable(ignoreId));
1414  ProblemSolutionIgnore *problemSolution = new ProblemSolutionIgnore(item);
1415  resolverProblem->addSolution (problemSolution,
1416  false); // Solutions will be shown at the end
1417  MIL << "ignore some dependencies of " << item << endl;
1418  MIL << "------------------------------------" << endl;
1419  }
1420 
1421  // save problem
1422  resolverProblems.push_back (resolverProblem);
1423  }
1424  }
1425  return resolverProblems;
1426 }
1427 
1428 void SATResolver::applySolutions( const ProblemSolutionList & solutions )
1429 { Resolver( _pool ).applySolutions( solutions ); }
1430 
1431 void SATResolver::setLocks()
1432 {
1433  unsigned icnt = 0;
1434  unsigned acnt = 0;
1435 
1436  for (PoolItemList::const_iterator iter = _items_to_lock.begin(); iter != _items_to_lock.end(); ++iter) {
1437  sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
1438  if (iter->status().isInstalled()) {
1439  ++icnt;
1440  queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
1441  queue_push( &(_jobQueue), ident );
1442  } else {
1443  ++acnt;
1444  queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE | MAYBE_CLEANDEPS );
1445  queue_push( &(_jobQueue), ident );
1446  }
1447  }
1448  MIL << "Locked " << icnt << " installed items and " << acnt << " NOT installed items." << endl;
1449 
1451  // Weak locks: Ignore if an item with this name is already installed.
1452  // If it's not installed try to keep it this way using a weak delete
1454  std::set<IdString> unifiedByName;
1455  for (PoolItemList::const_iterator iter = _items_to_keep.begin(); iter != _items_to_keep.end(); ++iter) {
1456  IdString ident( (*iter)->satSolvable().ident() );
1457  if ( unifiedByName.insert( ident ).second )
1458  {
1459  if ( ! ui::Selectable::get( *iter )->hasInstalledObj() )
1460  {
1461  MIL << "Keep NOT installed name " << ident << " (" << *iter << ")" << endl;
1462  queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_NAME | SOLVER_WEAK | MAYBE_CLEANDEPS );
1463  queue_push( &(_jobQueue), ident.id() );
1464  }
1465  }
1466  }
1467 }
1468 
1469 void SATResolver::setSystemRequirements()
1470 {
1471  CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1472  CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1473 
1474  for (CapabilitySet::const_iterator iter = system_requires.begin(); iter != system_requires.end(); ++iter) {
1475  queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES );
1476  queue_push( &(_jobQueue), iter->id() );
1477  MIL << "SYSTEM Requires " << *iter << endl;
1478  }
1479 
1480  for (CapabilitySet::const_iterator iter = system_conflicts.begin(); iter != system_conflicts.end(); ++iter) {
1481  queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES | MAYBE_CLEANDEPS );
1482  queue_push( &(_jobQueue), iter->id() );
1483  MIL << "SYSTEM Conflicts " << *iter << endl;
1484  }
1485 
1486  // Lock the architecture of the running systems rpm
1487  // package on distupgrade.
1488  if ( _distupgrade && ZConfig::instance().systemRoot() == "/" )
1489  {
1490  ResPool pool( ResPool::instance() );
1491  IdString rpm( "rpm" );
1492  for_( it, pool.byIdentBegin(rpm), pool.byIdentEnd(rpm) )
1493  {
1494  if ( (*it)->isSystem() )
1495  {
1496  Capability archrule( (*it)->arch(), rpm.c_str(), Capability::PARSED );
1497  queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_NAME | SOLVER_ESSENTIAL );
1498  queue_push( &(_jobQueue), archrule.id() );
1499 
1500  }
1501  }
1502  }
1503 }
1504 
1505 sat::StringQueue SATResolver::autoInstalled() const
1506 {
1507  sat::StringQueue ret;
1508  if ( _satSolver )
1509  ::solver_get_userinstalled( _satSolver, ret, GET_USERINSTALLED_NAMES|GET_USERINSTALLED_INVERTED );
1510  return ret;
1511 }
1512 
1513 sat::StringQueue SATResolver::userInstalled() const
1514 {
1515  sat::StringQueue ret;
1516  if ( _satSolver )
1517  ::solver_get_userinstalled( _satSolver, ret, GET_USERINSTALLED_NAMES );
1518  return ret;
1519 }
1520 
1521 
1523 };// namespace detail
1526  };// namespace solver
1529 };// namespace zypp
1531 
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
const std::string & asString(const std::string &t)
Global asString() that works with std::string too.
Definition: String.h:136
#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
unsigned size_type
Definition: Queue.h:37
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
#define DBG
Definition: Logger.h:78
static ResPool instance()
Singleton ctor.
Definition: ResPool.cc:33