1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Repository.h
12 #ifndef ZYPP_SAT_REPOSITORY_H
13 #define ZYPP_SAT_REPOSITORY_H
16 #include "zypp/base/SafeBool.h"
17 #include "zypp/Pathname.h"
18 #include "zypp/sat/detail/PoolMember.h"
19 #include "zypp/sat/LookupAttr.h" // LookupAttrTools.h included at EOF
20 #include "zypp/sat/Solvable.h"
21 #include "zypp/RepoInfo.h"
22 #include "zypp/Date.h"
24 ///////////////////////////////////////////////////////////////////
26 { /////////////////////////////////////////////////////////////////
33 ///////////////////////////////////////////////////////////////////
35 // CLASS NAME : Repository
38 class Repository : protected sat::detail::PoolMember,
39 private base::SafeBool<Repository>
42 typedef filter_iterator<detail::ByRepository, sat::detail::SolvableIterator> SolvableIterator;
43 typedef sat::detail::size_type size_type;
44 typedef sat::detail::RepoIdType IdType;
46 typedef sat::ArrayAttr<std::string,std::string> Keywords;
49 /** Default ctor creates \ref noRepository.*/
51 : _id( sat::detail::noRepoId ) {}
53 /** \ref PoolImpl ctor. */
54 explicit Repository( IdType id_r )
58 /** Represents no \ref Repository. */
59 static const Repository noRepository;
61 #ifndef SWIG // Swig treats it as syntax error
62 /** Evaluate \ref Repository in a boolean context (\c != \c noRepository). */
63 using base::SafeBool<Repository>::operator bool_type;
65 /** Reserved system repository alias \c @System. */
66 static const std::string & systemRepoAlias();
68 /** Return whether this is the system repository. */
69 bool isSystemRepo() const;
73 * Short unique string to identify a repo.
76 * If you are looking for a label to display
78 * ie: "openSUSE 10.3 Main repository"
81 std::string alias() const;
83 /** Label to display for this repo. */
84 std::string name() const;
87 * Timestamp when this repository was generated
89 * Usually this value is calculated as the newer
90 * timestamp from the timestamp of all the resources
91 * that conform the repository's metadata.
93 * For example in a rpm-md repository, it would be
94 * the resource specified in the xml file whith
95 * the newest timestamp attribute (which is the
96 * timestamp of the file in the server ).
98 * The timestamp is 0 if the repository does not
99 * specify when it was generated.
102 Date generatedTimestamp() const;
105 * Suggested expiration timestamp.
107 * Repositories can define an amount of time
108 * they expire, with the generated timestamp as
109 * the base point of time.
111 * Note that is the responsability of the repository
112 * to freshen the generated timestamp to tell the
113 * client that the repo is alive and updating the
116 * The timestamp is 0 if the repository does not specify
117 * an expiration date.
120 Date suggestedExpirationTimestamp() const;
123 * repository keywords (tags)
125 Keywords keywords() const;
128 * The suggested expiration date of this repository
131 * rpm-md repositories can provide this tag using the
132 * expire extension tag:
133 * \see http://en.opensuse.org/Standards/Rpm_Metadata#SUSE_repository_info_.28suseinfo.xml.29.2C_extensions_to_repomd.xml
135 bool maybeOutdated() const;
138 * if the repository claims to update something then
139 * it is an update repository
141 * This is implemented by looking at the repository updates
143 * \see http://en.opensuse.org/Standards/Rpm_Metadata#SUSE_repository_info_.28suseinfo.xml.29.2C_extensions_to_repomd.xml
145 bool isUpdateRepo() const;
148 * wether the repository claims to update something \ref prod
149 * with key \ref cpeid
151 * \see zypp::Product::cpeId()
153 * See http://cpe.mitre.org/ for more information on the
154 * Common Platform Enumearation.
156 bool providesUpdatesFor( const std::string &cpeid ) const;
158 /** Whether \ref Repository contains solvables. */
159 bool solvablesEmpty() const;
161 /** Number of solvables in \ref Repository. */
162 size_type solvablesSize() const;
164 /** Iterator to the first \ref Solvable. */
165 SolvableIterator solvablesBegin() const;
167 /** Iterator behind the last \ref Solvable. */
168 SolvableIterator solvablesEnd() const;
172 /** Query class for Repository */
173 class ProductInfoIterator;
176 * Get an iterator to the beginning of the repository
177 * compatible distros.
178 * \note This is only a hint. There is no guarantee that
179 * the repository is built for that product.
180 * \see Repository::ProductInfoIterator
182 ProductInfoIterator compatibleWithProductBegin() const;
185 * Get an iterator to the end of the repository
186 * compatible distros.
187 * \see Repository::ProductInfoIterator
189 ProductInfoIterator compatibleWithProductEnd() const;
192 * Get an iterator to the beginning of the repository
193 * compatible distros.
194 * \see Repository::ProductInfoIterator
196 ProductInfoIterator updatesProductBegin() const;
199 * Get an iterator to the end of the repository
200 * compatible distros.
201 * \see Repository::ProductInfoIterator
203 ProductInfoIterator updatesProductEnd() const;
206 /** Return any associated \ref RepoInfo. */
207 RepoInfo info() const;
209 /** Set \ref RepoInfo for this repository.
210 * \throws Exception if this is \ref noRepository
211 * \throws Exception if the \ref RepoInfo::alias
212 * does not match the \ref Repository::name.
214 void setInfo( const RepoInfo & info_r );
216 /** Remove any \ref RepoInfo set for this repository. */
220 /** Remove this \ref Repository from it's \ref Pool. */
221 void eraseFromPool();
223 /** Functor calling \ref eraseFromPool. */
224 struct EraseFromPool;
227 /** Return next Repository in \ref Pool (or \ref noRepository). */
228 Repository nextInPool() const;
231 /** \name Repository content manipulating methods.
232 * \todo maybe a separate Repository/Solvable content manip interface
233 * provided by the pool.
236 /** Load \ref Solvables from a solv-file.
237 * In case of an exception the repository remains in the \ref Pool.
238 * \throws Exception if this is \ref noRepository
239 * \throws Exception if loading the solv-file fails.
240 * \see \ref Pool::addRepoSolv and \ref Repository::EraseFromPool
242 void addSolv( const Pathname & file_r );
244 /** Load \ref Solvables from a helix-file.
245 * Supports loading of gzip compressed files (.gz). In case of an exception
246 * the repository remains in the \ref Pool.
247 * \throws Exception if this is \ref noRepository
248 * \throws Exception if loading the helix-file fails.
249 * \see \ref Pool::addRepoHelix and \ref Repository::EraseFromPool
251 void addHelix( const Pathname & file_r );
253 /** Add \c count_r new empty \ref Solvable to this \ref Repository. */
254 sat::Solvable::IdType addSolvables( unsigned count_r );
255 /** \overload Add only one new \ref Solvable. */
256 sat::Solvable::IdType addSolvable()
257 { return addSolvables( 1 ); }
261 /** Expert backdoor. */
262 ::_Repo * get() const;
263 /** Expert backdoor. */
264 IdType id() const { return _id; }
266 #ifndef SWIG // Swig treats it as syntax error
267 friend base::SafeBool<Repository>::operator bool_type() const;
269 bool boolTest() const { return get(); }
273 ///////////////////////////////////////////////////////////////////
275 /** \relates Repository Stream output */
276 std::ostream & operator<<( std::ostream & str, const Repository & obj );
278 /** \relates Repository */
279 inline bool operator==( const Repository & lhs, const Repository & rhs )
280 { return lhs.get() == rhs.get(); }
282 /** \relates Repository */
283 inline bool operator!=( const Repository & lhs, const Repository & rhs )
284 { return lhs.get() != rhs.get(); }
286 /** \relates Repository */
287 inline bool operator<( const Repository & lhs, const Repository & rhs )
288 { return lhs.get() < rhs.get(); }
290 ///////////////////////////////////////////////////////////////////
292 * Query class for Repository related products
294 * The iterator does not provide a dereference
295 * operator so you can do * on it, but you can
296 * access the attributes of each related product
297 * directly from the iterator.
300 * for_( it, repo.compatibleWithProductBegin(), repo.compatibleWithProductEnd() )
302 * cout << it.cpeid() << endl;
307 class Repository::ProductInfoIterator : public boost::iterator_adaptor<
308 Repository::ProductInfoIterator // Derived
309 , sat::LookupAttr::iterator // Base
311 , boost::forward_traversal_tag // CategoryOrTraversal
316 ProductInfoIterator()
322 std::string label() const;
325 * The Common Platform Enumeration name
328 * See http://cpe.mitre.org
330 std::string cpeId() const;
333 friend class Repository;
334 /** Hide ctor as just a limited set of attributes is valid. */
335 explicit ProductInfoIterator( sat::SolvAttr attr_r, Repository repo_r );
338 friend class boost::iterator_core_access;
339 int dereference() const { return 0; }
341 ///////////////////////////////////////////////////////////////////
343 ///////////////////////////////////////////////////////////////////
345 // CLASS NAME : Repository::EraseFromPool
347 /** Functor removing \ref Repository from it's \ref Pool.
349 * E.g. used as dispose function in. \ref AutoDispose
350 * to provide a convenient and exception safe temporary
354 * MIL << "1 " << satpool << endl;
356 * AutoDispose<Repository> tmprepo( (Repository::EraseFromPool()) );
357 * *tmprepo = satpool.reposInsert( "A" );
358 * tmprepo->addSolv( "sl10.1-beta7-packages.solv" );
359 * DBG << "2 " << satpool << endl;
360 * // Calling 'tmprepo.resetDispose();' here
361 * // would keep the Repo.
363 * MIL << "3 " << satpool << endl;
366 * 1 sat::pool(){0repos|2slov}
367 * 2 sat::pool(){1repos|2612slov}
368 * 3 sat::pool(){0repos|2slov}
370 * Leaving the block without calling <tt>tmprepo.resetDispose();</tt>
371 * before, will automatically remove the \ref Repo from it's \ref Pool.
373 struct Repository::EraseFromPool
375 void operator()( Repository repository_r ) const
376 { repository_r.eraseFromPool(); }
378 ///////////////////////////////////////////////////////////////////
380 ///////////////////////////////////////////////////////////////////
382 { /////////////////////////////////////////////////////////////////
383 ///////////////////////////////////////////////////////////////////
385 // CLASS NAME : RepositoryIterator
388 class RepositoryIterator : public boost::iterator_adaptor<
389 RepositoryIterator // Derived
391 , Repository // Value
392 , boost::forward_traversal_tag // CategoryOrTraversal
393 , Repository // Reference
398 : RepositoryIterator::iterator_adaptor_( 0 )
401 explicit RepositoryIterator( ::_Repo ** p )
402 : RepositoryIterator::iterator_adaptor_( p )
406 friend class boost::iterator_core_access;
408 Repository dereference() const
409 { return Repository( *base() ); }
411 ///////////////////////////////////////////////////////////////////
412 ///////////////////////////////////////////////////////////////////
414 // CLASS NAME : ByRepository
416 /** Functor filtering \ref Solvable by \ref Repository.*/
420 ByRepository( const Repository & repository_r ) : _repository( repository_r ) {}
421 ByRepository( sat::detail::RepoIdType id_r ) : _repository( id_r ) {}
424 bool operator()( const sat::Solvable & slv_r ) const
425 { return slv_r.repository() == _repository; }
428 Repository _repository;
430 ///////////////////////////////////////////////////////////////////
431 /////////////////////////////////////////////////////////////////
432 } // namespace detail
433 ///////////////////////////////////////////////////////////////////
434 /////////////////////////////////////////////////////////////////
436 ///////////////////////////////////////////////////////////////////
438 // Late include as sat::ArrayAttr requires Repository.h
439 #include "zypp/sat/LookupAttrTools.h"
441 #endif // ZYPP_SAT_REPOSITORY_H