libzypp  17.36.1
SelectableImpl.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_UI_SELECTABLEIMPL_H
13 #define ZYPP_UI_SELECTABLEIMPL_H
14 
15 #include <iostream>
16 #include <zypp/base/LogTools.h>
17 
18 #include <zypp/base/PtrTypes.h>
19 
20 #include <zypp/ResPool.h>
21 #include <zypp/Resolver.h>
22 #include <zypp/ui/Selectable.h>
24 #include <zypp/Package.h>
25 
26 using std::endl;
27 
29 namespace zypp
30 {
31  namespace ui
33  {
34 
36  //
37  // CLASS NAME : Selectable::Impl
38  //
44  {
45  public:
46 
51 
56 
58 
59  public:
60  template <class TIterator>
61  Impl( const ResKind & kind_r,
62  const std::string & name_r,
63  TIterator begin_r,
64  TIterator end_r )
65  : _ident( sat::Solvable::SplitIdent( kind_r, name_r ).ident() )
66  , _kind( kind_r )
67  , _name( name_r )
68  {
69  for_( it, begin_r, end_r )
70  {
71  if ( it->status().isInstalled() )
72  _installedItems.insert( *it );
73  else
74  _availableItems.insert( *it );
75  }
76  }
77 
78  public:
80  IdString ident() const
81  { return _ident; }
82 
84  ResKind kind() const
85  { return _kind; }
86 
88  const std::string & name() const
89  { return _name; }
90 
92  Status status() const;
93 
95  bool setStatus( Status state_r, ResStatus::TransactByValue causer_r );
96 
99  {
100  if ( installedEmpty() )
101  return PoolItem();
103  return ret ? ret : *_installedItems.begin();
104  }
105 
111  {
113  if ( ! ret )
115  return ret;
116  }
117 
122  PoolItem setCandidate( const PoolItem & newCandidate_r, ResStatus::TransactByValue causer_r );
123 
130  {
131  for ( const PoolItem & pi : available() )
132  {
133  if ( pi.isBlacklisted() )
134  continue;
135  if ( pi.repository() == repo_r )
136  return pi;
137  }
138  return PoolItem();
139  }
140 
148  {
149  PoolItem defaultCand( defaultCandidate() );
150 
151  // multiversionInstall: This returns the candidate for the last
152  // instance installed. Actually we'd need a list here.
153 
154  if ( ! defaultCand || defaultCand.isBlacklisted() )
155  return PoolItem();
156 
157  if ( installedEmpty() )
158  return defaultCand;
159  // Here: installed and defaultCand are non NULL and it's not a
160  // multiversion install.
161 
163  // check vendor change
164  if ( ! ( ResPool::instance().resolver().allowVendorChange()
165  || VendorAttr::instance().equivalent( defaultCand->vendor(), installed->vendor() ) ) )
166  return PoolItem();
167 
168  // check arch change (arch noarch changes are allowed)
169  if ( defaultCand->arch() != installed->arch()
170  && ! ( defaultCand->arch() == Arch_noarch || installed->arch() == Arch_noarch ) )
171  return PoolItem();
172 
173  // check greater edition
174  if ( defaultCand->edition() <= installed->edition() )
175  return PoolItem();
176 
177  return defaultCand;
178  }
179 
182  {
183  PoolItem ret;
184  bool blacklistedOk = false;
185  for ( const PoolItem & pi : available() )
186  {
187  if ( !blacklistedOk && pi.isBlacklisted() )
188  {
189  if ( ret )
190  break; // prefer a not retracted candidate
191  blacklistedOk = true;
192  }
193  if ( !ret || pi.edition() > ret.edition() )
194  ret = pi;
195  }
196  return ret;
197  }
198 
200  bool identIsAutoInstalled() const
202 
204  bool identicalAvailable( const PoolItem & rhs ) const
205  { return bool(identicalAvailableObj( rhs )); }
206 
208  bool identicalInstalled( const PoolItem & rhs ) const
209  { return bool(identicalInstalledObj( rhs )); }
210 
213  {
214  if ( !availableEmpty() && rhs )
215  {
216  for_( it, _availableItems.begin(), _availableItems.end() )
217  {
218  if ( identical( *it, rhs ) )
219  return *it;
220  }
221  }
222  return PoolItem();
223  }
224 
227  {
228  if ( !installedEmpty() && rhs )
229  {
230  for_( it, _installedItems.begin(), _installedItems.end() )
231  {
232  if ( identical( *it, rhs ) )
233  return *it;
234  }
235  }
236  return PoolItem();
237  }
238 
240  PoolItem theObj() const
241  {
242  PoolItem ret( candidateObj() );
243  if ( ret )
244  return ret;
245  return installedObj();
246  }
247 
248  std::vector<std::string> supersededBy() const
249  {
250  std::vector<std::string> ret;
251  if ( kind() == ResKind::package ) {
252  for ( const PoolItem & pi : available() ) {
253  ret = pi->asKind<Package>()->supersededBy();
254  if ( not ret.empty() )
255  break;
256  }
257  }
258  return ret;
259  }
260 
262 
263  bool availableEmpty() const
264  { return _availableItems.empty(); }
265 
267  { return _availableItems.size(); }
268 
270  { return _availableItems.begin(); }
271 
273  { return _availableItems.end(); }
274 
276  { return makeIterable( availableBegin(), availableEnd() ); }
277 
279 
280  bool installedEmpty() const
281  { return _installedItems.empty(); }
282 
284  { return _installedItems.size(); }
285 
287  { return _installedItems.begin(); }
288 
290  { return _installedItems.end(); }
291 
293  { return makeIterable( installedBegin(), installedEnd() ); }
294 
296 
297  const PickList & picklist() const
298  {
299  if ( ! _picklistPtr )
300  {
301  _picklistPtr.reset( new PickList );
302  // installed without identical avaialble first:
303  for ( const PoolItem & pi : installed() )
304  {
305  if ( ! identicalAvailable( pi ) )
306  _picklistPtr->push_back( pi );
307  }
308  _picklistPtr->insert( _picklistPtr->end(), availableBegin(), availableEnd() );
309  }
310  return *_picklistPtr;
311  }
312 
313  bool picklistEmpty() const
314  { return picklist().empty(); }
315 
317  { return picklist().size(); }
318 
320  { return picklist().begin(); }
321 
323  { return picklist().end(); }
324 
326  bool hasBlacklisted() const
327  { // Blacklisted items are sorted to the end of the available list.
328  return !_availableItems.empty() && _availableItems.rbegin()->isBlacklisted();
329  }
330 
332  { // Blacklisted items may be embedded in the installed list.
333  for ( const PoolItem & pi : installed() ) {
334  if ( pi.isBlacklisted() )
335  return true;
336  }
337  return false;
338  }
339 
340  bool hasRetracted() const
341  {
342  for ( const PoolItem & pi : makeIterable( _availableItems.rbegin(), _availableItems.rend() ) ) {
343  if ( not pi.isBlacklisted() )
344  break;
345  if ( pi.isRetracted() )
346  return true;
347  }
348  return false;
349  }
350 
352  {
353  for ( const PoolItem & pi : installed() ) {
354  if ( pi.isRetracted() )
355  return true;
356  }
357  return false;
358  }
359 
360  bool hasPtf() const
361  {
362  for ( const PoolItem & pi : makeIterable( _availableItems.rbegin(), _availableItems.rend() ) ) {
363  if ( not pi.isBlacklisted() )
364  break;
365  if ( pi.isPtf() )
366  return true;
367  }
368  return false;
369  }
370 
371  bool hasPtfInstalled() const
372  {
373  for ( const PoolItem & pi : installed() ) {
374  if ( pi.isPtf() )
375  return true;
376  }
377  return false;
378  }
379 
380 
381  bool isUnmaintained() const
382  { return availableEmpty(); }
383 
384  bool multiversionInstall() const
385  {
386  for ( const PoolItem & pi : picklist() )
387  {
388  if ( pi.multiversionInstall() )
389  return true;
390  }
391  return false;
392  }
393 
394  bool pickInstall( const PoolItem & pi_r, ResStatus::TransactByValue causer_r, bool yesno_r );
395 
396  bool pickDelete( const PoolItem & pi_r, ResStatus::TransactByValue causer_r, bool yesno_r );
397 
398  Status pickStatus( const PoolItem & pi_r ) const;
399 
400  bool setPickStatus( const PoolItem & pi_r, Status state_r, ResStatus::TransactByValue causer_r );
401 
403 
404  bool isUndetermined() const
405  {
406  PoolItem cand( candidateObj() );
407  return ! cand || cand.isUndetermined();
408  }
409  bool isRelevant() const
410  {
411  PoolItem cand( candidateObj() );
412  return cand && cand.isRelevant();
413  }
414  bool isSatisfied() const
415  {
416  PoolItem cand( candidateObj() );
417  return cand && cand.isSatisfied();
418  }
419  bool isBroken() const
420  {
421  PoolItem cand( candidateObj() );
422  return cand && cand.isBroken();
423  }
424 
427 
429  bool hasLicenceConfirmed() const
430  { return candidateObj() && candidateObj().status().isLicenceConfirmed(); }
431 
433  void setLicenceConfirmed( bool val_r )
434  { if ( candidateObj() ) candidateObj().status().setLicenceConfirmed( val_r ); }
435 
437  bool hasLocks() const
438  {
439  for ( const PoolItem & pi : available() )
440  {
441  if ( pi.status().isLocked() )
442  return true;
443  }
444  for ( const PoolItem & pi : installed() )
445  {
446  if ( pi.status().isLocked() )
447  return true;
448  }
449  return false;
450  }
451 
452  private:
454  {
455  for ( const PoolItem & pi : installed() )
456  {
457  if ( pi.status().transacts() )
458  return pi;
459  }
460  return PoolItem();
461  }
462 
464  {
465  for ( const PoolItem & pi : available() )
466  {
467  if ( pi.status().transacts() )
468  return pi;
469  }
470  return PoolItem();
471  }
472 
474  {
475  if ( ! installedEmpty() )
476  {
477  // prefer the installed objects arch and vendor
478  bool solver_allowVendorChange( ResPool::instance().resolver().allowVendorChange() );
479  for ( const PoolItem & ipi : installed() )
480  {
481  PoolItem sameArch; // in case there's no same vendor at least stay with same arch.
482  for ( const PoolItem & api : available() )
483  {
484  // 'same arch' includes allowed changes to/from noarch.
485  if ( ipi.arch() == api.arch() || ipi.arch() == Arch_noarch || api.arch() == Arch_noarch )
486  {
487  if ( ! solver_allowVendorChange )
488  {
489  if ( VendorAttr::instance().equivalent( ipi, api ) )
490  return api;
491  else if ( ! sameArch ) // remember best same arch in case no same vendor found
492  sameArch = api;
493  }
494  else // same arch is sufficient
495  return api;
496  }
497  }
498  if ( sameArch )
499  return sameArch;
500  }
501  }
502  if ( _availableItems.empty() )
503  return PoolItem();
504 
505  return *_availableItems.begin();
506  }
507 
508  bool allCandidatesLocked() const
509  {
510  for ( const PoolItem & pi : available() )
511  {
512  if ( ! pi.status().isLocked() )
513  return false;
514  }
515  return( ! _availableItems.empty() );
516  }
517 
518  bool allInstalledLocked() const
519  {
520  for ( const PoolItem & pi : installed() )
521  {
522  if ( ! pi.status().isLocked() )
523  return false;
524  }
525  return( ! _installedItems.empty() );
526  }
527 
528 
529  private:
531  const ResKind _kind;
532  const std::string _name;
538  mutable scoped_ptr<PickList> _picklistPtr;
539  };
541 
543  inline std::ostream & operator<<( std::ostream & str, const Selectable::Impl & obj )
544  {
545  return str << '[' << obj.kind() << ']' << obj.name() << ": " << obj.status()
546  << " (I " << obj.installedSize() << ")"
547  << " (A " << obj.availableSize() << ")"
548  << obj.candidateObj();
549  }
550 
552  inline std::ostream & dumpOn( std::ostream & str, const Selectable::Impl & obj )
553  {
554  str << '[' << obj.kind() << ']' << obj.name() << ": " << obj.status()
555  << ( obj.multiversionInstall() ? " (multiversion)" : "") << endl;
556 
557  if ( obj.installedEmpty() )
558  str << " (I 0) {}" << endl << " ";
559  else
560  {
561  PoolItem icand( obj.installedObj() );
562  str << " (I " << obj.installedSize() << ") {" << endl;
563  for ( const PoolItem & pi : obj.installed() )
564  {
565  char t = ' ';
566  if ( pi == icand )
567  {
568  t = 'i';
569  }
570  str << " " << t << " " << pi << endl;
571  }
572  str << "} ";
573  }
574 
575  if ( obj.availableEmpty() )
576  {
577  str << "(A 0) {}" << endl << " ";
578  }
579  else
580  {
581  PoolItem cand( obj.candidateObj() );
582  PoolItem up( obj.updateCandidateObj() );
583  str << "(A " << obj.availableSize() << ") {" << endl;
584  for ( const PoolItem & pi : obj.available() )
585  {
586  char t = ' ';
587  if ( pi == cand )
588  {
589  t = pi == up ? 'C' : 'c';
590  }
591  else if ( pi == up )
592  {
593  t = 'u';
594  }
595  str << " " << t << " " << pi << endl;
596  }
597  str << "} ";
598  }
599 
600  if ( obj.picklistEmpty() )
601  {
602  str << "(P 0) {}";
603  }
604  else
605  {
606  PoolItem cand( obj.candidateObj() );
607  PoolItem up( obj.updateCandidateObj() );
608  str << "(P " << obj.picklistSize() << ") {" << endl;
609  for ( const PoolItem & pi : obj.picklist() )
610  {
611  char t = ' ';
612  if ( pi == cand )
613  {
614  t = pi == up ? 'C' : 'c';
615  }
616  else if ( pi == up )
617  {
618  t = 'u';
619  }
620  str << " " << t << " " << pi << "\t" << obj.pickStatus( pi ) << endl;
621  }
622  str << "} ";
623  }
624 
625  return str;
626  }
628  } // namespace ui
631 } // namespace zypp
633 #endif // ZYPP_UI_SELECTABLEIMPL_H
bool hasLicenceConfirmed() const
Return value of LicenceConfirmed bit.
InstalledItemSet _installedItems
Status pickStatus(const PoolItem &pi_r) const
AvailableItemSet::const_iterator available_const_iterator
Status
UI status Status values calculated by Selectable.
Definition: Status.h:35
std::vector< PoolItem > PickList
ResStatus::TransactByValue modifiedBy() const
Return who caused the modification.
static const ResKind package
Definition: ResKind.h:40
AvailableItemSet _availableItems
AvailableItemSet::size_type available_size_type
bool equivalent(const Vendor &lVendor, const Vendor &rVendor) const
Return whether two vendor strings should be treated as the same vendor.
Definition: VendorAttr.cc:313
picklist_iterator picklistEnd() const
AvailableItemSet::iterator installed_iterator
scoped_ptr< PickList > _picklistPtr
lazy initialized picklist
bool hasBlacklistedInstalled() const
bool setStatus(Status state_r, ResStatus::TransactByValue causer_r)
bool identicalInstalled(const PoolItem &rhs) const
True if rhs has the same content as an installed one.
std::vector< std::string > supersededBy() const
ResStatus & status() const
Returns the current status.
Definition: PoolItem.cc:212
SelectableTraits::installed_iterator installed_iterator
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:27
String related utilities and Regular expression matching.
PoolItem defaultCandidate() const
Access to the sat-pools string space.
Definition: IdString.h:43
Edition edition() const
Definition: SolvableType.h:71
AvailableItemSet::size_type installed_size_type
bool isSatisfied() const
Whether a relevant items requirements are met.
Definition: PoolItem.cc:219
Iterable< installed_iterator > installed() const
void setLicenceConfirmed(bool toVal_r=true)
Definition: ResStatus.h:184
std::set< PoolItem, IOrder > InstalledItemSet
bool hasRetractedInstalled() const
PoolItem setCandidate(const PoolItem &newCandidate_r, ResStatus::TransactByValue causer_r)
Set a userCandidate (out of available objects).
PoolItem theObj() const
Best among all objects.
std::ostream & operator<<(std::ostream &str, const Selectable::Impl &obj)
PoolItem transactingCandidate() const
available_size_type availableSize() const
bool isBroken() const
Whether a relevant items requirements are broken.
Definition: PoolItem.cc:220
bool identIsAutoInstalled() const
Whether an installed solvable with the same ident is flagged as AutoInstalled.
Definition: Solvable.h:143
picklist_iterator picklistBegin() const
PoolItem identicalInstalledObj(const PoolItem &rhs) const
an installed Object with the same content as rhs.
installed_size_type installedSize() const
Package interface.
Definition: Package.h:33
bool identical(const SolvableType< Derived > &lhs, const Solvable &rhs)
Definition: SolvableType.h:231
Impl(const ResKind &kind_r, const std::string &name_r, TIterator begin_r, TIterator end_r)
bool isUndetermined() const
No validation is performed for packages.
Definition: PoolItem.cc:217
SelectableTraits::installed_size_type installed_size_type
bool hasLocks() const
True if it includes locked items (don&#39;t mix this with the locked status).
std::set< PoolItem, AVOrder > AvailableItemSet
installed_iterator installedEnd() const
PoolItem candidateObj() const
Best among available objects.
available_iterator availableBegin() const
const std::string & name() const
AvailableItemSet::const_iterator installed_const_iterator
PoolItem updateCandidateObj() const
The best candidate for update, if there is one.
std::ostream & dumpOn(std::ostream &str, const Selectable::Impl &obj)
picklist_size_type picklistSize() const
SelectableTraits::available_iterator available_iterator
bool identicalAvailable(const PoolItem &rhs) const
True if rhs is installed and one with the same content is available.
PoolItem identicalAvailableObj(const PoolItem &rhs) const
Return an available Object with the same content as rhs.
SelectableTraits::picklist_iterator picklist_iterator
Definition: Selectable.h:68
Iterable< available_iterator > available() const
bool isRelevant() const
Returns true if the solvable is relevant which means e.g.
Definition: PoolItem.cc:218
PoolItem _candidate
The object selected by setCandidateObj() method.
SelectableTraits::InstalledItemSet InstalledItemSet
bool isLicenceConfirmed() const
Definition: ResStatus.h:181
Selectable implementation.
bool isBlacklisted() const
Definition: SolvableType.h:85
PoolItem highestAvailableVersionObj() const
Simply the highest available version, ignoring priorities and policies.
available_iterator availableEnd() const
SelectableTraits::installed_const_iterator installed_const_iterator
void setLicenceConfirmed(bool val_r)
Set LicenceConfirmed bit.
installed_iterator installedBegin() const
PoolItem transactingInstalled() const
Combining sat::Solvable and ResStatus.
Definition: PoolItem.h:50
bool setPickStatus(const PoolItem &pi_r, Status state_r, ResStatus::TransactByValue causer_r)
SelectableTraits::available_size_type available_size_type
AvailableItemSet::iterator available_iterator
static const VendorAttr & instance()
(Pseudo)Singleton, mapped to the current Target::vendorAttr settings or to noTargetInstance.
Definition: VendorAttr.cc:230
bool pickInstall(const PoolItem &pi_r, ResStatus::TransactByValue causer_r, bool yesno_r)
bool identIsAutoInstalled() const
Whether this ident is flagged as AutoInstalled.
Resolvable kinds.
Definition: ResKind.h:32
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
PoolItem candidateObjFrom(Repository repo_r) const
The best candidate provided by a specific Repository, if there is one.
SelectableTraits::available_const_iterator available_const_iterator
SelectableTraits::AvailableItemSet AvailableItemSet
IdString vendor() const
Definition: SolvableType.h:73
SelectableTraits::picklist_size_type picklist_size_type
Definition: Selectable.h:69
bool pickDelete(const PoolItem &pi_r, ResStatus::TransactByValue causer_r, bool yesno_r)
SelectableTraits::PickList PickList
PoolItem installedObj() const
Installed object (transacting ot highest version).
const PickList & picklist() const
static ResPool instance()
Singleton ctor.
Definition: ResPool.cc:38