libzypp  17.7.2
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 
70  const SerialNumber & serialIDs() const
71  { return _serialIDs; }
72 
76  void prepare() const;
77 
78  private:
82  void setDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
83 
86  void localeSetDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
87 
90  void depSetDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
91 
93  static detail::IdType nsCallback( CPool *, void * data, detail::IdType lhs, detail::IdType rhs );
94 
95  public:
97  static const std::string & systemRepoAlias();
98 
99  bool isSystemRepo( CRepo * repo_r ) const
100  { return repo_r && _pool->installed == repo_r; }
101 
102  CRepo * systemRepo() const
103  { return _pool->installed; }
104 
107  {
108  const char * rd = ::pool_get_rootdir( _pool );
109  return( rd ? rd : "/" );
110  }
111 
113  void rootDir( const Pathname & root_r )
114  {
115  if ( root_r.empty() || root_r == "/" )
116  ::pool_set_rootdir( _pool, nullptr );
117  else
118  ::pool_set_rootdir( _pool, root_r.c_str() );
119  }
120 
121  public:
128  CRepo * _createRepo( const std::string & name_r );
129 
131  void _deleteRepo( CRepo * repo_r );
132 
137  int _addSolv( CRepo * repo_r, FILE * file_r );
138 
143  int _addHelix( CRepo * repo_r, FILE * file_r );
144 
146  detail::SolvableIdType _addSolvables( CRepo * repo_r, unsigned count_r );
148 
150  void _postRepoAdd( CRepo * repo_r );
151 
152  public:
154  bool validSolvable( const CSolvable & slv_r ) const
155  { return slv_r.repo; }
157  bool validSolvable( SolvableIdType id_r ) const
158  { return id_r < unsigned(_pool->nsolvables) && validSolvable( _pool->solvables[id_r] ); }
160  bool validSolvable( const CSolvable * slv_r ) const
161  { return _pool->solvables <= slv_r && slv_r <= _pool->solvables+_pool->nsolvables && validSolvable( *slv_r ); }
162 
163  public:
164  CPool * getPool() const
165  { return _pool; }
166 
168  CRepo * getRepo( RepoIdType id_r ) const
169  { return id_r; }
170 
175  {
176  if ( validSolvable( id_r ) )
177  return &_pool->solvables[id_r];
178  return 0;
179  }
180 
181  public:
186  { return getNextId( 1 ); }
187 
194  {
195  for( ++id_r; id_r < unsigned(_pool->nsolvables); ++id_r )
196  {
197  if ( validSolvable( _pool->solvables[id_r] ) )
198  return id_r;
199  }
200  return noSolvableId;
201  }
202 
203  public:
205  const RepoInfo & repoInfo( RepoIdType id_r )
206  { return _repoinfos[id_r]; }
208  void setRepoInfo( RepoIdType id_r, const RepoInfo & info_r );
211  { _repoinfos.erase( id_r ); }
212 
213  public:
217  const sat::detail::IdType whatProvidesData( unsigned offset_r )
218  { return _pool->whatprovidesdata[offset_r]; }
219 
223  unsigned whatProvides( Capability cap_r )
224  { prepare(); return ::pool_whatprovides( _pool, cap_r.id() ); }
225 
226  public:
233 
234 
235  void setTextLocale( const Locale & locale_r );
236 
237 
241  void initRequestedLocales( const LocaleSet & locales_r );
242 
245  { return _requestedLocalesTracker.added(); }
246 
249  { return _requestedLocalesTracker.removed(); }
250 
253  { return _requestedLocalesTracker.current(); }
254 
255  bool isRequestedLocale( const Locale & locale_r ) const
256  { return _requestedLocalesTracker.contains( locale_r ); }
257 
259  void setRequestedLocales( const LocaleSet & locales_r );
261  bool addRequestedLocale( const Locale & locale_r );
263  bool eraseRequestedLocale( const Locale & locale_r );
264 
266  const LocaleSet & getAvailableLocales() const;
267 
268  bool isAvailableLocale( const Locale & locale_r ) const
269  {
270  const LocaleSet & avl( getAvailableLocales() );
271  LocaleSet::const_iterator it( avl.find( locale_r ) );
272  return it != avl.end();
273  }
274 
276 
278  const TrackedLocaleIds & trackedLocaleIds() const;
280 
281  public:
285 
286  const MultiversionList & multiversionList() const;
287 
288  bool isMultiversion( const Solvable & solv_r ) const;
289 
292 
293  public:
298  { return _autoinstalled; }
299 
301  void setAutoInstalled( const StringQueue & autoInstalled_r )
302  { _autoinstalled = autoInstalled_r; }
303 
304  bool isOnSystemByUser( IdString ident_r ) const
305  { return !_autoinstalled.contains( ident_r.id() ); }
306 
307  bool isOnSystemByAuto( IdString ident_r ) const
308  { return _autoinstalled.contains( ident_r.id() ); }
310 
311  public:
313  const std::set<std::string> & requiredFilesystems() const;
314 
315  private:
325  std::map<RepoIdType,RepoInfo> _repoinfos;
326 
329  mutable scoped_ptr<TrackedLocaleIds> _trackedLocaleIdsPtr;
330 
331  mutable scoped_ptr<LocaleSet> _availableLocalesPtr;
332 
334  void multiversionListInit() const;
335  mutable scoped_ptr<MultiversionList> _multiversionListPtr;
336 
339 
341  mutable scoped_ptr<std::set<std::string> > _requiredFilesystemsPtr;
342  };
344 
346  } // namespace detail
349  } // namespace sat
352 } // namespace zypp
354 #define POOL_SETDIRTY
355 #endif // ZYPP_SAT_DETAIL_POOLIMPL_H
static const SolvableIdType noSolvableId(0)
Id to denote Solvable::noSolvable.
bool contains(const key_type &key_r) const
Whether val_r is in the set.
Definition: SetTracker.h:129
const SerialNumber & serial() const
Serial number changing whenever the content changes.
Definition: PoolImpl.h:66
Simple serial number watcher.
Definition: SerialNumber.h:122
SolvableSet MultiversionList
Definition: PoolImpl.h:284
int IdType
Generic Id type.
Definition: PoolMember.h:104
A Solvable object within the sat Pool.
Definition: Solvable.h:53
StringQueue autoInstalled() const
Get ident list of all autoinstalled solvables.
Definition: PoolImpl.h:297
const sat::detail::IdType whatProvidesData(unsigned offset_r)
Returns the id stored at offset_r in the internal whatprovidesdata array.
Definition: PoolImpl.h:217
bool eraseRequestedLocale(const Locale &locale_r)
User change (tracked).
Definition: PoolImpl.cc:468
scoped_ptr< LocaleSet > _availableLocalesPtr
Definition: PoolImpl.h:331
Track added/removed set items based on an initial set.
Definition: SetTracker.h:37
bool isRequestedLocale(const Locale &locale_r) const
Definition: PoolImpl.h:255
void multiversionListInit() const
Definition: PoolImpl.cc:571
int _addSolv(CRepo *repo_r, FILE *file_r)
Adding solv file to a repo.
Definition: PoolImpl.cc:322
base::SetTracker< LocaleSet > _requestedLocalesTracker
Definition: PoolImpl.h:328
::_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:457
void setDirty(const char *a1=0, const char *a2=0, const char *a3=0)
Invalidate housekeeping data (e.g.
Definition: PoolImpl.cc:228
unsigned whatProvides(Capability cap_r)
Returns offset into the internal whatprovidesdata array.
Definition: PoolImpl.h:223
const std::set< std::string > & requiredFilesystems() const
accessor for etc/sysconfig/storage reading file on demand
Definition: PoolImpl.cc:609
::_Repo * RepoIdType
Id type to connect Repo and sat-repo.
Definition: PoolMember.h:133
const MultiversionList & multiversionList() const
Definition: PoolImpl.cc:597
const LocaleSet & getAddedRequestedLocales() const
Added since last initRequestedLocales.
Definition: PoolImpl.h:244
void _deleteRepo(CRepo *repo_r)
Delete repo repo_r from pool.
Definition: PoolImpl.cc:306
IdType id() const
Expert backdoor.
Definition: IdString.h:115
bool isOnSystemByAuto(IdString ident_r) const
Definition: PoolImpl.h:307
::_Pool CPool
Wrapped libsolv C data type exposed as backdoor.
Definition: PoolMember.h:61
const char * c_str() const
String representation.
Definition: Pathname.h:109
void rootDir(const Pathname &root_r)
Set rootdir (for file conflicts check)
Definition: PoolImpl.h:113
unsigned SolvableIdType
Id type to connect Solvable and sat-solvable.
Definition: PoolMember.h:125
void eraseRepoInfo(RepoIdType id_r)
Definition: PoolImpl.h:210
What is known about a repository.
Definition: RepoInfo.h:71
CRepo * systemRepo() const
Definition: PoolImpl.h:102
Access to the sat-pools string space.
Definition: IdString.h:41
detail::SolvableIdType _addSolvables(CRepo *repo_r, unsigned count_r)
Adding Solvables to a repo.
Definition: PoolImpl.cc:384
void localeSetDirty(const char *a1=0, const char *a2=0, const char *a3=0)
Invalidate locale related housekeeping data.
Definition: PoolImpl.cc:243
::_Solvable CSolvable
Wrapped libsolv C data type exposed as backdoor.
Definition: PoolMember.h:64
CRepo * getRepo(RepoIdType id_r) const
Definition: PoolImpl.h:168
const set_type & removed() const
Return the set of removed items.
Definition: SetTracker.h:145
bool validSolvable(const CSolvable &slv_r) const
a valid Solvable has a non NULL repo pointer.
Definition: PoolImpl.h:154
sat::detail::IdType id() const
Expert backdoor.
Definition: Capability.h:253
bool isSystemRepo(CRepo *repo_r) const
Definition: PoolImpl.h:99
PoolImpl()
Default ctor.
Definition: PoolImpl.cc:183
bool empty() const
Test for an empty path.
Definition: Pathname.h:113
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:125
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
const SerialNumber & serialIDs() const
Serial number changing whenever resusePoolIDs==true was used.
Definition: PoolImpl.h:70
const LocaleSet & getRequestedLocales() const
Current set of requested Locales.
Definition: PoolImpl.h:252
void setRepoInfo(RepoIdType id_r, const RepoInfo &info_r)
Also adjust repo priority and subpriority accordingly.
Definition: PoolImpl.cc:390
CPool * getPool() const
Definition: PoolImpl.h:164
const TrackedLocaleIds & trackedLocaleIds() const
Expanded _requestedLocalesTracker for solver.
Definition: PoolImpl.cc:480
SerialNumberWatcher _watcher
Watch serial number.
Definition: PoolImpl.h:323
void setRequestedLocales(const LocaleSet &locales_r)
User change (tracked).
Definition: PoolImpl.cc:448
const set_type & current() const
Return the current set.
Definition: SetTracker.h:139
bool validSolvable(SolvableIdType id_r) const
Definition: PoolImpl.h:157
sat::StringQueue _autoinstalled
Definition: PoolImpl.h:338
const set_type & added() const
Return the set of added items.
Definition: SetTracker.h:142
const LocaleSet & getRemovedRequestedLocales() const
Removed since last initRequestedLocales.
Definition: PoolImpl.h:248
base::SetTracker< IdStringSet > TrackedLocaleIds
Definition: PoolImpl.h:275
SerialNumber _serialIDs
Serial number of IDs - changes whenever resusePoolIDs==true - ResPool must also invalidate it&#39;s PoolI...
Definition: PoolImpl.h:321
SolvableIdType getNextId(SolvableIdType id_r) const
Get id of the next valid Solvable.
Definition: PoolImpl.h:193
void prepare() const
Update housekeeping data (e.g.
Definition: PoolImpl.cc:266
bool validSolvable(const CSolvable *slv_r) const
Definition: PoolImpl.h:160
Simple serial number provider.
Definition: SerialNumber.h:44
bool isMultiversion(const Solvable &solv_r) const
Definition: PoolImpl.cc:604
&#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:340
SerialNumber _serial
Serial number - changes with each Pool content change.
Definition: PoolImpl.h:319
Pathname rootDir() const
Get rootdir (for file conflicts check)
Definition: PoolImpl.h:106
scoped_ptr< MultiversionList > _multiversionListPtr
Definition: PoolImpl.h:335
Libsolv Id queue wrapper.
Definition: Queue.h:34
bool contains(value_type val_r) const
Return whether the Queue contais at lest one element with value val_r.
Definition: Queue.h:57
bool isOnSystemByUser(IdString ident_r) const
Definition: PoolImpl.h:304
void depSetDirty(const char *a1=0, const char *a2=0, const char *a3=0)
Invalidate housekeeping data (e.g.
Definition: PoolImpl.cc:255
scoped_ptr< std::set< std::string > > _requiredFilesystemsPtr
filesystems mentioned in /etc/sysconfig/storage
Definition: PoolImpl.h:341
void setTextLocale(const Locale &locale_r)
Definition: PoolImpl.cc:422
std::map< RepoIdType, RepoInfo > _repoinfos
Additional RepoInfo.
Definition: PoolImpl.h:325
A sat capability.
Definition: Capability.h:59
void initRequestedLocales(const LocaleSet &locales_r)
Start tracking changes based on this locales_r.
Definition: PoolImpl.cc:439
static const std::string & systemRepoAlias()
Reserved system repository alias .
Definition: PoolImpl.cc:94
CPool * _pool
sat-pool.
Definition: PoolImpl.h:317
CSolvable * getSolvable(SolvableIdType id_r) const
Return pointer to the sat-solvable or NULL if it is not valid.
Definition: PoolImpl.h:174
const LocaleSet & getAvailableLocales() const
All Locales occurring in any repo.
Definition: PoolImpl.cc:551
CPool * operator->()
Pointer style access forwarded to sat-pool.
Definition: PoolImpl.h:61
scoped_ptr< TrackedLocaleIds > _trackedLocaleIdsPtr
Definition: PoolImpl.h:329
const RepoInfo & repoInfo(RepoIdType id_r)
Definition: PoolImpl.h:205
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
bool isAvailableLocale(const Locale &locale_r) const
Definition: PoolImpl.h:268
int _addHelix(CRepo *repo_r, FILE *file_r)
Adding helix file to a repo.
Definition: PoolImpl.cc:331
CRepo * _createRepo(const std::string &name_r)
Creating a new repo named name_r.
Definition: PoolImpl.cc:297
std::unordered_set< Locale > LocaleSet
Definition: Locale.h:27
SolvableIdType getFirstId() const
Get id of the first valid Solvable.
Definition: PoolImpl.h:185
void setAutoInstalled(const StringQueue &autoInstalled_r)
Set ident list of all autoinstalled solvables.
Definition: PoolImpl.h:301
Solvable set wrapper to allow adding additional convenience iterators.
Definition: SolvableSet.h:35