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  if ( (*it)->onSystem() ) // (to install) or (not to delete)
686  {
687  Product::constPtr prodCand( (*it)->candidateAsKind<Product>() );
688  if ( ! prodCand )
689  continue; // product no longer available
690 
691  CapabilitySet droplist( prodCand->droplist() );
692  dumpRangeLine( MIL << "Droplist for " << (*it)->candidateObj() << ": " << droplist.size() << " ", droplist.begin(), droplist.end() ) << endl;
693  for_( cap, droplist.begin(), droplist.end() )
694  {
695  queue_push( &_jobQueue, SOLVER_DROP_ORPHANED | SOLVER_SOLVABLE_NAME );
696  queue_push( &_jobQueue, cap->id() );
697  }
698  }
699  }
700  }
701  else
702  {
703  MIL << "Droplist processing is disabled." << endl;
704  }
705  }
706 }
707 
708 void
709 SATResolver::solverEnd()
710 {
711  // cleanup
712  if ( _satSolver )
713  {
714  solver_free(_satSolver);
715  _satSolver = NULL;
716  queue_free( &(_jobQueue) );
717  }
718 }
719 
720 
721 bool
722 SATResolver::resolvePool(const CapabilitySet & requires_caps,
723  const CapabilitySet & conflict_caps,
724  const PoolItemList & weakItems,
725  const std::set<Repository> & upgradeRepos)
726 {
727  MIL << "SATResolver::resolvePool()" << endl;
728 
729  // initialize
730  solverInit(weakItems);
731 
732  for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
733  Id id = (*iter)->satSolvable().id();
734  if (id == ID_NULL) {
735  ERR << "Install: " << *iter << " not found" << endl;
736  } else {
737  MIL << "Install " << *iter << endl;
738  queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
739  queue_push( &(_jobQueue), id );
740  }
741  }
742 
743  for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
744  Id id = (*iter)->satSolvable().id();
745  if (id == ID_NULL) {
746  ERR << "Delete: " << *iter << " not found" << endl;
747  } else {
748  MIL << "Delete " << *iter << endl;
749  queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE | MAYBE_CLEANDEPS );
750  queue_push( &(_jobQueue), id);
751  }
752  }
753 
754  for_( iter, upgradeRepos.begin(), upgradeRepos.end() )
755  {
756  queue_push( &(_jobQueue), SOLVER_DISTUPGRADE | SOLVER_SOLVABLE_REPO );
757  queue_push( &(_jobQueue), iter->get()->repoid );
758  MIL << "Upgrade repo " << *iter << endl;
759  }
760 
761  for (CapabilitySet::const_iterator iter = requires_caps.begin(); iter != requires_caps.end(); iter++) {
762  queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES );
763  queue_push( &(_jobQueue), iter->id() );
764  MIL << "Requires " << *iter << endl;
765  }
766 
767  for (CapabilitySet::const_iterator iter = conflict_caps.begin(); iter != conflict_caps.end(); iter++) {
768  queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES | MAYBE_CLEANDEPS );
769  queue_push( &(_jobQueue), iter->id() );
770  MIL << "Conflicts " << *iter << endl;
771  }
772 
773  // set requirements for a running system
774  setSystemRequirements();
775 
776  // set locks for the solver
777  setLocks();
778 
779  // solving
780  bool ret = solving(requires_caps, conflict_caps);
781 
782  (ret?MIL:WAR) << "SATResolver::resolvePool() done. Ret:" << ret << endl;
783  return ret;
784 }
785 
786 
787 bool
788 SATResolver::resolveQueue(const SolverQueueItemList &requestQueue,
789  const PoolItemList & weakItems)
790 {
791  MIL << "SATResolver::resolvQueue()" << endl;
792 
793  // initialize
794  solverInit(weakItems);
795 
796  // generate solver queue
797  for (SolverQueueItemList::const_iterator iter = requestQueue.begin(); iter != requestQueue.end(); iter++) {
798  (*iter)->addRule(_jobQueue);
799  }
800 
801  // Add addition item status to the resolve-queue cause these can be set by problem resolutions
802  for (PoolItemList::const_iterator iter = _items_to_install.begin(); iter != _items_to_install.end(); iter++) {
803  Id id = (*iter)->satSolvable().id();
804  if (id == ID_NULL) {
805  ERR << "Install: " << *iter << " not found" << endl;
806  } else {
807  MIL << "Install " << *iter << endl;
808  queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
809  queue_push( &(_jobQueue), id );
810  }
811  }
812  for (PoolItemList::const_iterator iter = _items_to_remove.begin(); iter != _items_to_remove.end(); iter++) {
813  sat::detail::IdType ident( (*iter)->satSolvable().ident().id() );
814  MIL << "Delete " << *iter << ident << endl;
815  queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_NAME | MAYBE_CLEANDEPS );
816  queue_push( &(_jobQueue), ident);
817  }
818 
819  // set requirements for a running system
820  setSystemRequirements();
821 
822  // set locks for the solver
823  setLocks();
824 
825  // solving
826  bool ret = solving();
827 
828  MIL << "SATResolver::resolveQueue() done. Ret:" << ret << endl;
829  return ret;
830 }
831 
833 void SATResolver::doUpdate()
834 {
835  MIL << "SATResolver::doUpdate()" << endl;
836 
837  // initialize
838  solverInit(PoolItemList());
839 
840  // set requirements for a running system
841  setSystemRequirements();
842 
843  // set locks for the solver
844  setLocks();
845 
846  _satSolver = solver_create( _satPool );
847  ::pool_set_custom_vendorcheck( _satPool, &vendorCheck );
848  if (_fixsystem) {
849  queue_push( &(_jobQueue), SOLVER_VERIFY|SOLVER_SOLVABLE_ALL);
850  queue_push( &(_jobQueue), 0 );
851  }
852  if (1) {
853  queue_push( &(_jobQueue), SOLVER_UPDATE|SOLVER_SOLVABLE_ALL);
854  queue_push( &(_jobQueue), 0 );
855  }
856  if (_distupgrade) {
857  queue_push( &(_jobQueue), SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_ALL);
858  queue_push( &(_jobQueue), 0 );
859  }
860  if (_distupgrade_removeunsupported) {
861  queue_push( &(_jobQueue), SOLVER_DROP_ORPHANED|SOLVER_SOLVABLE_ALL);
862  queue_push( &(_jobQueue), 0 );
863  }
864  solverSetFocus( *_satSolver, _focus );
865  solver_set_flag(_satSolver, SOLVER_FLAG_ADD_ALREADY_RECOMMENDED, !_ignorealreadyrecommended);
866  solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_DOWNGRADE, _allowdowngrade);
867  solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_NAMECHANGE, _allownamechange);
868  solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_ARCHCHANGE, _allowarchchange);
869  solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_VENDORCHANGE, _allowvendorchange);
870  solver_set_flag(_satSolver, SOLVER_FLAG_ALLOW_UNINSTALL, _allowuninstall);
871  solver_set_flag(_satSolver, SOLVER_FLAG_NO_UPDATEPROVIDE, _noupdateprovide);
872  solver_set_flag(_satSolver, SOLVER_FLAG_SPLITPROVIDES, _dosplitprovides);
873  solver_set_flag(_satSolver, SOLVER_FLAG_IGNORE_RECOMMENDED, false); // resolve recommended namespaces
874  solver_set_flag(_satSolver, SOLVER_FLAG_ONLY_NAMESPACE_RECOMMENDED, _onlyRequires); //
875 
877 
878  // Solve !
879  MIL << "Starting solving for update...." << endl;
880  MIL << *this;
881  solver_solve( _satSolver, &(_jobQueue) );
882  MIL << "....Solver end" << endl;
883 
884  // copying solution back to zypp pool
885  //-----------------------------------------
886 
887  /* solvables to be installed */
888  Queue decisionq;
889  queue_init(&decisionq);
890  solver_get_decisionqueue(_satSolver, &decisionq);
891  for (int i = 0; i < decisionq.count; i++)
892  {
893  Id p;
894  p = decisionq.elements[i];
895  if (p < 0 || !sat::Solvable(p))
896  continue;
897  if (sat::Solvable(p).repository().get() == _satSolver->pool->installed)
898  continue;
899 
900  PoolItem poolItem = _pool.find (sat::Solvable(p));
901  if (poolItem) {
903  } else {
904  ERR << "id " << p << " not found in ZYPP pool." << endl;
905  }
906  }
907  queue_free(&decisionq);
908 
909  /* solvables to be erased */
910  for (int i = _satSolver->pool->installed->start; i < _satSolver->pool->installed->start + _satSolver->pool->installed->nsolvables; i++)
911  {
912  if (solver_get_decisionlevel(_satSolver, i) > 0)
913  continue;
914 
915  PoolItem poolItem( _pool.find( sat::Solvable(i) ) );
916  if (poolItem) {
917  // Check if this is an update
918  CheckIfUpdate info( (sat::Solvable(i)) );
919  invokeOnEach( _pool.byIdentBegin( poolItem ),
920  _pool.byIdentEnd( poolItem ),
921  resfilter::ByUninstalled(), // ByUninstalled
922  functor::functorRef<bool,PoolItem> (info) );
923 
924  if (info.is_updated) {
926  } else {
928  }
929  } else {
930  ERR << "id " << i << " not found in ZYPP pool." << endl;
931  }
932  }
933  MIL << "SATResolver::doUpdate() done" << endl;
934 }
935 
936 
937 
938 //----------------------------------------------------------------------------
939 //----------------------------------------------------------------------------
940 // error handling
941 //----------------------------------------------------------------------------
942 //----------------------------------------------------------------------------
943 
944 //----------------------------------------------------------------------------
945 // helper function
946 //----------------------------------------------------------------------------
947 
949 {
950  ProblemSolutionCombi *problemSolution;
951  TransactionKind action;
952  FindPackage (ProblemSolutionCombi *p, const TransactionKind act)
953  : problemSolution (p)
954  , action (act)
955  {
956  }
957 
959  {
960  problemSolution->addSingleAction (p, action);
961  return true;
962  }
963 };
964 
965 
966 //----------------------------------------------------------------------------
967 // Checking if this solvable/item has a buddy which reflect the real
968 // user visible description of an item
969 // e.g. The release package has a buddy to the concerning product item.
970 // This user want's the message "Product foo conflicts with product bar" and
971 // NOT "package release-foo conflicts with package release-bar"
972 // (ma: that's why we should map just packages to buddies, not vice versa)
973 //----------------------------------------------------------------------------
974 inline sat::Solvable mapBuddy( const PoolItem & item_r )
975 {
976  if ( item_r.satSolvable().isKind<Package>() )
977  {
978  sat::Solvable buddy = item_r.buddy();
979  if ( buddy )
980  return buddy;
981  }
982  return item_r.satSolvable();
983 }
985 { return mapBuddy( PoolItem( item_r ) ); }
986 
987 PoolItem SATResolver::mapItem ( const PoolItem & item )
988 { return PoolItem( mapBuddy( item ) ); }
989 
990 sat::Solvable SATResolver::mapSolvable ( const Id & id )
991 { return mapBuddy( sat::Solvable(id) ); }
992 
993 std::vector<std::string> SATResolver::SATgetCompleteProblemInfoStrings ( Id problem )
994 {
995  std::vector<std::string> ret;
996  sat::Queue problems;
997  solver_findallproblemrules( _satSolver, problem, problems );
998 
999  bool nobad = false;
1000 
1001  //filter out generic rule information if more explicit ones are available
1002  for ( sat::Queue::size_type i = 0; i < problems.size(); i++ ) {
1003  SolverRuleinfo ruleClass = solver_ruleclass( _satSolver, problems[i]);
1004  if ( ruleClass != SolverRuleinfo::SOLVER_RULE_UPDATE && ruleClass != SolverRuleinfo::SOLVER_RULE_JOB ) {
1005  nobad = true;
1006  break;
1007  }
1008  }
1009  for ( sat::Queue::size_type i = 0; i < problems.size(); i++ ) {
1010  SolverRuleinfo ruleClass = solver_ruleclass( _satSolver, problems[i]);
1011  if ( nobad && ( ruleClass == SolverRuleinfo::SOLVER_RULE_UPDATE || ruleClass == SolverRuleinfo::SOLVER_RULE_JOB ) ) {
1012  continue;
1013  }
1014 
1015  std::string detail;
1016  Id ignore = 0;
1017  std::string pInfo = SATproblemRuleInfoString( problems[i], detail, ignore );
1018 
1019  //we get the same string multiple times, reduce the noise
1020  if ( std::find( ret.begin(), ret.end(), pInfo ) == ret.end() )
1021  ret.push_back( pInfo );
1022  }
1023  return ret;
1024 }
1025 
1026 string SATResolver::SATprobleminfoString(Id problem, string &detail, Id &ignoreId)
1027 {
1028  // FIXME: solver_findallproblemrules to get all rules for this problem
1029  // (the 'most relevabt' one returned by solver_findproblemrule is embedded
1030  Id probr = solver_findproblemrule(_satSolver, problem);
1031  return SATproblemRuleInfoString( probr, detail, ignoreId );
1032 }
1033 
1034 std::string SATResolver::SATproblemRuleInfoString (Id probr, std::string &detail, Id &ignoreId)
1035 {
1036  string ret;
1037  sat::detail::CPool *pool = _satSolver->pool;
1038  Id dep, source, target;
1039  SolverRuleinfo type = solver_ruleinfo(_satSolver, probr, &source, &target, &dep);
1040 
1041  ignoreId = 0;
1042 
1043  sat::Solvable s = mapSolvable( source );
1044  sat::Solvable s2 = mapSolvable( target );
1045 
1046  // @FIXME, these strings are a duplicate copied from the libsolv library
1047  // to provide translations. Instead of having duplicate code we should
1048  // translate those strings directly in libsolv
1049  switch ( type )
1050  {
1051  case SOLVER_RULE_DISTUPGRADE:
1052  ret = str::form (_("%s does not belong to a distupgrade repository"), s.asString().c_str());
1053  break;
1054  case SOLVER_RULE_INFARCH:
1055  ret = str::form (_("%s has inferior architecture"), s.asString().c_str());
1056  break;
1057  case SOLVER_RULE_UPDATE:
1058  ret = str::form (_("problem with installed package %s"), s.asString().c_str());
1059  break;
1060  case SOLVER_RULE_JOB:
1061  ret = _("conflicting requests");
1062  break;
1063  case SOLVER_RULE_PKG:
1064  ret = _("some dependency problem");
1065  break;
1066  case SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP:
1067  ret = str::form (_("nothing provides requested %s"), pool_dep2str(pool, dep));
1068  detail += _("Have you enabled all requested repositories?");
1069  break;
1070  case SOLVER_RULE_JOB_UNKNOWN_PACKAGE:
1071  ret = str::form (_("package %s does not exist"), pool_dep2str(pool, dep));
1072  detail += _("Have you enabled all requested repositories?");
1073  break;
1074  case SOLVER_RULE_JOB_UNSUPPORTED:
1075  ret = _("unsupported request");
1076  break;
1077  case SOLVER_RULE_JOB_PROVIDED_BY_SYSTEM:
1078  ret = str::form (_("%s is provided by the system and cannot be erased"), pool_dep2str(pool, dep));
1079  break;
1080  case SOLVER_RULE_PKG_NOT_INSTALLABLE:
1081  ret = str::form (_("%s is not installable"), s.asString().c_str());
1082  break;
1083  case SOLVER_RULE_PKG_NOTHING_PROVIDES_DEP:
1084  ignoreId = source; // for setting weak dependencies
1085  ret = str::form (_("nothing provides %s needed by %s"), pool_dep2str(pool, dep), s.asString().c_str());
1086  break;
1087  case SOLVER_RULE_PKG_SAME_NAME:
1088  ret = str::form (_("cannot install both %s and %s"), s.asString().c_str(), s2.asString().c_str());
1089  break;
1090  case SOLVER_RULE_PKG_CONFLICTS:
1091  ret = str::form (_("%s conflicts with %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1092  break;
1093  case SOLVER_RULE_PKG_OBSOLETES:
1094  ret = str::form (_("%s obsoletes %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1095  break;
1096  case SOLVER_RULE_PKG_INSTALLED_OBSOLETES:
1097  ret = str::form (_("installed %s obsoletes %s provided by %s"), s.asString().c_str(), pool_dep2str(pool, dep), s2.asString().c_str());
1098  break;
1099  case SOLVER_RULE_PKG_SELF_CONFLICT:
1100  ret = str::form (_("solvable %s conflicts with %s provided by itself"), s.asString().c_str(), pool_dep2str(pool, dep));
1101  break;
1102  case SOLVER_RULE_PKG_REQUIRES: {
1103  ignoreId = source; // for setting weak dependencies
1104  Capability cap(dep);
1105  sat::WhatProvides possibleProviders(cap);
1106 
1107  // check, if a provider will be deleted
1108  typedef list<PoolItem> ProviderList;
1109  ProviderList providerlistInstalled, providerlistUninstalled;
1110  for_( iter1, possibleProviders.begin(), possibleProviders.end() ) {
1111  PoolItem provider1 = ResPool::instance().find( *iter1 );
1112  // find pair of an installed/uninstalled item with the same NVR
1113  bool found = false;
1114  for_( iter2, possibleProviders.begin(), possibleProviders.end() ) {
1115  PoolItem provider2 = ResPool::instance().find( *iter2 );
1116  if (compareByNVR (provider1,provider2) == 0
1117  && ( (provider1.status().isInstalled() && provider2.status().isUninstalled())
1118  || (provider2.status().isInstalled() && provider1.status().isUninstalled()) )) {
1119  found = true;
1120  break;
1121  }
1122  }
1123  if (!found) {
1124  if (provider1.status().isInstalled())
1125  providerlistInstalled.push_back(provider1);
1126  else
1127  providerlistUninstalled.push_back(provider1);
1128  }
1129  }
1130 
1131  ret = str::form (_("%s requires %s, but this requirement cannot be provided"), s.asString().c_str(), pool_dep2str(pool, dep));
1132  if (providerlistInstalled.size() > 0) {
1133  detail += _("deleted providers: ");
1134  for (ProviderList::const_iterator iter = providerlistInstalled.begin(); iter != providerlistInstalled.end(); iter++) {
1135  if (iter == providerlistInstalled.begin())
1136  detail += itemToString( *iter );
1137  else
1138  detail += "\n " + itemToString( mapItem(*iter) );
1139  }
1140  }
1141  if (providerlistUninstalled.size() > 0) {
1142  if (detail.size() > 0)
1143  detail += _("\nnot installable providers: ");
1144  else
1145  detail = _("not installable providers: ");
1146  for (ProviderList::const_iterator iter = providerlistUninstalled.begin(); iter != providerlistUninstalled.end(); iter++) {
1147  if (iter == providerlistUninstalled.begin())
1148  detail += itemToString( *iter );
1149  else
1150  detail += "\n " + itemToString( mapItem(*iter) );
1151  }
1152  }
1153  break;
1154  }
1155  default: {
1156  DBG << "Unknown rule type(" << type << ") going to query libsolv for rule information." << endl;
1157  ret = str::asString( ::solver_problemruleinfo2str( _satSolver, type, static_cast<Id>(s.id()), static_cast<Id>(s2.id()), dep ) );
1158  break;
1159  }
1160  }
1161  return ret;
1162 }
1163 
1165 SATResolver::problems ()
1166 {
1167  ResolverProblemList resolverProblems;
1168  if (_satSolver && solver_problem_count(_satSolver)) {
1169  sat::detail::CPool *pool = _satSolver->pool;
1170  int pcnt;
1171  Id p, rp, what;
1172  Id problem, solution, element;
1173  sat::Solvable s, sd;
1174 
1175  CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1176  CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1177 
1178  MIL << "Encountered problems! Here are the solutions:\n" << endl;
1179  pcnt = 1;
1180  problem = 0;
1181  while ((problem = solver_next_problem(_satSolver, problem)) != 0) {
1182  MIL << "Problem " << pcnt++ << ":" << endl;
1183  MIL << "====================================" << endl;
1184  string detail;
1185  Id ignoreId;
1186  string whatString = SATprobleminfoString (problem,detail,ignoreId);
1187  MIL << whatString << endl;
1188  MIL << "------------------------------------" << endl;
1189  ResolverProblem_Ptr resolverProblem = new ResolverProblem (whatString, detail, SATgetCompleteProblemInfoStrings( problem ));
1190 
1191  solution = 0;
1192  while ((solution = solver_next_solution(_satSolver, problem, solution)) != 0) {
1193  element = 0;
1194  ProblemSolutionCombi *problemSolution = new ProblemSolutionCombi;
1195  while ((element = solver_next_solutionelement(_satSolver, problem, solution, element, &p, &rp)) != 0) {
1196  if (p == SOLVER_SOLUTION_JOB) {
1197  /* job, rp is index into job queue */
1198  what = _jobQueue.elements[rp];
1199  switch (_jobQueue.elements[rp-1]&(SOLVER_SELECTMASK|SOLVER_JOBMASK))
1200  {
1201  case SOLVER_INSTALL | SOLVER_SOLVABLE: {
1202  s = mapSolvable (what);
1203  PoolItem poolItem = _pool.find (s);
1204  if (poolItem) {
1205  if (pool->installed && s.get()->repo == pool->installed) {
1206  problemSolution->addSingleAction (poolItem, REMOVE);
1207  string description = str::form (_("remove lock to allow removal of %s"), s.asString().c_str() );
1208  MIL << description << endl;
1209  problemSolution->addDescription (description);
1210  } else {
1211  problemSolution->addSingleAction (poolItem, KEEP);
1212  string description = str::form (_("do not install %s"), s.asString().c_str());
1213  MIL << description << endl;
1214  problemSolution->addDescription (description);
1215  }
1216  } else {
1217  ERR << "SOLVER_INSTALL_SOLVABLE: No item found for " << s.asString() << endl;
1218  }
1219  }
1220  break;
1221  case SOLVER_ERASE | SOLVER_SOLVABLE: {
1222  s = mapSolvable (what);
1223  PoolItem poolItem = _pool.find (s);
1224  if (poolItem) {
1225  if (pool->installed && s.get()->repo == pool->installed) {
1226  problemSolution->addSingleAction (poolItem, KEEP);
1227  string description = str::form (_("keep %s"), s.asString().c_str());
1228  MIL << description << endl;
1229  problemSolution->addDescription (description);
1230  } else {
1231  problemSolution->addSingleAction (poolItem, UNLOCK);
1232  string description = str::form (_("remove lock to allow installation of %s"), itemToString( poolItem ).c_str());
1233  MIL << description << endl;
1234  problemSolution->addDescription (description);
1235  }
1236  } else {
1237  ERR << "SOLVER_ERASE_SOLVABLE: No item found for " << s.asString() << endl;
1238  }
1239  }
1240  break;
1241  case SOLVER_INSTALL | SOLVER_SOLVABLE_NAME:
1242  {
1243  IdString ident( what );
1244  SolverQueueItemInstall_Ptr install =
1245  new SolverQueueItemInstall(_pool, ident.asString(), false );
1246  problemSolution->addSingleAction (install, REMOVE_SOLVE_QUEUE_ITEM);
1247 
1248  string description = str::form (_("do not install %s"), ident.c_str() );
1249  MIL << description << endl;
1250  problemSolution->addDescription (description);
1251  }
1252  break;
1253  case SOLVER_ERASE | SOLVER_SOLVABLE_NAME:
1254  {
1255  // As we do not know, if this request has come from resolvePool or
1256  // resolveQueue we will have to take care for both cases.
1257  IdString ident( what );
1258  FindPackage info (problemSolution, KEEP);
1259  invokeOnEach( _pool.byIdentBegin( ident ),
1260  _pool.byIdentEnd( ident ),
1261  functor::chain (resfilter::ByInstalled (), // ByInstalled
1262  resfilter::ByTransact ()), // will be deinstalled
1263  functor::functorRef<bool,PoolItem> (info) );
1264 
1265  SolverQueueItemDelete_Ptr del =
1266  new SolverQueueItemDelete(_pool, ident.asString(), false );
1267  problemSolution->addSingleAction (del, REMOVE_SOLVE_QUEUE_ITEM);
1268 
1269  string description = str::form (_("keep %s"), ident.c_str());
1270  MIL << description << endl;
1271  problemSolution->addDescription (description);
1272  }
1273  break;
1274  case SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES:
1275  {
1276  problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_REQUIRE);
1277  string description = "";
1278 
1279  // Checking if this problem solution would break your system
1280  if (system_requires.find(Capability(what)) != system_requires.end()) {
1281  // Show a better warning
1282  resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1283  resolverProblem->setDescription(_("This request will break your system!"));
1284  description = _("ignore the warning of a broken system");
1285  description += string(" (requires:")+pool_dep2str(pool, what)+")";
1286  MIL << description << endl;
1287  problemSolution->addFrontDescription (description);
1288  } else {
1289  description = str::form (_("do not ask to install a solvable providing %s"), pool_dep2str(pool, what));
1290  MIL << description << endl;
1291  problemSolution->addDescription (description);
1292  }
1293  }
1294  break;
1295  case SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES:
1296  {
1297  problemSolution->addSingleAction (Capability(what), REMOVE_EXTRA_CONFLICT);
1298  string description = "";
1299 
1300  // Checking if this problem solution would break your system
1301  if (system_conflicts.find(Capability(what)) != system_conflicts.end()) {
1302  // Show a better warning
1303  resolverProblem->setDetails( resolverProblem->description() + "\n" + resolverProblem->details() );
1304  resolverProblem->setDescription(_("This request will break your system!"));
1305  description = _("ignore the warning of a broken system");
1306  description += string(" (conflicts:")+pool_dep2str(pool, what)+")";
1307  MIL << description << endl;
1308  problemSolution->addFrontDescription (description);
1309 
1310  } else {
1311  description = str::form (_("do not ask to delete all solvables providing %s"), pool_dep2str(pool, what));
1312  MIL << description << endl;
1313  problemSolution->addDescription (description);
1314  }
1315  }
1316  break;
1317  case SOLVER_UPDATE | SOLVER_SOLVABLE:
1318  {
1319  s = mapSolvable (what);
1320  PoolItem poolItem = _pool.find (s);
1321  if (poolItem) {
1322  if (pool->installed && s.get()->repo == pool->installed) {
1323  problemSolution->addSingleAction (poolItem, KEEP);
1324  string description = str::form (_("do not install most recent version of %s"), s.asString().c_str());
1325  MIL << description << endl;
1326  problemSolution->addDescription (description);
1327  } else {
1328  ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE " << poolItem << " is not selected for installation" << endl;
1329  }
1330  } else {
1331  ERR << "SOLVER_INSTALL_SOLVABLE_UPDATE: No item found for " << s.asString() << endl;
1332  }
1333  }
1334  break;
1335  default:
1336  MIL << "- do something different" << endl;
1337  ERR << "No valid solution available" << endl;
1338  break;
1339  }
1340  } else if (p == SOLVER_SOLUTION_INFARCH) {
1341  s = mapSolvable (rp);
1342  PoolItem poolItem = _pool.find (s);
1343  if (pool->installed && s.get()->repo == pool->installed) {
1344  problemSolution->addSingleAction (poolItem, LOCK);
1345  string description = str::form (_("keep %s despite the inferior architecture"), s.asString().c_str());
1346  MIL << description << endl;
1347  problemSolution->addDescription (description);
1348  } else {
1349  problemSolution->addSingleAction (poolItem, INSTALL);
1350  string description = str::form (_("install %s despite the inferior architecture"), s.asString().c_str());
1351  MIL << description << endl;
1352  problemSolution->addDescription (description);
1353  }
1354  } else if (p == SOLVER_SOLUTION_DISTUPGRADE) {
1355  s = mapSolvable (rp);
1356  PoolItem poolItem = _pool.find (s);
1357  if (pool->installed && s.get()->repo == pool->installed) {
1358  problemSolution->addSingleAction (poolItem, LOCK);
1359  string description = str::form (_("keep obsolete %s"), s.asString().c_str());
1360  MIL << description << endl;
1361  problemSolution->addDescription (description);
1362  } else {
1363  problemSolution->addSingleAction (poolItem, INSTALL);
1364  string description = str::form (_("install %s from excluded repository"), s.asString().c_str());
1365  MIL << description << endl;
1366  problemSolution->addDescription (description);
1367  }
1368  } else {
1369  /* policy, replace p with rp */
1370  s = mapSolvable (p);
1371  PoolItem itemFrom = _pool.find (s);
1372  if (rp)
1373  {
1374  int gotone = 0;
1375 
1376  sd = mapSolvable (rp);
1377  PoolItem itemTo = _pool.find (sd);
1378  if (itemFrom && itemTo) {
1379  problemSolution->addSingleAction (itemTo, INSTALL);
1380  int illegal = policy_is_illegal(_satSolver, s.get(), sd.get(), 0);
1381 
1382  if ((illegal & POLICY_ILLEGAL_DOWNGRADE) != 0)
1383  {
1384  string description = str::form (_("downgrade of %s to %s"), s.asString().c_str(), sd.asString().c_str());
1385  MIL << description << endl;
1386  problemSolution->addDescription (description);
1387  gotone = 1;
1388  }
1389  if ((illegal & POLICY_ILLEGAL_ARCHCHANGE) != 0)
1390  {
1391  string description = str::form (_("architecture change 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_VENDORCHANGE) != 0)
1397  {
1398  IdString s_vendor( s.vendor() );
1399  IdString sd_vendor( sd.vendor() );
1400  string description = str::form (_("install %s (with vendor change)\n %s --> %s") ,
1401  sd.asString().c_str(),
1402  ( s_vendor ? s_vendor.c_str() : " (no vendor) " ),
1403  ( sd_vendor ? sd_vendor.c_str() : " (no vendor) " ) );
1404  MIL << description << endl;
1405  problemSolution->addDescription (description);
1406  gotone = 1;
1407  }
1408  if (!gotone) {
1409  string description = str::form (_("replacement of %s with %s"), s.asString().c_str(), sd.asString().c_str());
1410  MIL << description << endl;
1411  problemSolution->addDescription (description);
1412  }
1413  } else {
1414  ERR << s.asString() << " or " << sd.asString() << " not found" << endl;
1415  }
1416  }
1417  else
1418  {
1419  if (itemFrom) {
1420  string description = str::form (_("deinstallation of %s"), s.asString().c_str());
1421  MIL << description << endl;
1422  problemSolution->addDescription (description);
1423  problemSolution->addSingleAction (itemFrom, REMOVE);
1424  }
1425  }
1426  }
1427  }
1428  resolverProblem->addSolution (problemSolution,
1429  problemSolution->actionCount() > 1 ? true : false); // Solutions with more than 1 action will be shown first.
1430  MIL << "------------------------------------" << endl;
1431  }
1432 
1433  if (ignoreId > 0) {
1434  // There is a possibility to ignore this error by setting weak dependencies
1435  PoolItem item = _pool.find (sat::Solvable(ignoreId));
1436  ProblemSolutionIgnore *problemSolution = new ProblemSolutionIgnore(item);
1437  resolverProblem->addSolution (problemSolution,
1438  false); // Solutions will be shown at the end
1439  MIL << "ignore some dependencies of " << item << endl;
1440  MIL << "------------------------------------" << endl;
1441  }
1442 
1443  // save problem
1444  resolverProblems.push_back (resolverProblem);
1445  }
1446  }
1447  return resolverProblems;
1448 }
1449 
1450 void SATResolver::applySolutions( const ProblemSolutionList & solutions )
1451 { Resolver( _pool ).applySolutions( solutions ); }
1452 
1453 void SATResolver::setLocks()
1454 {
1455  unsigned icnt = 0;
1456  unsigned acnt = 0;
1457 
1458  for (PoolItemList::const_iterator iter = _items_to_lock.begin(); iter != _items_to_lock.end(); ++iter) {
1459  sat::detail::SolvableIdType ident( (*iter)->satSolvable().id() );
1460  if (iter->status().isInstalled()) {
1461  ++icnt;
1462  queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE );
1463  queue_push( &(_jobQueue), ident );
1464  } else {
1465  ++acnt;
1466  queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE | MAYBE_CLEANDEPS );
1467  queue_push( &(_jobQueue), ident );
1468  }
1469  }
1470  MIL << "Locked " << icnt << " installed items and " << acnt << " NOT installed items." << endl;
1471 
1473  // Weak locks: Ignore if an item with this name is already installed.
1474  // If it's not installed try to keep it this way using a weak delete
1476  std::set<IdString> unifiedByName;
1477  for (PoolItemList::const_iterator iter = _items_to_keep.begin(); iter != _items_to_keep.end(); ++iter) {
1478  IdString ident( (*iter)->satSolvable().ident() );
1479  if ( unifiedByName.insert( ident ).second )
1480  {
1481  if ( ! ui::Selectable::get( *iter )->hasInstalledObj() )
1482  {
1483  MIL << "Keep NOT installed name " << ident << " (" << *iter << ")" << endl;
1484  queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_NAME | SOLVER_WEAK | MAYBE_CLEANDEPS );
1485  queue_push( &(_jobQueue), ident.id() );
1486  }
1487  }
1488  }
1489 }
1490 
1491 void SATResolver::setSystemRequirements()
1492 {
1493  CapabilitySet system_requires = SystemCheck::instance().requiredSystemCap();
1494  CapabilitySet system_conflicts = SystemCheck::instance().conflictSystemCap();
1495 
1496  for (CapabilitySet::const_iterator iter = system_requires.begin(); iter != system_requires.end(); ++iter) {
1497  queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES );
1498  queue_push( &(_jobQueue), iter->id() );
1499  MIL << "SYSTEM Requires " << *iter << endl;
1500  }
1501 
1502  for (CapabilitySet::const_iterator iter = system_conflicts.begin(); iter != system_conflicts.end(); ++iter) {
1503  queue_push( &(_jobQueue), SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES | MAYBE_CLEANDEPS );
1504  queue_push( &(_jobQueue), iter->id() );
1505  MIL << "SYSTEM Conflicts " << *iter << endl;
1506  }
1507 
1508  // Lock the architecture of the running systems rpm
1509  // package on distupgrade.
1510  if ( _distupgrade && ZConfig::instance().systemRoot() == "/" )
1511  {
1512  ResPool pool( ResPool::instance() );
1513  IdString rpm( "rpm" );
1514  for_( it, pool.byIdentBegin(rpm), pool.byIdentEnd(rpm) )
1515  {
1516  if ( (*it)->isSystem() )
1517  {
1518  Capability archrule( (*it)->arch(), rpm.c_str(), Capability::PARSED );
1519  queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE_NAME | SOLVER_ESSENTIAL );
1520  queue_push( &(_jobQueue), archrule.id() );
1521 
1522  }
1523  }
1524  }
1525 }
1526 
1527 sat::StringQueue SATResolver::autoInstalled() const
1528 {
1529  sat::StringQueue ret;
1530  if ( _satSolver )
1531  ::solver_get_userinstalled( _satSolver, ret, GET_USERINSTALLED_NAMES|GET_USERINSTALLED_INVERTED );
1532  return ret;
1533 }
1534 
1535 sat::StringQueue SATResolver::userInstalled() const
1536 {
1537  sat::StringQueue ret;
1538  if ( _satSolver )
1539  ::solver_get_userinstalled( _satSolver, ret, GET_USERINSTALLED_NAMES );
1540  return ret;
1541 }
1542 
1543 
1545 };// namespace detail
1548  };// namespace solver
1551 };// namespace zypp
1553 
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:950
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:952
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:984
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