libzypp: zypp/ng/sat/components/packagepolicycomponent.cc Source File

libzypp 17.38.6

packagepolicycomponent.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9#include "packagepolicycomponent.h"
10#include <zypp/ng/sat/preparedpool.h>
11#include <zypp/ng/sat/pool.h>
12#include <zypp/ng/sat/solvable.h>
13#include <zypp/ng/sat/capability.h>
14
15namespace zyppng::sat {
16
17 // -----------------------------------------------------------------------
18 // Construction: wire up the hardwired provides tokens
19 // -----------------------------------------------------------------------
20
21 PackagePolicyComponent::PackagePolicyComponent()
22 {
23 // Retracted: provides retracted-patch-package()
24 _retractedSpec.addProvides( Capability( Solvable::retractedToken.c_str(),
25 Capability::PARSED ) );
26
27 // PTF master: provides ptf()
28 _ptfMasterSpec.addProvides( Capability( Solvable::ptfMasterToken.c_str(),
29 Capability::PARSED ) );
30
31 // PTF package: provides ptf-package()
32 _ptfPackageSpec.addProvides( Capability( Solvable::ptfPackageToken.c_str(),
33 Capability::PARSED ) );
34 }
35
36 // -----------------------------------------------------------------------
37 // IPreparedPoolComponent overrides
38 // -----------------------------------------------------------------------
39
40 void PackagePolicyComponent::attach( Pool &p )
41 {
42 assert( _pool == nullptr && "PackagePolicyComponent can only be attached once");
43 _pool = &p;
44 }
45
46 void PackagePolicyComponent::prepare( PreparedPool & pp )
47 {
48 _retractedEval .emplace( pp, _retractedSpec );
49 _ptfMasterEval .emplace( pp, _ptfMasterSpec );
50 _ptfPackageEval.emplace( pp, _ptfPackageSpec );
51 _needrebootEval.emplace( pp, _needrebootSpec );
52 }
53
54 void PackagePolicyComponent::onInvalidate( Pool & /*pool*/, PoolInvalidation invalidation )
55 {
56 if ( invalidation == PoolInvalidation::Data ) {
57 _retractedEval .reset();
58 _ptfMasterEval .reset();
59 _ptfPackageEval.reset();
60 _needrebootEval.reset();
61 // Note: the specs themselves (definitions) are kept; only the
62 // evaluated forms are dropped. prepare() will rebuild them.
63 }
64 }
65
66 void PackagePolicyComponent::onReset( Pool & )
67 {
68 _retractedEval .reset();
69 _ptfMasterEval .reset();
70 _ptfPackageEval.reset();
71 _needrebootEval.reset();
72 }
73
74 // -----------------------------------------------------------------------
75 // Public query API
76 // -----------------------------------------------------------------------
77
78 bool PackagePolicyComponent::isRetracted( const Solvable & solv_r ) const
79 { return _retractedEval && _retractedEval->contains( solv_r ); }
80
81 bool PackagePolicyComponent::isPtfMaster( const Solvable & solv_r ) const
82 { return _ptfMasterEval && _ptfMasterEval->contains( solv_r ); }
83
84 bool PackagePolicyComponent::isPtfPackage( const Solvable & solv_r ) const
85 { return _ptfPackageEval && _ptfPackageEval->contains( solv_r ); }
86
87 void PackagePolicyComponent::setNeedrebootSpec( SolvableSpec spec )
88 {
89 _needrebootSpec = std::move( spec );
90 // The evaluated form is stale now; it will be rebuilt on next prepare().
91 _needrebootEval.reset();
92
93 if ( _pool )
94 _pool->setDirty( PoolInvalidation::Dependency, { __PRETTY_FUNCTION__, "setting new reboot spec"} );
95 }
96
97 bool PackagePolicyComponent::isNeedreboot( const Solvable & solv_r ) const
98 { return _needrebootEval && _needrebootEval->contains( solv_r ); }
99
100} // namespace zyppng::sat
zyppng::sat::Capability
A sat capability.
Definition capability.h:74
zyppng::sat::Capability::PARSED
@ PARSED
Definition capability.h:76
zyppng::sat::PackagePolicyComponent::_pool
Pool * _pool
Definition packagepolicycomponent.h:92
zyppng::sat::PackagePolicyComponent::_needrebootEval
std::optional< EvaluatedSolvableSpec > _needrebootEval
Definition packagepolicycomponent.h:104
zyppng::sat::PackagePolicyComponent::attach
void attach(Pool &p) override
called when the component is attached to a pool
Definition packagepolicycomponent.cc:40
zyppng::sat::PackagePolicyComponent::prepare
void prepare(PreparedPool &pp) override
Called by Pool::prepare() — evaluates all specs against the prepared pool.
Definition packagepolicycomponent.cc:46
zyppng::sat::PackagePolicyComponent::setNeedrebootSpec
void setNeedrebootSpec(SolvableSpec spec)
Replace the reboot-needed spec.
Definition packagepolicycomponent.cc:87
zyppng::sat::PackagePolicyComponent::onReset
void onReset(Pool &pool) override
Called on full pool reset — resets all evaluated forms.
Definition packagepolicycomponent.cc:66
zyppng::sat::PackagePolicyComponent::_ptfMasterSpec
SolvableSpec _ptfMasterSpec
hardwired: provides ptf()
Definition packagepolicycomponent.h:95
zyppng::sat::PackagePolicyComponent::_ptfPackageEval
std::optional< EvaluatedSolvableSpec > _ptfPackageEval
Definition packagepolicycomponent.h:103
zyppng::sat::PackagePolicyComponent::isNeedreboot
bool isNeedreboot(const Solvable &solv_r) const
Definition packagepolicycomponent.cc:97
zyppng::sat::PackagePolicyComponent::isRetracted
bool isRetracted(const Solvable &solv_r) const
Definition packagepolicycomponent.cc:78
zyppng::sat::PackagePolicyComponent::onInvalidate
void onInvalidate(Pool &pool, PoolInvalidation invalidation) override
Called when pool content changes — resets all evaluated forms.
Definition packagepolicycomponent.cc:54
zyppng::sat::PackagePolicyComponent::_ptfMasterEval
std::optional< EvaluatedSolvableSpec > _ptfMasterEval
Definition packagepolicycomponent.h:102
zyppng::sat::PackagePolicyComponent::PackagePolicyComponent
PackagePolicyComponent()
Definition packagepolicycomponent.cc:21
zyppng::sat::PackagePolicyComponent::_retractedEval
std::optional< EvaluatedSolvableSpec > _retractedEval
Definition packagepolicycomponent.h:101
zyppng::sat::PackagePolicyComponent::_ptfPackageSpec
SolvableSpec _ptfPackageSpec
hardwired: provides ptf-package()
Definition packagepolicycomponent.h:96
zyppng::sat::PackagePolicyComponent::_retractedSpec
SolvableSpec _retractedSpec
hardwired: provides retracted-patch-package()
Definition packagepolicycomponent.h:94
zyppng::sat::PackagePolicyComponent::isPtfPackage
bool isPtfPackage(const Solvable &solv_r) const
Definition packagepolicycomponent.cc:84
zyppng::sat::PackagePolicyComponent::_needrebootSpec
SolvableSpec _needrebootSpec
user-supplied
Definition packagepolicycomponent.h:97
zyppng::sat::PackagePolicyComponent::isPtfMaster
bool isPtfMaster(const Solvable &solv_r) const
Definition packagepolicycomponent.cc:81
zyppng::sat::Pool
Orchestrator for a libsolv pool instance.
Definition pool.h:37
zyppng::sat::PreparedPool
A move-only, non-owning view of a Pool that guarantees the whatprovides index is valid.
Definition preparedpool.h:51
zyppng::sat::SolvableSpec
A pure data container describing a set of solvables by ident and/or provides.
Definition solvablespec.h:55
zyppng::sat::Solvable
A Solvable object within the sat Pool.
Definition solvable.h:65
zyppng::sat::Solvable::ptfPackageToken
static const IdString ptfPackageToken
Indicator provides ptf-package().
Definition solvable.h:74
zyppng::sat::Solvable::retractedToken
static const IdString retractedToken
Indicator provides retracted-patch-package().
Definition solvable.h:72
zyppng::sat::Solvable::ptfMasterToken
static const IdString ptfMasterToken
Indicator provides ptf().
Definition solvable.h:73
zyppng::sat
This file contains private API, this might break at any time between releases.
Definition capabilities.h:22
zyppng::sat::PoolInvalidation
PoolInvalidation
Defines the scope of an invalidation request for the Pool.
Definition poolconstants.h:66
zyppng::sat::PoolInvalidation::Dependency
@ Dependency
Only external requirements/context changed (e.g., Locales).
Definition poolconstants.h:71
zyppng::sat::PoolInvalidation::Data
@ Data
Structural or data change (e.g., Rootfs, Arch, or Repo content).
Definition poolconstants.h:76
packagepolicycomponent.h
pool.h
preparedpool.h
capability.h
solvable.h