libzypp 17.37.17
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
26using std::endl;
27
29namespace zypp
30{
32 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:
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
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
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
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
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 }
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
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
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
509 {
510 for ( const PoolItem & pi : available() )
511 {
512 if ( ! pi.status().isLocked() )
513 return false;
514 }
515 return( ! _availableItems.empty() );
516 }
517
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:
532 const std::string _name;
539 };
540
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 }
627
628 } // namespace ui
631} // namespace zypp
633#endif // ZYPP_UI_SELECTABLEIMPL_H
Access to the sat-pools string space.
Definition IdString.h:44
Iterable< TIterator > makeIterable(TIterator &&begin_r, TIterator &&end_r)
convenient construction.
Definition Iterable.h:88
Package interface.
Definition Package.h:34
Combining sat::Solvable and ResStatus.
Definition PoolItem.h:51
bool isRelevant() const
Returns true if the solvable is relevant which means e.g.
Definition PoolItem.cc:218
bool isBroken() const
Whether a relevant items requirements are broken.
Definition PoolItem.cc:220
ResStatus & status() const
Returns the current status.
Definition PoolItem.cc:212
bool isSatisfied() const
Whether a relevant items requirements are met.
Definition PoolItem.cc:219
bool isUndetermined() const
No validation is performed for packages.
Definition PoolItem.cc:217
Resolvable kinds.
Definition ResKind.h:33
static const ResKind package
Definition ResKind.h:40
static ResPool instance()
Singleton ctor.
Definition ResPool.cc:38
bool isLicenceConfirmed() const
Definition ResStatus.h:181
void setLicenceConfirmed(bool toVal_r=true)
Definition ResStatus.h:184
static const VendorAttr & instance()
(Pseudo)Singleton, mapped to the current Target::vendorAttr settings or to noTargetInstance.
bool identIsAutoInstalled() const
Whether an installed solvable with the same ident is flagged as AutoInstalled.
Definition Solvable.h:143
SelectableTraits::picklist_size_type picklist_size_type
Definition Selectable.h:69
SelectableTraits::picklist_iterator picklist_iterator
Definition Selectable.h:68
String related utilities and Regular expression matching.
Libsolv interface
Status
UI status Status values calculated by Selectable.
Definition Status.h:36
Easy-to use interface to the ZYPP dependency resolver.
bool isBlacklisted() const
Edition edition() const
AvailableItemSet::size_type available_size_type
std::set< PoolItem, AVOrder > AvailableItemSet
AvailableItemSet::iterator available_iterator
AvailableItemSet::const_iterator installed_const_iterator
std::vector< PoolItem > PickList
AvailableItemSet::iterator installed_iterator
AvailableItemSet::const_iterator available_const_iterator
AvailableItemSet::size_type installed_size_type
std::set< PoolItem, IOrder > InstalledItemSet
Selectable implementation.
PoolItem installedObj() const
Installed object (transacting ot highest version).
PoolItem theObj() const
Best among all objects.
installed_iterator installedEnd() const
SelectableTraits::AvailableItemSet AvailableItemSet
PoolItem transactingCandidate() const
SelectableTraits::installed_const_iterator installed_const_iterator
PoolItem transactingInstalled() const
PoolItem _candidate
The object selected by setCandidateObj() method.
SelectableTraits::installed_iterator installed_iterator
SelectableTraits::InstalledItemSet InstalledItemSet
bool setPickStatus(const PoolItem &pi_r, Status state_r, ResStatus::TransactByValue causer_r)
const std::string & name() const
available_iterator availableBegin() const
SelectableTraits::PickList PickList
bool identicalInstalled(const PoolItem &rhs) const
True if rhs has the same content as an installed one.
installed_iterator installedBegin() const
SelectableTraits::available_const_iterator available_const_iterator
SelectableTraits::installed_size_type installed_size_type
PoolItem identicalAvailableObj(const PoolItem &rhs) const
Return an available Object with the same content as rhs.
picklist_iterator picklistBegin() const
available_iterator availableEnd() const
SelectableTraits::available_iterator available_iterator
InstalledItemSet _installedItems
std::vector< std::string > supersededBy() const
PoolItem updateCandidateObj() const
The best candidate for update, if there is one.
AvailableItemSet _availableItems
Iterable< installed_iterator > installed() const
bool pickInstall(const PoolItem &pi_r, ResStatus::TransactByValue causer_r, bool yesno_r)
picklist_size_type picklistSize() const
Iterable< available_iterator > available() const
PoolItem identicalInstalledObj(const PoolItem &rhs) const
\Return an installed Object with the same content as rhs.
SelectableTraits::available_size_type available_size_type
picklist_iterator picklistEnd() const
PoolItem defaultCandidate() const
bool setStatus(Status state_r, ResStatus::TransactByValue causer_r)
scoped_ptr< PickList > _picklistPtr
lazy initialized picklist
ResStatus::TransactByValue modifiedBy() const
Return who caused the modification.
PoolItem candidateObj() const
Best among available objects.
Status pickStatus(const PoolItem &pi_r) const
std::ostream & dumpOn(std::ostream &str, const Selectable::Impl &obj)
Stream output.
bool identicalAvailable(const PoolItem &rhs) const
True if rhs is installed and one with the same content is available.
PoolItem highestAvailableVersionObj() const
Simply the highest available version, ignoring priorities and policies.
std::ostream & operator<<(std::ostream &str, const Selectable::Impl &obj)
Stream output.
Impl(const ResKind &kind_r, const std::string &name_r, TIterator begin_r, TIterator end_r)
void setLicenceConfirmed(bool val_r)
Set LicenceConfirmed bit.
PoolItem setCandidate(const PoolItem &newCandidate_r, ResStatus::TransactByValue causer_r)
Set a userCandidate (out of available objects).
PoolItem candidateObjFrom(Repository repo_r) const
The best candidate provided by a specific Repository, if there is one.
bool hasLicenceConfirmed() const
Return value of LicenceConfirmed bit.
bool identIsAutoInstalled() const
Whether this ident is flagged as AutoInstalled.
available_size_type availableSize() const
bool pickDelete(const PoolItem &pi_r, ResStatus::TransactByValue causer_r, bool yesno_r)
bool hasLocks() const
True if it includes locked items (don't mix this with the locked status).
installed_size_type installedSize() const
const PickList & picklist() const
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition Easy.h:27