libzypp 17.38.6
repository.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#include <climits>
13#include <iostream>
14#include <utility>
15
19
21#include <zypp-core/Pathname.h>
22
24#include <zypp/ng/sat/pool.h>
27
28using std::endl;
29
31namespace zyppng
32{
33 namespace sat
34 {
35 namespace detail {
36 template<> Pool & poolFromType( Repository & r )
37 {
38 detail::CRepo * repo = r.get();
39 ZYPP_PRECONDITION( repo && repo->pool && repo->pool->appdata );
40 return *static_cast<Pool *>( repo->pool->appdata );
41 }
42 template<> const Pool & poolFromType( const Repository & r )
43 {
44 const detail::CRepo * repo = r.get();
45 ZYPP_PRECONDITION( repo && repo->pool && repo->pool->appdata );
46 return *static_cast<const Pool *>( repo->pool->appdata );
47 }
48 }
49
51
52 const std::string & Repository::systemRepoAlias()
53 { return Pool::systemRepoAlias(); }
54
56
58 { return _id; }
59
60#define NO_REPOSITORY_RETURN( VAL ) \
61 detail::CRepo * _repo( get() ); \
62 if ( ! _repo ) return VAL
63
64#define NO_REPOSITORY_THROW( VAL ) \
65 detail::CRepo * _repo( get() ); \
66 if ( ! _repo ) ZYPP_THROW( VAL )
67
69 {
70 NO_REPOSITORY_RETURN( false );
71 return pool().isSystemRepo( _repo );
72 }
73
74 std::string Repository::alias() const
75 {
76 NO_REPOSITORY_RETURN( std::string() );
77 if ( ! _repo->name )
78 return std::string();
79 return _repo->name;
80 }
81
83 {
84 NO_REPOSITORY_RETURN( INT_MIN );
85 return _repo->priority;
86 }
87
89 {
90 NO_REPOSITORY_RETURN( INT_MIN );
91 return _repo->subpriority;
92 }
93
100
107
109 {
110 NO_REPOSITORY_RETURN( false );
111
113 for_( it, q.begin(), q.end() )
114 if ( it.asString() == id_r )
115 return true;
116
117 return false;
118 }
119
127
129 {
131 zypp::Date generated = generatedTimestamp();
132 if ( ! generated )
133 return 0; // do not calculate over a missing generated timestamp
134
136 if ( q.empty() )
137 return 0;
138
139 return generated + zypp::Date(q.begin().asUnsigned());
140
141 }
142
144 {
145 NO_REPOSITORY_RETURN( false );
146 // system repo is not mirrored
147 if ( isSystemRepo() )
148 return false;
149
151
152 // if no data, don't suggest
153 if ( ! suggested )
154 return false;
155
156 return suggested < zypp::Date::now();
157 }
158
160 {
161 NO_REPOSITORY_RETURN( true );
162 return !_repo->nsolvables;
163 }
164
166 {
168 return _repo->nsolvables;
169 }
170
172 {
173 NO_REPOSITORY_RETURN( zypp::make_filter_iterator( detail::ByRepository( *this ),
176 return zypp::make_filter_iterator( detail::ByRepository( *this ),
177 sat::detail::SolvableIterator(_repo->start),
178 sat::detail::SolvableIterator(_repo->end) );
179 }
180
182 {
183 NO_REPOSITORY_RETURN( zypp::make_filter_iterator( detail::ByRepository( *this ),
186 return zypp::make_filter_iterator(detail::ByRepository( *this ),
188 sat::detail::SolvableIterator(_repo->end) );
189 }
190
192 {
194 //MIL << *this << " removed from pool" << endl;
195 pool()._deleteRepo( _repo );
197 }
198
200 {
202 auto iterable = pool().repos();
203 for( auto it = iterable.begin(); it != iterable.end(); ++it )
204 {
205 if ( *it == *this )
206 {
207 if ( ++it != iterable.end() )
208 return *it;
209 break;
210 }
211 }
212 return noRepository;
213 }
214
215 void Repository::addSolv( const zypp::Pathname & file_r )
216 {
217 NO_REPOSITORY_THROW( zypp::Exception( "Can't add solvables to norepo." ) );
218
219 zypp::AutoDispose<FILE*> file( ::fopen( file_r.c_str(), "re" ), ::fclose );
220 if ( file == NULL )
221 {
222 file.resetDispose();
223 ZYPP_THROW( zypp::Exception( "Can't open solv-file: "+file_r.asString() ) );
224 }
225
226 if ( pool()._addSolv( _repo, file ) != 0 )
227 {
228 ZYPP_THROW( zypp::Exception( "Error reading solv-file: "+file_r.asString() ) );
229 }
230
231 //MIL << *this << " after adding " << file_r << endl;
232 }
233
235 {
236 NO_REPOSITORY_THROW( zypp::Exception( "Can't add solvables to norepo." ) );
237
238 std::string command( file_r.extension() == ".gz" ? "zcat " : "cat " );
239 command += "'";
240 command += file_r.asString();
241 command += "'";
242
243 zypp::AutoDispose<FILE*> file( ::popen( command.c_str(), "re" ), ::pclose );
244 if ( file == NULL )
245 {
246 file.resetDispose();
247 ZYPP_THROW( zypp::Exception( "Can't open helix-file: "+file_r.asString() ) );
248 }
249
250 if ( pool()._addHelix( _repo, file ) != 0 )
251 {
252 ZYPP_THROW( zypp::Exception( "Error reading helix-file: "+file_r.asString() ) );
253 }
254
255 //MIL << *this << " after adding " << file_r << endl;
256 }
257
259 {
260 NO_REPOSITORY_THROW( zypp::Exception( "Can't add solvables to norepo." ) );
261
262 std::string command( file_r.extension() == ".gz" ? "zcat " : "cat " );
263 command += "'";
264 command += file_r.asString();
265 command += "'";
266
267 zypp::AutoDispose<FILE*> file( ::popen( command.c_str(), "re" ), ::pclose );
268 if ( file == NULL )
269 {
270 file.resetDispose();
271 ZYPP_THROW( zypp::Exception( "Can't open testtags-file: "+file_r.asString() ) );
272 }
273
274 if ( pool()._addTesttags( _repo, file ) != 0 )
275 {
276 ZYPP_THROW( zypp::Exception( "Error reading testtags-file: "+file_r.asString() ) );
277 }
278
279 //MIL << *this << " after adding " << file_r << endl;
280 }
281
283 {
284 NO_REPOSITORY_THROW( zypp::Exception( "Can't add solvables to norepo.") );
285 return pool()._addSolvables( _repo, count_r );
286 }
287
288 namespace detail
289 {
291 {
292 if ( base() )
293 {
294 sat::detail::CPool * satpool = (*base())->pool;
295 do {
296 ++base_reference();
297 } while ( base() < satpool->repos+satpool->nrepos && !*base() );
298 }
299 }
300 }
301
302 } // namespace sat
303} // namespace zyppng
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition Easy.h:27
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition Exception.h:459
#define NO_REPOSITORY_THROW(VAL)
Definition Repository.cc:50
#define NO_REPOSITORY_RETURN(VAL)
Definition Repository.cc:46
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition AutoDispose.h:95
void resetDispose()
Set no dispose function.
Store and operate on date (time_t).
Definition Date.h:33
static Date now()
Return the current time.
Definition Date.h:78
Base class for Exception.
Definition Exception.h:153
Repository nextInPool() const
Return next Repository in Pool (or noRepository).
int satInternalSubPriority() const
Definition Repository.cc:80
static const Repository noRepository
Represents no Repository.
Definition Repository.h:67
void addHelix(const Pathname &file_r)
Load Solvables from a helix-file.
sat::detail::CRepo * get() const
Expert backdoor.
Definition Repository.cc:43
bool solvablesEmpty() const
Whether Repository contains solvables.
Date suggestedExpirationTimestamp() const
Suggested expiration timestamp.
SolvableIterator solvablesEnd() const
Iterator behind the last Solvable.
int satInternalPriority() const
libsolv internal priorities.
Definition Repository.cc:74
sat::Solvable::IdType addSolvables(unsigned count_r)
Add count_r new empty Solvable to this Repository.
SolvableIterator solvablesBegin() const
Iterator to the first Solvable.
void addTesttags(const Pathname &file_r)
Load Solvables from a libsolv testtags-file.
ContentIdentifier contentIdentifier() const
Unique string identifying a repositories content.
Definition Repository.cc:93
bool maybeOutdated() const
The suggested expiration date of this repository already passed.
std::string alias() const
Short unique string to identify a repo.
Definition Repository.cc:60
bool hasContentIdentifier(const ContentIdentifier &id_r) const
Whether id_r matches this repos content identifier.
size_type solvablesSize() const
Number of solvables in Repository.
void addSolv(const Pathname &file_r)
Load Solvables from a solv-file.
ContentRevision contentRevision() const
Timestamp or arbitrary user supplied string.
Definition Repository.cc:86
Date generatedTimestamp() const
Timestamp when this repository was generated.
static const std::string & systemRepoAlias()
Reserved system repository alias @System .
Definition Repository.cc:38
void eraseFromPool()
Remove this Repository from its Pool.
bool isSystemRepo() const
Return whether this is the system repository.
Definition Repository.cc:54
const char * c_str() const
String representation.
Definition Pathname.h:113
const std::string & asString() const
String representation.
Definition Pathname.h:94
std::string extension() const
Return all of the characters in name after and including the last dot in the last element of name.
Definition Pathname.h:144
unsigned asUnsigned() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::string asString() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
iterator end() const
Iterator behind the end of query results.
iterator begin() const
Iterator to the begin of query results.
bool empty() const
Whether the query is empty.
Lightweight repository attribute value lookup.
Definition lookupattr.h:257
Orchestrator for a libsolv pool instance.
Definition pool.h:37
void _deleteRepo(detail::CRepo *repo_r)
Delete repo repo_r from pool.
Definition pool.cc:277
bool isSystemRepo(detail::CRepo *repo_r) const
Definition pool.h:132
RepositoryIterable repos() const
Iteratable to the repositories.
Definition pool.cc:208
static const std::string & systemRepoAlias()
Reserved system repository alias @System .
Definition pool.cc:178
detail::SolvableIdType _addSolvables(detail::CRepo *repo_r, unsigned count_r)
Adding Solvables to a repo.
Definition pool.cc:318
Repository()
Default ctor creates noRepository.
Definition repository.h:64
bool isSystemRepo() const
Return whether this is the system repository.
Definition repository.cc:68
static const Repository noRepository
Represents no Repository.
Definition repository.h:78
zypp::Date generatedTimestamp() const
Timestamp when this repository was generated.
boost::filter_iterator< detail::ByRepository, sat::detail::SolvableIterator > SolvableIterator
Definition repository.h:52
std::string ContentRevision
Definition repository.h:59
detail::CRepo * get() const
Expert backdoor.
Definition repository.cc:57
std::string ContentIdentifier
Definition repository.h:60
unsigned int size_type
Definition repository.h:54
zypp::Date suggestedExpirationTimestamp() const
Suggested expiration timestamp.
static const SolvAttr repositoryRepoid
Definition SolvAttr.h:190
static const SolvAttr repositoryRevision
Definition SolvAttr.h:192
static const SolvAttr repositoryTimestamp
Definition SolvAttr.h:184
static const SolvAttr repositoryExpire
Definition SolvAttr.h:185
detail::SolvableIdType IdType
Definition solvable.h:67
Iterate over valid Solvables in the pool.
Definition solvable.h:417
CLASS NAME : detail::DIWrap.
Definition cap2str.cc:14
zypp::sat::detail::CPool CPool
Pool & poolFromType(T &)
static const RepoIdType noRepoId(0)
Id to denote Repo::noRepository.
zypp::sat::detail::CRepo CRepo
This file contains private API, this might break at any time between releases.
Always-on precondition checking for NG code.
#define ZYPP_PRECONDITION(EXPR,...)
Always-on precondition check — fires in debug AND release builds.
Functor filtering Solvable by Repository.
Definition repository.h:507