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 * Repository priority for solver.
89 * Some number between \c 1 (highest priority) and \c 99 (\ref defaultPriority).
91 unsigned priority() const;
93 * Set repository priority for solver.
94 * A \c newval_r of \c 0 sets the default priority.
97 void setPriority( unsigned newval_r );
99 typedef std::list<Url> url_set;
100 typedef url_set::size_type urls_size_type;
101 typedef transform_iterator<repo::RepoVariablesUrlReplacer, url_set::const_iterator> urls_const_iterator;
103 * whether repository urls are available
105 bool baseUrlsEmpty() const;
107 * Whether there are manualy configured repository urls.
108 * If \c false, a mirrorlist might be used.
110 bool baseUrlSet() const;
112 * number of repository urls
114 urls_size_type baseUrlsSize() const;
116 * iterator that points at begin of repository urls
118 urls_const_iterator baseUrlsBegin() const;
120 * iterator that points at end of repository urls
122 urls_const_iterator baseUrlsEnd() const;
125 * Pars pro toto: The first repository url
128 { return( baseUrlsEmpty() ? Url() : *baseUrlsBegin()); }
130 * Pars pro toto: The first repository raw url (no variables replaced)
135 * The complete set of repository urls
137 * These are either the configured baseurls, or if empty, the downloaded
138 * mirror list (\see \ref mirrorListUrl)
140 url_set baseUrls() const;
142 * The complete set of raw repository urls (no variables replaced)
144 url_set rawBaseUrls() const;
147 * Add a base url. \see baseUrls
148 * \param url The base url for the repository.
150 * To recreate the base URLs list, use \ref setBaseUrl(const Url &) followed
153 void addBaseUrl( const Url &url );
155 * Clears current base URL list and adds \a url.
157 void setBaseUrl( const Url &url );
159 * Clears current base URL list and adds an \ref url_set.
161 void setBaseUrls( url_set urls );
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 );
205 * Type of repository,
208 repo::RepoType type() const;
210 * This allows to adjust the \ref RepoType lazy, from \c NONE to
211 * some probed value, even for const objects.
213 * This is a NOOP if the current type is not \c NONE.
215 void setProbedType( const repo::RepoType &t ) const;
217 * set the repository type \see type
220 void setType( const repo::RepoType &t );
223 * \short Path where this repo metadata was read from
225 * \note could be an empty pathname for repo
226 * infos created in memory.
228 Pathname metadataPath() const;
230 * \short set the path where the local metadata is stored
232 * The path to the metadata of this repository
233 * was defined, or empty if nowhere.
235 * \param path directory path
237 void setMetadataPath( const Pathname &path );
240 * \short Path where this repo packages are cached
242 Pathname packagesPath() const;
244 * \short set the path where the local packages are stored
246 * \param path directory path
248 void setPackagesPath( const Pathname &path );
251 /** Whether default signature checking should be performed for this repo.
253 * This will turn on \ref repoGpgCheck for signed repos and
254 * \ref pkgGpgCheck for unsigned ones or if \ref repoGpgCheck is off.
256 * The default is \c true but may be overwritten by \c zypp.conf or a \ref .repo file.
258 bool gpgCheck() const;
259 /** Set the value for \ref gpgCheck (or \c indeterminate to use the default). */
260 void setGpgCheck( TriBool value_r );
261 /** \overload \deprecated legacy and for squid */
262 void setGpgCheck( bool value_r );
264 /** Whether the signature of repo metadata should be checked for this repo.
265 * The default is defined by \ref gpgCheck but may be overwritten by \c zypp.conf or a \ref .repo file.
267 bool repoGpgCheck() const;
268 /** Set the value for \ref repoGpgCheck (or \c indeterminate to use the default). */
269 void setRepoGpgCheck( TriBool value_r );
271 /** Whether the signature of rpm packages should be checked for this repo.
272 * The default is defined by \ref gpgCheck but may be overwritten by \c zypp.conf or a \ref .repo file.
274 bool pkgGpgCheck() const;
275 /** Set the value for \ref pkgGpgCheck (or \c indeterminate to use the default). */
276 void setPkgGpgCheck( TriBool value_r );
278 /** Whether the repo metadata are signed and successfully validated or \c indeterminate if unsigned.
279 * The value is usually set by \ref repo::Downloader when retrieving the metadata.
281 TriBool validRepoSignature() const;
282 /** Set the value for \ref validRepoSignature (or \c indeterminate if unsigned). */
283 void setValidRepoSignature( TriBool value_r );
286 /** Whether gpgkey URLs are defined */
287 bool gpgKeyUrlsEmpty() const;
288 /** Number of gpgkey URLs defined */
289 urls_size_type gpgKeyUrlsSize() const;
291 /** The list of gpgkey URLs defined for this repo */
292 url_set gpgKeyUrls() const;
293 /** The list of raw gpgkey URLs defined for this repo (no variables replaced) */
294 url_set rawGpgKeyUrls() const;
295 /** Set a list of gpgkey URLs defined for this repo */
296 void setGpgKeyUrls( url_set urls );
298 /** (leagcy API) The 1st gpgkey URL defined for this repo */
299 Url gpgKeyUrl() const;
300 /** (leagcy API) The 1st raw gpgkey URL defined for this repo (no variables replaced) */
301 Url rawGpgKeyUrl() const;
302 /** (leagcy API) Set the gpgkey URL defined for this repo */
303 void setGpgKeyUrl( const Url &gpgkey );
307 * \short Whether packages downloaded from this repository will be kept in local cache
309 bool keepPackages() const;
311 * \short Set if packaqes downloaded from this repository will be kept in local cache
313 * If the setting is true, all downloaded packages from this repository will be
314 * copied to the local raw cache.
316 * \param keep true (keep the downloaded packages) or false (delete them after installation)
319 void setKeepPackages( bool keep );
322 * Gets name of the service to which this repository belongs or empty string
323 * if it has been added manually.
325 std::string service() const;
327 * sets service which added this repository
329 void setService( const std::string& name );
332 * Distribution for which is this repository meant.
334 std::string targetDistribution() const;
336 * Sets the distribution for which is this repository meant. This is
337 * an in-memory value only, does not get written to the .repo file upon
340 void setTargetDistribution(const std::string & targetDistribution);
342 /** Add content keywords */
343 void addContent( const std::string & keyword_r );
344 /** \overload add keywords from container */
345 template <class _Iterator>
346 void addContentFrom( _Iterator begin_r, _Iterator end_r )
347 { for_( it, begin_r, end_r ) addContent( *it ); }
349 template <class _Container>
350 void addContentFrom( const _Container & container_r )
351 { addContentFrom( container_r.begin(), container_r.end() ); }
353 /** Check for content keywords.
354 * Checking for an empty string returns whether content kewords are
355 * known at all. They may be missing due to missing metadata in disabled
358 bool hasContent( const std::string & keyword_r = std::string() ) const;
359 /** \overload check for \b all keywords being present */
360 template <class _Iterator>
361 bool hasContentAll( _Iterator begin_r, _Iterator end_r ) const
362 { for_( it, begin_r, end_r ) if ( ! hasContent( *it ) ) return false; return true; }
364 template <class _Container>
365 bool hasContentAll( const _Container & container_r ) const
366 { return hasContentAll( container_r.begin(), container_r.end() ); }
367 /** \overload check for \b any keyword being present */
368 template <class _Iterator>
369 bool hasContentAny( _Iterator begin_r, _Iterator end_r ) const
370 { for_( it, begin_r, end_r ) if ( hasContent( *it ) ) return true; return false; }
372 template <class _Container>
373 bool hasContentAny( const _Container & container_r ) const
374 { return hasContentAny( container_r.begin(), container_r.end() ); }
377 /** \name Repository license
380 /** Whether there is a license associated with the repo. */
381 bool hasLicense() const;
383 /** Whether the repo license has to be accepted, e.g. there is no
384 * no acceptance needed for openSUSE.
386 bool needToAcceptLicense() const;
388 /** Return the best license for the current (or a specified) locale. */
389 std::string getLicense( const Locale & lang_r = Locale() ) const;
390 std::string getLicense( const Locale & lang_r = Locale() ); // LEGACY API
392 /** Return the locales the license is available for.
393 * \ref Locale::noCode is included in case of \c license.txt which does
394 * not specify a specific locale.
396 LocaleSet getLicenseLocales() const;
401 * Write a human-readable representation of this RepoInfo object
402 * into the \a str stream. Useful for logging.
404 virtual std::ostream & dumpOn( std::ostream & str ) const;
407 * Write this RepoInfo object into \a str in a <tr>.repo</tt> file format.
408 * Raw values, no variable replacement.
410 virtual std::ostream & dumpAsIniOn( std::ostream & str ) const;
413 * Write an XML representation of this RepoInfo object.
414 * Repo variables replaced.
417 * \param content this argument is ignored (used in other classed derived
420 virtual std::ostream & dumpAsXmlOn( std::ostream & str, const std::string & content = "" ) const;
424 friend class RepoManager;
425 /** Raw values for RepoManager */
426 void getRawGpgChecks( TriBool & g_r, TriBool & r_r, TriBool & p_r ) const;
428 /** Pointer to implementation */
429 RWCOW_pointer<Impl> _pimpl;
431 ///////////////////////////////////////////////////////////////////
433 /** \relates RepoInfo */
434 typedef shared_ptr<RepoInfo> RepoInfo_Ptr;
435 /** \relates RepoInfo */
436 typedef shared_ptr<const RepoInfo> RepoInfo_constPtr;
437 /** \relates RepoInfo */
438 typedef std::list<RepoInfo> RepoInfoList;
440 /** \relates RepoInfo Stream output */
441 std::ostream & operator<<( std::ostream & str, const RepoInfo & obj );
444 /////////////////////////////////////////////////////////////////
446 ///////////////////////////////////////////////////////////////////
447 #endif // ZYPP2_REPOSITORYINFO_H