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"
22 #include "zypp/CpeId.h"
24 ///////////////////////////////////////////////////////////////////
26 { /////////////////////////////////////////////////////////////////
33 ///////////////////////////////////////////////////////////////////
35 // CLASS NAME : Repository
38 class Repository : protected sat::detail::PoolMember
41 typedef filter_iterator<detail::ByRepository, sat::detail::SolvableIterator> SolvableIterator;
42 typedef sat::detail::size_type size_type;
43 typedef sat::detail::RepoIdType IdType;
45 typedef sat::ArrayAttr<std::string,std::string> Keywords;
47 typedef std::string ContentRevision;
48 typedef std::string ContentIdentifier;
51 /** Default ctor creates \ref noRepository.*/
53 : _id( sat::detail::noRepoId ) {}
55 /** \ref PoolImpl ctor. */
56 explicit Repository( IdType id_r )
60 /** Represents no \ref Repository. */
61 static const Repository noRepository;
63 /** Evaluate \ref Repository in a boolean context (\c != \c noRepository). */
64 explicit operator bool() const
65 { return get() != nullptr; }
67 /** Reserved system repository alias \c @System. */
68 static const std::string & systemRepoAlias();
70 /** Return whether this is the system repository. */
71 bool isSystemRepo() const;
75 * Short unique string to identify a repo.
78 * If you are looking for a label to display
80 * ie: "openSUSE 10.3 Main repository"
83 std::string alias() const;
85 /** Label to display for this repo. */
86 std::string name() const;
88 /** Alias or name, according to \ref ZConfig::repoLabelIsAlias */
89 std::string label() const;
91 /** User string: \ref label (alias or name) */
92 std::string asUserString() const
96 /** Timestamp or arbitrary user supplied string.
97 * \c /repomd/revision/text() in \c repomd.xml.
99 ContentRevision contentRevision() const;
101 /** Unique string identifying a repositories content.
102 * \c /repomd/tags/repo/text() in \c repomd.xml.
106 * <repo>obsrepository://build.suse.de/SUSE:Factory:Head:Internal/standard</repo>
108 * Semantically the value is just a plain string, even
109 * if OBS often uses the location of the project as
112 ContentIdentifier contentIdentifier() const;
114 /** Whether \a id_r matches this repos content identifier. */
115 bool hasContentIdentifier( const ContentIdentifier & id_r ) const;
118 * Timestamp when this repository was generated
120 * Usually this value is calculated as the newer
121 * timestamp from the timestamp of all the resources
122 * that conform the repository's metadata.
124 * For example in a rpm-md repository, it would be
125 * the resource specified in the xml file whith
126 * the newest timestamp attribute (which is the
127 * timestamp of the file in the server ).
129 * The timestamp is 0 if the repository does not
130 * specify when it was generated.
133 Date generatedTimestamp() const;
136 * Suggested expiration timestamp.
138 * Repositories can define an amount of time
139 * they expire, with the generated timestamp as
140 * the base point of time.
142 * Note that is the responsability of the repository
143 * to freshen the generated timestamp to tell the
144 * client that the repo is alive and updating the
147 * The timestamp is 0 if the repository does not specify
148 * an expiration date.
151 Date suggestedExpirationTimestamp() const;
154 * repository keywords (tags)
156 Keywords keywords() const;
158 /** Whether \a val_r is present in keywords. */
159 bool hasKeyword( const std::string & val_r ) const;
162 * The suggested expiration date of this repository
165 * rpm-md repositories can provide this tag using the
166 * expire extension tag:
167 * \see http://en.opensuse.org/Standards/Rpm_Metadata#SUSE_repository_info_.28suseinfo.xml.29.2C_extensions_to_repomd.xml
169 bool maybeOutdated() const;
172 * if the repository claims to update something then
173 * it is an update repository
175 * This is implemented by looking at the repository updates
177 * \see http://en.opensuse.org/Standards/Rpm_Metadata#SUSE_repository_info_.28suseinfo.xml.29.2C_extensions_to_repomd.xml
179 bool isUpdateRepo() const;
181 /** Whether the repository claims to provide updates for product identified by it's \ref CpeId */
182 bool providesUpdatesFor( const CpeId & cpeid_r ) const;
184 /** Whether \ref Repository contains solvables. */
185 bool solvablesEmpty() const;
187 /** Number of solvables in \ref Repository. */
188 size_type solvablesSize() const;
190 /** Iterator to the first \ref Solvable. */
191 SolvableIterator solvablesBegin() const;
193 /** Iterator behind the last \ref Solvable. */
194 SolvableIterator solvablesEnd() const;
198 /** Query class for Repository */
199 class ProductInfoIterator;
202 * Get an iterator to the beginning of the repository
203 * compatible distros.
204 * \note This is only a hint. There is no guarantee that
205 * the repository is built for that product.
206 * \see Repository::ProductInfoIterator
208 ProductInfoIterator compatibleWithProductBegin() const;
211 * Get an iterator to the end of the repository
212 * compatible distros.
213 * \see Repository::ProductInfoIterator
215 ProductInfoIterator compatibleWithProductEnd() const;
218 * Get an iterator to the beginning of the repository
219 * compatible distros.
220 * \see Repository::ProductInfoIterator
222 ProductInfoIterator updatesProductBegin() const;
225 * Get an iterator to the end of the repository
226 * compatible distros.
227 * \see Repository::ProductInfoIterator
229 ProductInfoIterator updatesProductEnd() const;
232 /** Return any associated \ref RepoInfo. */
233 RepoInfo info() const;
235 /** Set \ref RepoInfo for this repository.
236 * \throws Exception if this is \ref noRepository
237 * \throws Exception if the \ref RepoInfo::alias
238 * does not match the \ref Repository::name.
240 void setInfo( const RepoInfo & info_r );
242 /** Remove any \ref RepoInfo set for this repository. */
246 /** Remove this \ref Repository from it's \ref Pool. */
247 void eraseFromPool();
249 /** Functor calling \ref eraseFromPool. */
250 struct EraseFromPool;
253 /** Return next Repository in \ref Pool (or \ref noRepository). */
254 Repository nextInPool() const;
257 /** \name Repository content manipulating methods.
258 * \todo maybe a separate Repository/Solvable content manip interface
259 * provided by the pool.
262 /** Load \ref Solvables from a solv-file.
263 * In case of an exception the repository remains in the \ref Pool.
264 * \throws Exception if this is \ref noRepository
265 * \throws Exception if loading the solv-file fails.
266 * \see \ref Pool::addRepoSolv and \ref Repository::EraseFromPool
268 void addSolv( const Pathname & file_r );
270 /** Load \ref Solvables from a helix-file.
271 * Supports loading of gzip compressed files (.gz). In case of an exception
272 * the repository remains in the \ref Pool.
273 * \throws Exception if this is \ref noRepository
274 * \throws Exception if loading the helix-file fails.
275 * \see \ref Pool::addRepoHelix and \ref Repository::EraseFromPool
277 void addHelix( const Pathname & file_r );
279 /** Add \c count_r new empty \ref Solvable to this \ref Repository. */
280 sat::Solvable::IdType addSolvables( unsigned count_r );
281 /** \overload Add only one new \ref Solvable. */
282 sat::Solvable::IdType addSolvable()
283 { return addSolvables( 1 ); }
287 /** Expert backdoor. */
288 ::_Repo * get() const;
289 /** Expert backdoor. */
290 IdType id() const { return _id; }
291 /** libsolv internal priorities.
292 * Unlike the \ref RepoInfo priority which tries to be YUM conform
293 * (H[1-99]L), this one is the solvers internal priority representation.
294 * It is type \c int and as one might expect it, the higher the value
295 * the higher the priority. Subpriority is currently used to express
296 * media preferences (\see \ref MediaPriority).
299 int satInternalPriority() const;
300 int satInternalSubPriority() const;
306 ///////////////////////////////////////////////////////////////////
308 /** \relates Repository Stream output */
309 std::ostream & operator<<( std::ostream & str, const Repository & obj );
311 /** \relates Repository XML output */
312 std::ostream & dumpAsXmlOn( std::ostream & str, const Repository & obj );
314 /** \relates Repository */
315 inline bool operator==( const Repository & lhs, const Repository & rhs )
316 { return lhs.get() == rhs.get(); }
318 /** \relates Repository */
319 inline bool operator!=( const Repository & lhs, const Repository & rhs )
320 { return lhs.get() != rhs.get(); }
322 /** \relates Repository */
323 inline bool operator<( const Repository & lhs, const Repository & rhs )
324 { return lhs.get() < rhs.get(); }
326 ///////////////////////////////////////////////////////////////////
328 * Query class for Repository related products
330 * The iterator does not provide a dereference
331 * operator so you can do * on it, but you can
332 * access the attributes of each related product
333 * directly from the iterator.
336 * for_( it, repo.compatibleWithProductBegin(), repo.compatibleWithProductEnd() )
338 * cout << it.cpeid() << endl;
343 class Repository::ProductInfoIterator : public boost::iterator_adaptor<
344 Repository::ProductInfoIterator // Derived
345 , sat::LookupAttr::iterator // Base
347 , boost::forward_traversal_tag // CategoryOrTraversal
352 ProductInfoIterator()
356 std::string label() const;
358 /** The Common Platform Enumeration name for this product. */
362 friend class Repository;
363 /** Hide ctor as just a limited set of attributes is valid. */
364 explicit ProductInfoIterator( sat::SolvAttr attr_r, Repository repo_r );
367 friend class boost::iterator_core_access;
368 int dereference() const { return 0; }
370 ///////////////////////////////////////////////////////////////////
372 ///////////////////////////////////////////////////////////////////
374 // CLASS NAME : Repository::EraseFromPool
376 /** Functor removing \ref Repository from it's \ref Pool.
378 * E.g. used as dispose function in. \ref AutoDispose
379 * to provide a convenient and exception safe temporary
383 * MIL << "1 " << satpool << endl;
385 * AutoDispose<Repository> tmprepo( (Repository::EraseFromPool()) );
386 * *tmprepo = satpool.reposInsert( "A" );
387 * tmprepo->addSolv( "sl10.1-beta7-packages.solv" );
388 * DBG << "2 " << satpool << endl;
389 * // Calling 'tmprepo.resetDispose();' here
390 * // would keep the Repo.
392 * MIL << "3 " << satpool << endl;
395 * 1 sat::pool(){0repos|2slov}
396 * 2 sat::pool(){1repos|2612slov}
397 * 3 sat::pool(){0repos|2slov}
399 * Leaving the block without calling <tt>tmprepo.resetDispose();</tt>
400 * before, will automatically remove the \ref Repo from it's \ref Pool.
402 struct Repository::EraseFromPool
404 void operator()( Repository repository_r ) const
405 { repository_r.eraseFromPool(); }
407 ///////////////////////////////////////////////////////////////////
409 ///////////////////////////////////////////////////////////////////
411 { /////////////////////////////////////////////////////////////////
412 ///////////////////////////////////////////////////////////////////
414 // CLASS NAME : RepositoryIterator
417 class RepositoryIterator : public boost::iterator_adaptor<
418 RepositoryIterator // Derived
420 , Repository // Value
421 , boost::forward_traversal_tag // CategoryOrTraversal
422 , Repository // Reference
427 : RepositoryIterator::iterator_adaptor_( 0 )
430 explicit RepositoryIterator( ::_Repo ** p )
431 : RepositoryIterator::iterator_adaptor_( p )
435 friend class boost::iterator_core_access;
437 Repository dereference() const
438 { return Repository( *base() ); }
442 ///////////////////////////////////////////////////////////////////
443 ///////////////////////////////////////////////////////////////////
445 // CLASS NAME : ByRepository
447 /** Functor filtering \ref Solvable by \ref Repository.*/
451 ByRepository( const Repository & repository_r ) : _repository( repository_r ) {}
452 ByRepository( sat::detail::RepoIdType id_r ) : _repository( id_r ) {}
455 bool operator()( const sat::Solvable & slv_r ) const
456 { return slv_r.repository() == _repository; }
459 Repository _repository;
461 ///////////////////////////////////////////////////////////////////
462 /////////////////////////////////////////////////////////////////
463 } // namespace detail
464 ///////////////////////////////////////////////////////////////////
465 /////////////////////////////////////////////////////////////////
467 ///////////////////////////////////////////////////////////////////
469 // Late include as sat::ArrayAttr requires Repository.h
470 #include "zypp/sat/LookupAttrTools.h"
472 #endif // ZYPP_SAT_REPOSITORY_H