libzypp  17.38.7
pool.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 ----------------------------------------------------------------------/
9 *
10 * This file contains private API, this might break at any time between releases.
11 * You have been warned!
12 *
13 */
14 #ifndef ZYPPNG_SAT_POOL_H_INCLUDED
15 #define ZYPPNG_SAT_POOL_H_INCLUDED
16 
18 #include <zypp-core/Pathname.h>
20 
21 #include <zypp/ng/arch.h>
25 #include <zypp/ng/sat/repository.h>
26 #include <zypp/ng/sat/solvable.h>
27 #include <zypp/ng/sat/queue.h>
29 
30 namespace zyppng::sat {
31 
36  class Pool
37  {
38  friend class Repository;
39  friend class Solvable;
40 
41  public:
44 
45  public:
46 
48  Pool();
49 
50  Pool(const Pool &) = delete;
51  Pool(Pool &&) = delete;
52  Pool &operator=(const Pool &) = delete;
53  Pool &operator=(Pool &&) = delete;
54 
56  ~Pool();
57 
59  detail::CPool * get() const
60  { return _pool; }
61 
63  const SerialNumber & serial() const
64  { return _serial; }
65 
67  const SerialNumber & serialIDs() const
68  { return _serialIDs; }
69 
74 
75 
77 
81  void setDirty( PoolInvalidation invalidation, std::initializer_list<std::string_view> reasons );
82 
87  void clear();
88 
89  public:
93  static const std::string & systemRepoAlias();
94 
98  Repository reposFind( const std::string & alias_r ) const;
99 
104  Repository reposInsert( const std::string & alias_r );
105 
107  void reposErase( const std::string & alias_r )
108  { reposFind( alias_r ).eraseFromPool(); }
109 
115  { while ( ! reposEmpty() ) reposErase( (*repos().begin()).alias() ); }
116 
118  bool reposEmpty() const;
119 
122 
124  RepositoryIterable repos() const;
125 
127  Repository findSystemRepo() const;
128 
131 
132  bool isSystemRepo( detail::CRepo * repo_r ) const
133  { return repo_r && _pool->installed == repo_r; }
134 
135  private:
137  { return _pool->installed; }
139 
140  public:
144  bool solvablesEmpty() const;
145 
148 
150  SolvableIterable solvables() const;
152 
153  public:
156  {
157  const char * rd = ::pool_get_rootdir( _pool );
158  return( rd ? rd : "/" );
159  }
160 
162  void rootDir( const zypp::Pathname & root_r )
163  {
164  if ( root_r.empty() || root_r == "/" )
165  ::pool_set_rootdir( _pool, nullptr );
166  else
167  ::pool_set_rootdir( _pool, root_r.c_str() );
168  }
169 
170  private:
177  detail::CRepo * _createRepo( const std::string & name_r );
178 
180  void _deleteRepo( detail::CRepo * repo_r );
181 
186  int _addSolv( detail::CRepo * repo_r, FILE * file_r );
187 
192  int _addHelix( detail::CRepo * repo_r, FILE * file_r );
193 
198  int _addTesttags( detail::CRepo * repo_r, FILE * file_r );
199 
201  detail::SolvableIdType _addSolvables( detail::CRepo * repo_r, unsigned count_r );
203 
205  void _postRepoAdd( detail::CRepo * repo_r );
206 
208  bool validSolvable( const detail::CSolvable & slv_r ) const
209  { return slv_r.repo; }
212  { return id_r < unsigned(_pool->nsolvables) && validSolvable( _pool->solvables[id_r] ); }
214  bool validSolvable( const detail::CSolvable * slv_r ) const
215  { return _pool->solvables <= slv_r && slv_r <= _pool->solvables+_pool->nsolvables && validSolvable( *slv_r ); }
216 
218  { return _pool; }
219 
222  { return id_r; }
223 
228  {
229  if ( validSolvable( id_r ) )
230  return &_pool->solvables[id_r];
231  return 0;
232  }
233 
234  public:
236  detail::IdType parserpmrichdep( const char * capstr_r )
237  { return ::pool_parserpmrichdep( _pool, capstr_r ); }
238 
243  { return getNextId( 1 ); }
244 
251  {
252  for( ++id_r; id_r < unsigned(_pool->nsolvables); ++id_r )
253  {
254  if ( validSolvable( _pool->solvables[id_r] ) )
255  return id_r;
256  }
257  return detail::noSolvableId;
258  }
259 
263  const PoolComponentSet & components() const { return _componentsSet; }
264 
265  template <typename T>
266  T & component() { return _componentsSet.assertComponent<T>(); }
267 
268  template <typename T>
269  const T * findComponent() const { return _componentsSet.findComponent<T>(); }
271 
272  private:
283 #ifndef NDEBUG
284 
285  bool _preparing = false;
286 #endif
287  };
288 }
289 
290 #endif
static const SolvableIdType noSolvableId(0)
Id to denote Solvable::noSolvable.
detail::SolvableIdType getNextId(detail::SolvableIdType id_r) const
Get id of the next valid Solvable.
Definition: pool.h:250
SerialNumberWatcher _watcher
Watch serial number.
Definition: pool.h:280
RepositoryIterable repos() const
Iteratable to the repositories.
Definition: pool.cc:208
detail::size_type solvablesSize() const
Number of solvables in Pool.
Definition: pool.cc:245
Simple serial number watcher.
Definition: SerialNumber.h:122
detail::size_type reposSize() const
Number of repos in Pool.
Definition: pool.cc:205
detail::CSolvable * getSolvable(detail::SolvableIdType id_r) const
Return pointer to the sat-solvable or NULL if it is not valid.
Definition: pool.h:227
A Solvable object within the sat Pool.
Definition: solvable.h:64
int _addTesttags(detail::CRepo *repo_r, FILE *file_r)
Adding testtags file to a repo.
Definition: pool.cc:309
bool _preparing
True while prepare() is running — setDirty() is illegal in this window.
Definition: pool.h:285
const PoolComponentSet & components() const
Definition: pool.h:263
zypp::sat::detail::CSolvable CSolvable
Definition: poolconstants.h:39
zypp::Iterable< detail::SolvableIterator > SolvableIterable
Definition: pool.h:43
const SerialNumber & serialIDs() const
Serial number changing whenever resusePoolIDs==true was used.
Definition: pool.h:67
void reposEraseAll()
Remove all repos from the pool.
Definition: pool.h:114
bool isSystemRepo(detail::CRepo *repo_r) const
Definition: pool.h:132
const char * c_str() const
String representation.
Definition: Pathname.h:113
detail::CRepo * getRepo(detail::RepoIdType id_r) const
Definition: pool.h:221
Repository findSystemRepo() const
Return the system repository if it is on the pool.
Definition: pool.cc:222
void _postRepoAdd(detail::CRepo *repo_r)
Helper postprocessing the repo after adding solv or helix files.
Definition: pool.cc:324
const T * findComponent() const
Orchestrator for a libsolv pool instance.
Definition: pool.h:36
Pool & operator=(const Pool &)=delete
PreparedPool prepare()
Update housekeeping data (e.g.
Definition: pool.cc:106
zypp::sat::detail::CPool CPool
Definition: poolconstants.h:36
void rootDir(const zypp::Pathname &root_r)
Set rootdir (for file conflicts check)
Definition: pool.h:162
zypp::Pathname rootDir() const
Definition: pool.h:155
zypp::sat::detail::SolvableIdType SolvableIdType
Definition: poolconstants.h:44
detail::SolvableIdType _addSolvables(detail::CRepo *repo_r, unsigned count_r)
Adding Solvables to a repo.
Definition: pool.cc:318
PoolComponentSet _componentsSet
Component set managing modular pool logic.
Definition: pool.h:282
A move-only, non-owning view of a Pool that guarantees the whatprovides index is valid.
Definition: preparedpool.h:50
bool solvablesEmpty() const
Whether Pool contains solvables.
Definition: pool.cc:232
SerialNumber _serialIDs
Serial number of IDs - changes whenever resusePoolIDs==true - ResPool must also invalidate its PoolIt...
Definition: pool.h:278
bool empty() const
Test for an empty path.
Definition: Pathname.h:117
Repository systemRepo()
Return the system repository, create it if missing.
Definition: pool.cc:225
Registry and dispatcher for all pool components.
This file contains private API, this might break at any time between releases.
Definition: capabilities.h:22
detail::CPool * getPool() const
Definition: pool.h:217
const T * findComponent() const
Definition: pool.h:269
detail::CPool * _pool
sat-pool.
Definition: pool.h:274
detail::CRepo * _systemRepoPtr() const
Definition: pool.h:136
T & component()
Definition: pool.h:266
void setDirty(PoolInvalidation invalidation, std::initializer_list< std::string_view > reasons)
Invalidate everything.
Definition: pool.cc:152
bool validSolvable(const detail::CSolvable &slv_r) const
a valid Solvable has a non NULL repo pointer.
Definition: pool.h:208
zypp::Iterable< detail::RepositoryIterator > RepositoryIterable
Definition: pool.h:42
SolvableIdType size_type
Definition: poolconstants.h:59
zypp::sat::detail::IdType IdType
Definition: poolconstants.h:43
Simple serial number provider.
Definition: SerialNumber.h:44
void eraseFromPool()
Query class for Repository related products.
Definition: repository.cc:191
zypp::sat::detail::CRepo CRepo
Definition: poolconstants.h:38
constexpr std::string_view FILE("file")
PoolComponentSet & components()
Get rootdir (for file conflicts check)
Definition: pool.h:262
detail::CRepo * _createRepo(const std::string &name_r)
Creating a new repo named name_r.
Definition: pool.cc:266
bool reposEmpty() const
Whether Pool contains repos.
Definition: pool.cc:202
PoolInvalidation
Defines the scope of an invalidation request for the Pool.
Definition: poolconstants.h:66
~Pool()
Dtor.
Definition: pool.cc:97
SerialNumber _serial
Serial number - changes with each Pool content change.
Definition: pool.h:276
int _addHelix(detail::CRepo *repo_r, FILE *file_r)
Adding helix file to a repo.
Definition: pool.cc:300
Repository reposFind(const std::string &alias_r) const
Find a Repository named alias_r.
Definition: pool.cc:184
SolvableIterable solvables() const
Iterator to the first Solvable.
Definition: pool.cc:258
detail::size_type capacity() const
Definition: pool.cc:103
const SerialNumber & serial() const
Serial number changing whenever the content changes.
Definition: pool.h:63
T & assertComponent(std::unique_ptr< T > &&compPtr={})
detail::IdType parserpmrichdep(const char *capstr_r)
libsolv capability parser
Definition: pool.h:236
void _deleteRepo(detail::CRepo *repo_r)
Delete repo repo_r from pool.
Definition: pool.cc:277
detail::SolvableIdType getFirstId() const
Get id of the first valid Solvable.
Definition: pool.h:242
bool validSolvable(const detail::CSolvable *slv_r) const
Definition: pool.h:214
Repository reposInsert(const std::string &alias_r)
Return a Repository named alias_r.
Definition: pool.cc:194
int _addSolv(detail::CRepo *repo_r, FILE *file_r)
Adding solv file to a repo.
Definition: pool.cc:291
void clear()
Reset the pool by removing all repositories and solvables.
Definition: pool.cc:143
Pool()
Default ctor.
Definition: pool.cc:89
static const std::string & systemRepoAlias()
Reserved system repository alias .
Definition: pool.cc:178
void reposErase(const std::string &alias_r)
Remove a Repository named alias_r.
Definition: pool.h:107
bool validSolvable(detail::SolvableIdType id_r) const
Definition: pool.h:211
zypp::sat::detail::RepoIdType RepoIdType
Definition: poolconstants.h:45