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 );
163 * Clears current base URL list and adds an \ref url_set.
165 void setBaseUrls( url_set urls );
168 * \short Repository path
170 * Pathname relative to the base Url where the product/repository
173 * For media containing more than one product, or repositories not
174 * located at the root of the media it is important to know the path
175 * to the product directory relative to the media root. So a media
176 * verifier can be set for that media. You may also read it as
177 * <tt>baseUrl = url to mount</tt> and <tt>path = path on the
178 * mounted media</tt>.
180 * It is not mandatory, and the default is \c /.
182 * \note As a repository can have multiple Urls, the path is unique and
183 * the same for all Urls, so it is assumed all the Urls have the
187 Pathname path() const;
189 * set the product path. \see path()
190 * \param path the path to the product
192 void setPath( const Pathname &path );
195 * Url of a file which contains a list of repository urls
197 Url mirrorListUrl() const;
199 * The raw mirrorListUrl (no variables replaced).
201 Url rawMirrorListUrl() const;
203 * Set mirror list url. \see mirrorListUrl
204 * \param url The base url for the list
206 void setMirrorListUrl( const Url &url );
208 * Like \ref setMirrorListUrl but expect metalink format.
210 void setMetalinkUrl( const Url &url );
213 * Type of repository,
216 repo::RepoType type() const;
218 * This allows to adjust the \ref RepoType lazy, from \c NONE to
219 * some probed value, even for const objects.
221 * This is a NOOP if the current type is not \c NONE.
223 void setProbedType( const repo::RepoType &t ) const;
225 * set the repository type \see type
228 void setType( const repo::RepoType &t );
231 * \short Path where this repo metadata was read from
233 * \note could be an empty pathname for repo
234 * infos created in memory.
236 Pathname metadataPath() const;
238 * \short set the path where the local metadata is stored
240 * The path to the metadata of this repository
241 * was defined, or empty if nowhere.
243 * \param path directory path
245 void setMetadataPath( const Pathname &path );
248 * \short Path where this repo packages are cached
250 Pathname packagesPath() const;
252 * \short set the path where the local packages are stored
254 * \param path directory path
256 void setPackagesPath( const Pathname &path );
259 /** Whether default signature checking should be performed for this repo.
261 * This will turn on \ref repoGpgCheck for signed repos and
262 * \ref pkgGpgCheck for unsigned ones or if \ref repoGpgCheck is off.
264 * The default is \c true but may be overwritten by \c zypp.conf or a \ref .repo file.
266 bool gpgCheck() const;
267 /** Set the value for \ref gpgCheck (or \c indeterminate to use the default). */
268 void setGpgCheck( TriBool value_r );
269 /** \overload \deprecated legacy and for squid */
270 void setGpgCheck( bool value_r );
272 /** Whether the signature of repo metadata should be checked for this repo.
273 * The default is defined by \ref gpgCheck but may be overwritten by \c zypp.conf or a \ref .repo file.
275 bool repoGpgCheck() const;
276 /** Set the value for \ref repoGpgCheck (or \c indeterminate to use the default). */
277 void setRepoGpgCheck( TriBool value_r );
279 /** Whether the signature of rpm packages should be checked for this repo.
280 * The default is defined by \ref gpgCheck but may be overwritten by \c zypp.conf or a \ref .repo file.
282 bool pkgGpgCheck() const;
283 /** Set the value for \ref pkgGpgCheck (or \c indeterminate to use the default). */
284 void setPkgGpgCheck( TriBool value_r );
286 /** Whether the repo metadata are signed and successfully validated or \c indeterminate if unsigned.
287 * The value is usually set by \ref repo::Downloader when retrieving the metadata.
289 TriBool validRepoSignature() const;
290 /** Set the value for \ref validRepoSignature (or \c indeterminate if unsigned). */
291 void setValidRepoSignature( TriBool value_r );
294 /** Whether gpgkey URLs are defined */
295 bool gpgKeyUrlsEmpty() const;
296 /** Number of gpgkey URLs defined */
297 urls_size_type gpgKeyUrlsSize() const;
299 /** The list of gpgkey URLs defined for this repo */
300 url_set gpgKeyUrls() const;
301 /** The list of raw gpgkey URLs defined for this repo (no variables replaced) */
302 url_set rawGpgKeyUrls() const;
303 /** Set a list of gpgkey URLs defined for this repo */
304 void setGpgKeyUrls( url_set urls );
306 /** (leagcy API) The 1st gpgkey URL defined for this repo */
307 Url gpgKeyUrl() const;
308 /** (leagcy API) The 1st raw gpgkey URL defined for this repo (no variables replaced) */
309 Url rawGpgKeyUrl() const;
310 /** (leagcy API) Set the gpgkey URL defined for this repo */
311 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