libzypp 17.37.10

PoolItem.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#include <iostream>
13#include <zypp/base/Logger.h>
14#include <utility>
15#include <zypp-core/base/DefaultIntegral>
16
17#include <zypp/PoolItem.h>
18#include <zypp/ResPool.h>
19#include <zypp/Package.h>
20#include <zypp/VendorAttr.h>
21
22 using std::endl;
23
25 namespace zypp
26{
27
29 //
30 // CLASS NAME : PoolItem::Impl
31 //
38 struct PoolItem::Impl
39 {
40 public:
41 Impl() {}
42
43 Impl( ResObject::constPtr &&res_r,
44 ResStatus &&status_r )
45 : _status( std::move(status_r) )
46 , _resolvable( std::move(res_r) )
47 {}
48
49 ResStatus & status() const
50 { return _buddy > 0 ? PoolItem(buddy()).status() : _status; }
51
52 sat::Solvable buddy() const
53 {
54 if ( !_buddy )
55 return sat::Solvable::noSolvable;
56 if ( _buddy < 0 )
57 return sat::Solvable( -_buddy );
58 return sat::Solvable( _buddy );
59 }
60
61 void setBuddy( const sat::Solvable & solv_r );
62
63 ResObject::constPtr resolvable() const
64 { return _resolvable; }
65
66 ResStatus & statusReset() const
67 {
68 _status.setLock( false, zypp::ResStatus::USER );
69 _status.resetTransact( zypp::ResStatus::USER );
70 return _status;
71 }
72
73 ResStatus & statusReinit() const
74 {
75 _status.setLock( _status.isUserLockQueryMatch(), zypp::ResStatus::USER );
76 _status.resetTransact( zypp::ResStatus::USER );
77 return _status;
78 }
79
80 public:
81 bool isUndetermined() const
82 {
83 return status().isUndetermined();
84 }
85
86 bool isRelevant() const
87 {
88 return !status().isNonRelevant();
89 }
90
91 bool isSatisfied() const
92 {
93 return status().isSatisfied();
94 }
95
96 bool isBroken() const
97 {
98 return status().isBroken();
99 }
100
101 bool isNeeded() const
102 {
103 return status().isToBeInstalled() || ( isBroken() && ! status().isLocked() );
104 }
105
106 bool isUnwanted() const
107 {
108 return isBroken() && status().isLocked();
109 }
110
111 private:
112 mutable ResStatus _status;
113 ResObject::constPtr _resolvable;
114 DefaultIntegral<sat::detail::IdType,sat::detail::noId> _buddy;
115
120 public:
121 void saveState() const
122 { _savedStatus = status(); }
123 void restoreState() const
124 { status() = _savedStatus; }
125 bool sameState() const
126 {
127 if ( status() == _savedStatus )
128 return true;
129 // some bits changed...
130 if ( status().getTransactValue() != _savedStatus.getTransactValue()
131 && ( ! status().isBySolver() // ignore solver state changes
132 // removing a user lock also goes to bySolver
133 || _savedStatus.getTransactValue() == ResStatus::LOCKED ) )
134 return false;
135 if ( status().isLicenceConfirmed() != _savedStatus.isLicenceConfirmed() )
136 return false;
137 return true;
138 }
139 private:
140 mutable ResStatus _savedStatus;
142
143 public:
145 static shared_ptr<Impl> nullimpl()
146 {
147 static shared_ptr<Impl> _nullimpl( new Impl );
148 return _nullimpl;
149 }
150 };
151
152
154 inline std::ostream & operator<<( std::ostream & str, const PoolItem::Impl & obj )
155 {
156 str << obj.status();
157 if (obj.resolvable())
158 str << *obj.resolvable();
159 else
160 str << "(NULL)";
161 return str;
162 }
163
164 inline void PoolItem::Impl::setBuddy( const sat::Solvable & solv_r )
165 {
166 PoolItem myBuddy( solv_r );
167 if ( myBuddy )
168 {
169 if ( myBuddy._pimpl->_buddy )
170 {
171 ERR << *this << " would be buddy2 in " << myBuddy << endl;
172 return;
173 }
174 myBuddy._pimpl->_buddy = -resolvable()->satSolvable().id();
175 _buddy = myBuddy.satSolvable().id();
176 DBG << *this << " has buddy " << myBuddy << endl;
177 }
178 }
179
181 // class PoolItem
183
184 PoolItem::PoolItem()
185 : _pimpl( Impl::nullimpl() )
186 {}
187
188 PoolItem::PoolItem( const sat::Solvable & solvable_r )
189 : _pimpl( ResPool::instance().find( solvable_r )._pimpl )
190 {}
191
192 PoolItem::PoolItem( const ResObject::constPtr & resolvable_r )
193 : _pimpl( ResPool::instance().find( resolvable_r )._pimpl )
194 {}
195
196 PoolItem::PoolItem( Impl * implptr_r )
197 : _pimpl( implptr_r )
198 {}
199
200 PoolItem PoolItem::makePoolItem( const sat::Solvable & solvable_r )
201 {
202 return PoolItem( new Impl( makeResObject( solvable_r ), solvable_r.isSystem() ) );
203 }
204
205 PoolItem::~PoolItem()
206 {}
207
208 ResPool PoolItem::pool() const
209 { return ResPool::instance(); }
210
211
212 ResStatus & PoolItem::status() const { return _pimpl->status(); }
213 ResStatus & PoolItem::statusReset() const { return _pimpl->statusReset(); }
214 ResStatus & PoolItem::statusReinit() const { return _pimpl->statusReinit(); }
215 sat::Solvable PoolItem::buddy() const { return _pimpl->buddy(); }
216 void PoolItem::setBuddy( const sat::Solvable & solv_r ) { _pimpl->setBuddy( solv_r ); }
217 bool PoolItem::isUndetermined() const { return _pimpl->isUndetermined(); }
218 bool PoolItem::isRelevant() const { return _pimpl->isRelevant(); }
219 bool PoolItem::isSatisfied() const { return _pimpl->isSatisfied(); }
220 bool PoolItem::isBroken() const { return _pimpl->isBroken(); }
221 bool PoolItem::isNeeded() const { return _pimpl->isNeeded(); }
222 bool PoolItem::isUnwanted() const { return _pimpl->isUnwanted(); }
223
224 void PoolItem::saveState() const { _pimpl->saveState(); }
225 void PoolItem::restoreState() const { _pimpl->restoreState(); }
226 bool PoolItem::sameState() const { return _pimpl->sameState(); }
227 ResObject::constPtr PoolItem::resolvable() const { return _pimpl->resolvable(); }
228
229
230 std::ostream & operator<<( std::ostream & str, const PoolItem & obj )
231 { return str << *obj._pimpl; }
232
233} // namespace zypp
Package.h
PoolItem.h
ResPool.h
VendorAttr.h
shared_ptr
zypp::DefaultIntegral
Integral type with defined initial value when default constructed.
Definition defaultintegral.h:42
zypp::PoolItem::isRelevant
bool isRelevant() const
Returns true if the solvable is relevant which means e.g.
Definition PoolItem.cc:218
zypp::PoolItem::isNeeded
bool isNeeded() const
This includes unlocked broken patches, as well as those already selected to be installed (otherwise c...
Definition PoolItem.cc:221
zypp::PoolItem::restoreState
void restoreState() const
Definition PoolItem.cc:225
zypp::PoolItem::saveState
void saveState() const
Definition PoolItem.cc:224
zypp::PoolItem::resolvable
ResObject::constPtr resolvable() const
Returns the ResObject::constPtr.
Definition PoolItem.cc:227
zypp::PoolItem::sameState
bool sameState() const
Definition PoolItem.cc:226
zypp::PoolItem::isBroken
bool isBroken() const
Whether a relevant items requirements are broken.
Definition PoolItem.cc:220
zypp::PoolItem::status
ResStatus & status() const
Returns the current status.
Definition PoolItem.cc:212
zypp::PoolItem::setBuddy
void setBuddy(const sat::Solvable &solv_r)
Buddies are set by pool::PoolImpl.
Definition PoolItem.cc:216
zypp::PoolItem::isSatisfied
bool isSatisfied() const
Whether a relevant items requirements are met.
Definition PoolItem.cc:219
zypp::PoolItem::isUnwanted
bool isUnwanted() const
Broken (needed) but locked patches.
Definition PoolItem.cc:222
zypp::PoolItem::makePoolItem
static PoolItem makePoolItem(const sat::Solvable &solvable_r)
PoolItem generator for pool::PoolImpl.
Definition PoolItem.cc:200
zypp::PoolItem::~PoolItem
~PoolItem()
Dtor.
Definition PoolItem.cc:205
zypp::PoolItem::statusReset
ResStatus & statusReset() const
Resets status to the default state (KEEP_STATE bySOLVER; clears any lock!).
Definition PoolItem.cc:213
zypp::PoolItem::pool
ResPool pool() const
Return the ResPool the item belongs to.
Definition PoolItem.cc:208
zypp::PoolItem::PoolItem
PoolItem()
Default ctor for use in std::container.
Definition PoolItem.cc:184
zypp::PoolItem::buddy
sat::Solvable buddy() const
Return the buddy we share our status object with.
Definition PoolItem.cc:215
zypp::PoolItem::_pimpl
RW_pointer< Impl > _pimpl
Pointer to implementation.
Definition PoolItem.h:157
zypp::PoolItem::isUndetermined
bool isUndetermined() const
No validation is performed for packages.
Definition PoolItem.cc:217
zypp::PoolItem::statusReinit
ResStatus & statusReinit() const
Resets status to it's initial state in the ResPool (KEEP_STATE bySOLVER or LOCKED byUSER).
Definition PoolItem.cc:214
zypp::ResObject::constPtr
TraitsType::constPtrType constPtr
Definition ResObject.h:43
zypp::ResPool
Global ResObject pool.
Definition ResPool.h:62
zypp::ResPool::instance
static ResPool instance()
Singleton ctor.
Definition ResPool.cc:38
zypp::ResStatus
Status bitfield.
Definition ResStatus.h:55
zypp::ResStatus::isUndetermined
bool isUndetermined() const
Definition ResStatus.h:222
zypp::ResStatus::isToBeInstalled
bool isToBeInstalled() const
Definition ResStatus.h:259
zypp::ResStatus::isBroken
bool isBroken() const
Definition ResStatus.h:228
zypp::ResStatus::isNonRelevant
bool isNonRelevant() const
Definition ResStatus.h:231
zypp::ResStatus::isLocked
bool isLocked() const
Definition ResStatus.h:270
zypp::ResStatus::USER
@ USER
Definition ResStatus.h:112
zypp::ResStatus::isSatisfied
bool isSatisfied() const
Definition ResStatus.h:225
zypp::ResStatus::LOCKED
@ LOCKED
Definition ResStatus.h:104
zypp::sat::Solvable
A Solvable object within the sat Pool.
Definition Solvable.h:54
zypp::sat::Solvable::id
IdType id() const
Expert backdoor.
Definition Solvable.h:445
zypp::sat::Solvable::noSolvable
static const Solvable noSolvable
Represents no Solvable.
Definition Solvable.h:80
zypp::sat::Solvable::isSystem
bool isSystem() const
Return whether this Solvable belongs to the system repo.
Definition Solvable.cc:374
std
Definition Arch.h:364
str
String related utilities and Regular expression matching.
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition SerialNumber.cc:52
zypp::makeResObject
ResObject::Ptr makeResObject(const sat::Solvable &solvable_r)
Create ResObject from sat::Solvable.
Definition ResObject.cc:43
zypp::PoolItem::Impl
PoolItem implementation.
Definition PoolItem.cc:39
zypp::PoolItem::Impl::Impl
Impl()
Definition PoolItem.cc:41
zypp::PoolItem::Impl::isNeeded
bool isNeeded() const
Definition PoolItem.cc:101
zypp::PoolItem::Impl::setBuddy
void setBuddy(const sat::Solvable &solv_r)
Definition PoolItem.cc:164
zypp::PoolItem::Impl::status
ResStatus & status() const
Definition PoolItem.cc:49
zypp::PoolItem::Impl::sameState
bool sameState() const
Definition PoolItem.cc:125
zypp::PoolItem::Impl::_resolvable
ResObject::constPtr _resolvable
Definition PoolItem.cc:113
zypp::PoolItem::Impl::restoreState
void restoreState() const
Definition PoolItem.cc:123
zypp::PoolItem::Impl::saveState
void saveState() const
Definition PoolItem.cc:121
zypp::PoolItem::Impl::buddy
sat::Solvable buddy() const
Definition PoolItem.cc:52
zypp::PoolItem::Impl::isBroken
bool isBroken() const
Definition PoolItem.cc:96
zypp::PoolItem::Impl::operator<<
std::ostream & operator<<(std::ostream &str, const PoolItem::Impl &obj)
Stream output.
Definition PoolItem.cc:154
zypp::PoolItem::Impl::nullimpl
static shared_ptr< Impl > nullimpl()
Offer default Impl.
Definition PoolItem.cc:145
zypp::PoolItem::Impl::isRelevant
bool isRelevant() const
Definition PoolItem.cc:86
zypp::PoolItem::Impl::isUndetermined
bool isUndetermined() const
Definition PoolItem.cc:81
zypp::PoolItem::Impl::_savedStatus
ResStatus _savedStatus
Definition PoolItem.cc:140
zypp::PoolItem::Impl::Impl
Impl(ResObject::constPtr &&res_r, ResStatus &&status_r)
Definition PoolItem.cc:43
zypp::PoolItem::Impl::_buddy
DefaultIntegral< sat::detail::IdType, sat::detail::noId > _buddy
Definition PoolItem.cc:114
zypp::PoolItem::Impl::_status
ResStatus _status
Definition PoolItem.cc:112
zypp::PoolItem::Impl::isSatisfied
bool isSatisfied() const
Definition PoolItem.cc:91
zypp::PoolItem::Impl::statusReset
ResStatus & statusReset() const
Definition PoolItem.cc:66
zypp::PoolItem::Impl::isUnwanted
bool isUnwanted() const
Definition PoolItem.cc:106
zypp::PoolItem::Impl::statusReinit
ResStatus & statusReinit() const
Definition PoolItem.cc:73
zypp::PoolItem::Impl::resolvable
ResObject::constPtr resolvable() const
Definition PoolItem.cc:63
zypp::sat::SolvableType::satSolvable
Solvable satSolvable() const
Return the corresponding sat::Solvable.
Definition SolvableType.h:57
DBG
#define DBG
Definition Logger.h:99
ERR
#define ERR
Definition Logger.h:102
Logger.h