libzypp  15.28.6
PoolImpl.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_SAT_DETAIL_POOLIMPL_H
13 #define ZYPP_SAT_DETAIL_POOLIMPL_H
14 extern "C"
15 {
16 #include <solv/pool.h>
17 #include <solv/repo.h>
18 #include <solv/solvable.h>
19 #include <solv/poolarch.h>
20 #include <solv/repo_solv.h>
21 }
22 #include <iosfwd>
23 
24 #include "zypp/base/Hash.h"
25 #include "zypp/base/NonCopyable.h"
26 #include "zypp/base/SerialNumber.h"
27 #include "zypp/base/SetTracker.h"
29 #include "zypp/sat/Queue.h"
30 #include "zypp/RepoInfo.h"
31 #include "zypp/Locale.h"
32 #include "zypp/Capability.h"
33 #include "zypp/IdString.h"
34 
36 namespace zypp
37 {
38  namespace sat
40  {
41  class SolvableSet;
43  namespace detail
44  {
45 
47  //
48  // CLASS NAME : PoolImpl
49  //
51  class PoolImpl : private base::NonCopyable
52  {
53  public:
55  PoolImpl();
56 
58  ~PoolImpl();
59 
62  { return _pool; }
63 
64  public:
66  const SerialNumber & serial() const
67  { return _serial; }
68 
72  void prepare() const;
74  void prepareForSolving() const;
75 
76  private:
80  void setDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
81 
84  void localeSetDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
85 
88  void depSetDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
89 
91  static detail::IdType nsCallback( CPool *, void * data, detail::IdType lhs, detail::IdType rhs );
92 
93  public:
95  static const std::string & systemRepoAlias();
96 
97  bool isSystemRepo( CRepo * repo_r ) const
98  { return repo_r && _pool->installed == repo_r; }
99 
100  CRepo * systemRepo() const
101  { return _pool->installed; }
102 
104  Pathname rootDir() const
105  {
106  const char * rd = ::pool_get_rootdir( _pool );
107  return( rd ? rd : "/" );
108  }
109 
111  void rootDir( const Pathname & root_r )
112  {
113  if ( root_r.empty() || root_r == "/" )
114  ::pool_set_rootdir( _pool, nullptr );
115  else
116  ::pool_set_rootdir( _pool, root_r.c_str() );
117  }
118 
119  public:
126  CRepo * _createRepo( const std::string & name_r );
127 
129  void _deleteRepo( CRepo * repo_r );
130 
135  int _addSolv( CRepo * repo_r, FILE * file_r );
136 
141  int _addHelix( CRepo * repo_r, FILE * file_r );
142 
144  detail::SolvableIdType _addSolvables( CRepo * repo_r, unsigned count_r );
146 
148  void _postRepoAdd( CRepo * repo_r );
149 
150  public:
152  bool validSolvable( const CSolvable & slv_r ) const
153  { return slv_r.repo; }
155  bool validSolvable( SolvableIdType id_r ) const
156  { return id_r < unsigned(_pool->nsolvables) && validSolvable( _pool->solvables[id_r] ); }
158  bool validSolvable( const CSolvable * slv_r ) const
159  { return _pool->solvables <= slv_r && slv_r <= _pool->solvables+_pool->nsolvables && validSolvable( *slv_r ); }
160 
161  public:
162  CPool * getPool() const
163  { return _pool; }
164 
166  CRepo * getRepo( RepoIdType id_r ) const
167  { return id_r; }
168 
173  {
174  if ( validSolvable( id_r ) )
175  return &_pool->solvables[id_r];
176  return 0;
177  }
178 
179  public:
184  { return getNextId( 1 ); }
185 
192  {
193  for( ++id_r; id_r < unsigned(_pool->nsolvables); ++id_r )
194  {
195  if ( validSolvable( _pool->solvables[id_r] ) )
196  return id_r;
197  }
198  return noSolvableId;
199  }
200 
201  public:
203  const RepoInfo & repoInfo( RepoIdType id_r )
204  { return _repoinfos[id_r]; }
206  void setRepoInfo( RepoIdType id_r, const RepoInfo & info_r );
209  { _repoinfos.erase( id_r ); }
210 
211  public:
215  const sat::detail::IdType whatProvidesData( unsigned offset_r )
216  { return _pool->whatprovidesdata[offset_r]; }
217 
221  unsigned whatProvides( Capability cap_r )
222  { prepare(); return ::pool_whatprovides( _pool, cap_r.id() ); }
223 
224  public:
231 
232 
233  void setTextLocale( const Locale & locale_r );
234 
235 
239  void initRequestedLocales( const LocaleSet & locales_r );
240 
243  { return _requestedLocalesTracker.added(); }
244 
247  { return _requestedLocalesTracker.removed(); }
248 
251  { return _requestedLocalesTracker.current(); }
252 
253  bool isRequestedLocale( const Locale & locale_r ) const
254  { return _requestedLocalesTracker.contains( locale_r ); }
255 
257  void setRequestedLocales( const LocaleSet & locales_r );
259  bool addRequestedLocale( const Locale & locale_r );
261  bool eraseRequestedLocale( const Locale & locale_r );
262 
264  const LocaleSet & getAvailableLocales() const;
265 
266  bool isAvailableLocale( const Locale & locale_r ) const
267  {
268  const LocaleSet & avl( getAvailableLocales() );
269  LocaleSet::const_iterator it( avl.find( locale_r ) );
270  return it != avl.end();
271  }
272 
274 
276  const TrackedLocaleIds & trackedLocaleIds() const;
278 
279  public:
283 
284  const MultiversionList & multiversionList() const;
285 
286  bool isMultiversion( const Solvable & solv_r ) const;
287 
290 
291  public:
296  { return _autoinstalled; }
297 
299  void setAutoInstalled( const StringQueue & autoInstalled_r )
300  { _autoinstalled = autoInstalled_r; }
301 
302  bool isOnSystemByUser( IdString ident_r ) const
303  { return !_autoinstalled.contains( ident_r.id() ); }
305 
306  public:
308  const std::set<std::string> & requiredFilesystems() const;
309 
310  private:
318  std::map<RepoIdType,RepoInfo> _repoinfos;
319 
322  mutable scoped_ptr<TrackedLocaleIds> _trackedLocaleIdsPtr;
323 
324  mutable scoped_ptr<LocaleSet> _availableLocalesPtr;
325 
327  void multiversionListInit() const;
328  mutable scoped_ptr<MultiversionList> _multiversionListPtr;
329 
332 
334  mutable scoped_ptr<std::set<std::string> > _requiredFilesystemsPtr;
335  };
337 
339  } // namespace detail
342  } // namespace sat
345 } // namespace zypp
347 #define POOL_SETDIRTY
348 #endif // ZYPP_SAT_DETAIL_POOLIMPL_H
static const SolvableIdType noSolvableId(0)
Id to denote Solvable::noSolvable.
Simple serial number watcher.
Definition: SerialNumber.h:122
SolvableSet MultiversionList
Definition: PoolImpl.h:282
int IdType
Generic Id type.
Definition: PoolMember.h:130
Pathname rootDir() const
Get rootdir (for file conflicts check)
Definition: PoolImpl.h:104
A Solvable object within the sat Pool.
Definition: Solvable.h:53
const sat::detail::IdType whatProvidesData(unsigned offset_r)
Returns the id stored at offset_r in the internal whatprovidesdata array.
Definition: PoolImpl.h:215
bool eraseRequestedLocale(const Locale &locale_r)
User change (tracked).
Definition: PoolImpl.cc:463
scoped_ptr< LocaleSet > _availableLocalesPtr
Definition: PoolImpl.h:324
Track added/removed set items based on an initial set.
Definition: SetTracker.h:37
int _addSolv(CRepo *repo_r, FILE *file_r)
Adding solv file to a repo.
Definition: PoolImpl.cc:317
base::SetTracker< LocaleSet > _requestedLocalesTracker
Definition: PoolImpl.h:321
const set_type & removed() const
Return the set of removed items.
Definition: SetTracker.h:145
IdType id() const
Expert backdoor.
Definition: IdString.h:115
::_Repo CRepo
Wrapped libsolv C data type exposed as backdoor.
Definition: PoolMember.h:88
bool addRequestedLocale(const Locale &locale_r)
User change (tracked).
Definition: PoolImpl.cc:452
void setDirty(const char *a1=0, const char *a2=0, const char *a3=0)
Invalidate housekeeping data (e.g.
Definition: PoolImpl.cc:223
unsigned whatProvides(Capability cap_r)
Returns offset into the internal whatprovidesdata array.
Definition: PoolImpl.h:221
void prepareForSolving() const
prepare plus some expensive checks done before solving only.
Definition: PoolImpl.cc:284
void _deleteRepo(CRepo *repo_r)
Creating a new repo named name_r.
Definition: PoolImpl.cc:308
CPool * getPool() const
Definition: PoolImpl.h:162
::_Pool CPool
Wrapped libsolv C data type exposed as backdoor.
Definition: PoolMember.h:86
void rootDir(const Pathname &root_r)
Set rootdir (for file conflicts check)
Definition: PoolImpl.h:111
unsigned SolvableIdType
Id type to connect Solvable and sat-solvable.
Definition: PoolMember.h:151
bool validSolvable(const CSolvable &slv_r) const
a valid Solvable has a non NULL repo pointer.
Definition: PoolImpl.h:152
void eraseRepoInfo(RepoIdType id_r)
Definition: PoolImpl.h:208
const set_type & current() const
Return the current set.
Definition: SetTracker.h:139
What is known about a repository.
Definition: RepoInfo.h:72
CRepo * RepoIdType
Id type to connect Repo and sat-repo.
Definition: PoolMember.h:159
const std::set< std::string > & requiredFilesystems() const
accessor for etc/sysconfig/storage reading file on demand
Definition: PoolImpl.cc:604
bool isAvailableLocale(const Locale &locale_r) const
Definition: PoolImpl.h:266
Access to the sat-pools string space.
Definition: IdString.h:41
bool validSolvable(SolvableIdType id_r) const
Definition: PoolImpl.h:155
detail::SolvableIdType _addSolvables(CRepo *repo_r, unsigned count_r)
Adding Solvables to a repo.
Definition: PoolImpl.cc:379
const LocaleSet & getAddedRequestedLocales() const
Added since last initRequestedLocales.
Definition: PoolImpl.h:242
void localeSetDirty(const char *a1=0, const char *a2=0, const char *a3=0)
Invalidate locale related housekeeping data.
Definition: PoolImpl.cc:238
::_Solvable CSolvable
Wrapped libsolv C data type exposed as backdoor.
Definition: PoolMember.h:89
CSolvable * getSolvable(SolvableIdType id_r) const
Return pointer to the sat-solvable or NULL if it is not valid.
Definition: PoolImpl.h:172
const MultiversionList & multiversionList() const
Definition: PoolImpl.cc:592
const LocaleSet & getRequestedLocales() const
Current set of requested Locales.
Definition: PoolImpl.h:250
const TrackedLocaleIds & trackedLocaleIds() const
Expanded _requestedLocalesTracker for solver.
Definition: PoolImpl.cc:475
const SerialNumber & serial() const
Serial number changing whenever the content changes.
Definition: PoolImpl.h:66
void multiversionListInit() const
Definition: PoolImpl.cc:566
CRepo * getRepo(RepoIdType id_r) const
Definition: PoolImpl.h:166
const LocaleSet & getAvailableLocales() const
All Locales occurring in any repo.
Definition: PoolImpl.cc:546
PoolImpl()
Default ctor.
Definition: PoolImpl.cc:178
SolvableIdType getNextId(SolvableIdType id_r) const
Get id of the next valid Solvable.
Definition: PoolImpl.h:191
static detail::IdType nsCallback(CPool *, void *data, detail::IdType lhs, detail::IdType rhs)
Callback to resolve namespace dependencies (language, modalias, filesystem, etc.).
Definition: PoolImpl.cc:120
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
const LocaleSet & getRemovedRequestedLocales() const
Removed since last initRequestedLocales.
Definition: PoolImpl.h:246
void setRepoInfo(RepoIdType id_r, const RepoInfo &info_r)
Also adjust repo priority and subpriority accordingly.
Definition: PoolImpl.cc:385
SerialNumberWatcher _watcher
Watch serial number.
Definition: PoolImpl.h:316
void setRequestedLocales(const LocaleSet &locales_r)
User change (tracked).
Definition: PoolImpl.cc:443
bool isOnSystemByUser(IdString ident_r) const
Definition: PoolImpl.h:302
sat::StringQueue _autoinstalled
Definition: PoolImpl.h:331
bool contains(const key_type &key_r) const
Whether val_r is in the set.
Definition: SetTracker.h:129
base::SetTracker< IdStringSet > TrackedLocaleIds
Definition: PoolImpl.h:273
StringQueue autoInstalled() const
Get ident list of all autoinstalled solvables.
Definition: PoolImpl.h:295
CRepo * systemRepo() const
Definition: PoolImpl.h:100
Simple serial number provider.
Definition: SerialNumber.h:44
'Language[_Country]' codes.
Definition: Locale.h:49
void _postRepoAdd(CRepo *repo_r)
Helper postprocessing the repo after adding solv or helix files.
Definition: PoolImpl.cc:335
SerialNumber _serial
Serial number.
Definition: PoolImpl.h:314
const set_type & added() const
Return the set of added items.
Definition: SetTracker.h:142
scoped_ptr< MultiversionList > _multiversionListPtr
Definition: PoolImpl.h:328
Libsolv Id queue wrapper.
Definition: Queue.h:34
void depSetDirty(const char *a1=0, const char *a2=0, const char *a3=0)
Invalidate housekeeping data (e.g.
Definition: PoolImpl.cc:250
SolvableIdType getFirstId() const
Get id of the first valid Solvable.
Definition: PoolImpl.h:183
scoped_ptr< std::set< std::string > > _requiredFilesystemsPtr
filesystems mentioned in /etc/sysconfig/storage
Definition: PoolImpl.h:334
void setTextLocale(const Locale &locale_r)
Definition: PoolImpl.cc:417
std::map< RepoIdType, RepoInfo > _repoinfos
Additional RepoInfo.
Definition: PoolImpl.h:318
bool validSolvable(const CSolvable *slv_r) const
Definition: PoolImpl.h:158
A sat capability.
Definition: Capability.h:59
void prepare() const
Update housekeeping data (e.g.
Definition: PoolImpl.cc:262
bool isSystemRepo(CRepo *repo_r) const
Definition: PoolImpl.h:97
void initRequestedLocales(const LocaleSet &locales_r)
Start tracking changes based on this locales_r.
Definition: PoolImpl.cc:434
static const std::string & systemRepoAlias()
Reserved system repository alias .
Definition: PoolImpl.cc:94
CPool * _pool
sat-pool.
Definition: PoolImpl.h:312
CPool * operator->()
Pointer style access forwarded to sat-pool.
Definition: PoolImpl.h:61
scoped_ptr< TrackedLocaleIds > _trackedLocaleIdsPtr
Definition: PoolImpl.h:322
bool isRequestedLocale(const Locale &locale_r) const
Definition: PoolImpl.h:253
const RepoInfo & repoInfo(RepoIdType id_r)
Definition: PoolImpl.h:203
int _addHelix(CRepo *repo_r, FILE *file_r)
Adding helix file to a repo.
Definition: PoolImpl.cc:326
CRepo * _createRepo(const std::string &name_r)
Creating a new repo named name_r.
Definition: PoolImpl.cc:299
std::unordered_set< Locale > LocaleSet
Definition: Locale.h:27
void setAutoInstalled(const StringQueue &autoInstalled_r)
Set ident list of all autoinstalled solvables.
Definition: PoolImpl.h:299
bool isMultiversion(const Solvable &solv_r) const
Definition: PoolImpl.cc:599
sat::detail::IdType id() const
Expert backdoor.
Definition: Capability.h:253
bool contains(value_type val_r) const
Return whether the Queue contais at lest one element with value val_r.
Definition: Queue.h:57
Solvable set wrapper to allow adding additioanal convenience iterators.
Definition: SolvableSet.h:35