1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/RepoInfo.h
12 #ifndef ZYPP2_REPOSITORYINFO_H
13 #define ZYPP2_REPOSITORYINFO_H
18 #include "zypp/base/Iterator.h"
19 #include "zypp/APIConfig.h"
22 #include "zypp/Locale.h"
23 #include "zypp/TriBool.h"
24 #include "zypp/repo/RepoType.h"
25 #include "zypp/repo/RepoVariables.h"
27 #include "zypp/repo/RepoInfoBase.h"
29 ///////////////////////////////////////////////////////////////////
31 { /////////////////////////////////////////////////////////////////
33 ///////////////////////////////////////////////////////////////////
35 // CLASS NAME : RepoInfo
38 * \short What is known about a repository
40 * The class RepoInfo represents everything that
41 * is known about a software repository.
43 * It can be used to store information about known
46 * This class tries to be compatible with the
47 * concept of a .repo file used by YUM and
48 * also available in the openSUSE build service.
49 * See <tt>man yum.conf</tt>.
55 * name=Ruby repository (openSUSE_10.2)
57 * baseurl=http://software.opensuse.org/download/ruby/openSUSE_10.2/
58 * http://some.opensuse.mirror/ruby/openSUSE_10.2/
60 * gpgkey=http://software.opensuse.org/openSUSE-Build-Service.asc
65 * \note A RepoInfo is a hint about how
66 * to create a Repository.
68 * \note Name, baseUrls and mirrorUrl are subject to repo variable replacement
69 * (\see \ref RepoVariablesStringReplacer).
71 class RepoInfo : public repo::RepoInfoBase
73 friend std::ostream & operator<<( std::ostream & str, const RepoInfo & obj );
79 /** Represents no Repository (one with an empty alias). */
80 static const RepoInfo noRepo;
84 * The default priority (\c 99).
86 static unsigned defaultPriority();
88 * The least priority (<tt>unsigned(-1)</tt>).
90 static unsigned noPriority();
92 * Repository priority for solver.
93 * Some number between \c 1 (highest priority) and \c 99 (\ref defaultPriority).
95 unsigned priority() const;
97 * Set repository priority for solver.
98 * A \c newval_r of \c 0 sets the default priority.
101 void setPriority( unsigned newval_r );
103 typedef std::list<Url> url_set;
104 typedef url_set::size_type urls_size_type;
105 typedef transform_iterator<repo::RepoVariablesUrlReplacer, url_set::const_iterator> urls_const_iterator;
107 * whether repository urls are available
109 bool baseUrlsEmpty() const;
111 * Whether there are manualy configured repository urls.
112 * If \c false, a mirrorlist might be used.
114 bool baseUrlSet() const;
116 * number of repository urls
118 urls_size_type baseUrlsSize() const;
120 * iterator that points at begin of repository urls
122 urls_const_iterator baseUrlsBegin() const;
124 * iterator that points at end of repository urls
126 urls_const_iterator baseUrlsEnd() const;
129 * Pars pro toto: The first repository url
132 { return( baseUrlsEmpty() ? Url() : *baseUrlsBegin()); }
134 * Pars pro toto: The first repository raw url (no variables replaced)
139 * The complete set of repository urls
141 * These are either the configured baseurls, or if empty, the downloaded
142 * mirror list (\see \ref mirrorListUrl)
144 url_set baseUrls() const;
146 * The complete set of raw repository urls (no variables replaced)
148 url_set rawBaseUrls() const;
151 * Add a base url. \see baseUrls
152 * \param url The base url for the repository.
154 * To recreate the base URLs list, use \ref setBaseUrl(const Url &) followed
157 void addBaseUrl( const Url &url );
159 * Clears current base URL list and adds \a url.
161 void setBaseUrl( const Url &url );
164 * \short Repository path
166 * Pathname relative to the base Url where the product/repository
169 * For media containing more than one product, or repositories not
170 * located at the root of the media it is important to know the path
171 * to the product directory relative to the media root. So a media
172 * verifier can be set for that media. You may also read it as
173 * <tt>baseUrl = url to mount</tt> and <tt>path = path on the
174 * mounted media</tt>.
176 * It is not mandatory, and the default is \c /.
178 * \note As a repository can have multiple Urls, the path is unique and
179 * the same for all Urls, so it is assumed all the Urls have the
183 Pathname path() const;
185 * set the product path. \see path()
186 * \param path the path to the product
188 void setPath( const Pathname &path );
191 * Url of a file which contains a list of repository urls
193 Url mirrorListUrl() const;
195 * The raw mirrorListUrl (no variables replaced).
197 Url rawMirrorListUrl() const;
199 * Set mirror list url. \see mirrorListUrl
200 * \param url The base url for the list
202 void setMirrorListUrl( const Url &url );
204 * Like \ref setMirrorListUrl but expect metalink format.
206 void setMetalinkUrl( const Url &url );
209 * Type of repository,
212 repo::RepoType type() const;
214 * This allows to adjust the \ref RepoType lazy, from \c NONE to
215 * some probed value, even for const objects.
217 * This is a NOOP if the current type is not \c NONE.
219 void setProbedType( const repo::RepoType &t ) const;
221 * set the repository type \see type
224 void setType( const repo::RepoType &t );
227 * \short Path where this repo metadata was read from
229 * \note could be an empty pathname for repo
230 * infos created in memory.
232 Pathname metadataPath() const;
234 * \short set the path where the local metadata is stored
236 * The path to the metadata of this repository
237 * was defined, or empty if nowhere.
239 * \param path directory path
241 void setMetadataPath( const Pathname &path );
244 * \short Path where this repo packages are cached
246 Pathname packagesPath() const;
248 * \short set the path where the local packages are stored
250 * \param path directory path
252 void setPackagesPath( const Pathname &path );
255 /** Whether default signature checking should be performed for this repo.
257 * This will turn on \ref repoGpgCheck for signed repos and
258 * \ref pkgGpgCheck for unsigned ones or if \ref repoGpgCheck is off.
260 * The default is \c true but may be overwritten by \c zypp.conf or a \ref .repo file.
262 bool gpgCheck() const;
263 /** Set the value for \ref gpgCheck (or \c indeterminate to use the default). */
264 void setGpgCheck( TriBool value_r );
265 /** \overload \deprecated legacy and for squid */
266 void setGpgCheck( bool value_r );
268 /** Whether the signature of repo metadata should be checked for this repo.
269 * The default is defined by \ref gpgCheck but may be overwritten by \c zypp.conf or a \ref .repo file.
271 bool repoGpgCheck() const;
272 /** Set the value for \ref repoGpgCheck (or \c indeterminate to use the default). */
273 void setRepoGpgCheck( TriBool value_r );
275 /** Whether the signature of rpm packages should be checked for this repo.
276 * The default is defined by \ref gpgCheck but may be overwritten by \c zypp.conf or a \ref .repo file.
278 bool pkgGpgCheck() const;
279 /** Set the value for \ref pkgGpgCheck (or \c indeterminate to use the default). */
280 void setPkgGpgCheck( TriBool value_r );
282 /** Whether the repo metadata are signed and successfully validated or \c indeterminate if unsigned.
283 * The value is usually set by \ref repo::Downloader when retrieving the metadata.
285 TriBool validRepoSignature() const;
286 /** Set the value for \ref validRepoSignature (or \c indeterminate if unsigned). */
287 void setValidRepoSignature( TriBool value_r );
290 * \short Key to use for gpg checking of this repository
292 * \param url Url to the key in ASCII armored format
294 * \note This is a just a hint to the application and can
298 Url gpgKeyUrl() const;
300 * The raw gpgKeyUrl (no variables replaced).
302 Url rawGpgKeyUrl() const;
304 * \short Key to use for gpg checking of this repository
306 * \param url Url to the key in ASCII armored format
308 * \note This is a just a hint to the application and can
312 void setGpgKeyUrl( const Url &gpgkey );
315 * \short Whether packages downloaded from this repository will be kept in local cache
317 bool keepPackages() const;
319 * \short Set if packaqes downloaded from this repository will be kept in local cache
321 * If the setting is true, all downloaded packages from this repository will be
322 * copied to the local raw cache.
324 * \param keep true (keep the downloaded packages) or false (delete them after installation)
327 void setKeepPackages( bool keep );
330 * Gets name of the service to which this repository belongs or empty string
331 * if it has been added manually.
333 std::string service() const;
335 * sets service which added this repository
337 void setService( const std::string& name );
340 * Distribution for which is this repository meant.
342 std::string targetDistribution() const;
344 * Sets the distribution for which is this repository meant. This is
345 * an in-memory value only, does not get written to the .repo file upon
348 void setTargetDistribution(const std::string & targetDistribution);
351 /** Content keywords defined. */
352 const std::set<std::string> & contentKeywords() const;
354 /** Add content keywords */
355 void addContent( const std::string & keyword_r );
356 /** \overload add keywords from container */
357 template <class TIterator>
358 void addContentFrom( TIterator begin_r, TIterator end_r )
359 { for_( it, begin_r, end_r ) addContent( *it ); }
361 template <class TContainer>
362 void addContentFrom( const TContainer & container_r )
363 { addContentFrom( container_r.begin(), container_r.end() ); }
365 /** Check for content keywords.
366 * They may be missing due to missing metadata in disabled repos.
368 bool hasContent() const;
369 /** \overload check for a keywords being present */
370 bool hasContent( const std::string & keyword_r ) const;
371 /** \overload check for \b all keywords being present */
372 template <class TIterator>
373 bool hasContentAll( TIterator begin_r, TIterator end_r ) const
374 { for_( it, begin_r, end_r ) if ( ! hasContent( *it ) ) return false; return true; }
376 template <class TContainer>
377 bool hasContentAll( const TContainer & container_r ) const
378 { return hasContentAll( container_r.begin(), container_r.end() ); }
379 /** \overload check for \b any keyword being present */
380 template <class TIterator>
381 bool hasContentAny( TIterator begin_r, TIterator end_r ) const
382 { for_( it, begin_r, end_r ) if ( hasContent( *it ) ) return true; return false; }
384 template <class TContainer>
385 bool hasContentAny( const TContainer & container_r ) const
386 { return hasContentAny( container_r.begin(), container_r.end() ); }
389 /** \name Repository license
392 /** Whether there is a license associated with the repo. */
393 bool hasLicense() const;
395 /** Whether the repo license has to be accepted, e.g. there is no
396 * no acceptance needed for openSUSE.
398 bool needToAcceptLicense() const;
400 /** Return the best license for the current (or a specified) locale. */
401 std::string getLicense( const Locale & lang_r = Locale() ) const;
402 std::string getLicense( const Locale & lang_r = Locale() ); // LEGACY API
404 /** Return the locales the license is available for.
405 * \ref Locale::noCode is included in case of \c license.txt which does
406 * not specify a specific locale.
408 LocaleSet getLicenseLocales() const;
413 * Write a human-readable representation of this RepoInfo object
414 * into the \a str stream. Useful for logging.
416 virtual std::ostream & dumpOn( std::ostream & str ) const;
419 * Write this RepoInfo object into \a str in a <tr>.repo</tt> file format.
420 * Raw values, no variable replacement.
422 virtual std::ostream & dumpAsIniOn( std::ostream & str ) const;
425 * Write an XML representation of this RepoInfo object.
426 * Repo variables replaced.
429 * \param content this argument is ignored (used in other classed derived
432 virtual std::ostream & dumpAsXmlOn( std::ostream & str, const std::string & content = "" ) const;
436 friend class RepoManager;
437 /** Raw values for RepoManager */
438 void getRawGpgChecks( TriBool & g_r, TriBool & r_r, TriBool & p_r ) const;
440 /** Pointer to implementation */
441 RWCOW_pointer<Impl> _pimpl;
443 ///////////////////////////////////////////////////////////////////
445 /** \relates RepoInfo */
446 typedef shared_ptr<RepoInfo> RepoInfo_Ptr;
447 /** \relates RepoInfo */
448 typedef shared_ptr<const RepoInfo> RepoInfo_constPtr;
449 /** \relates RepoInfo */
450 typedef std::list<RepoInfo> RepoInfoList;
452 /** \relates RepoInfo Stream output */
453 std::ostream & operator<<( std::ostream & str, const RepoInfo & obj );
456 /////////////////////////////////////////////////////////////////
458 ///////////////////////////////////////////////////////////////////
459 #endif // ZYPP2_REPOSITORYINFO_H