libzypp  14.48.5
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/Tr1hash.h"
25 #include "zypp/base/NonCopyable.h"
26 #include "zypp/base/SerialNumber.h"
28 #include "zypp/sat/Queue.h"
29 #include "zypp/RepoInfo.h"
30 #include "zypp/Locale.h"
31 #include "zypp/Capability.h"
32 #include "zypp/IdString.h"
33 
35 namespace zypp
36 {
37  namespace sat
39  {
40  namespace detail
42  {
43 
45  //
46  // CLASS NAME : PoolImpl
47  //
49  class PoolImpl : private base::NonCopyable
50  {
51  public:
53  PoolImpl();
54 
56  ~PoolImpl();
57 
60  { return _pool; }
61 
62  public:
64  const SerialNumber & serial() const
65  { return _serial; }
66 
70  void prepare() const;
72  void prepareForSolving() const;
73 
74  private:
78  void setDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
79 
82  void depSetDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
83 
85  static detail::IdType nsCallback( CPool *, void * data, detail::IdType lhs, detail::IdType rhs );
86 
87  public:
89  static const std::string & systemRepoAlias();
90 
91  bool isSystemRepo( CRepo * repo_r ) const
92  { return repo_r && _pool->installed == repo_r; }
93 
94  CRepo * systemRepo() const
95  { return _pool->installed; }
96 
98  Pathname rootDir() const
99  {
100  const char * rd = ::pool_get_rootdir( _pool );
101  return( rd ? rd : "/" );
102  }
103 
105  void rootDir( const Pathname & root_r )
106  {
107  if ( root_r.empty() || root_r == "/" )
108  ::pool_set_rootdir( _pool, nullptr );
109  else
110  ::pool_set_rootdir( _pool, root_r.c_str() );
111  }
112 
113  public:
120  CRepo * _createRepo( const std::string & name_r );
121 
123  void _deleteRepo( CRepo * repo_r );
124 
129  int _addSolv( CRepo * repo_r, FILE * file_r );
130 
135  int _addHelix( CRepo * repo_r, FILE * file_r );
136 
138  detail::SolvableIdType _addSolvables( CRepo * repo_r, unsigned count_r );
140 
142  void _postRepoAdd( CRepo * repo_r );
143 
144  public:
146  bool validSolvable( const CSolvable & slv_r ) const
147  { return slv_r.repo; }
149  bool validSolvable( SolvableIdType id_r ) const
150  { return id_r < unsigned(_pool->nsolvables) && validSolvable( _pool->solvables[id_r] ); }
152  bool validSolvable( const CSolvable * slv_r ) const
153  { return _pool->solvables <= slv_r && slv_r <= _pool->solvables+_pool->nsolvables && validSolvable( *slv_r ); }
154 
155  public:
156  CPool * getPool() const
157  { return _pool; }
158 
160  CRepo * getRepo( RepoIdType id_r ) const
161  { return id_r; }
162 
167  {
168  if ( validSolvable( id_r ) )
169  return &_pool->solvables[id_r];
170  return 0;
171  }
172 
173  public:
178  { return getNextId( 1 ); }
179 
186  {
187  for( ++id_r; id_r < unsigned(_pool->nsolvables); ++id_r )
188  {
189  if ( validSolvable( _pool->solvables[id_r] ) )
190  return id_r;
191  }
192  return noSolvableId;
193  }
194 
195  public:
197  const RepoInfo & repoInfo( RepoIdType id_r )
198  { return _repoinfos[id_r]; }
200  void setRepoInfo( RepoIdType id_r, const RepoInfo & info_r );
203  { _repoinfos.erase( id_r ); }
204 
205  public:
209  const sat::detail::IdType whatProvidesData( unsigned offset_r )
210  { return _pool->whatprovidesdata[offset_r]; }
211 
215  unsigned whatProvides( Capability cap_r )
216  { prepare(); return ::pool_whatprovides( _pool, cap_r.id() ); }
217 
218  public:
221  void setTextLocale( const Locale & locale_r );
222  void setRequestedLocales( const LocaleSet & locales_r );
223  bool addRequestedLocale( const Locale & locale_r );
224  bool eraseRequestedLocale( const Locale & locale_r );
225 
227  { return _requestedLocales; }
228 
229  bool isRequestedLocale( const Locale & locale_r ) const
230  {
231  LocaleSet::const_iterator it( _requestedLocales.find( locale_r ) );
232  return it != _requestedLocales.end();
233  }
234 
235  const LocaleSet & getAvailableLocales() const;
236 
237  bool isAvailableLocale( const Locale & locale_r ) const
238  {
239  const LocaleSet & avl( getAvailableLocales() );
240  LocaleSet::const_iterator it( avl.find( locale_r ) );
241  return it != avl.end();
242  }
244 
245  public:
249 
251  {
252  if ( ! _multiversionListPtr )
254  return *_multiversionListPtr;
255  }
256 
257  bool isMultiversion( IdString ident_r ) const
258  {
259  const MultiversionList & l( multiversionList() );
260  return l.find( ident_r ) != l.end();
261  }
263 
264  public:
269  { return _autoinstalled; }
270 
272  void setAutoInstalled( const StringQueue & autoInstalled_r )
273  { _autoinstalled = autoInstalled_r; }
274 
275  bool isOnSystemByUser( IdString ident_r ) const
276  { return !_autoinstalled.contains( ident_r.id() ); }
278 
279  public:
281  const std::set<std::string> & requiredFilesystems() const;
282 
283  private:
291  std::map<RepoIdType,RepoInfo> _repoinfos;
292 
295  mutable scoped_ptr<LocaleSet> _availableLocalesPtr;
296  mutable std::tr1::unordered_set<IdString> _locale2Solver;
297 
299  void multiversionListInit() const;
300  mutable scoped_ptr<MultiversionList> _multiversionListPtr;
301 
304 
306  mutable scoped_ptr<std::set<std::string> > _requiredFilesystemsPtr;
307  };
309 
311  } // namespace detail
314  } // namespace sat
317 } // namespace zypp
319 #define POOL_SETDIRTY
320 #endif // ZYPP_SAT_DETAIL_POOLIMPL_H
static const SolvableIdType noSolvableId(0)
Id to denote Solvable::noSolvable.
Simple serial number watcher.
Definition: SerialNumber.h:122
int IdType
Generic Id type.
Definition: PoolMember.h:130
Pathname rootDir() const
Get rootdir (for file conflicts check)
Definition: PoolImpl.h:98
const sat::detail::IdType whatProvidesData(unsigned offset_r)
Returns the id stored at offset_r in the internal whatprovidesdata array.
Definition: PoolImpl.h:209
bool eraseRequestedLocale(const Locale &locale_r)
Definition: PoolImpl.cc:454
scoped_ptr< LocaleSet > _availableLocalesPtr
Definition: PoolImpl.h:295
int _addSolv(CRepo *repo_r, FILE *file_r)
Adding solv file to a repo.
Definition: PoolImpl.cc:305
IdType id() const
Expert backdoor.
Definition: IdString.h:103
::_Repo CRepo
Wrapped libsolv C data type exposed as backdoor.
Definition: PoolMember.h:88
bool addRequestedLocale(const Locale &locale_r)
Definition: PoolImpl.cc:443
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:215
void prepareForSolving() const
prepare plus some expensive checks done before solving only.
Definition: PoolImpl.cc:272
void _deleteRepo(CRepo *repo_r)
Creating a new repo named name_r.
Definition: PoolImpl.cc:296
CPool * getPool() const
Definition: PoolImpl.h:156
::_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:105
unsigned SolvableIdType
Id type to connect Solvable and sat-solvable.
Definition: PoolMember.h:146
bool validSolvable(const CSolvable &slv_r) const
a valid Solvable has a non NULL repo pointer.
Definition: PoolImpl.h:146
void eraseRepoInfo(RepoIdType id_r)
Definition: PoolImpl.h:202
What is known about a repository.
Definition: RepoInfo.h:72
CRepo * RepoIdType
Id type to connect Repo and sat-repo.
Definition: PoolMember.h:154
const std::set< std::string > & requiredFilesystems() const
accessor for etc/sysconfig/storage reading file on demand
Definition: PoolImpl.cc:553
bool isAvailableLocale(const Locale &locale_r) const
Definition: PoolImpl.h:237
Access to the sat-pools string space.
Definition: IdString.h:39
bool validSolvable(SolvableIdType id_r) const
Definition: PoolImpl.h:149
detail::SolvableIdType _addSolvables(CRepo *repo_r, unsigned count_r)
Adding Solvables to a repo.
Definition: PoolImpl.cc:367
::_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:166
const LocaleSet & getRequestedLocales() const
Definition: PoolImpl.h:226
const SerialNumber & serial() const
Serial number changing whenever the content changes.
Definition: PoolImpl.h:64
void multiversionListInit() const
Definition: PoolImpl.cc:520
CRepo * getRepo(RepoIdType id_r) const
Definition: PoolImpl.h:160
const LocaleSet & getAvailableLocales() const
Definition: PoolImpl.cc:495
PoolImpl()
Default ctor.
Definition: PoolImpl.cc:178
SolvableIdType getNextId(SolvableIdType id_r) const
Get id of the next valid Solvable.
Definition: PoolImpl.h:185
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:115
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
bool isMultiversion(IdString ident_r) const
Definition: PoolImpl.h:257
void setRepoInfo(RepoIdType id_r, const RepoInfo &info_r)
Also adjust repo priority and subpriority accordingly.
Definition: PoolImpl.cc:373
SerialNumberWatcher _watcher
Watch serial number.
Definition: PoolImpl.h:289
void setRequestedLocales(const LocaleSet &locales_r)
Definition: PoolImpl.cc:435
bool isOnSystemByUser(IdString ident_r) const
Definition: PoolImpl.h:275
std::tr1::unordered_set< IdString > _locale2Solver
Definition: PoolImpl.h:296
sat::StringQueue _autoinstalled
Definition: PoolImpl.h:303
std::tr1::unordered_set< Locale > LocaleSet
Definition: Locale.h:28
StringQueue autoInstalled() const
Get ident list of all autoinstalled solvables.
Definition: PoolImpl.h:268
CRepo * systemRepo() const
Definition: PoolImpl.h:94
Simple serial number provider.
Definition: SerialNumber.h:44
void _postRepoAdd(CRepo *repo_r)
Helper postprocessing the repo after adding solv or helix files.
Definition: PoolImpl.cc:323
SerialNumber _serial
Serial number.
Definition: PoolImpl.h:287
scoped_ptr< MultiversionList > _multiversionListPtr
Definition: PoolImpl.h:300
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:239
SolvableIdType getFirstId() const
Get id of the first valid Solvable.
Definition: PoolImpl.h:177
scoped_ptr< std::set< std::string > > _requiredFilesystemsPtr
filesystems mentioned in /etc/sysconfig/storage
Definition: PoolImpl.h:306
void setTextLocale(const Locale &locale_r)
Definition: PoolImpl.cc:418
std::map< RepoIdType, RepoInfo > _repoinfos
Additional RepoInfo.
Definition: PoolImpl.h:291
bool validSolvable(const CSolvable *slv_r) const
Definition: PoolImpl.h:152
A sat capability.
Definition: Capability.h:59
void prepare() const
Update housekeeping data (e.g.
Definition: PoolImpl.cc:250
bool isSystemRepo(CRepo *repo_r) const
Definition: PoolImpl.h:91
static const std::string & systemRepoAlias()
Reserved system repository alias .
Definition: PoolImpl.cc:89
CPool * _pool
sat-pool.
Definition: PoolImpl.h:285
CPool * operator->()
Pointer style access forwarded to sat-pool.
Definition: PoolImpl.h:59
IdStringSet MultiversionList
Definition: PoolImpl.h:248
bool isRequestedLocale(const Locale &locale_r) const
Definition: PoolImpl.h:229
const RepoInfo & repoInfo(RepoIdType id_r)
Definition: PoolImpl.h:197
const MultiversionList & multiversionList() const
Definition: PoolImpl.h:250
int _addHelix(CRepo *repo_r, FILE *file_r)
Adding helix file to a repo.
Definition: PoolImpl.cc:314
CRepo * _createRepo(const std::string &name_r)
Creating a new repo named name_r.
Definition: PoolImpl.cc:287
std::tr1::unordered_set< IdString > IdStringSet
Definition: IdString.h:24
void setAutoInstalled(const StringQueue &autoInstalled_r)
Set ident list of all autoinstalled solvables.
Definition: PoolImpl.h:272
sat::detail::IdType id() const
Expert backdoor.
Definition: Capability.h:244
bool contains(value_type val_r) const
Return whether the Queue contais at lest one element with value val_r.
Definition: Queue.h:57