Let RepoInfo::keepPackages properly default to FALSE (bnc#727385)
[platform/upstream/libzypp.git] / zypp / RepoInfo.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/RepoInfo.h
10  *
11 */
12 #ifndef ZYPP2_REPOSITORYINFO_H
13 #define ZYPP2_REPOSITORYINFO_H
14
15 #include <list>
16 #include <set>
17
18 #include "zypp/base/Iterator.h"
19 #include "zypp/base/Deprecated.h"
20
21 #include "zypp/Url.h"
22 #include "zypp/Locale.h"
23 #include "zypp/repo/RepoType.h"
24 #include "zypp/repo/RepoVariables.h"
25
26 #include "zypp/repo/RepoInfoBase.h"
27
28 ///////////////////////////////////////////////////////////////////
29 namespace zypp
30 { /////////////////////////////////////////////////////////////////
31
32   ///////////////////////////////////////////////////////////////////
33   //
34   //    CLASS NAME : RepoInfo
35   //
36   /**
37    * \short What is known about a repository
38    *
39    * The class RepoInfo represents everything that
40    * is known about a software repository.
41    *
42    * It can be used to store information about known
43    * sources.
44    *
45    * This class tries to be compatible with the
46    * concept of a .repo file used by YUM and
47    * also available in the openSUSE build service.
48    * See <tt>man yum.conf</tt>.
49    *
50    * Example file
51    *
52    * \code
53    * [ruby]
54    * name=Ruby repository (openSUSE_10.2)
55    * type=rpm-md
56    * baseurl=http://software.opensuse.org/download/ruby/openSUSE_10.2/
57    * gpgcheck=1
58    * gpgkey=http://software.opensuse.org/openSUSE-Build-Service.asc
59    * enabled=1
60    * priority=10
61    * \endcode
62    *
63    * \note A RepoInfo is a hint about how
64    * to create a Repository.
65    */
66   class RepoInfo : public repo::RepoInfoBase
67   {
68     friend std::ostream & operator<<( std::ostream & str, const RepoInfo & obj );
69
70     public:
71       RepoInfo();
72       virtual ~RepoInfo();
73
74       /** Represents no Repository (one with an empty alias). */
75       static const RepoInfo noRepo;
76
77     public:
78       /**
79        * The default priority (\c 99).
80        */
81       static unsigned defaultPriority();
82       /**
83        * Repository priority for solver.
84        * Some number between \c 1 (highest priority) and \c 99 (\ref defaultPriority).
85        */
86       unsigned priority() const;
87       /**
88        * Set repository priority for solver.
89        * A \c newval_r of \c 0 sets the default priority.
90        * \see \ref priority.
91        */
92       void setPriority( unsigned newval_r );
93
94       typedef std::set<Url>           url_set;
95       typedef url_set::size_type      urls_size_type;
96       typedef transform_iterator<repo::RepoVariablesUrlReplacer, url_set::const_iterator> urls_const_iterator;
97       /**
98        * whether repository urls are available
99        */
100       bool baseUrlsEmpty() const;
101       /**
102        * whether there are manualy configured repository urls
103        */
104       bool baseUrlSet() const;
105       /**
106        * number of repository urls
107        */
108       urls_size_type baseUrlsSize() const;
109       /**
110        * iterator that points at begin of repository urls
111        */
112       urls_const_iterator baseUrlsBegin() const;
113       /**
114        * iterator that points at end of repository urls
115        */
116       urls_const_iterator baseUrlsEnd() const;
117       /**
118        * Pars pro toto: The first repository url
119        */
120       Url url() const
121       { return( baseUrlsEmpty() ? Url() : *baseUrlsBegin()); }
122       /**
123        * A Url under which the metadata are located, or a set of mirrors.
124        *
125        * This can't be empty in order the repository to be valid
126        * unless the download of the mirror list succeeds and it
127        * contains a valid url.
128        *
129        * \deprecated IMO superfluous as we provide begin/end iterator.
130        */
131       std::set<Url> baseUrls() const;
132       /**
133        * Add a base url. \see baseUrls
134        * \param url The base url for the repository.
135        * \note can change keepPackages,so change it after this call
136        *
137        * To recreate the base URLs list, use \ref setBaseUrl(const Url &) followed
138        * by addBaseUrl().
139        */
140       void addBaseUrl( const Url &url );
141       /**
142        * Clears current base URL list and adds \a url.
143        * \note can change keepPackages,so change it after this call
144        */
145       void setBaseUrl( const Url &url );
146
147       /**
148        * \short Repository path
149        *
150        * Pathname relative to the base Url where the product/repository
151        * is located
152        *
153        * For media containing more than one product, or repositories not
154        * located at the root of the media it is important to know the path
155        * to the product directory relative to the media root. So a media
156        * verifier can be set for that media. You may also read it as
157        * <tt>baseUrl = url to mount</tt> and <tt>path = path on the
158        * mounted media</tt>.
159        *
160        * It is not mandatory, and the default is \c /.
161        *
162        * \note As a repository can have multiple Urls, the path is unique and
163        * the same for all Urls, so it is assumed all the Urls have the
164        * same media layout.
165        *
166        */
167       Pathname path() const;
168       /**
169        * set the product path. \see path()
170        * \param path the path to the product
171        */
172       void setPath( const Pathname &path );
173
174       /**
175        * Url of a file which contains a list of Urls
176        * If empty, the base url will be used.
177        */
178       Url mirrorListUrl() const;
179       /**
180        * Set mirror list url. \see mirrorListUrl
181        * \param url The base url for the list
182        */
183       void setMirrorListUrl( const Url &url );
184
185       /**
186        * Type of repository,
187        *
188        */
189       repo::RepoType type() const;
190       /**
191        * This allows to adjust the \ref  RepoType lazy, from \c NONE to
192        * some probed value, even for const objects.
193        *
194        * This is a NOOP if the current type is not \c NONE.
195        */
196       void setProbedType( const repo::RepoType &t ) const;
197       /**
198        * set the repository type \see type
199        * \param t
200        */
201       void setType( const repo::RepoType &t );
202
203       /**
204        * \short Path where this repo metadata was read from
205        *
206        * \note could be an empty pathname for repo
207        * infos created in memory.
208        */
209       Pathname metadataPath() const;
210       /**
211        * \short set the path where the local metadata is stored
212        *
213        * The path to the metadata of this repository
214        * was defined, or empty if nowhere.
215        *
216        * \param path directory path
217        */
218       void setMetadataPath( const Pathname &path );
219
220       /**
221        * \short Path where this repo packages are cached
222        */
223       Pathname packagesPath() const;
224       /**
225        * \short set the path where the local packages are stored
226        *
227        * \param path directory path
228        */
229       void setPackagesPath( const Pathname &path );
230
231       /**
232        * \short Whether to check or not this repository with gpg
233        *
234        * \note This is a just a hint to the application and can
235        * be ignored.
236        *
237        */
238       bool gpgCheck() const;
239       /**
240        * \short Whether to check or not this repository with gpg
241        *
242        * \param check true (check) or false (dont'check)
243        *
244        * \note This is a just a hint to the application and can
245        * be ignored.
246        *
247        */
248       void setGpgCheck( bool check );
249
250       /**
251        * \short Key to use for gpg checking of this repository
252        *
253        * \param url Url to the key in ASCII armored format
254        *
255        * \note This is a just a hint to the application and can
256        * be ignored.
257        *
258        */
259       Url gpgKeyUrl() const;
260       /**
261        * \short Key to use for gpg checking of this repository
262        *
263        * \param url Url to the key in ASCII armored format
264        *
265        * \note This is a just a hint to the application and can
266        * be ignored.
267        *
268        */
269       void setGpgKeyUrl( const Url &gpgkey );
270
271       /**
272        * \short Whether packages downloaded from this repository will be kept in local cache
273        */
274       bool keepPackages() const;
275       /**
276        * \short Set if packaqes downloaded from this repository will be kept in local cache
277        *
278        * If the setting is true, all downloaded packages from this repository will be
279        * copied to the local raw cache.
280        *
281        * \param keep true (keep the downloaded packages) or false (delete them after installation)
282        *
283        */
284       void setKeepPackages( bool keep );
285
286       /**
287        * Gets name of the service to which this repository belongs or empty string
288        * if it has been added manually.
289        */
290       std::string service() const;
291       /**
292        * sets service which added this repository
293        */
294       void setService( const std::string& name );
295
296       /**
297        * Distribution for which is this repository meant.
298        */
299       std::string targetDistribution() const;
300       /**
301        * Sets the distribution for which is this repository meant. This is
302        * an in-memory value only, does not get written to the .repo file upon
303        * saving.
304        */
305       void setTargetDistribution(const std::string & targetDistribution);
306
307     public:
308       /** \name Repository license
309       */
310       //@{
311       /** Whether there is a license associated with the repo. */
312       bool hasLicense() const;
313
314       /** Return the best license for the current (or a specified) locale. */
315       std::string getLicense( const Locale & lang_r = Locale() );
316
317       /** Return the locales the license is available for.
318        * \ref Locale::noCode is included in case of \c license.txt which does
319        * not specify a specific locale.
320        */
321       LocaleSet getLicenseLocales() const;
322       //@}
323
324       /** \name Repository global unique id
325        *
326        *
327        */
328       //@{
329       //@}
330
331     public:
332       /**
333        * Write a human-readable representation of this RepoInfo object
334        * into the \a str stream. Useful for logging.
335        */
336       virtual std::ostream & dumpOn( std::ostream & str ) const;
337
338       /**
339        * Write this RepoInfo object into \a str in a <tr>.repo</tt> file format.
340        */
341       virtual std::ostream & dumpAsIniOn( std::ostream & str ) const;
342
343       /**
344        * Write an XML representation of this RepoInfo object.
345        */
346       virtual std::ostream & dumpAsXMLOn(std::ostream & str) const;
347
348       /**
349        * Write an XML representation of this RepoInfo object.
350        *
351        * \param str
352        * \param content this argument is ignored (used in other classed derived
353        *                from RepoInfoBase.
354        */
355       virtual std::ostream & dumpAsXMLOn( std::ostream & str, const std::string & content ) const;
356
357       class Impl;
358     private:
359       /** Pointer to implementation */
360       RWCOW_pointer<Impl> _pimpl;
361   };
362   ///////////////////////////////////////////////////////////////////
363
364   /** \relates RepoInfo */
365   typedef shared_ptr<RepoInfo> RepoInfo_Ptr;
366   /** \relates RepoInfo */
367   typedef shared_ptr<const RepoInfo> RepoInfo_constPtr;
368   /** \relates RepoInfo */
369   typedef std::list<RepoInfo> RepoInfoList;
370
371   /** \relates RepoInfo Stream output */
372   std::ostream & operator<<( std::ostream & str, const RepoInfo & obj );
373
374
375   /////////////////////////////////////////////////////////////////
376 } // namespace zypp
377 ///////////////////////////////////////////////////////////////////
378 #endif // ZYPP2_REPOSITORYINFO_H