1
/*---------------------------------------------------------------------\
3
| |__ / \ / / . \ . \ |
8
\---------------------------------------------------------------------*/
9
/** \file zypp/sat/Repository.cc
15
#include "zypp/base/Logger.h"
16
#include "zypp/base/Gettext.h"
17
#include "zypp/base/Exception.h"
18
#include "zypp/base/Xml.h"
20
#include "zypp/AutoDispose.h"
21
#include "zypp/Pathname.h"
23
#include "zypp/sat/detail/PoolImpl.h"
24
#include "zypp/Repository.h"
25
#include "zypp/sat/Pool.h"
29
///////////////////////////////////////////////////////////////////
31
{ /////////////////////////////////////////////////////////////////
33
const Repository Repository::noRepository;
35
const std::string & Repository::systemRepoAlias()
36
{ return sat::detail::PoolImpl::systemRepoAlias(); }
38
/////////////////////////////////////////////////////////////////
40
::_Repo * Repository::get() const
41
{ return myPool().getRepo( _id ); }
43
#define NO_REPOSITORY_RETURN( VAL ) \
44
::_Repo * _repo( get() ); \
45
if ( ! _repo ) return VAL
47
#define NO_REPOSITORY_THROW( VAL ) \
48
::_Repo * _repo( get() ); \
49
if ( ! _repo ) ZYPP_THROW( VAL )
51
bool Repository::isSystemRepo() const
53
NO_REPOSITORY_RETURN( false );
54
return myPool().isSystemRepo( _repo );
57
std::string Repository::alias() const
59
NO_REPOSITORY_RETURN( std::string() );
65
std::string Repository::name() const
66
{ return info().name(); }
68
int Repository::satInternalPriority() const
70
NO_REPOSITORY_RETURN( INT_MIN );
71
return _repo->priority;
74
int Repository::satInternalSubPriority() const
76
NO_REPOSITORY_RETURN( INT_MIN );
77
return _repo->subpriority;
81
zypp::Date Repository::generatedTimestamp() const
83
NO_REPOSITORY_RETURN( 0 );
84
sat::LookupRepoAttr q( sat::SolvAttr::repositoryTimestamp, *this );
85
return( q.empty() ? 0 : q.begin().asUnsigned() );
88
zypp::Date Repository::suggestedExpirationTimestamp() const
90
NO_REPOSITORY_RETURN( 0 );
91
Date generated = generatedTimestamp();
93
return 0; // do not calculate over a missing generated timestamp
95
sat::LookupRepoAttr q( sat::SolvAttr::repositoryExpire, *this );
99
return generated + q.begin().asUnsigned();
102
Repository::Keywords Repository::keywords() const
104
NO_REPOSITORY_RETURN( Keywords() );
105
return Keywords( sat::SolvAttr::repositoryKeywords, *this, sat::LookupAttr::REPO_ATTR );
108
bool Repository::maybeOutdated() const
110
NO_REPOSITORY_RETURN( false );
111
// system repo is not mirrored
112
if ( isSystemRepo() )
115
Date suggested = suggestedExpirationTimestamp();
117
// if no data, don't suggest
121
return suggestedExpirationTimestamp() < Date::now();
124
bool Repository::providesUpdatesFor( const std::string &key ) const
126
NO_REPOSITORY_RETURN( false );
129
updatesProductBegin(),
130
updatesProductEnd() )
132
// FIXME implement real CPE matching here
134
if ( key == it.cpeId() )
141
bool Repository::isUpdateRepo() const
143
NO_REPOSITORY_RETURN( false );
144
return ( updatesProductBegin() != updatesProductEnd() );
147
bool Repository::solvablesEmpty() const
149
NO_REPOSITORY_RETURN( true );
150
return !_repo->nsolvables;
153
Repository::size_type Repository::solvablesSize() const
155
NO_REPOSITORY_RETURN( 0 );
156
return _repo->nsolvables;
159
Repository::SolvableIterator Repository::solvablesBegin() const
161
NO_REPOSITORY_RETURN( make_filter_iterator( detail::ByRepository( *this ),
162
sat::detail::SolvableIterator(),
163
sat::detail::SolvableIterator() ) );
164
return make_filter_iterator( detail::ByRepository( *this ),
165
sat::detail::SolvableIterator(_repo->start),
166
sat::detail::SolvableIterator(_repo->end) );
169
Repository::SolvableIterator Repository::solvablesEnd() const
171
NO_REPOSITORY_RETURN( make_filter_iterator( detail::ByRepository( *this ),
172
sat::detail::SolvableIterator(),
173
sat::detail::SolvableIterator() ) );
174
return make_filter_iterator(detail::ByRepository( *this ),
175
sat::detail::SolvableIterator(_repo->end),
176
sat::detail::SolvableIterator(_repo->end) );
179
Repository::ProductInfoIterator Repository::compatibleWithProductBegin() const
181
NO_REPOSITORY_RETURN( ProductInfoIterator() );
182
return ProductInfoIterator( sat::SolvAttr::repositoryDistros, *this );
185
Repository::ProductInfoIterator Repository::compatibleWithProductEnd() const
187
return ProductInfoIterator();
190
Repository::ProductInfoIterator Repository::updatesProductBegin() const
192
NO_REPOSITORY_RETURN( ProductInfoIterator() );
193
return ProductInfoIterator( sat::SolvAttr::repositoryUpdates, *this );
196
Repository::ProductInfoIterator Repository::updatesProductEnd() const
198
return ProductInfoIterator();
201
RepoInfo Repository::info() const
203
NO_REPOSITORY_RETURN( RepoInfo() );
204
return myPool().repoInfo( _repo );
207
void Repository::setInfo( const RepoInfo & info_r )
209
NO_REPOSITORY_THROW( Exception( "Can't set RepoInfo for norepo." ) );
210
if ( info_r.alias() != alias() )
212
ZYPP_THROW( Exception( str::form( "RepoInfo alias (%s) does not match repository alias (%s)",
213
info_r.alias().c_str(), alias().c_str() ) ) );
215
myPool().setRepoInfo( _repo, info_r );
216
MIL << *this << endl;
219
void Repository::clearInfo()
221
NO_REPOSITORY_RETURN();
222
myPool().setRepoInfo( _repo, RepoInfo() );
225
void Repository::eraseFromPool()
227
NO_REPOSITORY_RETURN();
228
MIL << *this << " removed from pool" << endl;
229
myPool()._deleteRepo( _repo );
230
_id = sat::detail::noRepoId;
233
Repository Repository::nextInPool() const
235
NO_REPOSITORY_RETURN( noRepository );
236
for_( it, sat::Pool::instance().reposBegin(), sat::Pool::instance().reposEnd() )
240
if ( ++it != _for_end )
248
void Repository::addSolv( const Pathname & file_r )
250
NO_REPOSITORY_THROW( Exception( "Can't add solvables to norepo." ) );
252
AutoDispose<FILE*> file( ::fopen( file_r.c_str(), "re" ), ::fclose );
256
ZYPP_THROW( Exception( "Can't open solv-file: "+file_r.asString() ) );
259
if ( myPool()._addSolv( _repo, file ) != 0 )
261
ZYPP_THROW( Exception( "Error reading solv-file: "+file_r.asString() ) );
264
MIL << *this << " after adding " << file_r << endl;
267
void Repository::addHelix( const Pathname & file_r )
269
NO_REPOSITORY_THROW( Exception( "Can't add solvables to norepo." ) );
271
std::string command( file_r.extension() == ".gz" ? "zcat " : "cat " );
272
command += file_r.asString();
274
AutoDispose<FILE*> file( ::popen( command.c_str(), "re" ), ::pclose );
278
ZYPP_THROW( Exception( "Can't open helix-file: "+file_r.asString() ) );
281
if ( myPool()._addHelix( _repo, file ) != 0 )
283
ZYPP_THROW( Exception( "Error reading helix-file: "+file_r.asString() ) );
286
MIL << *this << " after adding " << file_r << endl;
289
sat::detail::SolvableIdType Repository::addSolvables( unsigned count_r )
291
NO_REPOSITORY_THROW( Exception( "Can't add solvables to norepo.") );
292
return myPool()._addSolvables( _repo, count_r );
295
/******************************************************************
297
** FUNCTION NAME : operator<<
298
** FUNCTION TYPE : std::ostream &
300
std::ostream & operator<<( std::ostream & str, const Repository & obj )
303
return str << "noRepository";
305
return str << "sat::repo(" << obj.alias() << ")"
307
<< "prio " << obj.get()->priority << '.' << obj.get()->subpriority
308
<< ", size " << obj.solvablesSize()
312
std::ostream & dumpAsXmlOn( std::ostream & str, const Repository & obj )
314
return xmlout::node( str, "repository", {
315
{ "alias", obj.name() },
316
{ "name", obj.alias() }
320
//////////////////////////////////////////////////////////////////
323
void RepositoryIterator::increment()
327
::_Pool * satpool = sat::Pool::instance().get();
330
} while ( base() < satpool->repos+satpool->nrepos && !*base() );
333
} // namespace detail
334
//////////////////////////////////////////////////////////////////
336
///////////////////////////////////////////////////////////////////
338
// Repository::ProductInfoIterator
340
///////////////////////////////////////////////////////////////////
342
Repository::ProductInfoIterator::ProductInfoIterator( sat::SolvAttr attr_r, Repository repo_r )
343
{ base_reference() = sat::LookupRepoAttr( attr_r, repo_r ).begin(); }
345
std::string Repository::ProductInfoIterator::label() const
346
{ return base_reference().subFind( sat::SolvAttr::repositoryProductLabel ).asString(); }
348
std::string Repository::ProductInfoIterator::cpeId() const
349
{ return base_reference().subFind( sat::SolvAttr::repositoryProductCpeid ).asString(); }
351
/////////////////////////////////////////////////////////////////
353
///////////////////////////////////////////////////////////////////