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