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