libzypp: zypp/ng/sat/pool.h Source File

libzypp 17.38.14

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
17#include <zypp-core/base/NonCopyable.h>
18#include <zypp-core/Pathname.h>
19#include <zypp-core/base/Iterable.h>
20
21#include <zypp/ng/arch.h>
22#include <zypp/ng/sat/poolconstants.h>
23#include <zypp/ng/sat/components/poolcomponents.h>
24#include <zypp/ng/base/serialnumber.h>
25#include <zypp/ng/sat/repository.h>
26#include <zypp/ng/sat/solvable.h>
27#include <zypp/ng/sat/queue.h>
28#include <zypp/ng/sat/preparedpool.h>
29
30namespace zyppng::sat {
31
36 class Pool
37 {
38 friend class Repository;
39 friend class Solvable;
40
41 public:
42 using RepositoryIterable = zypp::Iterable<detail::RepositoryIterator>;
43 using SolvableIterable = zypp::Iterable<detail::SolvableIterator>;
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
73 PreparedPool prepare();
74
75
76 detail::size_type capacity() const;
77
81 void setDirty( PoolInvalidation invalidation, std::initializer_list<std::string_view> reasons );
82
87 void clear();
88
89 public:
92
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
114 void reposEraseAll()
115 { while ( ! reposEmpty() ) reposErase( (*repos().begin()).alias() ); }
116
118 bool reposEmpty() const;
119
121 detail::size_type reposSize() const;
122
124 RepositoryIterable repos() const;
125
127 Repository findSystemRepo() const;
128
130 Repository systemRepo();
131
132 bool isSystemRepo( detail::CRepo * repo_r ) const
133 { return repo_r && _pool->installed == repo_r; }
134
135 private:
136 detail::CRepo * _systemRepoPtr() const
137 { return _pool->installed; }
138
139
140 public:
143
144 bool solvablesEmpty() const;
145
147 detail::size_type solvablesSize() const;
148
150 SolvableIterable solvables() const;
152
153 public:
155 zypp::Pathname rootDir() const
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:
176
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; }
210
211 bool validSolvable( detail::SolvableIdType id_r ) const
212 { return id_r < unsigned(_pool->nsolvables) && validSolvable( _pool->solvables[id_r] ); }
213
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
217 detail::CPool * getPool() const
218 { return _pool; }
219
221 detail::CRepo * getRepo( detail::RepoIdType id_r ) const
222 { return id_r; }
223
227 detail::CSolvable * getSolvable( detail::SolvableIdType id_r ) const
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
242 detail::SolvableIdType getFirstId() const
243 { return getNextId( 1 ); }
244
250 detail::SolvableIdType getNextId( detail::SolvableIdType id_r ) const
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
262 PoolComponentSet & components() { return _componentsSet; }
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:
274 detail::CPool * _pool;
276 SerialNumber _serial;
278 SerialNumber _serialIDs;
280 SerialNumberWatcher _watcher;
282 PoolComponentSet _componentsSet;
283#ifndef NDEBUG
285 bool _preparing = false;
286#endif
287 };
288}
289
290#endif
Iterable.h
NonCopyable.h
Pathname.h
arch.h
zypp::Iterable
Definition Iterable.h:37
zypp::SerialNumberWatcher
Simple serial number watcher.
Definition SerialNumber.h:123
zypp::SerialNumber
Simple serial number provider.
Definition SerialNumber.h:45
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:48
zypp::filesystem::Pathname::c_str
const char * c_str() const
String representation.
Definition Pathname.h:113
zypp::filesystem::Pathname::empty
bool empty() const
Test for an empty path.
Definition Pathname.h:117
zyppng::sat::PoolComponentSet
Registry and dispatcher for all pool components.
Definition poolcomponents.h:138
zyppng::sat::Pool::~Pool
~Pool()
Dtor.
Definition pool.cc:97
zyppng::sat::Pool::serialIDs
const SerialNumber & serialIDs() const
Serial number changing whenever resusePoolIDs==true was used.
Definition pool.h:67
zyppng::sat::Pool::_postRepoAdd
void _postRepoAdd(detail::CRepo *repo_r)
Helper postprocessing the repo after adding solv or helix files.
Definition pool.cc:324
zyppng::sat::Pool::_preparing
bool _preparing
True while prepare() is running — setDirty() is illegal in this window.
Definition pool.h:285
zyppng::sat::Pool::_createRepo
detail::CRepo * _createRepo(const std::string &name_r)
Creating a new repo named name_r.
Definition pool.cc:266
zyppng::sat::Pool::reposErase
void reposErase(const std::string &alias_r)
Remove a Repository named alias_r.
Definition pool.h:107
zyppng::sat::Pool::solvables
SolvableIterable solvables() const
Iterator to the first Solvable.
Definition pool.cc:258
zyppng::sat::Pool::components
const PoolComponentSet & components() const
Definition pool.h:263
zyppng::sat::Pool::_deleteRepo
void _deleteRepo(detail::CRepo *repo_r)
Delete repo repo_r from pool.
Definition pool.cc:277
zyppng::sat::Pool::get
detail::CPool * get() const
Expert backdoor.
Definition pool.h:59
zyppng::sat::Pool::validSolvable
bool validSolvable(const detail::CSolvable &slv_r) const
a valid Solvable has a non NULL repo pointer.
Definition pool.h:208
zyppng::sat::Pool::_serialIDs
SerialNumber _serialIDs
Serial number of IDs - changes whenever resusePoolIDs==true - ResPool must also invalidate its PoolIt...
Definition pool.h:278
zyppng::sat::Pool::RepositoryIterable
zypp::Iterable< detail::RepositoryIterator > RepositoryIterable
Definition pool.h:42
zyppng::sat::Pool::_systemRepoPtr
detail::CRepo * _systemRepoPtr() const
Definition pool.h:136
zyppng::sat::Pool::systemRepo
Repository systemRepo()
Return the system repository, create it if missing.
Definition pool.cc:225
zyppng::sat::Pool::validSolvable
bool validSolvable(const detail::CSolvable *slv_r) const
Definition pool.h:214
zyppng::sat::Pool::_addTesttags
int _addTesttags(detail::CRepo *repo_r, FILE *file_r)
Adding testtags file to a repo.
Definition pool.cc:309
zyppng::sat::Pool::SolvableIterable
zypp::Iterable< detail::SolvableIterator > SolvableIterable
Definition pool.h:43
zyppng::sat::Pool::serial
const SerialNumber & serial() const
Serial number changing whenever the content changes.
Definition pool.h:63
zyppng::sat::Pool::_watcher
SerialNumberWatcher _watcher
Watch serial number.
Definition pool.h:280
zyppng::sat::Pool::clear
void clear()
Reset the pool by removing all repositories and solvables.
Definition pool.cc:143
zyppng::sat::Pool::solvablesSize
detail::size_type solvablesSize() const
Number of solvables in Pool.
Definition pool.cc:245
zyppng::sat::Pool::_addHelix
int _addHelix(detail::CRepo *repo_r, FILE *file_r)
Adding helix file to a repo.
Definition pool.cc:300
zyppng::sat::Pool::rootDir
void rootDir(const zypp::Pathname &root_r)
Set rootdir (for file conflicts check).
Definition pool.h:162
zyppng::sat::Pool::_componentsSet
PoolComponentSet _componentsSet
Component set managing modular pool logic.
Definition pool.h:282
zyppng::sat::Pool::getFirstId
detail::SolvableIdType getFirstId() const
Get id of the first valid Solvable.
Definition pool.h:242
zyppng::sat::Pool::getRepo
detail::CRepo * getRepo(detail::RepoIdType id_r) const
Definition pool.h:221
zyppng::sat::Pool::getSolvable
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
zyppng::sat::Pool::Pool
Pool()
Default ctor.
Definition pool.cc:89
zyppng::sat::Pool::reposFind
Repository reposFind(const std::string &alias_r) const
Find a Repository named alias_r.
Definition pool.cc:184
zyppng::sat::Pool::solvablesEmpty
bool solvablesEmpty() const
Whether Pool contains solvables.
Definition pool.cc:232
zyppng::sat::Pool::_addSolv
int _addSolv(detail::CRepo *repo_r, FILE *file_r)
Adding solv file to a repo.
Definition pool.cc:291
zyppng::sat::Pool::validSolvable
bool validSolvable(detail::SolvableIdType id_r) const
Definition pool.h:211
zyppng::sat::Pool::setDirty
void setDirty(PoolInvalidation invalidation, std::initializer_list< std::string_view > reasons)
Invalidate everything.
Definition pool.cc:152
zyppng::sat::Pool::reposEraseAll
void reposEraseAll()
Remove all repos from the pool.
Definition pool.h:114
zyppng::sat::Pool::getPool
detail::CPool * getPool() const
Definition pool.h:217
zyppng::sat::Pool::_pool
detail::CPool * _pool
sat-pool.
Definition pool.h:274
zyppng::sat::Pool::findSystemRepo
Repository findSystemRepo() const
Return the system repository if it is on the pool.
Definition pool.cc:222
zyppng::sat::Pool::components
PoolComponentSet & components()
Get rootdir (for file conflicts check).
Definition pool.h:262
zyppng::sat::Pool::reposEmpty
bool reposEmpty() const
Whether Pool contains repos.
Definition pool.cc:202
zyppng::sat::Pool::operator=
Pool & operator=(const Pool &)=delete
zyppng::sat::Pool::reposSize
detail::size_type reposSize() const
Number of repos in Pool.
Definition pool.cc:205
zyppng::sat::Pool::Repository
friend class Repository
Definition pool.h:38
zyppng::sat::Pool::prepare
PreparedPool prepare()
Update housekeeping data (e.g.
Definition pool.cc:106
zyppng::sat::Pool::Pool
Pool(Pool &&)=delete
zyppng::sat::Pool::Solvable
friend class Solvable
Definition pool.h:39
zyppng::sat::Pool::component
T & component()
Definition pool.h:266
zyppng::sat::Pool::getNextId
detail::SolvableIdType getNextId(detail::SolvableIdType id_r) const
Get id of the next valid Solvable.
Definition pool.h:250
zyppng::sat::Pool::reposInsert
Repository reposInsert(const std::string &alias_r)
Return a Repository named alias_r.
Definition pool.cc:194
zyppng::sat::Pool::_serial
SerialNumber _serial
Serial number - changes with each Pool content change.
Definition pool.h:276
zyppng::sat::Pool::operator=
Pool & operator=(Pool &&)=delete
zyppng::sat::Pool::isSystemRepo
bool isSystemRepo(detail::CRepo *repo_r) const
Definition pool.h:132
zyppng::sat::Pool::Pool
Pool(const Pool &)=delete
zyppng::sat::Pool::rootDir
zypp::Pathname rootDir() const
Definition pool.h:155
zyppng::sat::Pool::repos
RepositoryIterable repos() const
Iteratable to the repositories.
Definition pool.cc:208
zyppng::sat::Pool::systemRepoAlias
static const std::string & systemRepoAlias()
Reserved system repository alias @System .
Definition pool.cc:178
zyppng::sat::Pool::capacity
detail::size_type capacity() const
Definition pool.cc:103
zyppng::sat::Pool::findComponent
const T * findComponent() const
Definition pool.h:269
zyppng::sat::Pool::parserpmrichdep
detail::IdType parserpmrichdep(const char *capstr_r)
libsolv capability parser
Definition pool.h:236
zyppng::sat::Pool::_addSolvables
detail::SolvableIdType _addSolvables(detail::CRepo *repo_r, unsigned count_r)
Adding Solvables to a repo.
Definition pool.cc:318
zyppng::sat::PreparedPool
A move-only, non-owning view of a Pool that guarantees the whatprovides index is valid.
Definition preparedpool.h:51
zyppng::sat::Repository
Definition repository.h:51
zyppng::sat::Repository::eraseFromPool
void eraseFromPool()
Query class for Repository related products.
Definition repository.cc:190
zyppng::sat::detail::CSolvable
zypp::sat::detail::CSolvable CSolvable
Definition poolconstants.h:39
zyppng::sat::detail::RepoIdType
zypp::sat::detail::RepoIdType RepoIdType
Definition poolconstants.h:45
zyppng::sat::detail::CPool
zypp::sat::detail::CPool CPool
Definition poolconstants.h:36
zyppng::sat::detail::SolvableIdType
zypp::sat::detail::SolvableIdType SolvableIdType
Definition poolconstants.h:44
zyppng::sat::detail::noSolvableId
static const SolvableIdType noSolvableId(0)
Id to denote Solvable::noSolvable.
zyppng::sat::detail::IdType
zypp::sat::detail::IdType IdType
Definition poolconstants.h:43
zyppng::sat::detail::CRepo
zypp::sat::detail::CRepo CRepo
Definition poolconstants.h:38
zyppng::sat::detail::size_type
SolvableIdType size_type
Definition poolconstants.h:59
zyppng::sat
This file contains private API, this might break at any time between releases.
Definition capabilities.h:22
zyppng::sat::PoolInvalidation
PoolInvalidation
Defines the scope of an invalidation request for the Pool.
Definition poolconstants.h:66
poolcomponents.h
poolconstants.h
preparedpool.h
queue.h
repository.h
solvable.h
serialnumber.h