libzypp  15.28.6
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.repository() == repo_r )
133  return pi;
134  }
135  return PoolItem();
136  }
137 
145  {
146  PoolItem defaultCand( defaultCandidate() );
147 
148  // multiversionInstall: This returns the candidate for the last
149  // instance installed. Actually we'd need a list here.
150 
151  if ( installedEmpty() || ! defaultCand )
152  return defaultCand;
153  // Here: installed and defaultCand are non NULL and it's not a
154  // multiversion install.
155 
157  // check vendor change
158  if ( ! ( ResPool::instance().resolver().allowVendorChange()
159  || VendorAttr::instance().equivalent( defaultCand->vendor(), installed->vendor() ) ) )
160  return PoolItem();
161 
162  // check arch change (arch noarch changes are allowed)
163  if ( defaultCand->arch() != installed->arch()
164  && ! ( defaultCand->arch() == Arch_noarch || installed->arch() == Arch_noarch ) )
165  return PoolItem();
166 
167  // check greater edition
168  if ( defaultCand->edition() <= installed->edition() )
169  return PoolItem();
170 
171  return defaultCand;
172  }
173 
176  {
177  PoolItem ret;
178  for ( const PoolItem & pi : available() )
179  {
180  if ( !ret || pi.edition() > ret.edition() )
181  ret = pi;
182  }
183  return ret;
184  }
185 
187  bool identicalAvailable( const PoolItem & rhs ) const
188  { return bool(identicalAvailableObj( rhs )); }
189 
191  bool identicalInstalled( const PoolItem & rhs ) const
192  { return bool(identicalInstalledObj( rhs )); }
193 
196  {
197  if ( !availableEmpty() && rhs )
198  {
199  for_( it, _availableItems.begin(), _availableItems.end() )
200  {
201  if ( identical( *it, rhs ) )
202  return *it;
203  }
204  }
205  return PoolItem();
206  }
207 
210  {
211  if ( !installedEmpty() && rhs )
212  {
213  for_( it, _installedItems.begin(), _installedItems.end() )
214  {
215  if ( identical( *it, rhs ) )
216  return *it;
217  }
218  }
219  return PoolItem();
220  }
221 
223  PoolItem theObj() const
224  {
225  PoolItem ret( candidateObj() );
226  if ( ret )
227  return ret;
228  return installedObj();
229  }
230 
232 
233  bool availableEmpty() const
234  { return _availableItems.empty(); }
235 
237  { return _availableItems.size(); }
238 
240  { return _availableItems.begin(); }
241 
243  { return _availableItems.end(); }
244 
246  { return makeIterable( availableBegin(), availableEnd() ); }
247 
249 
250  bool installedEmpty() const
251  { return _installedItems.empty(); }
252 
254  { return _installedItems.size(); }
255 
257  { return _installedItems.begin(); }
258 
260  { return _installedItems.end(); }
261 
263  { return makeIterable( installedBegin(), installedEnd() ); }
264 
266 
267  const PickList & picklist() const
268  {
269  if ( ! _picklistPtr )
270  {
271  _picklistPtr.reset( new PickList );
272  // installed without identical avaialble first:
273  for ( const PoolItem & pi : installed() )
274  {
275  if ( ! identicalAvailable( pi ) )
276  _picklistPtr->push_back( pi );
277  }
278  _picklistPtr->insert( _picklistPtr->end(), availableBegin(), availableEnd() );
279  }
280  return *_picklistPtr;
281  }
282 
283  bool picklistEmpty() const
284  { return picklist().empty(); }
285 
287  { return picklist().size(); }
288 
290  { return picklist().begin(); }
291 
293  { return picklist().end(); }
294 
296 
297  bool isUnmaintained() const
298  { return availableEmpty(); }
299 
300  bool multiversionInstall() const
301  {
302  for ( const PoolItem & pi : picklist() )
303  {
304  if ( pi.multiversionInstall() )
305  return true;
306  }
307  return false;
308  }
309 
310  bool pickInstall( const PoolItem & pi_r, ResStatus::TransactByValue causer_r, bool yesno_r );
311 
312  bool pickDelete( const PoolItem & pi_r, ResStatus::TransactByValue causer_r, bool yesno_r );
313 
314  Status pickStatus( const PoolItem & pi_r ) const;
315 
316  bool setPickStatus( const PoolItem & pi_r, Status state_r, ResStatus::TransactByValue causer_r );
317 
319 
320  bool isUndetermined() const
321  {
322  PoolItem cand( candidateObj() );
323  return ! cand || cand.isUndetermined();
324  }
325  bool isRelevant() const
326  {
327  PoolItem cand( candidateObj() );
328  return cand && cand.isRelevant();
329  }
330  bool isSatisfied() const
331  {
332  PoolItem cand( candidateObj() );
333  return cand && cand.isSatisfied();
334  }
335  bool isBroken() const
336  {
337  PoolItem cand( candidateObj() );
338  return cand && cand.isBroken();
339  }
340 
343 
345  bool hasLicenceConfirmed() const
346  { return candidateObj() && candidateObj().status().isLicenceConfirmed(); }
347 
349  void setLicenceConfirmed( bool val_r )
350  { if ( candidateObj() ) candidateObj().status().setLicenceConfirmed( val_r ); }
351 
353  bool hasLocks() const
354  {
355  for ( const PoolItem & pi : available() )
356  {
357  if ( pi.status().isLocked() )
358  return true;
359  }
360  for ( const PoolItem & pi : installed() )
361  {
362  if ( pi.status().isLocked() )
363  return true;
364  }
365  return false;
366  }
367 
368  private:
370  {
371  for ( const PoolItem & pi : installed() )
372  {
373  if ( pi.status().transacts() )
374  return pi;
375  }
376  return PoolItem();
377  }
378 
380  {
381  for ( const PoolItem & pi : available() )
382  {
383  if ( pi.status().transacts() )
384  return pi;
385  }
386  return PoolItem();
387  }
388 
390  {
391  if ( ! installedEmpty() )
392  {
393  // prefer the installed objects arch and vendor
394  bool solver_allowVendorChange( ResPool::instance().resolver().allowVendorChange() );
395  for ( const PoolItem & ipi : installed() )
396  {
397  PoolItem sameArch; // in case there's no same vendor at least stay with same arch.
398  for ( const PoolItem & api : available() )
399  {
400  // 'same arch' includes allowed changes to/from noarch.
401  if ( ipi.arch() == api.arch() || ipi.arch() == Arch_noarch || api.arch() == Arch_noarch )
402  {
403  if ( ! solver_allowVendorChange )
404  {
405  if ( VendorAttr::instance().equivalent( ipi, api ) )
406  return api;
407  else if ( ! sameArch ) // remember best same arch in case no same vendor found
408  sameArch = api;
409  }
410  else // same arch is sufficient
411  return api;
412  }
413  }
414  if ( sameArch )
415  return sameArch;
416  }
417  }
418  if ( _availableItems.empty() )
419  return PoolItem();
420 
421  return *_availableItems.begin();
422  }
423 
424  bool allCandidatesLocked() const
425  {
426  for ( const PoolItem & pi : available() )
427  {
428  if ( ! pi.status().isLocked() )
429  return false;
430  }
431  return( ! _availableItems.empty() );
432  }
433 
434  bool allInstalledLocked() const
435  {
436  for ( const PoolItem & pi : installed() )
437  {
438  if ( ! pi.status().isLocked() )
439  return false;
440  }
441  return( ! _installedItems.empty() );
442  }
443 
444 
445  private:
447  const ResKind _kind;
448  const std::string _name;
454  mutable scoped_ptr<PickList> _picklistPtr;
455  };
457 
459  inline std::ostream & operator<<( std::ostream & str, const Selectable::Impl & obj )
460  {
461  return str << '[' << obj.kind() << ']' << obj.name() << ": " << obj.status()
462  << " (I " << obj.installedSize() << ")"
463  << " (A " << obj.availableSize() << ")"
464  << obj.candidateObj();
465  }
466 
468  inline std::ostream & dumpOn( std::ostream & str, const Selectable::Impl & obj )
469  {
470  str << '[' << obj.kind() << ']' << obj.name() << ": " << obj.status()
471  << ( obj.multiversionInstall() ? " (multiversion)" : "") << endl;
472 
473  if ( obj.installedEmpty() )
474  str << " (I 0) {}" << endl << " ";
475  else
476  {
477  PoolItem icand( obj.installedObj() );
478  str << " (I " << obj.installedSize() << ") {" << endl;
479  for ( const PoolItem & pi : obj.installed() )
480  {
481  char t = ' ';
482  if ( pi == icand )
483  {
484  t = 'i';
485  }
486  str << " " << t << " " << pi << endl;
487  }
488  str << "} ";
489  }
490 
491  if ( obj.availableEmpty() )
492  {
493  str << "(A 0) {}" << endl << " ";
494  }
495  else
496  {
497  PoolItem cand( obj.candidateObj() );
498  PoolItem up( obj.updateCandidateObj() );
499  str << "(A " << obj.availableSize() << ") {" << endl;
500  for ( const PoolItem & pi : obj.available() )
501  {
502  char t = ' ';
503  if ( pi == cand )
504  {
505  t = pi == up ? 'C' : 'c';
506  }
507  else if ( pi == up )
508  {
509  t = 'u';
510  }
511  str << " " << t << " " << pi << endl;
512  }
513  str << "} ";
514  }
515 
516  if ( obj.picklistEmpty() )
517  {
518  str << "(P 0) {}";
519  }
520  else
521  {
522  PoolItem cand( obj.candidateObj() );
523  PoolItem up( obj.updateCandidateObj() );
524  str << "(P " << obj.picklistSize() << ") {" << endl;
525  for ( const PoolItem & pi : obj.picklist() )
526  {
527  char t = ' ';
528  if ( pi == cand )
529  {
530  t = pi == up ? 'C' : 'c';
531  }
532  else if ( pi == up )
533  {
534  t = 'u';
535  }
536  str << " " << t << " " << pi << "\t" << obj.pickStatus( pi ) << endl;
537  }
538  str << "} ";
539  }
540 
541  return str;
542  }
544  } // namespace ui
547 } // namespace zypp
549 #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
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.
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 shold be treated as the same vendor.
Definition: VendorAttr.cc:285
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.
const std::string & name() const
bool identical(const SolvableType< Derived > &lhs, const Solvable &rhs)
Definition: SolvableType.h:211
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 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
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:123
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