libzypp 17.31.23
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
17#include <zypp/base/Easy.h>
18#include <zypp/base/LogTools.h>
20#include <zypp/APIConfig.h>
21
23#include <zypp/ResPoolProxy.h>
25
26#include <zypp/sat/Pool.h>
27#include <zypp/Product.h>
28
29using std::endl;
30
32namespace zypp
33{
34
35 namespace resstatus
36 {
43 {
45 static void setLock( ResStatus & status_r, bool yesno_r )
46 {
47 status_r.setLock( yesno_r, ResStatus::USER );
48 status_r.setUserLockQueryMatch( yesno_r );
49 }
50
52 static void reapplyLock( ResStatus & status_r, bool yesno_r )
53 {
54 if ( yesno_r && ! status_r.isUserLockQueryMatch() )
55 {
56 status_r.setLock( yesno_r, ResStatus::USER );
57 status_r.setUserLockQueryMatch( yesno_r );
58 }
59 }
60
62 static int diffLock( const ResStatus & status_r )
63 {
64 bool userLock( status_r.isUserLocked() );
65 if ( userLock == status_r.isUserLockQueryMatch() )
66 return 0;
67 return userLock ? 1 : -1;
68 }
69
70 };
71 }
72
73 namespace
74 {
75 inline PoolQuery makeTrivialQuery( IdString ident_r )
76 {
77 sat::Solvable::SplitIdent ident( ident_r );
78
79 PoolQuery q;
80 q.addAttribute( sat::SolvAttr::name, ident.name().asString() );
81 q.addKind( ident.kind() );
82 q.setMatchExact();
83 q.setCaseSensitive(true);
84 return q;
85 }
86
87 inline bool hardLockQueriesRemove( pool::PoolTraits::HardLockQueries & activeLocks_r, IdString ident_r )
88 {
89 unsigned s( activeLocks_r.size() );
90 activeLocks_r.remove( makeTrivialQuery( ident_r ) );
91 return( activeLocks_r.size() != s );
92 }
93
94 inline bool hardLockQueriesAdd( pool::PoolTraits::HardLockQueries & activeLocks_r, IdString ident_r )
95 {
96 PoolQuery q( makeTrivialQuery( ident_r ) );
97 for_( it, activeLocks_r.begin(), activeLocks_r.end() )
98 {
99 if ( *it == q )
100 return false;
101 }
102 activeLocks_r.push_back( q );
103 return true;
104 }
105 }
106
108 namespace solver {
109 namespace detail {
110 void establish( sat::Queue & pseudoItems_r, sat::Queue & pseudoFlags_r ); // in solver/detail/SATResolver.cc
111 }
112 }
117 {
118 public:
121
124 {
126
127 if ( ! _pseudoItems.empty() )
128 {
129 for ( sat::Queue::size_type i = 0; i < _pseudoItems.size(); ++i )
130 {
133 if ( pi.status().validate() != vorig )
134 ret[pi] = vorig;
135 }
136 }
137 return ret;
138 }
139
140 private:
142 {
144 switch ( _pseudoFlags[i] )
145 {
146 case 0: ret = ResStatus::BROKEN /*2*/; break;
147 case 1: ret = ResStatus::SATISFIED /*4*/; break;
148 case -1: ret = ResStatus::NONRELEVANT /*6*/; break;
149 }
150 return ret;
151 }
152
153 private:
156 };
157
159 namespace pool
160 {
161
163 //
164 // CLASS NAME : PoolImpl
165 //
168 {
169 friend std::ostream & operator<<( std::ostream & str, const PoolImpl & obj );
170
171 public:
177
179
181
183
184 public:
186 PoolImpl();
188 ~PoolImpl();
189
190 public:
192 const sat::Pool satpool() const
193 { return sat::Pool::instance(); }
194
196 const SerialNumber & serial() const
197 { return satpool().serial(); }
198
200 //
202 public:
204 bool empty() const
205 { return satpool().solvablesEmpty(); }
206
209 { return satpool().solvablesSize(); }
210
212 { return make_filter_begin( pool::ByPoolItem(), store() ); }
213
215 { return make_filter_end( pool::ByPoolItem(), store() ); }
216
217 public:
223 PoolItem find( const sat::Solvable & slv_r ) const
224 {
225 const ContainerT & mystore( store() );
226 return( slv_r.id() < mystore.size() ? mystore[slv_r.id()] : PoolItem() );
227 }
228
230 //
232 public:
235 void SaveState( const ResKind & kind_r );
236
237 void RestoreState( const ResKind & kind_r );
239
241 //
243 public:
245 {
246 checkSerial();
247 if ( !_poolProxy )
248 {
249 _poolProxy.reset( new ResPoolProxy( self, *this ) );
250 }
251 return *_poolProxy;
252 }
253
261
262 public:
265 { checkSerial(); return satpool().reposSize(); }
266
268 { checkSerial(); return satpool().reposBegin(); }
269
271 { checkSerial(); return satpool().reposEnd(); }
272
273 Repository reposFind( const std::string & alias_r ) const
274 { checkSerial(); return satpool().reposFind( alias_r ); }
275
277 //
279 public:
282
284 { return _hardLockQueries; }
285
286 void reapplyHardLocks() const
287 {
288 // It is assumed that reapplyHardLocks is called after new
289 // items were added to the pool, but the _hardLockQueries
290 // did not change since. Action is to be performed only on
291 // those items that gained the bit in the UserLockQueryField.
292 MIL << "Re-apply " << _hardLockQueries.size() << " HardLockQueries" << endl;
293 PoolQueryResult locked;
294 for_( it, _hardLockQueries.begin(), _hardLockQueries.end() )
295 {
296 locked += *it;
297 }
298 MIL << "HardLockQueries match " << locked.size() << " Solvables." << endl;
299 for_( it, begin(), end() )
300 {
301 resstatus::UserLockQueryManip::reapplyLock( it->status(), locked.contains( *it ) );
302 }
303 }
304
305 void setHardLockQueries( const HardLockQueries & newLocks_r )
306 {
307 MIL << "Apply " << newLocks_r.size() << " HardLockQueries" << endl;
308 _hardLockQueries = newLocks_r;
309 // now adjust the pool status
310 PoolQueryResult locked;
311 for_( it, _hardLockQueries.begin(), _hardLockQueries.end() )
312 {
313 locked += *it;
314 }
315 MIL << "HardLockQueries match " << locked.size() << " Solvables." << endl;
316 for_( it, begin(), end() )
317 {
318 resstatus::UserLockQueryManip::setLock( it->status(), locked.contains( *it ) );
319 }
320 }
321
322 bool getHardLockQueries( HardLockQueries & activeLocks_r )
323 {
324 activeLocks_r = _hardLockQueries; // current queries
325 // Now diff to the pool collecting names only.
326 // Thus added and removed locks are not necessarily
327 // disjoint. Added locks win.
328 typedef std::unordered_set<IdString> IdentSet;
329 IdentSet addedLocks;
330 IdentSet removedLocks;
331 for_( it, begin(), end() )
332 {
333 switch ( resstatus::UserLockQueryManip::diffLock( it->status() ) )
334 {
335 case 0: // unchanged
336 break;
337 case 1:
338 addedLocks.insert( it->satSolvable().ident() );
339 break;
340 case -1:
341 removedLocks.insert( it->satSolvable().ident() );
342 break;
343 }
344 }
345 // now the bad part - adjust the queries
346 bool setChanged = false;
347 for_( it, removedLocks.begin(), removedLocks.end() )
348 {
349 if ( addedLocks.find( *it ) != addedLocks.end() )
350 continue; // Added locks win
351 if ( hardLockQueriesRemove( activeLocks_r, *it ) && ! setChanged )
352 setChanged = true;
353 }
354 for_( it, addedLocks.begin(), addedLocks.end() )
355 {
356 if ( hardLockQueriesAdd( activeLocks_r, *it ) && ! setChanged )
357 setChanged = true;
358 }
359 return setChanged;
360 }
361
362 public:
363 const ContainerT & store() const
364 {
365 checkSerial();
366 if ( _storeDirty )
367 {
368 sat::Pool pool( satpool() );
369 bool addedItems = false;
370 bool reusedIDs = _watcherIDs.remember( pool.serialIDs() );
371 std::list<PoolItem> addedProducts;
372
373 _store.resize( pool.capacity() );
374
375 if ( pool.capacity() )
376 {
377 for ( sat::detail::SolvableIdType i = pool.capacity()-1; i != 0; --i )
378 {
379 sat::Solvable s( i );
380 PoolItem & pi( _store[i] );
381 if ( ! s && pi )
382 {
383 // the PoolItem got invalidated (e.g unloaded repo)
384 pi = PoolItem();
385 }
386 else if ( reusedIDs || (s && ! pi) )
387 {
388 // new PoolItem to add
389 pi = PoolItem::makePoolItem( s ); // the only way to create a new one!
390 // remember products for buddy processing (requires clean store)
391 if ( s.isKind( ResKind::product ) )
392 addedProducts.push_back( pi );
393 if ( !addedItems )
394 addedItems = true;
395 }
396 }
397 }
398 _storeDirty = false;
399
400 // Now, as the pool is adjusted, ....
401
402 // .... we check for product buddies.
403 if ( ! addedProducts.empty() )
404 {
405 for_( it, addedProducts.begin(), addedProducts.end() )
406 {
407 it->setBuddy( asKind<Product>(*it)->referencePackage() );
408 }
409 }
410
411 // .... we must reapply those query based hard locks.
412 if ( addedItems )
413 {
415 }
416
417 // Compute the initial status of Patches etc.
418 if ( !_establishedStates )
420 }
421 return _store;
422 }
423
424 const Id2ItemT & id2item () const
425 {
426 checkSerial();
427 if ( _id2itemDirty )
428 {
429 store();
430 _id2item = Id2ItemT( size() );
431 for_( it, begin(), end() )
432 {
433 const sat::Solvable &s = (*it)->satSolvable();
434 sat::detail::IdType id = s.ident().id();
435 if ( s.isKind( ResKind::srcpackage ) )
436 id = -id;
437 _id2item.insert( std::make_pair( id, *it ) );
438 }
439 //INT << _id2item << endl;
440 _id2itemDirty = false;
441 }
442 return _id2item;
443 }
444
446 //
448 private:
449 void checkSerial() const
450 {
451 if ( _watcher.remember( serial() ) )
452 invalidate();
453 satpool().prepare(); // always ajust dependencies.
454 }
455
456 void invalidate() const
457 {
458 _storeDirty = true;
459 _id2itemDirty = true;
460 _id2item.clear();
461 _poolProxy.reset();
462 _establishedStates.reset();
463 }
464
465 private:
474
475 private:
476 mutable shared_ptr<ResPoolProxy> _poolProxy;
477 mutable shared_ptr<EstablishedStatesImpl> _establishedStates;
478
479 private:
482 };
484
486 } // namespace pool
489} // namespace zypp
491#endif // ZYPP_POOL_POOLIMPL_H
Provides API related macros.
Integral type with defined initial value when default constructed.
std::string asString() const
Definition: IdStringType.h:106
IdType id() const
Expert backdoor.
Definition: IdString.h:122
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:199
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();.
Definition: ResPoolProxy.h:35
Store initial establish status of pseudo installed items.
Definition: PoolImpl.h:117
ResStatus::ValidateValue validateValue(sat::Queue::size_type i) const
Definition: PoolImpl.h:141
ResPool::EstablishedStates::ChangedPseudoInstalled changedPseudoInstalled() const
Return all pseudo installed items whose current state differs from their initial one.
Definition: PoolImpl.h:123
A copy of the Pools initial ValidateValues of pseudo installed items.
Definition: ResPool.h:314
std::map< PoolItem, ResStatus::ValidateValue > ChangedPseudoInstalled
Map holding pseudo installed items where current and established status differ.
Definition: ResPool.h:318
Global ResObject pool.
Definition: ResPool.h:61
Status bitfield.
Definition: ResStatus.h:54
void setUserLockQueryMatch(bool match_r)
Definition: ResStatus.h:335
bool isUserLockQueryMatch() const
Definition: ResStatus.h:339
bool setLock(bool toLock_r, TransactByValue causer_r)
Apply a lock (prevent transaction).
Definition: ResStatus.h:387
bool isUserLocked() const
Definition: ResStatus.h:267
Simple serial number watcher.
Definition: SerialNumber.h:123
bool remember(unsigned serial_r) const
Return isDirty, storing serial_r as new value.
Definition: SerialNumber.h:160
Simple serial number provider.
Definition: SerialNumber.h:45
PoolTraits::Id2ItemT Id2ItemT
Definition: PoolImpl.h:176
PoolTraits::size_type size_type
Definition: PoolImpl.h:174
PoolTraits::const_iterator const_iterator
Definition: PoolImpl.h:175
const_iterator begin() const
Definition: PoolImpl.h:211
void reapplyHardLocks() const
Definition: PoolImpl.h:286
bool empty() const
Definition: PoolImpl.h:204
PoolItem find(const sat::Solvable &slv_r) const
Return the corresponding PoolItem.
Definition: PoolImpl.h:223
HardLockQueries _hardLockQueries
Set of queries that define hardlocks.
Definition: PoolImpl.h:481
PoolImpl()
Default ctor.
Definition: PoolImpl.cc:44
void invalidate() const
Definition: PoolImpl.h:456
ResPool::EstablishedStates establishedStates() const
True factory for ResPool::EstablishedStates.
Definition: PoolImpl.h:259
Repository reposFind(const std::string &alias_r) const
Definition: PoolImpl.h:273
shared_ptr< ResPoolProxy > _poolProxy
Definition: PoolImpl.h:476
const HardLockQueries & hardLockQueries() const
Definition: PoolImpl.h:283
repository_iterator knownRepositoriesBegin() const
Definition: PoolImpl.h:267
PoolTraits::hardLockQueries_iterator hardLockQueries_iterator
Definition: PoolImpl.h:281
void RestoreState(const ResKind &kind_r)
const SerialNumber & serial() const
Housekeeping data serial number.
Definition: PoolImpl.h:196
friend std::ostream & operator<<(std::ostream &str, const PoolImpl &obj)
DefaultIntegral< bool, true > _id2itemDirty
Definition: PoolImpl.h:473
shared_ptr< EstablishedStatesImpl > _establishedStates
Definition: PoolImpl.h:477
const_iterator end() const
Definition: PoolImpl.h:214
ResPool::EstablishedStates::Impl EstablishedStatesImpl
Definition: PoolImpl.h:182
ResPoolProxy proxy(ResPool self) const
Definition: PoolImpl.h:244
PoolTraits::repository_iterator repository_iterator
Definition: PoolImpl.h:178
sat::detail::SolvableIdType SolvableIdType
Definition: PoolImpl.h:180
DefaultIntegral< bool, true > _storeDirty
Definition: PoolImpl.h:471
void SaveState(const ResKind &kind_r)
PoolTraits::HardLockQueries HardLockQueries
Definition: PoolImpl.h:280
PoolTraits::ItemContainerT ContainerT
Definition: PoolImpl.h:173
void setHardLockQueries(const HardLockQueries &newLocks_r)
Definition: PoolImpl.h:305
SerialNumberWatcher _watcherIDs
Watch sat pools Serial number of IDs - changes whenever resusePoolIDs==true - ResPool must also inval...
Definition: PoolImpl.h:469
const sat::Pool satpool() const
convenience.
Definition: PoolImpl.h:192
SerialNumberWatcher _watcher
Watch sat pools serial number.
Definition: PoolImpl.h:467
bool getHardLockQueries(HardLockQueries &activeLocks_r)
Definition: PoolImpl.h:322
size_type knownRepositoriesSize() const
Forward list of Repositories that contribute ResObjects from sat::Pool.
Definition: PoolImpl.h:264
size_type size() const
Definition: PoolImpl.h:208
const Id2ItemT & id2item() const
Definition: PoolImpl.h:424
const ContainerT & store() const
Definition: PoolImpl.h:363
void checkSerial() const
Definition: PoolImpl.h:449
repository_iterator knownRepositoriesEnd() const
Definition: PoolImpl.h:270
ContainerT _store
Definition: PoolImpl.h:470
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:35
size_type size() const
Definition: Queue.cc:49
unsigned size_type
Definition: Queue.h:37
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
IdType id() const
Expert backdoor.
Definition: Solvable.h:428
bool isKind(const ResKind &kind_r) const
Test whether a Solvable is of a certain ResKind.
Definition: Solvable.cc:302
IdString ident() const
The identifier.
Definition: Solvable.cc:269
String related utilities and Regular expression matching.
int IdType
Generic Id type.
Definition: PoolMember.h:104
unsigned SolvableIdType
Id type to connect Solvable and sat-solvable.
Definition: PoolMember.h:125
void establish(sat::Queue &pseudoItems_r, sat::Queue &pseudoFlags_r)
ResPool helper to compute the initial status of Patches etc.
Definition: SATResolver.cc:186
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
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:74
std::vector< PoolItem > ItemContainerT
pure items
Definition: PoolTraits.h:71
std::unordered_multimap< sat::detail::IdType, PoolItem > Id2ItemT
ident index
Definition: PoolTraits.h:79
std::list< PoolQuery > HardLockQueries
hard locks from etc/zypp/locks
Definition: PoolTraits.h:88
HardLockQueries::const_iterator hardLockQueries_iterator
Definition: PoolTraits.h:89
ItemContainerT::size_type size_type
Definition: PoolTraits.h:75
Manipulator for ResStatus::UserLockQueryField.
Definition: PoolImpl.h:43
static void setLock(ResStatus &status_r, bool yesno_r)
Set lock and UserLockQuery bit according to yesno_r.
Definition: PoolImpl.h:45
static void reapplyLock(ResStatus &status_r, bool yesno_r)
Update lock and UserLockQuery bit IFF the item gained the bit.
Definition: PoolImpl.h:52
static int diffLock(const ResStatus &status_r)
Test whether the lock status differs from the remembered UserLockQuery bit.
Definition: PoolImpl.h:62
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:28
#define MIL
Definition: Logger.h:96