libzypp  17.38.17
PoolInstallState.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include "PoolInstallState.h"
13 
14 #include <zypp/PoolItem.h>
15 #include <zypp/ResTraits.h>
16 #include <zypp/ResStatus.h>
17 #include <zypp/ui/Selectable.h>
18 
19 namespace zypp::misc
20 {
21  PoolInstallStateFlags poolInstallState( const PoolItem & pi )
22  {
23  using S = PoolInstallState;
24  PoolInstallStateFlags flags; // NotInstalled = 0
25 
26  const ResStatus & status = pi.status();
27 
28  // ── Pseudo-installed kinds (patch, pattern) ───────────────────────────────
29  // These use validate() rather than isInstalled() to determine state.
30  if ( traits::isPseudoInstalled( pi->kind() ) )
31  {
32  switch ( status.validate() )
33  {
34  case ResStatus::SATISFIED: flags |= S::Satisfied; break;
35  case ResStatus::BROKEN: flags |= S::Broken; break;
36  case ResStatus::UNDETERMINED: // [[fallthrough]]
37  case ResStatus::NONRELEVANT: break;
38  }
39  }
40  else
41  // ── Regular resolvables ───────────────────────────────────────────────────
42  {
43  if ( status.isInstalled() )
44  {
46  }
47  else
48  {
49  // Check if a different version of this package is installed.
51  if ( sel && sel->hasInstalledObj() )
52  {
53  if ( sel->identicalInstalled( pi ) )
55  else
56  {
57  // Different version installed — combine with auto/user distinction
58  // so the caller knows both that the version differs AND how it got there.
59  flags |= S::OtherVersionInstalled;
60  flags |= sel->identIsAutoInstalled() ? S::AutoInstalled : S::UserInstalled;
61  }
62  }
63  // else: NotInstalled (zero) — nothing to set
64  }
65  }
66 
67  // ── Modifiers — independent of install state ──────────────────────────────
68  if ( status.isLocked() ) flags |= S::Locked;
69  if ( pi.isBlacklisted() ) flags |= S::Retracted;
70 
71  return flags;
72  }
73 
74  PoolInstallStateFlags poolInstallState( const ui::Selectable & sel )
75  {
76  using S = PoolInstallState;
77  PoolInstallStateFlags flags; // NotInstalled = 0
78 
79  // ── Pseudo-installed kinds ────────────────────────────────────────────────
80  if ( traits::isPseudoInstalled( sel.kind() ) )
81  {
82  switch ( sel.theObj().status().validate() )
83  {
84  case ResStatus::SATISFIED: flags |= S::Satisfied; break;
85  case ResStatus::BROKEN: flags |= S::Broken; break;
86  default: break;
87  }
88  }
89  else
90  // ── Regular resolvables ───────────────────────────────────────────────────
91  {
92  if ( sel.hasInstalledObj() )
93  {
95 
96  // OtherVersionInstalled: no available candidate is identical to what is
97  // installed. In a repo-filtered pool this is the "foreign installed" (v)
98  // case from zypper — no separate flag required.
99  if ( !sel.identicalAvailable( sel.installedObj() ) )
100  flags |= S::OtherVersionInstalled;
101  }
102  // else: NotInstalled (zero) — nothing to set
103  }
104 
105  // ── Modifiers ─────────────────────────────────────────────────────────────
106  if ( sel.locked() ) flags |= S::Locked;
107  if ( sel.hasBlacklistedInstalled() ) flags |= S::Retracted;
108 
109  return flags;
110  }
111 
112 } // namespace zypp::misc
bool locked() const
True if locked (subclass of unmodified).
Definition: Selectable.h:478
Collects PoolItems of same kind and name.
Definition: Selectable.h:52
Explicitly installed by the user.
bool hasBlacklistedInstalled() const
True if this Selectable contains an installed blacklisted item (retracted,ptf,...).
Definition: Selectable.cc:182
bool isInstalled() const
Definition: ResStatus.h:246
ResStatus & status() const
Returns the current status.
Definition: PoolItem.cc:212
ValidateValue validate() const
Definition: ResStatus.h:219
Retracted (PTF / blacklisted)
PoolInstallState
Install-state flags for a pool item or selectable.
bool identIsAutoInstalled() const
Definition: SolvableType.h:81
Structured install-state flags for pool items and selectables.
Installed as a dependency (auto)
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
ResKind kind() const
The ResObjects kind.
Definition: Selectable.cc:59
bool identIsAutoInstalled() const
Whether this ident is flagged as AutoInstalled.
Definition: Selectable.cc:86
PoolInstallStateFlags poolInstallState(const PoolItem &pi)
Compute install-state flags for a PoolItem.
static Ptr get(const pool::ByIdent &ident_r)
Get the Selctable.
Definition: Selectable.cc:29
bool isBlacklisted() const
Definition: SolvableType.h:90
Pseudo-installed and requirements are not met.
bool isLocked() const
Definition: ResStatus.h:270
bool isPseudoInstalled(const ResKind &kind_r)
Those are denoted to be installed, if the solver verifies them as being satisfied.
Definition: ResTraits.h:28
Status bitfield.
Definition: ResStatus.h:54
Combining sat::Solvable and ResStatus.
Definition: PoolItem.h:50
Always combined with AutoInstalled or UserInstalled.
Installed, but no identical candidate available.
Locked — solver will not change this item.
PoolItem installedObj() const
The last Installed object.
Definition: Selectable.cc:71
bool hasInstalledObj() const
True if installed object is present.
Definition: Selectable.h:318
ResKind kind() const
Definition: SolvableType.h:63
intrusive_ptr< Selectable > Ptr
Definition: Selectable.h:58