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