1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Repository.h
12 #ifndef ZYPP_SAT_REPOSITORY_H
13 #define ZYPP_SAT_REPOSITORY_H
16 #include "zypp/Pathname.h"
17 #include "zypp/sat/detail/PoolMember.h"
18 #include "zypp/sat/LookupAttr.h" // LookupAttrTools.h included at EOF
19 #include "zypp/sat/Solvable.h"
20 #include "zypp/RepoInfo.h"
21 #include "zypp/Date.h"
23 ///////////////////////////////////////////////////////////////////
25 { /////////////////////////////////////////////////////////////////
32 ///////////////////////////////////////////////////////////////////
34 // CLASS NAME : Repository
37 class Repository : protected sat::detail::PoolMember
40 typedef filter_iterator<detail::ByRepository, sat::detail::SolvableIterator> SolvableIterator;
41 typedef sat::detail::size_type size_type;
42 typedef sat::detail::RepoIdType IdType;
44 typedef sat::ArrayAttr<std::string,std::string> Keywords;
47 /** Default ctor creates \ref noRepository.*/
49 : _id( sat::detail::noRepoId ) {}
51 /** \ref PoolImpl ctor. */
52 explicit Repository( IdType id_r )
56 /** Represents no \ref Repository. */
57 static const Repository noRepository;
59 /** Evaluate \ref Repository in a boolean context (\c != \c noRepository). */
60 explicit operator bool() const
61 { return get() != nullptr; }
63 /** Reserved system repository alias \c @System. */
64 static const std::string & systemRepoAlias();
66 /** Return whether this is the system repository. */
67 bool isSystemRepo() const;
71 * Short unique string to identify a repo.
74 * If you are looking for a label to display
76 * ie: "openSUSE 10.3 Main repository"
79 std::string alias() const;
81 /** Label to display for this repo. */
82 std::string name() const;
85 std::string asUserString() const
89 * Timestamp when this repository was generated
91 * Usually this value is calculated as the newer
92 * timestamp from the timestamp of all the resources
93 * that conform the repository's metadata.
95 * For example in a rpm-md repository, it would be
96 * the resource specified in the xml file whith
97 * the newest timestamp attribute (which is the
98 * timestamp of the file in the server ).
100 * The timestamp is 0 if the repository does not
101 * specify when it was generated.
104 Date generatedTimestamp() const;
107 * Suggested expiration timestamp.
109 * Repositories can define an amount of time
110 * they expire, with the generated timestamp as
111 * the base point of time.
113 * Note that is the responsability of the repository
114 * to freshen the generated timestamp to tell the
115 * client that the repo is alive and updating the
118 * The timestamp is 0 if the repository does not specify
119 * an expiration date.
122 Date suggestedExpirationTimestamp() const;
125 * repository keywords (tags)
127 Keywords keywords() const;
130 * The suggested expiration date of this repository
133 * rpm-md repositories can provide this tag using the
134 * expire extension tag:
135 * \see http://en.opensuse.org/Standards/Rpm_Metadata#SUSE_repository_info_.28suseinfo.xml.29.2C_extensions_to_repomd.xml
137 bool maybeOutdated() const;
140 * if the repository claims to update something then
141 * it is an update repository
143 * This is implemented by looking at the repository updates
145 * \see http://en.opensuse.org/Standards/Rpm_Metadata#SUSE_repository_info_.28suseinfo.xml.29.2C_extensions_to_repomd.xml
147 bool isUpdateRepo() const;
150 * whether the repository claims to update something \ref prod
151 * with key \ref cpeid
153 * \see zypp::Product::cpeId()
155 * See http://cpe.mitre.org/ for more information on the
156 * Common Platform Enumearation.
158 bool providesUpdatesFor( const std::string &cpeid ) const;
160 /** Whether \ref Repository contains solvables. */
161 bool solvablesEmpty() const;
163 /** Number of solvables in \ref Repository. */
164 size_type solvablesSize() const;
166 /** Iterator to the first \ref Solvable. */
167 SolvableIterator solvablesBegin() const;
169 /** Iterator behind the last \ref Solvable. */
170 SolvableIterator solvablesEnd() const;
174 /** Query class for Repository */
175 class ProductInfoIterator;
178 * Get an iterator to the beginning of the repository
179 * compatible distros.
180 * \note This is only a hint. There is no guarantee that
181 * the repository is built for that product.
182 * \see Repository::ProductInfoIterator
184 ProductInfoIterator compatibleWithProductBegin() const;
187 * Get an iterator to the end of the repository
188 * compatible distros.
189 * \see Repository::ProductInfoIterator
191 ProductInfoIterator compatibleWithProductEnd() const;
194 * Get an iterator to the beginning of the repository
195 * compatible distros.
196 * \see Repository::ProductInfoIterator
198 ProductInfoIterator updatesProductBegin() const;
201 * Get an iterator to the end of the repository
202 * compatible distros.
203 * \see Repository::ProductInfoIterator
205 ProductInfoIterator updatesProductEnd() const;
208 /** Return any associated \ref RepoInfo. */
209 RepoInfo info() const;
211 /** Set \ref RepoInfo for this repository.
212 * \throws Exception if this is \ref noRepository
213 * \throws Exception if the \ref RepoInfo::alias
214 * does not match the \ref Repository::name.
216 void setInfo( const RepoInfo & info_r );
218 /** Remove any \ref RepoInfo set for this repository. */
222 /** Remove this \ref Repository from it's \ref Pool. */
223 void eraseFromPool();
225 /** Functor calling \ref eraseFromPool. */
226 struct EraseFromPool;
229 /** Return next Repository in \ref Pool (or \ref noRepository). */
230 Repository nextInPool() const;
233 /** \name Repository content manipulating methods.
234 * \todo maybe a separate Repository/Solvable content manip interface
235 * provided by the pool.
238 /** Load \ref Solvables from a solv-file.
239 * In case of an exception the repository remains in the \ref Pool.
240 * \throws Exception if this is \ref noRepository
241 * \throws Exception if loading the solv-file fails.
242 * \see \ref Pool::addRepoSolv and \ref Repository::EraseFromPool
244 void addSolv( const Pathname & file_r );
246 /** Load \ref Solvables from a helix-file.
247 * Supports loading of gzip compressed files (.gz). In case of an exception
248 * the repository remains in the \ref Pool.
249 * \throws Exception if this is \ref noRepository
250 * \throws Exception if loading the helix-file fails.
251 * \see \ref Pool::addRepoHelix and \ref Repository::EraseFromPool
253 void addHelix( const Pathname & file_r );
255 /** Add \c count_r new empty \ref Solvable to this \ref Repository. */
256 sat::Solvable::IdType addSolvables( unsigned count_r );
257 /** \overload Add only one new \ref Solvable. */
258 sat::Solvable::IdType addSolvable()
259 { return addSolvables( 1 ); }
263 /** Expert backdoor. */
264 ::_Repo * get() const;
265 /** Expert backdoor. */
266 IdType id() const { return _id; }
267 /** libsolv internal priorities.
268 * Unlike the \ref RepoInfo priority which tries to be YUM conform
269 * (H[1-99]L), this one is the solvers internal priority representation.
270 * It is type \c int and as one might expect it, the higher the value
271 * the higher the priority. Subpriority is currently used to express
272 * media preferences (\see \ref MediaPriority).
275 int satInternalPriority() const;
276 int satInternalSubPriority() const;
282 ///////////////////////////////////////////////////////////////////
284 /** \relates Repository Stream output */
285 std::ostream & operator<<( std::ostream & str, const Repository & obj );
287 /** \relates Repository */
288 inline bool operator==( const Repository & lhs, const Repository & rhs )
289 { return lhs.get() == rhs.get(); }
291 /** \relates Repository */
292 inline bool operator!=( const Repository & lhs, const Repository & rhs )
293 { return lhs.get() != rhs.get(); }
295 /** \relates Repository */
296 inline bool operator<( const Repository & lhs, const Repository & rhs )
297 { return lhs.get() < rhs.get(); }
299 ///////////////////////////////////////////////////////////////////
301 * Query class for Repository related products
303 * The iterator does not provide a dereference
304 * operator so you can do * on it, but you can
305 * access the attributes of each related product
306 * directly from the iterator.
309 * for_( it, repo.compatibleWithProductBegin(), repo.compatibleWithProductEnd() )
311 * cout << it.cpeid() << endl;
316 class Repository::ProductInfoIterator : public boost::iterator_adaptor<
317 Repository::ProductInfoIterator // Derived
318 , sat::LookupAttr::iterator // Base
320 , boost::forward_traversal_tag // CategoryOrTraversal
325 ProductInfoIterator()
331 std::string label() const;
334 * The Common Platform Enumeration name
337 * See http://cpe.mitre.org
339 std::string cpeId() const;
342 friend class Repository;
343 /** Hide ctor as just a limited set of attributes is valid. */
344 explicit ProductInfoIterator( sat::SolvAttr attr_r, Repository repo_r );
347 friend class boost::iterator_core_access;
348 int dereference() const { return 0; }
350 ///////////////////////////////////////////////////////////////////
352 ///////////////////////////////////////////////////////////////////
354 // CLASS NAME : Repository::EraseFromPool
356 /** Functor removing \ref Repository from it's \ref Pool.
358 * E.g. used as dispose function in. \ref AutoDispose
359 * to provide a convenient and exception safe temporary
363 * MIL << "1 " << satpool << endl;
365 * AutoDispose<Repository> tmprepo( (Repository::EraseFromPool()) );
366 * *tmprepo = satpool.reposInsert( "A" );
367 * tmprepo->addSolv( "sl10.1-beta7-packages.solv" );
368 * DBG << "2 " << satpool << endl;
369 * // Calling 'tmprepo.resetDispose();' here
370 * // would keep the Repo.
372 * MIL << "3 " << satpool << endl;
375 * 1 sat::pool(){0repos|2slov}
376 * 2 sat::pool(){1repos|2612slov}
377 * 3 sat::pool(){0repos|2slov}
379 * Leaving the block without calling <tt>tmprepo.resetDispose();</tt>
380 * before, will automatically remove the \ref Repo from it's \ref Pool.
382 struct Repository::EraseFromPool
384 void operator()( Repository repository_r ) const
385 { repository_r.eraseFromPool(); }
387 ///////////////////////////////////////////////////////////////////
389 ///////////////////////////////////////////////////////////////////
391 { /////////////////////////////////////////////////////////////////
392 ///////////////////////////////////////////////////////////////////
394 // CLASS NAME : RepositoryIterator
397 class RepositoryIterator : public boost::iterator_adaptor<
398 RepositoryIterator // Derived
400 , Repository // Value
401 , boost::forward_traversal_tag // CategoryOrTraversal
402 , Repository // Reference
407 : RepositoryIterator::iterator_adaptor_( 0 )
410 explicit RepositoryIterator( ::_Repo ** p )
411 : RepositoryIterator::iterator_adaptor_( p )
415 friend class boost::iterator_core_access;
417 Repository dereference() const
418 { 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