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; }
265 /** satsolver internal priorities.
266 * Unlike the \ref RepoInfo priority which tries to be YUM conform
267 * (H[1-99]L), this one is the solvers internal priority representation.
268 * It is type \c int and as one might expect it, the higher the value
269 * the higher the priority. Subpriority is currently used to express
270 * media preferences (\see \ref MediaPriority).
273 int satInternalPriority() const;
274 int satInternalSubPriority() const;
277 #ifndef SWIG // Swig treats it as syntax error
278 friend base::SafeBool<Repository>::operator bool_type() const;
280 bool boolTest() const { return get(); }
284 ///////////////////////////////////////////////////////////////////
286 /** \relates Repository Stream output */
287 std::ostream & operator<<( std::ostream & str, const Repository & obj );
289 /** \relates Repository */
290 inline bool operator==( const Repository & lhs, const Repository & rhs )
291 { return lhs.get() == rhs.get(); }
293 /** \relates Repository */
294 inline bool operator!=( const Repository & lhs, const Repository & rhs )
295 { return lhs.get() != rhs.get(); }
297 /** \relates Repository */
298 inline bool operator<( const Repository & lhs, const Repository & rhs )
299 { return lhs.get() < rhs.get(); }
301 ///////////////////////////////////////////////////////////////////
303 * Query class for Repository related products
305 * The iterator does not provide a dereference
306 * operator so you can do * on it, but you can
307 * access the attributes of each related product
308 * directly from the iterator.
311 * for_( it, repo.compatibleWithProductBegin(), repo.compatibleWithProductEnd() )
313 * cout << it.cpeid() << endl;
318 class Repository::ProductInfoIterator : public boost::iterator_adaptor<
319 Repository::ProductInfoIterator // Derived
320 , sat::LookupAttr::iterator // Base
322 , boost::forward_traversal_tag // CategoryOrTraversal
327 ProductInfoIterator()
333 std::string label() const;
336 * The Common Platform Enumeration name
339 * See http://cpe.mitre.org
341 std::string cpeId() const;
344 friend class Repository;
345 /** Hide ctor as just a limited set of attributes is valid. */
346 explicit ProductInfoIterator( sat::SolvAttr attr_r, Repository repo_r );
349 friend class boost::iterator_core_access;
350 int dereference() const { return 0; }
352 ///////////////////////////////////////////////////////////////////
354 ///////////////////////////////////////////////////////////////////
356 // CLASS NAME : Repository::EraseFromPool
358 /** Functor removing \ref Repository from it's \ref Pool.
360 * E.g. used as dispose function in. \ref AutoDispose
361 * to provide a convenient and exception safe temporary
365 * MIL << "1 " << satpool << endl;
367 * AutoDispose<Repository> tmprepo( (Repository::EraseFromPool()) );
368 * *tmprepo = satpool.reposInsert( "A" );
369 * tmprepo->addSolv( "sl10.1-beta7-packages.solv" );
370 * DBG << "2 " << satpool << endl;
371 * // Calling 'tmprepo.resetDispose();' here
372 * // would keep the Repo.
374 * MIL << "3 " << satpool << endl;
377 * 1 sat::pool(){0repos|2slov}
378 * 2 sat::pool(){1repos|2612slov}
379 * 3 sat::pool(){0repos|2slov}
381 * Leaving the block without calling <tt>tmprepo.resetDispose();</tt>
382 * before, will automatically remove the \ref Repo from it's \ref Pool.
384 struct Repository::EraseFromPool
386 void operator()( Repository repository_r ) const
387 { repository_r.eraseFromPool(); }
389 ///////////////////////////////////////////////////////////////////
391 ///////////////////////////////////////////////////////////////////
393 { /////////////////////////////////////////////////////////////////
394 ///////////////////////////////////////////////////////////////////
396 // CLASS NAME : RepositoryIterator
399 class RepositoryIterator : public boost::iterator_adaptor<
400 RepositoryIterator // Derived
402 , Repository // Value
403 , boost::forward_traversal_tag // CategoryOrTraversal
404 , Repository // Reference
409 : RepositoryIterator::iterator_adaptor_( 0 )
412 explicit RepositoryIterator( ::_Repo ** p )
413 : RepositoryIterator::iterator_adaptor_( p )
417 friend class boost::iterator_core_access;
419 Repository dereference() const
420 { return Repository( *base() ); }
422 ///////////////////////////////////////////////////////////////////
423 ///////////////////////////////////////////////////////////////////
425 // CLASS NAME : ByRepository
427 /** Functor filtering \ref Solvable by \ref Repository.*/
431 ByRepository( const Repository & repository_r ) : _repository( repository_r ) {}
432 ByRepository( sat::detail::RepoIdType id_r ) : _repository( id_r ) {}
435 bool operator()( const sat::Solvable & slv_r ) const
436 { return slv_r.repository() == _repository; }
439 Repository _repository;
441 ///////////////////////////////////////////////////////////////////
442 /////////////////////////////////////////////////////////////////
443 } // namespace detail
444 ///////////////////////////////////////////////////////////////////
445 /////////////////////////////////////////////////////////////////
447 ///////////////////////////////////////////////////////////////////
449 // Late include as sat::ArrayAttr requires Repository.h
450 #include "zypp/sat/LookupAttrTools.h"
452 #endif // ZYPP_SAT_REPOSITORY_H