libzypp 17.38.15

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 {
45 flags |= pi.identIsAutoInstalled() ? S::AutoInstalled : S::UserInstalled;
46 }
47 else
48 {
49 // Check if a different version of this package is installed.
50 ui::Selectable::Ptr sel = ui::Selectable::get( pi );
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
PoolInstallState.h
Structured install-state flags for pool items and selectables.
PoolItem.h
ResStatus.h
ResTraits.h
Selectable.h
zypp::PoolItem
Combining sat::Solvable and ResStatus.
Definition PoolItem.h:51
zypp::PoolItem::status
ResStatus & status() const
Returns the current status.
Definition PoolItem.cc:212
zypp::ResStatus
Status bitfield.
Definition ResStatus.h:55
zypp::ResStatus::validate
ValidateValue validate() const
Definition ResStatus.h:219
zypp::ResStatus::isLocked
bool isLocked() const
Definition ResStatus.h:270
zypp::ResStatus::NONRELEVANT
@ NONRELEVANT
Definition ResStatus.h:99
zypp::ResStatus::SATISFIED
@ SATISFIED
Definition ResStatus.h:98
zypp::ResStatus::UNDETERMINED
@ UNDETERMINED
Definition ResStatus.h:96
zypp::ResStatus::BROKEN
@ BROKEN
Definition ResStatus.h:97
zypp::ResStatus::isInstalled
bool isInstalled() const
Definition ResStatus.h:246
zypp::ui::Selectable
Collects PoolItems of same kind and name.
Definition Selectable.h:53
zypp::ui::Selectable::get
static Ptr get(const pool::ByIdent &ident_r)
Get the Selctable.
Definition Selectable.cc:29
zypp::ui::Selectable::locked
bool locked() const
True if locked (subclass of unmodified).
Definition Selectable.h:476
zypp::ui::Selectable::installedObj
PoolItem installedObj() const
The last Installed object.
Definition Selectable.cc:71
zypp::ui::Selectable::hasBlacklistedInstalled
bool hasBlacklistedInstalled() const
True if this Selectable contains an installed blacklisted item (retracted,ptf,...).
Definition Selectable.cc:182
zypp::ui::Selectable::theObj
PoolItem theObj() const
An object you could use as pars pro toto.
Definition Selectable.cc:114
zypp::ui::Selectable::identIsAutoInstalled
bool identIsAutoInstalled() const
Whether this ident is flagged as AutoInstalled.
Definition Selectable.cc:86
zypp::ui::Selectable::identicalAvailable
bool identicalAvailable(const PoolItem &rhs) const
True if rhs is installed and one with the same content is available.
Definition Selectable.cc:89
zypp::ui::Selectable::hasInstalledObj
bool hasInstalledObj() const
True if installed object is present.
Definition Selectable.h:316
zypp::ui::Selectable::Ptr
intrusive_ptr< Selectable > Ptr
Definition Selectable.h:58
zypp::ui::Selectable::kind
ResKind kind() const
The ResObjects kind.
Definition Selectable.cc:59
zypp::misc
Definition DefaultLoadSystem.cc:35
zypp::misc::PoolInstallState
PoolInstallState
Install-state flags for a pool item or selectable.
Definition PoolInstallState.h:59
zypp::misc::poolInstallState
PoolInstallStateFlags poolInstallState(const PoolItem &pi)
Compute install-state flags for a PoolItem.
Definition PoolInstallState.cc:21
zypp::traits::isPseudoInstalled
bool isPseudoInstalled(const ResKind &kind_r)
Those are denoted to be installed, if the solver verifies them as being satisfied.
Definition ResTraits.h:28
zypp::sat::SolvableType::isBlacklisted
bool isBlacklisted() const
Definition SolvableType.h:90
zypp::sat::SolvableType::identIsAutoInstalled
bool identIsAutoInstalled() const
Definition SolvableType.h:81