libzypp  16.1.1
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;
73 
74  private:
78  void setDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
79 
82  void localeSetDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
83 
86  void depSetDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
87 
89  static detail::IdType nsCallback( CPool *, void * data, detail::IdType lhs, detail::IdType rhs );
90 
91  public:
93  static const std::string & systemRepoAlias();
94 
95  bool isSystemRepo( CRepo * repo_r ) const
96  { return repo_r && _pool->installed == repo_r; }
97 
98  CRepo * systemRepo() const
99  { return _pool->installed; }
100 
102  Pathname rootDir() const
103  {
104  const char * rd = ::pool_get_rootdir( _pool );
105  return( rd ? rd : "/" );
106  }
107 
109  void rootDir( const Pathname & root_r )
110  {
111  if ( root_r.empty() || root_r == "/" )
112  ::pool_set_rootdir( _pool, nullptr );
113  else
114  ::pool_set_rootdir( _pool, root_r.c_str() );
115  }
116 
117  public:
124  CRepo * _createRepo( const std::string & name_r );
125 
127  void _deleteRepo( CRepo * repo_r );
128 
133  int _addSolv( CRepo * repo_r, FILE * file_r );
134 
139  int _addHelix( CRepo * repo_r, FILE * file_r );
140 
142  detail::SolvableIdType _addSolvables( CRepo * repo_r, unsigned count_r );
144 
146  void _postRepoAdd( CRepo * repo_r );
147 
148  public:
150  bool validSolvable( const CSolvable & slv_r ) const
151  { return slv_r.repo; }
153  bool validSolvable( SolvableIdType id_r ) const
154  { return id_r < unsigned(_pool->nsolvables) && validSolvable( _pool->solvables[id_r] ); }
156  bool validSolvable( const CSolvable * slv_r ) const
157  { return _pool->solvables <= slv_r && slv_r <= _pool->solvables+_pool->nsolvables && validSolvable( *slv_r ); }
158 
159  public:
160  CPool * getPool() const
161  { return _pool; }
162 
164  CRepo * getRepo( RepoIdType id_r ) const
165  { return id_r; }
166 
171  {
172  if ( validSolvable( id_r ) )
173  return &_pool->solvables[id_r];
174  return 0;
175  }
176 
177  public:
182  { return getNextId( 1 ); }
183 
190  {
191  for( ++id_r; id_r < unsigned(_pool->nsolvables); ++id_r )
192  {
193  if ( validSolvable( _pool->solvables[id_r] ) )
194  return id_r;
195  }
196  return noSolvableId;
197  }
198 
199  public:
201  const RepoInfo & repoInfo( RepoIdType id_r )
202  { return _repoinfos[id_r]; }
204  void setRepoInfo( RepoIdType id_r, const RepoInfo & info_r );
207  { _repoinfos.erase( id_r ); }
208 
209  public:
213  const sat::detail::IdType whatProvidesData( unsigned offset_r )
214  { return _pool->whatprovidesdata[offset_r]; }
215 
219  unsigned whatProvides( Capability cap_r )
220  { prepare(); return ::pool_whatprovides( _pool, cap_r.id() ); }
221 
222  public:
229 
230 
231  void setTextLocale( const Locale & locale_r );
232 
233 
237  void initRequestedLocales( const LocaleSet & locales_r );
238 
241  { return _requestedLocalesTracker.added(); }
242 
245  { return _requestedLocalesTracker.removed(); }
246 
249  { return _requestedLocalesTracker.current(); }
250 
251  bool isRequestedLocale( const Locale & locale_r ) const
252  { return _requestedLocalesTracker.contains( locale_r ); }
253 
255  void setRequestedLocales( const LocaleSet & locales_r );
257  bool addRequestedLocale( const Locale & locale_r );
259  bool eraseRequestedLocale( const Locale & locale_r );
260 
262  const LocaleSet & getAvailableLocales() const;
263 
264  bool isAvailableLocale( const Locale & locale_r ) const
265  {
266  const LocaleSet & avl( getAvailableLocales() );
267  LocaleSet::const_iterator it( avl.find( locale_r ) );
268  return it != avl.end();
269  }
270 
272 
274  const TrackedLocaleIds & trackedLocaleIds() const;
276 
277  public:
281 
282  const MultiversionList & multiversionList() const;
283 
284  bool isMultiversion( const Solvable & solv_r ) const;
285 
288 
289  public:
294  { return _autoinstalled; }
295 
297  void setAutoInstalled( const StringQueue & autoInstalled_r )
298  { _autoinstalled = autoInstalled_r; }
299 
300  bool isOnSystemByUser( IdString ident_r ) const
301  { return !_autoinstalled.contains( ident_r.id() ); }
303 
304  public:
306  const std::set<std::string> & requiredFilesystems() const;
307 
308  private:
316  std::map<RepoIdType,RepoInfo> _repoinfos;
317 
320  mutable scoped_ptr<TrackedLocaleIds> _trackedLocaleIdsPtr;
321 
322  mutable scoped_ptr<LocaleSet> _availableLocalesPtr;
323 
325  void multiversionListInit() const;
326  mutable scoped_ptr<MultiversionList> _multiversionListPtr;
327 
330 
332  mutable scoped_ptr<std::set<std::string> > _requiredFilesystemsPtr;
333  };
335 
337  } // namespace detail
340  } // namespace sat
343 } // namespace zypp
345 #define POOL_SETDIRTY
346 #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:280
int IdType
Generic Id type.
Definition: PoolMember.h:104
Pathname rootDir() const
Get rootdir (for file conflicts check)
Definition: PoolImpl.h:102
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:213
bool eraseRequestedLocale(const Locale &locale_r)
User change (tracked).
Definition: PoolImpl.cc:459
scoped_ptr< LocaleSet > _availableLocalesPtr
Definition: PoolImpl.h:322
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:313
base::SetTracker< LocaleSet > _requestedLocalesTracker
Definition: PoolImpl.h:319
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:63
bool addRequestedLocale(const Locale &locale_r)
User change (tracked).
Definition: PoolImpl.cc:448
void setDirty(const char *a1=0, const char *a2=0, const char *a3=0)
Invalidate housekeeping data (e.g.
Definition: PoolImpl.cc:222
unsigned whatProvides(Capability cap_r)
Returns offset into the internal whatprovidesdata array.
Definition: PoolImpl.h:219
::_Repo * RepoIdType
Id type to connect Repo and sat-repo.
Definition: PoolMember.h:133
void _deleteRepo(CRepo *repo_r)
Delete repo repo_r from pool.
Definition: PoolImpl.cc:300
CPool * getPool() const
Definition: PoolImpl.h:160
::_Pool CPool
Wrapped libsolv C data type exposed as backdoor.
Definition: PoolMember.h:61
void rootDir(const Pathname &root_r)
Set rootdir (for file conflicts check)
Definition: PoolImpl.h:109
unsigned SolvableIdType
Id type to connect Solvable and sat-solvable.
Definition: PoolMember.h:125
bool validSolvable(const CSolvable &slv_r) const
a valid Solvable has a non NULL repo pointer.
Definition: PoolImpl.h:150
void eraseRepoInfo(RepoIdType id_r)
Definition: PoolImpl.h:206
const set_type & current() const
Return the current set.
Definition: SetTracker.h:139
What is known about a repository.
Definition: RepoInfo.h:71
const std::set< std::string > & requiredFilesystems() const
accessor for etc/sysconfig/storage reading file on demand
Definition: PoolImpl.cc:600
bool isAvailableLocale(const Locale &locale_r) const
Definition: PoolImpl.h:264
Access to the sat-pools string space.
Definition: IdString.h:41
bool validSolvable(SolvableIdType id_r) const
Definition: PoolImpl.h:153
detail::SolvableIdType _addSolvables(CRepo *repo_r, unsigned count_r)
Adding Solvables to a repo.
Definition: PoolImpl.cc:375
const LocaleSet & getAddedRequestedLocales() const
Added since last initRequestedLocales.
Definition: PoolImpl.h:240
void localeSetDirty(const char *a1=0, const char *a2=0, const char *a3=0)
Invalidate locale related housekeeping data.
Definition: PoolImpl.cc:237
::_Solvable CSolvable
Wrapped libsolv C data type exposed as backdoor.
Definition: PoolMember.h:64
CSolvable * getSolvable(SolvableIdType id_r) const
Return pointer to the sat-solvable or NULL if it is not valid.
Definition: PoolImpl.h:170
const MultiversionList & multiversionList() const
Definition: PoolImpl.cc:588
const LocaleSet & getRequestedLocales() const
Current set of requested Locales.
Definition: PoolImpl.h:248
const TrackedLocaleIds & trackedLocaleIds() const
Expanded _requestedLocalesTracker for solver.
Definition: PoolImpl.cc:471
const SerialNumber & serial() const
Serial number changing whenever the content changes.
Definition: PoolImpl.h:66
void multiversionListInit() const
Definition: PoolImpl.cc:562
CRepo * getRepo(RepoIdType id_r) const
Definition: PoolImpl.h:164
const LocaleSet & getAvailableLocales() const
All Locales occurring in any repo.
Definition: PoolImpl.cc:542
PoolImpl()
Default ctor.
Definition: PoolImpl.cc:177
SolvableIdType getNextId(SolvableIdType id_r) const
Get id of the next valid Solvable.
Definition: PoolImpl.h:189
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:119
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
const LocaleSet & getRemovedRequestedLocales() const
Removed since last initRequestedLocales.
Definition: PoolImpl.h:244
void setRepoInfo(RepoIdType id_r, const RepoInfo &info_r)
Also adjust repo priority and subpriority accordingly.
Definition: PoolImpl.cc:381
SerialNumberWatcher _watcher
Watch serial number.
Definition: PoolImpl.h:314
void setRequestedLocales(const LocaleSet &locales_r)
User change (tracked).
Definition: PoolImpl.cc:439
bool isOnSystemByUser(IdString ident_r) const
Definition: PoolImpl.h:300
sat::StringQueue _autoinstalled
Definition: PoolImpl.h:329
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:271
StringQueue autoInstalled() const
Get ident list of all autoinstalled solvables.
Definition: PoolImpl.h:293
CRepo * systemRepo() const
Definition: PoolImpl.h:98
Simple serial number provider.
Definition: SerialNumber.h:44
&#39;Language[_Country]&#39; codes.
Definition: Locale.h:49
void _postRepoAdd(CRepo *repo_r)
Helper postprocessing the repo after adding solv or helix files.
Definition: PoolImpl.cc:331
SerialNumber _serial
Serial number.
Definition: PoolImpl.h:312
const set_type & added() const
Return the set of added items.
Definition: SetTracker.h:142
scoped_ptr< MultiversionList > _multiversionListPtr
Definition: PoolImpl.h:326
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:249
SolvableIdType getFirstId() const
Get id of the first valid Solvable.
Definition: PoolImpl.h:181
scoped_ptr< std::set< std::string > > _requiredFilesystemsPtr
filesystems mentioned in /etc/sysconfig/storage
Definition: PoolImpl.h:332
void setTextLocale(const Locale &locale_r)
Definition: PoolImpl.cc:413
std::map< RepoIdType, RepoInfo > _repoinfos
Additional RepoInfo.
Definition: PoolImpl.h:316
bool validSolvable(const CSolvable *slv_r) const
Definition: PoolImpl.h:156
A sat capability.
Definition: Capability.h:59
void prepare() const
Update housekeeping data (e.g.
Definition: PoolImpl.cc:260
bool isSystemRepo(CRepo *repo_r) const
Definition: PoolImpl.h:95
void initRequestedLocales(const LocaleSet &locales_r)
Start tracking changes based on this locales_r.
Definition: PoolImpl.cc:430
static const std::string & systemRepoAlias()
Reserved system repository alias .
Definition: PoolImpl.cc:94
CPool * _pool
sat-pool.
Definition: PoolImpl.h:310
CPool * operator->()
Pointer style access forwarded to sat-pool.
Definition: PoolImpl.h:61
scoped_ptr< TrackedLocaleIds > _trackedLocaleIdsPtr
Definition: PoolImpl.h:320
bool isRequestedLocale(const Locale &locale_r) const
Definition: PoolImpl.h:251
const RepoInfo & repoInfo(RepoIdType id_r)
Definition: PoolImpl.h:201
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
int _addHelix(CRepo *repo_r, FILE *file_r)
Adding helix file to a repo.
Definition: PoolImpl.cc:322
CRepo * _createRepo(const std::string &name_r)
Creating a new repo named name_r.
Definition: PoolImpl.cc:291
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:297
bool isMultiversion(const Solvable &solv_r) const
Definition: PoolImpl.cc:595
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 additional convenience iterators.
Definition: SolvableSet.h:35