libzypp 17.38.14
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
19namespace 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 {
45 flags |= pi.identIsAutoInstalled() ? S::AutoInstalled : S::UserInstalled;
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 ) )
54 flags |= pi.identIsAutoInstalled() ? S::AutoInstalled : S::UserInstalled;
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 {
94 flags |= sel.identIsAutoInstalled() ? S::AutoInstalled : S::UserInstalled;
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
Structured install-state flags for pool items and selectables.
Combining sat::Solvable and ResStatus.
Definition PoolItem.h:51
ResStatus & status() const
Returns the current status.
Definition PoolItem.cc:212
Status bitfield.
Definition ResStatus.h:55
ValidateValue validate() const
Definition ResStatus.h:219
bool isLocked() const
Definition ResStatus.h:270
bool isInstalled() const
Definition ResStatus.h:246
Collects PoolItems of same kind and name.
Definition Selectable.h:53
static Ptr get(const pool::ByIdent &ident_r)
Get the Selctable.
Definition Selectable.cc:29
bool locked() const
True if locked (subclass of unmodified).
Definition Selectable.h:476
PoolItem installedObj() const
The last Installed object.
Definition Selectable.cc:71
bool hasBlacklistedInstalled() const
True if this Selectable contains an installed blacklisted item (retracted,ptf,...).
PoolItem theObj() const
An object you could use as pars pro toto.
bool identIsAutoInstalled() const
Whether this ident is flagged as AutoInstalled.
Definition Selectable.cc:86
bool identicalAvailable(const PoolItem &rhs) const
True if rhs is installed and one with the same content is available.
Definition Selectable.cc:89
bool hasInstalledObj() const
True if installed object is present.
Definition Selectable.h:316
intrusive_ptr< Selectable > Ptr
Definition Selectable.h:58
ResKind kind() const
The ResObjects kind.
Definition Selectable.cc:59
PoolInstallState
Install-state flags for a pool item or selectable.
PoolInstallStateFlags poolInstallState(const PoolItem &pi)
Compute install-state flags for a PoolItem.
bool isPseudoInstalled(const ResKind &kind_r)
Those are denoted to be installed, if the solver verifies them as being satisfied.
Definition ResTraits.h:28
bool isBlacklisted() const
bool identIsAutoInstalled() const