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