libzypp 17.34.0
PoolImpl.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_POOL_POOLIMPL_H
13#define ZYPP_POOL_POOLIMPL_H
14
15#include <iosfwd>
16#include <utility>
17
18#include <zypp/base/Easy.h>
19#include <zypp/base/LogTools.h>
21#include <zypp/APIConfig.h>
22
24#include <zypp/ResPoolProxy.h>
26
27#include <zypp/sat/Pool.h>
28#include <zypp/Product.h>
29
30using std::endl;
31
33namespace zypp
34{
35
36 namespace resstatus
37 {
44 {
46 static void setLock( ResStatus & status_r, bool yesno_r )
47 {
49 status_r.setUserLockQueryMatch( yesno_r );
50 }
51
53 static void reapplyLock( ResStatus & status_r, bool yesno_r )
54 {
55 if ( yesno_r && ! status_r.isUserLockQueryMatch() )
56 {
58 status_r.setUserLockQueryMatch( yesno_r );
59 }
60 }
61
63 static int diffLock( const ResStatus & status_r )
64 {
65 bool userLock( status_r.isUserLocked() );
66 if ( userLock == status_r.isUserLockQueryMatch() )
67 return 0;
68 return userLock ? 1 : -1;
69 }
70
71 };
72 }
73
74 namespace
75 {
76 inline PoolQuery makeTrivialQuery( IdString ident_r )
77 {
78 sat::Solvable::SplitIdent ident( ident_r );
79
80 PoolQuery q;
81 q.addAttribute( sat::SolvAttr::name, ident.name().asString() );
82 q.addKind( ident.kind() );
83 q.setMatchExact();
84 q.setCaseSensitive(true);
85 return q;
86 }
87
88 inline bool hardLockQueriesRemove( pool::PoolTraits::HardLockQueries & activeLocks_r, IdString ident_r )
89 {
90 unsigned s( activeLocks_r.size() );
91 activeLocks_r.remove( makeTrivialQuery( ident_r ) );
92 return( activeLocks_r.size() != s );
93 }
94
95 inline bool hardLockQueriesAdd( pool::PoolTraits::HardLockQueries & activeLocks_r, IdString ident_r )
96 {
97 PoolQuery q( makeTrivialQuery( ident_r ) );
98 for_( it, activeLocks_r.begin(), activeLocks_r.end() )
99 {
100 if ( *it == q )
101 return false;
102 }
103 activeLocks_r.push_back( q );
104 return true;
105 }
106 }
107
109 namespace solver {
110 namespace detail {
111 void establish( sat::Queue & pseudoItems_r, sat::Queue & pseudoFlags_r ); // in solver/detail/SATResolver.cc
112 }
113 }
118 {
119 public:
122
125 {
127
128 if ( ! _pseudoItems.empty() )
129 {
130 for ( sat::Queue::size_type i = 0; i < _pseudoItems.size(); ++i )
131 {
134 if ( pi.status().validate() != vorig )
135 ret[pi] = vorig;
136 }
137 }
138 return ret;
139 }
140
141 private:
143 {
145 switch ( _pseudoFlags[i] )
146 {
147 case 0: ret = ResStatus::BROKEN /*2*/; break;
148 case 1: ret = ResStatus::SATISFIED /*4*/; break;
149 case -1: ret = ResStatus::NONRELEVANT /*6*/; break;
150 }
151 return ret;
152 }
153
154 private:
157 };
158
160 namespace pool
161 {
162
164 //
165 // CLASS NAME : PoolImpl
166 //
169 {
170 friend std::ostream & operator<<( std::ostream & str, const PoolImpl & obj );
171
172 public:
178
180
182
184
185 public:
187 PoolImpl();
189 ~PoolImpl();
190
191 public:
193 const sat::Pool satpool() const
194 { return sat::Pool::instance(); }
195
197 const SerialNumber & serial() const
198 { return satpool().serial(); }
199
201 //
203 public:
205 bool empty() const
206 { return satpool().solvablesEmpty(); }
207
210 { return satpool().solvablesSize(); }
211
214
216 { return make_filter_end( pool::ByPoolItem(), store() ); }
217
218 public:
225 {
226 const ContainerT & mystore( store() );
227 return( slv_r.id() < mystore.size() ? mystore[slv_r.id()] : PoolItem() );
228 }
229
231 //
233 public:
236 void SaveState( const ResKind & kind_r );
237
238 void RestoreState( const ResKind & kind_r );
240
242 //
244 public:
246 {
247 checkSerial();
248 if ( !_poolProxy )
249 {
250 _poolProxy.reset( new ResPoolProxy( std::move(self), *this ) );
251 }
252 return *_poolProxy;
253 }
254
262
263 public:
267
270
273
274 Repository reposFind( const std::string & alias_r ) const
275 { checkSerial(); return satpool().reposFind( alias_r ); }
276
278 //
280 public:
283
285 { return _hardLockQueries; }
286
287 void reapplyHardLocks() const
288 {
289 // It is assumed that reapplyHardLocks is called after new
290 // items were added to the pool, but the _hardLockQueries
291 // did not change since. Action is to be performed only on
292 // those items that gained the bit in the UserLockQueryField.
293 MIL << "Re-apply " << _hardLockQueries.size() << " HardLockQueries" << endl;
294 PoolQueryResult locked;
295 for_( it, _hardLockQueries.begin(), _hardLockQueries.end() )
296 {
297 locked += *it;
298 }
299 MIL << "HardLockQueries match " << locked.size() << " Solvables." << endl;
300 for_( it, begin(), end() )
301 {
303 }
304 }
305
307 {
308 MIL << "Apply " << newLocks_r.size() << " HardLockQueries" << endl;
310 // now adjust the pool status
311 PoolQueryResult locked;
312 for_( it, _hardLockQueries.begin(), _hardLockQueries.end() )
313 {
314 locked += *it;
315 }
316 MIL << "HardLockQueries match " << locked.size() << " Solvables." << endl;
317 for_( it, begin(), end() )
318 {
319 resstatus::UserLockQueryManip::setLock( it->status(), locked.contains( *it ) );
320 }
321 }
322
324 {
325 activeLocks_r = _hardLockQueries; // current queries
326 // Now diff to the pool collecting names only.
327 // Thus added and removed locks are not necessarily
328 // disjoint. Added locks win.
329 typedef std::unordered_set<IdString> IdentSet;
332 for_( it, begin(), end() )
333 {
334 switch ( resstatus::UserLockQueryManip::diffLock( it->status() ) )
335 {
336 case 0: // unchanged
337 break;
338 case 1:
339 addedLocks.insert( it->satSolvable().ident() );
340 break;
341 case -1:
342 removedLocks.insert( it->satSolvable().ident() );
343 break;
344 }
345 }
346 // now the bad part - adjust the queries
347 bool setChanged = false;
348 for_( it, removedLocks.begin(), removedLocks.end() )
349 {
350 if ( addedLocks.find( *it ) != addedLocks.end() )
351 continue; // Added locks win
353 setChanged = true;
354 }
355 for_( it, addedLocks.begin(), addedLocks.end() )
356 {
358 setChanged = true;
359 }
360 return setChanged;
361 }
362
363 public:
364 const ContainerT & store() const
365 {
366 checkSerial();
367 if ( _storeDirty )
368 {
369 sat::Pool pool( satpool() );
370 bool addedItems = false;
371 bool reusedIDs = _watcherIDs.remember( pool.serialIDs() );
372 std::list<PoolItem> addedProducts;
373
374 _store.resize( pool.capacity() );
375
376 if ( pool.capacity() )
377 {
378 for ( sat::detail::SolvableIdType i = pool.capacity()-1; i != 0; --i )
379 {
380 sat::Solvable s( i );
381 PoolItem & pi( _store[i] );
382 if ( ! s && pi )
383 {
384 // the PoolItem got invalidated (e.g unloaded repo)
385 pi = PoolItem();
386 }
387 else if ( reusedIDs || (s && ! pi) )
388 {
389 // new PoolItem to add
390 pi = PoolItem::makePoolItem( s ); // the only way to create a new one!
391 // remember products for buddy processing (requires clean store)
392 if ( s.isKind( ResKind::product ) )
393 addedProducts.push_back( pi );
394 if ( !addedItems )
395 addedItems = true;
396 }
397 }
398 }
399 _storeDirty = false;
400
401 // Now, as the pool is adjusted, ....
402
403 // .... we check for product buddies.
404 if ( ! addedProducts.empty() )
405 {
406 for_( it, addedProducts.begin(), addedProducts.end() )
407 {
408 it->setBuddy( asKind<Product>(*it)->referencePackage() );
409 }
410 }
411
412 // .... we must reapply those query based hard locks.
413 if ( addedItems )
414 {
416 }
417
418 // Compute the initial status of Patches etc.
419 if ( !_establishedStates )
421 }
422 return _store;
423 }
424
425 const Id2ItemT & id2item () const
426 {
427 checkSerial();
428 if ( _id2itemDirty )
429 {
430 store();
431 _id2item = Id2ItemT( size() );
432 for_( it, begin(), end() )
433 {
434 const sat::Solvable &s = (*it)->satSolvable();
435 sat::detail::IdType id = s.ident().id();
436 if ( s.isKind( ResKind::srcpackage ) )
437 id = -id;
438 _id2item.insert( std::make_pair( id, *it ) );
439 }
440 //INT << _id2item << endl;
441 _id2itemDirty = false;
442 }
443 return _id2item;
444 }
445
447 //
449 private:
450 void checkSerial() const
451 {
452 if ( _watcher.remember( serial() ) )
453 invalidate();
454 satpool().prepare(); // always ajust dependencies.
455 }
456
457 void invalidate() const
458 {
459 _storeDirty = true;
460 _id2itemDirty = true;
461 _id2item.clear();
464 }
465
466 private:
475
476 private:
479
480 private:
483 };
485
487 } // namespace pool
490} // namespace zypp
492#endif // ZYPP_POOL_POOLIMPL_H
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition AutoDispose.h:95
void reset()
Reset to default Ctor values.
Combining sat::Solvable and ResStatus.
Definition PoolItem.h:51
static PoolItem makePoolItem(const sat::Solvable &solvable_r)
PoolItem generator for pool::PoolImpl.
Definition PoolItem.cc:200
Helper class to collect (not only) PoolQuery results.
size_type size() const
The number of sat::Solvables.
bool contains(sat::Solvable result_r) const
Test whether some item is in the result set.
Resolvable kinds.
Definition ResKind.h:33
static const ResKind srcpackage
Definition ResKind.h:44
static const ResKind product
Definition ResKind.h:43
ResPool::instance().proxy();.
Store initial establish status of pseudo installed items.
Definition PoolImpl.h:118
ResStatus::ValidateValue validateValue(sat::Queue::size_type i) const
Definition PoolImpl.h:142
ResPool::EstablishedStates::ChangedPseudoInstalled changedPseudoInstalled() const
Return all pseudo installed items whose current state differs from their initial one.
Definition PoolImpl.h:124
A copy of the Pools initial ValidateValues of pseudo installed items.
Definition ResPool.h:315
std::map< PoolItem, ResStatus::ValidateValue > ChangedPseudoInstalled
Map holding pseudo installed items where current and established status differ.
Definition ResPool.h:319
Global ResObject pool.
Definition ResPool.h:62
Status bitfield.
Definition ResStatus.h:55
Simple serial number watcher.
bool remember(unsigned serial_r) const
Return isDirty, storing serial_r as new value.
Simple serial number provider.
const_iterator begin() const
Definition PoolImpl.h:212
void reapplyHardLocks() const
Definition PoolImpl.h:287
PoolTraits::HardLockQueries HardLockQueries
Definition PoolImpl.h:281
bool empty() const
Definition PoolImpl.h:205
PoolItem find(const sat::Solvable &slv_r) const
Return the corresponding PoolItem.
Definition PoolImpl.h:224
HardLockQueries _hardLockQueries
Set of queries that define hardlocks.
Definition PoolImpl.h:482
PoolTraits::ItemContainerT ContainerT
Definition PoolImpl.h:174
PoolImpl()
Default ctor.
Definition PoolImpl.cc:44
void invalidate() const
Definition PoolImpl.h:457
ResPool::EstablishedStates establishedStates() const
True factory for ResPool::EstablishedStates.
Definition PoolImpl.h:260
Repository reposFind(const std::string &alias_r) const
Definition PoolImpl.h:274
PoolTraits::size_type size_type
Definition PoolImpl.h:175
shared_ptr< ResPoolProxy > _poolProxy
Definition PoolImpl.h:477
const HardLockQueries & hardLockQueries() const
Definition PoolImpl.h:284
repository_iterator knownRepositoriesBegin() const
Definition PoolImpl.h:268
void RestoreState(const ResKind &kind_r)
const SerialNumber & serial() const
Housekeeping data serial number.
Definition PoolImpl.h:197
friend std::ostream & operator<<(std::ostream &str, const PoolImpl &obj)
DefaultIntegral< bool, true > _id2itemDirty
Definition PoolImpl.h:474
shared_ptr< EstablishedStatesImpl > _establishedStates
Definition PoolImpl.h:478
const_iterator end() const
Definition PoolImpl.h:215
ResPoolProxy proxy(ResPool self) const
Definition PoolImpl.h:245
DefaultIntegral< bool, true > _storeDirty
Definition PoolImpl.h:472
void SaveState(const ResKind &kind_r)
void setHardLockQueries(const HardLockQueries &newLocks_r)
Definition PoolImpl.h:306
SerialNumberWatcher _watcherIDs
Watch sat pools Serial number of IDs - changes whenever resusePoolIDs==true - ResPool must also inval...
Definition PoolImpl.h:470
const sat::Pool satpool() const
convenience.
Definition PoolImpl.h:193
PoolTraits::hardLockQueries_iterator hardLockQueries_iterator
Definition PoolImpl.h:282
SerialNumberWatcher _watcher
Watch sat pools serial number.
Definition PoolImpl.h:468
bool getHardLockQueries(HardLockQueries &activeLocks_r)
Definition PoolImpl.h:323
size_type knownRepositoriesSize() const
Forward list of Repositories that contribute ResObjects from sat::Pool.
Definition PoolImpl.h:265
size_type size() const
Definition PoolImpl.h:209
const Id2ItemT & id2item() const
Definition PoolImpl.h:425
const ContainerT & store() const
Definition PoolImpl.h:364
PoolTraits::Id2ItemT Id2ItemT
Definition PoolImpl.h:177
void checkSerial() const
Definition PoolImpl.h:450
repository_iterator knownRepositoriesEnd() const
Definition PoolImpl.h:271
ContainerT _store
Definition PoolImpl.h:471
Global sat-pool.
Definition Pool.h:47
const SerialNumber & serialIDs() const
Serial number changing whenever resusePoolIDs==true was used.
Definition Pool.cc:58
RepositoryIterator reposEnd() const
Iterator behind the last Repository.
Definition Pool.cc:87
size_type reposSize() const
Number of repos in Pool.
Definition Pool.cc:73
bool solvablesEmpty() const
Whether Pool contains solvables.
Definition Pool.cc:90
size_type capacity() const
Internal array size for stats only.
Definition Pool.cc:52
RepositoryIterator reposBegin() const
Iterator to the first Repository.
Definition Pool.cc:76
Repository reposFind(const std::string &alias_r) const
Find a Repository named alias_r.
Definition Pool.cc:163
size_type solvablesSize() const
Number of solvables in Pool.
Definition Pool.cc:103
const SerialNumber & serial() const
Housekeeping data serial number.
Definition Pool.cc:55
static Pool instance()
Singleton ctor.
Definition Pool.h:55
void prepare() const
Update housekeeping data if necessary (e.g.
Definition Pool.cc:61
Libsolv Id queue wrapper.
Definition Queue.h:36
size_type size() const
Definition Queue.cc:49
bool empty() const
Definition Queue.cc:46
static const SolvAttr name
Definition SolvAttr.h:52
A Solvable object within the sat Pool.
Definition Solvable.h:54
String related utilities and Regular expression matching.
unsigned int SolvableIdType
Id type to connect Solvable and sat-solvable.
Definition PoolMember.h:125
int IdType
Generic Id type.
Definition PoolMember.h:104
void establish(sat::Queue &pseudoItems_r, sat::Queue &pseudoFlags_r)
ResPool helper to compute the initial status of Patches etc.
Easy-to use interface to the ZYPP dependency resolver.
filter_iterator< TFilter, typename TContainer::const_iterator > make_filter_begin(TFilter f, const TContainer &c)
Convenience to create filter_iterator from container::begin().
Definition Iterator.h:101
filter_iterator< TFilter, typename TContainer::const_iterator > make_filter_end(TFilter f, const TContainer &c)
Convenience to create filter_iterator from container::end().
Definition Iterator.h:117
Pool internal filter skiping invalid/unwanted PoolItems.
Definition PoolTraits.h:41
filter_iterator< ByPoolItem, ItemContainerT::const_iterator > const_iterator
Definition PoolTraits.h:73
sat::Pool::RepositoryIterator repository_iterator
list of known Repositories
Definition PoolTraits.h:82
std::unordered_multimap< sat::detail::IdType, PoolItem > Id2ItemT
ident index
Definition PoolTraits.h:77
ItemContainerT::size_type size_type
Definition PoolTraits.h:74
HardLockQueries::const_iterator hardLockQueries_iterator
Definition PoolTraits.h:86
std::vector< PoolItem > ItemContainerT
pure items
Definition PoolTraits.h:71
std::list< PoolQuery > HardLockQueries
hard locks from etc/zypp/locks
Definition PoolTraits.h:85
Manipulator for ResStatus::UserLockQueryField.
Definition PoolImpl.h:44
static void setLock(ResStatus &status_r, bool yesno_r)
Set lock and UserLockQuery bit according to yesno_r.
Definition PoolImpl.h:46
static void reapplyLock(ResStatus &status_r, bool yesno_r)
Update lock and UserLockQuery bit IFF the item gained the bit.
Definition PoolImpl.h:53
static int diffLock(const ResStatus &status_r)
Test whether the lock status differs from the remembered UserLockQuery bit.
Definition PoolImpl.h:63
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition Easy.h:28
#define MIL
Definition Logger.h:98