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;
171 /** Hint whether the Repo may provide updates for a product.
173 * Either the repository claims to update a product via a repository updates
174 * tag in it's metadata or a known product lists the repositories ContentIdentifier
175 * as required update repo.
177 bool isUpdateRepo() const;
179 /** Hint whether the Repo may provide updates for a product identified by it's \ref CpeId
181 * Either the repository claims to update a product via a repository updates
182 * tag in it's metadata or a known product lists the repositories ContentIdentifier
183 * as required update repo.
185 bool providesUpdatesFor( const CpeId & cpeid_r ) const;
187 /** Whether \ref Repository contains solvables. */
188 bool solvablesEmpty() const;
190 /** Number of solvables in \ref Repository. */
191 size_type solvablesSize() const;
193 /** Iterator to the first \ref Solvable. */
194 SolvableIterator solvablesBegin() const;
196 /** Iterator behind the last \ref Solvable. */
197 SolvableIterator solvablesEnd() const;
201 /** Query class for Repository related products */
202 class ProductInfoIterator;
205 * Get an iterator to the beginning of the repository
206 * compatible distros.
207 * \note This is only a hint. There is no guarantee that
208 * the repository is built for that product.
209 * \see Repository::ProductInfoIterator
211 ProductInfoIterator compatibleWithProductBegin() const;
214 * Get an iterator to the end of the repository
215 * compatible distros.
216 * \see Repository::ProductInfoIterator
218 ProductInfoIterator compatibleWithProductEnd() const;
221 * Get an iterator to the beginning of distos the repository
222 * provides upadates for.
223 * \note This is only a hint within the repositories metadata.
224 * The same realation might be expressed by a product listing
225 * this repositories ContentIdentifier as required update repo.
226 * \see Repository::ProductInfoIterator
228 ProductInfoIterator updatesProductBegin() const;
231 * Get an iterator to the end of distos the repository
232 * provides upadates for.
233 * \see Repository::ProductInfoIterator
235 ProductInfoIterator updatesProductEnd() const;
238 /** Return any associated \ref RepoInfo. */
239 RepoInfo info() const;
241 /** Set \ref RepoInfo for this repository.
242 * \throws Exception if this is \ref noRepository
243 * \throws Exception if the \ref RepoInfo::alias
244 * does not match the \ref Repository::name.
246 void setInfo( const RepoInfo & info_r );
248 /** Remove any \ref RepoInfo set for this repository. */
252 /** Remove this \ref Repository from it's \ref Pool. */
253 void eraseFromPool();
255 /** Functor calling \ref eraseFromPool. */
256 struct EraseFromPool;
259 /** Return next Repository in \ref Pool (or \ref noRepository). */
260 Repository nextInPool() const;
263 /** \name Repository content manipulating methods.
264 * \todo maybe a separate Repository/Solvable content manip interface
265 * provided by the pool.
268 /** Load \ref Solvables from a solv-file.
269 * In case of an exception the repository remains in the \ref Pool.
270 * \throws Exception if this is \ref noRepository
271 * \throws Exception if loading the solv-file fails.
272 * \see \ref Pool::addRepoSolv and \ref Repository::EraseFromPool
274 void addSolv( const Pathname & file_r );
276 /** Load \ref Solvables from a helix-file.
277 * Supports loading of gzip compressed files (.gz). In case of an exception
278 * the repository remains in the \ref Pool.
279 * \throws Exception if this is \ref noRepository
280 * \throws Exception if loading the helix-file fails.
281 * \see \ref Pool::addRepoHelix and \ref Repository::EraseFromPool
283 void addHelix( const Pathname & file_r );
285 /** Add \c count_r new empty \ref Solvable to this \ref Repository. */
286 sat::Solvable::IdType addSolvables( unsigned count_r );
287 /** \overload Add only one new \ref Solvable. */
288 sat::Solvable::IdType addSolvable()
289 { return addSolvables( 1 ); }
293 /** Expert backdoor. */
294 ::_Repo * get() const;
295 /** Expert backdoor. */
296 IdType id() const { return _id; }
297 /** libsolv internal priorities.
298 * Unlike the \ref RepoInfo priority which tries to be YUM conform
299 * (H[1-99]L), this one is the solvers internal priority representation.
300 * It is type \c int and as one might expect it, the higher the value
301 * the higher the priority. Subpriority is currently used to express
302 * media preferences (\see \ref MediaPriority).
305 int satInternalPriority() const;
306 int satInternalSubPriority() const;
312 ///////////////////////////////////////////////////////////////////
314 /** \relates Repository Stream output */
315 std::ostream & operator<<( std::ostream & str, const Repository & obj );
317 /** \relates Repository XML output */
318 std::ostream & dumpAsXmlOn( std::ostream & str, const Repository & obj );
320 /** \relates Repository */
321 inline bool operator==( const Repository & lhs, const Repository & rhs )
322 { return lhs.get() == rhs.get(); }
324 /** \relates Repository */
325 inline bool operator!=( const Repository & lhs, const Repository & rhs )
326 { return lhs.get() != rhs.get(); }
328 /** \relates Repository */
329 inline bool operator<( const Repository & lhs, const Repository & rhs )
330 { return lhs.get() < rhs.get(); }
332 ///////////////////////////////////////////////////////////////////
334 * Query class for Repository related products
336 * Products are identified by CpeIds within the repositories metadata.
337 * \see http://en.opensuse.org/Standards/Rpm_Metadata#SUSE_repository_info_.28suseinfo.xml.29.2C_extensions_to_repomd.xml
339 * The iterator does not provide a dereference
340 * operator so you can do * on it, but you can
341 * access the attributes of each related product
342 * directly from the iterator.
345 * for_( it, repo.compatibleWithProductBegin(), repo.compatibleWithProductEnd() )
347 * cout << it.label() << ": " << it.cpeid() << endl;
352 class Repository::ProductInfoIterator : public boost::iterator_adaptor<
353 Repository::ProductInfoIterator // Derived
354 , sat::LookupAttr::iterator // Base
356 , boost::forward_traversal_tag // CategoryOrTraversal
361 ProductInfoIterator()
365 std::string label() const;
367 /** The Common Platform Enumeration name for this product. */
371 friend class Repository;
372 /** Hide ctor as just a limited set of attributes is valid. */
373 explicit ProductInfoIterator( sat::SolvAttr attr_r, Repository repo_r );
376 friend class boost::iterator_core_access;
377 int dereference() const { return 0; }
379 ///////////////////////////////////////////////////////////////////
381 ///////////////////////////////////////////////////////////////////
383 // CLASS NAME : Repository::EraseFromPool
385 /** Functor removing \ref Repository from it's \ref Pool.
387 * E.g. used as dispose function in. \ref AutoDispose
388 * to provide a convenient and exception safe temporary
392 * MIL << "1 " << satpool << endl;
394 * AutoDispose<Repository> tmprepo( (Repository::EraseFromPool()) );
395 * *tmprepo = satpool.reposInsert( "A" );
396 * tmprepo->addSolv( "sl10.1-beta7-packages.solv" );
397 * DBG << "2 " << satpool << endl;
398 * // Calling 'tmprepo.resetDispose();' here
399 * // would keep the Repo.
401 * MIL << "3 " << satpool << endl;
404 * 1 sat::pool(){0repos|2slov}
405 * 2 sat::pool(){1repos|2612slov}
406 * 3 sat::pool(){0repos|2slov}
408 * Leaving the block without calling <tt>tmprepo.resetDispose();</tt>
409 * before, will automatically remove the \ref Repo from it's \ref Pool.
411 struct Repository::EraseFromPool
413 void operator()( Repository repository_r ) const
414 { repository_r.eraseFromPool(); }
416 ///////////////////////////////////////////////////////////////////
418 ///////////////////////////////////////////////////////////////////
420 { /////////////////////////////////////////////////////////////////
421 ///////////////////////////////////////////////////////////////////
423 // CLASS NAME : RepositoryIterator
426 class RepositoryIterator : public boost::iterator_adaptor<
427 RepositoryIterator // Derived
429 , Repository // Value
430 , boost::forward_traversal_tag // CategoryOrTraversal
431 , Repository // Reference
436 : RepositoryIterator::iterator_adaptor_( 0 )
439 explicit RepositoryIterator( ::_Repo ** p )
440 : RepositoryIterator::iterator_adaptor_( p )
444 friend class boost::iterator_core_access;
446 Repository dereference() const
447 { return Repository( *base() ); }
451 ///////////////////////////////////////////////////////////////////
452 ///////////////////////////////////////////////////////////////////
454 // CLASS NAME : ByRepository
456 /** Functor filtering \ref Solvable by \ref Repository.*/
460 ByRepository( const Repository & repository_r ) : _repository( repository_r ) {}
461 ByRepository( sat::detail::RepoIdType id_r ) : _repository( id_r ) {}
464 bool operator()( const sat::Solvable & slv_r ) const
465 { return slv_r.repository() == _repository; }
468 Repository _repository;
470 ///////////////////////////////////////////////////////////////////
471 /////////////////////////////////////////////////////////////////
472 } // namespace detail
473 ///////////////////////////////////////////////////////////////////
474 /////////////////////////////////////////////////////////////////
476 ///////////////////////////////////////////////////////////////////
478 // Late include as sat::ArrayAttr requires Repository.h
479 #include "zypp/sat/LookupAttrTools.h"
481 #endif // ZYPP_SAT_REPOSITORY_H