libzypp  17.36.3
Selectable.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <iostream>
13 #include <utility>
14 //#include <zypp/base/Logger.h>
15 
16 #include <zypp/ui/Selectable.h>
17 #include <zypp/ui/SelectableImpl.h>
18 #include <zypp/ResPool.h>
19 
21 namespace zypp
22 {
23  namespace ui
25  {
26 
27  IMPL_PTR_TYPE(Selectable);
28 
30  { return ResPool::instance().proxy().lookup( ident_r ); }
31 
33  //
34  // METHOD NAME : Selectable::Selectable
35  // METHOD TYPE : Ctor
36  //
38  : _pimpl( std::move(pimpl_r) )
39  {}
40 
42  //
43  // METHOD NAME : Selectable::~Selectable
44  // METHOD TYPE : Dtor
45  //
47  {}
48 
50  //
51  // Forward to implementation.
52  // Restrict PoolItems to ResObject::constPtr!
53  //
55 
57  { return _pimpl->ident(); }
58 
60  { return _pimpl->kind(); }
61 
62  const std::string & Selectable::name() const
63  { return _pimpl->name(); }
64 
66  { return _pimpl->status(); }
67 
69  { return _pimpl->setStatus( state_r, causer_r ); }
70 
72  { return _pimpl->installedObj(); }
73 
75  { return _pimpl->candidateObj(); }
76 
78  { return _pimpl->candidateObjFrom( repo_r ); }
79 
81  { return _pimpl->updateCandidateObj(); }
82 
84  { return _pimpl->highestAvailableVersionObj(); }
85 
87  { return _pimpl->identIsAutoInstalled(); }
88 
89  bool Selectable::identicalAvailable( const PoolItem & rhs ) const
90  { return _pimpl->identicalAvailable( rhs ); }
91 
92  bool Selectable::identicalInstalled( const PoolItem & rhs ) const
93  { return _pimpl->identicalInstalled( rhs ); }
94 
96  { return _pimpl->identicalAvailableObj( rhs ); }
97 
99  { return _pimpl->identicalInstalledObj( rhs ); }
100 
102  { return _pimpl->setCandidate( newCandidate_r, causer_r ); }
103 
105  { return _pimpl->setCandidate( PoolItem( newCandidate_r ), causer_r ); }
106 
107  bool Selectable::setOnSystem( const PoolItem & newCandidate_r, ResStatus::TransactByValue causer_r )
108  {
109  if ( identicalInstalled( newCandidate_r ) )
110  return setFate( UNMODIFIED, causer_r );
111  return setCandidate( newCandidate_r, causer_r ) && setFate( TO_INSTALL, causer_r );
112  }
113 
115  { return _pimpl->theObj(); }
116 
117  std::vector<std::string> Selectable::supersededBy() const
118  { return _pimpl->supersededBy(); }
119 
121 
123  { return _pimpl->availableEmpty(); }
124 
126  { return _pimpl->availableSize(); }
127 
129  { return _pimpl->availableBegin(); }
130 
132  { return _pimpl->availableEnd(); }
133 
135 
137  { return _pimpl->installedEmpty(); }
138 
140  { return _pimpl->installedSize(); }
141 
143  { return _pimpl->installedBegin(); }
144 
146  { return _pimpl->installedEnd(); }
147 
149 
151  { return _pimpl->picklistEmpty(); }
152 
154  { return _pimpl->picklistSize(); }
155 
157  { return _pimpl->picklistBegin(); }
158 
160  { return _pimpl->picklistEnd(); }
161 
163  { return picklistPos( pi_r.satSolvable() ); }
164 
166  {
168  for ( const auto & pi : picklist() )
169  {
170  if ( pi == solv_r )
171  return idx;
172  ++idx;
173  }
174  return picklistNoPos;
175  }
176 
178 
180  { return _pimpl->hasBlacklisted(); }
181 
183  { return _pimpl->hasBlacklistedInstalled(); }
184 
186  { return _pimpl->hasRetracted(); }
187 
189  { return _pimpl->hasRetractedInstalled(); }
190 
191  bool Selectable::hasPtf() const
192  { return _pimpl->hasPtf(); }
193 
195  { return _pimpl->hasPtfInstalled(); }
196 
197 
199  { return _pimpl->isUnmaintained(); }
200 
202  { return _pimpl->multiversionInstall(); }
203 
204  bool Selectable::pickInstall( const PoolItem & pi_r, ResStatus::TransactByValue causer_r, bool yesno_r )
205  { return _pimpl->pickInstall( pi_r, causer_r, yesno_r ); }
206 
207  bool Selectable::pickDelete( const PoolItem & pi_r, ResStatus::TransactByValue causer_r, bool yesno_r )
208  { return _pimpl->pickDelete( pi_r, causer_r, yesno_r ); }
209 
210  Status Selectable::pickStatus( const PoolItem & pi_r ) const
211  { return _pimpl->pickStatus( pi_r ); }
212 
213  bool Selectable::setPickStatus( const PoolItem & pi_r, Status state_r, ResStatus::TransactByValue causer_r )
214  { return _pimpl->setPickStatus( pi_r, state_r, causer_r ); }
215 
217 
219  { return _pimpl->isUndetermined(); }
220 
222  { return _pimpl->isRelevant(); }
223 
225  { return _pimpl->isSatisfied(); }
226 
227  bool Selectable::isBroken() const
228  { return _pimpl->isBroken(); }
229 
230  bool Selectable::isNeeded() const
231  {
232  return fate() == TO_INSTALL || ( ! locked() && isBroken() );
233  }
234 
236  {
237  return locked() && isBroken() ;
238  }
239 
241  { return _pimpl->modifiedBy(); }
242 
244  { return _pimpl->hasLicenceConfirmed(); }
245 
247  { _pimpl->setLicenceConfirmed( val_r ); }
248 
249  bool Selectable::hasLocks() const
250  { return _pimpl->hasLocks(); }
251 
253  {
254  switch ( status() ) {
255  case S_Update:
256  case S_Install:
257  case S_AutoUpdate:
258  case S_AutoInstall:
259  return TO_INSTALL;
260  break;
261 
262  case S_Del:
263  case S_AutoDel:
264  return TO_DELETE;
265  break;
266 
267  case S_Protected:
268  case S_Taboo:
269  case S_KeepInstalled:
270  case S_NoInst:
271  break;
272  }
273  return UNMODIFIED;
274  };
275 
277  {
278  switch ( fate_r )
279  {
280  case TO_INSTALL:
281  return setStatus( hasInstalledObj() ? S_Update : S_Install, causer_r );
282  break;
283 
284  case TO_DELETE:
285  return setStatus( S_Del, causer_r );
286  break;
287 
288  case UNMODIFIED:
289  switch ( status() ) {
290  case S_Protected:
291  case S_Taboo:
292  return true;
293  break;
294  default:
295  return setStatus( hasInstalledObj() ? S_KeepInstalled : S_NoInst, causer_r );
296  break;
297  }
298  break;
299  }
300  return false;
301  }
302 
304  {
305  return( hasInstalledObj() || setStatus( S_Install, causer_r ) );
306  }
307 
309  {
310  if ( ! hasInstalledObj() )
311  return setStatus( S_Install, causer_r );
312 
313  PoolItem cand( candidateObj() );
314  if ( ! cand )
315  return true;
316 
317  return( installedObj()->edition() >= cand->edition()
318  || setStatus( S_Update, causer_r ) );
319  }
320 
322  {
323  return( ! hasInstalledObj() || setStatus( S_Del, causer_r ) );
324  }
325 
326  /******************************************************************
327  **
328  ** FUNCTION NAME : operator<<
329  ** FUNCTION TYPE : std::ostream &
330  */
331  std::ostream & operator<<( std::ostream & str, const Selectable & obj )
332  { return str << *(obj._pimpl); }
333 
334  std::ostream & dumpOn( std::ostream & str, const Selectable & obj )
335  { return dumpOn( str, *(obj._pimpl) ); }
336 
338  } // namespace ui
341 } // namespace zypp
bool locked() const
True if locked (subclass of unmodified).
Definition: Selectable.h:478
bool hasLicenceConfirmed() const
Return value of LicenceConfirmed bit.
Status pickStatus(const PoolItem &pi_r) const
ResStatus::TransactByValue modifiedBy() const
Return who caused the modification.
Definition: Selectable.cc:240
A Solvable object within the sat Pool.
Definition: Solvable.h:53
SelectableTraits::available_size_type available_size_type
Definition: Selectable.h:63
ResPoolProxy proxy() const
preliminary
Definition: ResPool.cc:59
Status
UI status Status values calculated by Selectable.
Definition: Status.h:35
bool hasRetractedInstalled() const
True if this Selectable contains an installed retracted item.
Definition: Selectable.cc:188
ResStatus::TransactByValue modifiedBy() const
Return who caused the modification.
bool hasLocks() const
True if it includes locked items (don&#39;t mix this with the locked status).
Definition: Selectable.cc:249
Collects PoolItems of same kind and name.
Definition: Selectable.h:52
~Selectable() override
Dtor.
Definition: Selectable.cc:46
PoolItem setCandidate(const PoolItem &newCandidate_r, ResStatus::TransactByValue causer_r=ResStatus::USER)
Set a candidate (out of available objects).
Definition: Selectable.cc:101
picklist_iterator picklistEnd() const
bool isBroken() const
Whether a relevant patchs requirements are broken.
Definition: Selectable.cc:227
bool hasBlacklistedInstalled() const
PoolItem identicalAvailableObj(const PoolItem &rhs) const
Return an available Object with the same content as rhs.
Definition: Selectable.cc:95
bool hasBlacklistedInstalled() const
True if this Selectable contains an installed blacklisted item (retracted,ptf,...).
Definition: Selectable.cc:182
available_iterator availableEnd() const
Definition: Selectable.cc:131
bool installedEmpty() const
Definition: Selectable.cc:136
bool hasPtfInstalled() const
True if this Selectable contains an installed ptf item.
Definition: Selectable.cc:194
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
PoolItem identicalInstalledObj(const PoolItem &rhs) const
an installed Object with the same content as rhs.
Definition: Selectable.cc:98
shared_ptr< Impl > Impl_Ptr
Definition: Selectable.h:564
String related utilities and Regular expression matching.
Definition: Arch.h:363
Access to the sat-pools string space.
Definition: IdString.h:43
PoolItem updateCandidateObj() const
The best candidate for update, if there is one.
Definition: Selectable.cc:80
Edition edition() const
Definition: SolvableType.h:71
static constexpr const picklist_size_type picklistNoPos
Returned by picklistPos if the Item does not belong to the picklist.
Definition: Selectable.h:295
std::vector< std::string > supersededBy() const
The name(s) of the successor package if vendorSupport is VendorSupportSuperseded. ...
Definition: Selectable.cc:117
bool hasRetracted() const
True if this Selectable contains available retracted items.
Definition: Selectable.cc:185
IdString ident() const
The identifier.
Definition: Selectable.cc:56
bool hasRetractedInstalled() const
picklist_size_type picklistPos(const PoolItem &pi_r) const
Return the position of pi_r in the piclist or picklistNoPos.
Definition: Selectable.cc:162
PoolItem setCandidate(const PoolItem &newCandidate_r, ResStatus::TransactByValue causer_r)
Set a userCandidate (out of available objects).
PoolItem theObj() const
Best among all objects.
bool setStatus(Status state_r, ResStatus::TransactByValue causer_r=ResStatus::USER)
Try to set a new Status.
Definition: Selectable.cc:68
available_size_type availableSize() const
void setLicenceConfirmed(bool val_r=true)
Set LicenceConfirmed bit.
Definition: Selectable.cc:246
Fate fate() const
Definition: Selectable.cc:252
bool setOnSystem(const PoolItem &newCandidate_r, ResStatus::TransactByValue causer_r=ResStatus::USER)
Arrange the specified candidate (out of available objects) to be on system after commit.
Definition: Selectable.cc:107
PoolItem candidateObj() const
The &#39;best&#39; or &#39;most interesting&#39; among all available objects.
Definition: Selectable.cc:74
bool setInstalled(ResStatus::TransactByValue causer_r=ResStatus::USER)
Take care the item gets installed if it is not.
Definition: Selectable.cc:303
picklist_iterator picklistBegin() const
PoolItem identicalInstalledObj(const PoolItem &rhs) const
an installed Object with the same content as rhs.
SelectableTraits::available_iterator available_iterator
Iterates over ResObject::constPtr.
Definition: Selectable.h:62
installed_size_type installedSize() const
bool isSatisfied() const
Whether a relevant patchs requirements are met.
Definition: Selectable.cc:224
std::ostream & operator<<(std::ostream &str, const Selectable &obj)
Definition: Selectable.cc:331
bool hasLocks() const
True if it includes locked items (don&#39;t mix this with the locked status).
bool isUndetermined() const
Returns true for packages, because packages are not classified by the solver.
Definition: Selectable.cc:218
installed_iterator installedEnd() const
PoolItem candidateObj() const
Best among available objects.
std::ostream & dumpOn(std::ostream &str, const Selectable &obj)
Definition: Selectable.cc:334
PoolItem theObj() const
An object you could use as pars pro toto.
Definition: Selectable.cc:114
bool identicalAvailable(const PoolItem &rhs) const
True if rhs is installed and one with the same content is available.
Definition: Selectable.cc:89
available_iterator availableBegin() const
const std::string & name() const
PoolItem updateCandidateObj() const
The best candidate for update, if there is one.
TraitsType::constPtrType constPtr
Definition: ResObject.h:43
bool setDeleted(ResStatus::TransactByValue causer_r=ResStatus::USER)
Take care the item gets deleted if it is installed.
Definition: Selectable.cc:321
picklist_iterator picklistBegin() const
Definition: Selectable.cc:156
PoolItem highestAvailableVersionObj() const
Simply the highest available version, ignoring priorities and policies.
Definition: Selectable.cc:83
SelectableTraits::installed_size_type installed_size_type
Definition: Selectable.h:66
picklist_size_type picklistSize() const
bool identicalAvailable(const PoolItem &rhs) const
True if rhs is installed and one with the same content is available.
ResKind kind() const
The ResObjects kind.
Definition: Selectable.cc:59
bool setPickStatus(const PoolItem &pi_r, Status state_r, ResStatus::TransactByValue causer_r=ResStatus::USER)
Assign a new status to a specific item.
Definition: Selectable.cc:213
bool identIsAutoInstalled() const
Whether this ident is flagged as AutoInstalled.
Definition: Selectable.cc:86
PoolItem identicalAvailableObj(const PoolItem &rhs) const
Return an available Object with the same content as rhs.
bool identicalInstalled(const PoolItem &rhs) const
True if rhs has the same content as an installed one.
Definition: Selectable.cc:92
SelectableTraits::picklist_iterator picklist_iterator
Definition: Selectable.h:68
installed_size_type installedSize() const
Definition: Selectable.cc:139
bool isNeeded() const
This includes unlocked broken patches, as well as those already selected to be installed.
Definition: Selectable.cc:230
available_iterator availableBegin() const
Definition: Selectable.cc:128
picklist_iterator picklistEnd() const
Definition: Selectable.cc:159
available_size_type availableSize() const
Definition: Selectable.cc:125
Status pickStatus(const PoolItem &pi_r) const
Compute the ui::Status for an individual PoolItem.
Definition: Selectable.cc:210
static Ptr get(const pool::ByIdent &ident_r)
Get the Selctable.
Definition: Selectable.cc:29
Status status() const
Return the current Status.
Definition: Selectable.cc:65
IMPL_PTR_TYPE(Selectable)
bool hasBlacklisted() const
True if this Selectable contains available blacklisted items (retracted,ptf,...). ...
Definition: Selectable.cc:179
bool isUnwanted() const
Broken (needed) but locked patches.
Definition: Selectable.cc:235
bool multiversionInstall() const
Whether at least one of the available packages has multiversionInstall set.
Definition: Selectable.cc:201
PoolItem highestAvailableVersionObj() const
Simply the highest available version, ignoring priorities and policies.
available_iterator availableEnd() const
bool pickInstall(const PoolItem &pi_r, ResStatus::TransactByValue causer_r=ResStatus::USER, bool yesno_r=true)
Select a specific available item for installation.
Definition: Selectable.cc:204
Selectable(Impl_Ptr pimpl_r)
Default ctor.
Definition: Selectable.cc:37
void setLicenceConfirmed(bool val_r)
Set LicenceConfirmed bit.
installed_iterator installedBegin() const
Iterable< picklist_iterator > picklist() const
Definition: Selectable.h:291
bool hasPtf() const
True if this Selectable contains available ptf items.
Definition: Selectable.cc:191
bool setUpToDate(ResStatus::TransactByValue causer_r=ResStatus::USER)
Take care the item gets installed if it is not, or is older.
Definition: Selectable.cc:308
bool picklistEmpty() const
Definition: Selectable.cc:150
Combining sat::Solvable and ResStatus.
Definition: PoolItem.h:50
bool setFate(Fate fate_r, ResStatus::TransactByValue causer_r=ResStatus::USER)
Definition: Selectable.cc:276
bool setPickStatus(const PoolItem &pi_r, Status state_r, ResStatus::TransactByValue causer_r)
installed_iterator installedEnd() const
Definition: Selectable.cc:145
bool pickInstall(const PoolItem &pi_r, ResStatus::TransactByValue causer_r, bool yesno_r)
ui::Selectable::Ptr lookup(const pool::ByIdent &ident_r) const
SelectableTraits::installed_iterator installed_iterator
Definition: Selectable.h:65
bool hasLicenceConfirmed() const
Return value of LicenceConfirmed bit.
Definition: Selectable.cc:243
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
bool availableEmpty() const
Definition: Selectable.cc:122
PoolItem candidateObjFrom(Repository repo_r) const
The best candidate provided by a specific Repository, if there is one.
Definition: Selectable.cc:77
PoolItem candidateObjFrom(Repository repo_r) const
The best candidate provided by a specific Repository, if there is one.
bool pickDelete(const PoolItem &pi_r, ResStatus::TransactByValue causer_r=ResStatus::USER, bool yesno_r=true)
Select a specific installed item for deletion.
Definition: Selectable.cc:207
Solvable satSolvable() const
Return the corresponding sat::Solvable.
Definition: SolvableType.h:57
PoolItem installedObj() const
The last Installed object.
Definition: Selectable.cc:71
installed_iterator installedBegin() const
Definition: Selectable.cc:142
bool hasInstalledObj() const
True if installed object is present.
Definition: Selectable.h:318
SelectableTraits::picklist_size_type picklist_size_type
Definition: Selectable.h:69
bool pickDelete(const PoolItem &pi_r, ResStatus::TransactByValue causer_r, bool yesno_r)
Main filter selecting PoolItems by name and kind.
Definition: ByIdent.h:28
RW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: Selectable.h:572
intrusive_ptr< Selectable > Ptr
Definition: Selectable.h:58
PoolItem installedObj() const
Installed object (transacting ot highest version).
bool isRelevant() const
Returns true if the patch is relevant which means that at least one package of the patch is installed...
Definition: Selectable.cc:221
picklist_size_type picklistSize() const
Definition: Selectable.cc:153
static ResPool instance()
Singleton ctor.
Definition: ResPool.cc:38
bool isUnmaintained() const
True if this package has no replacement from the available repositories.
Definition: Selectable.cc:198
const std::string & name() const
The ResObjects name.
Definition: Selectable.cc:62