libzypp 17.38.8
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
25#include <zypp/ng/sat/pool.h>
28
29using std::endl;
30
32namespace zyppng
33{
34 namespace sat
35 {
36 namespace detail {
37 template<> Pool & poolFromType( Repository & r )
38 {
39 detail::CRepo * repo = r.get();
40 ZYPP_PRECONDITION( repo && repo->pool && repo->pool->appdata );
41 return *static_cast<Pool *>( repo->pool->appdata );
42 }
43 template<> const Pool & poolFromType( const Repository & r )
44 {
45 const detail::CRepo * repo = r.get();
46 ZYPP_PRECONDITION( repo && repo->pool && repo->pool->appdata );
47 return *static_cast<const Pool *>( repo->pool->appdata );
48 }
49 }
50
52
53 const std::string & Repository::systemRepoAlias()
54 { return Pool::systemRepoAlias(); }
55
57
59 { return _id; }
60
61#define NO_REPOSITORY_RETURN( VAL ) \
62 detail::CRepo * _repo( get() ); \
63 if ( ! _repo ) return VAL
64
65#define NO_REPOSITORY_THROW( VAL ) \
66 detail::CRepo * _repo( get() ); \
67 if ( ! _repo ) ZYPP_THROW( VAL )
68
70 {
71 NO_REPOSITORY_RETURN( false );
72 return pool().isSystemRepo( _repo );
73 }
74
75 std::string Repository::alias() const
76 {
77 NO_REPOSITORY_RETURN( std::string() );
78 if ( ! _repo->name )
79 return std::string();
80 return _repo->name;
81 }
82
84 {
85 NO_REPOSITORY_RETURN( INT_MIN );
86 return _repo->priority;
87 }
88
90 {
91 NO_REPOSITORY_RETURN( INT_MIN );
92 return _repo->subpriority;
93 }
94
96 {
99 return q.empty() ? std::string() : (*q.begin()).asString();
100 }
101
103 {
106 return q.empty() ? std::string() : (*q.begin()).asString();
107 }
108
110 {
111 NO_REPOSITORY_RETURN( false );
112
114 return ranges::any_of( q, [&id_r]( const sat::LookupAttrValue v ){
115 return v.asString() == id_r;
116 });
117 }
118
120 {
123 return( q.empty() ? 0 : (*q.begin()).asUnsigned() );
124
125 }
126
128 {
130 zypp::Date generated = generatedTimestamp();
131 if ( ! generated )
132 return 0; // do not calculate over a missing generated timestamp
133
135 if ( q.empty() )
136 return 0;
137
138 return generated + zypp::Date((*q.begin()).asUnsigned());
139
140 }
141
143 {
144 NO_REPOSITORY_RETURN( false );
145 // system repo is not mirrored
146 if ( isSystemRepo() )
147 return false;
148
150
151 // if no data, don't suggest
152 if ( ! suggested )
153 return false;
154
155 return suggested < zypp::Date::now();
156 }
157
159 {
160 NO_REPOSITORY_RETURN( true );
161 return !_repo->nsolvables;
162 }
163
165 {
167 return _repo->nsolvables;
168 }
169
179
189
191 {
193 //MIL << *this << " removed from pool" << endl;
194 pool()._deleteRepo( _repo );
196 }
197
199 {
201 auto iterable = pool().repos();
202 for( auto it = iterable.begin(); it != iterable.end(); ++it )
203 {
204 if ( *it == *this )
205 {
206 if ( ++it != iterable.end() )
207 return *it;
208 break;
209 }
210 }
211 return noRepository;
212 }
213
214 void Repository::addSolv( const zypp::Pathname & file_r )
215 {
216 NO_REPOSITORY_THROW( zypp::Exception( "Can't add solvables to norepo." ) );
217
218 zypp::AutoDispose<FILE*> file( ::fopen( file_r.c_str(), "re" ), ::fclose );
219 if ( file == NULL )
220 {
221 file.resetDispose();
222 ZYPP_THROW( zypp::Exception( "Can't open solv-file: "+file_r.asString() ) );
223 }
224
225 if ( pool()._addSolv( _repo, file ) != 0 )
226 {
227 ZYPP_THROW( zypp::Exception( "Error reading solv-file: "+file_r.asString() ) );
228 }
229
230 //MIL << *this << " after adding " << file_r << endl;
231 }
232
234 {
235 NO_REPOSITORY_THROW( zypp::Exception( "Can't add solvables to norepo." ) );
236
237 std::string command( file_r.extension() == ".gz" ? "zcat " : "cat " );
238 command += "'";
239 command += file_r.asString();
240 command += "'";
241
242 zypp::AutoDispose<FILE*> file( ::popen( command.c_str(), "re" ), ::pclose );
243 if ( file == NULL )
244 {
245 file.resetDispose();
246 ZYPP_THROW( zypp::Exception( "Can't open helix-file: "+file_r.asString() ) );
247 }
248
249 if ( pool()._addHelix( _repo, file ) != 0 )
250 {
251 ZYPP_THROW( zypp::Exception( "Error reading helix-file: "+file_r.asString() ) );
252 }
253
254 //MIL << *this << " after adding " << file_r << endl;
255 }
256
258 {
259 NO_REPOSITORY_THROW( zypp::Exception( "Can't add solvables to norepo." ) );
260
261 std::string command( file_r.extension() == ".gz" ? "zcat " : "cat " );
262 command += "'";
263 command += file_r.asString();
264 command += "'";
265
266 zypp::AutoDispose<FILE*> file( ::popen( command.c_str(), "re" ), ::pclose );
267 if ( file == NULL )
268 {
269 file.resetDispose();
270 ZYPP_THROW( zypp::Exception( "Can't open testtags-file: "+file_r.asString() ) );
271 }
272
273 if ( pool()._addTesttags( _repo, file ) != 0 )
274 {
275 ZYPP_THROW( zypp::Exception( "Error reading testtags-file: "+file_r.asString() ) );
276 }
277
278 //MIL << *this << " after adding " << file_r << endl;
279 }
280
282 {
283 NO_REPOSITORY_THROW( zypp::Exception( "Can't add solvables to norepo.") );
284 return pool()._addSolvables( _repo, count_r );
285 }
286
287 namespace detail
288 {
290 {
291 if ( _base )
292 {
293 sat::detail::CPool * satpool = (*_base)->pool;
294 do {
295 ++_base;
296 } while ( _base < satpool->repos+satpool->nrepos && !*_base );
297 }
298 }
299 }
300
301 } // namespace sat
302} // namespace zyppng
#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
Value proxy returned by LookupAttr::iterator::operator*().
Definition lookupattr.h:454
std::string asString() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
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:259
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:65
bool isSystemRepo() const
Return whether this is the system repository.
Definition repository.cc:69
static const Repository noRepository
Represents no Repository.
Definition repository.h:79
zypp::Date generatedTimestamp() const
Timestamp when this repository was generated.
std::string ContentRevision
Definition repository.h:60
zyppng::FilterIterator< detail::ByRepository, sat::detail::SolvableIterator > SolvableIterator
Definition repository.h:53
detail::CRepo * get() const
Expert backdoor.
Definition repository.cc:58
std::string ContentIdentifier
Definition repository.h:61
unsigned int size_type
Definition repository.h:55
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:68
Iterate over valid Solvables in the pool.
Definition solvable.h:415
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.
FilterIterator< Pred, Base > make_filter_iterator(Pred p, Base it, Base end)
Helper function to deduce types and construct a FilterIterator.
Definition iterators.h:116
Always-on precondition checking for NG code.
#define ZYPP_PRECONDITION(EXPR,...)
Always-on precondition check — fires in debug AND release builds.
Namespace routing for C++20 ranges and C++23 ranges::to<T>() backport.
Functor filtering Solvable by Repository.
Definition repository.h:523