- merge Stano's patch to keep downloaded rpms
[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 <iosfwd>
16 #include <list>
17 #include <set>
18 #include "zypp/base/PtrTypes.h"
19 #include "zypp/base/Iterator.h"
20 #include "zypp/base/Deprecated.h"
21
22 #include "zypp/Pathname.h"
23 #include "zypp/Url.h"
24 #include "zypp/repo/RepoType.h"
25 #include "zypp/repo/RepoVariables.h"
26
27 ///////////////////////////////////////////////////////////////////
28 namespace zypp
29 { /////////////////////////////////////////////////////////////////
30
31   ///////////////////////////////////////////////////////////////////
32   //
33   //    CLASS NAME : RepoInfo
34   //
35   /**
36    * \short What is known about a repository
37    *
38    * The class RepoInfo represents everything that
39    * is known about a software repository.
40    *
41    * It can be used to store information about known
42    * sources.
43    *
44    * This class tries to be compatible with the
45    * concept of a .repo file used by YUM and
46    * also available in the openSUSE build service.
47    * See <tt>man yum.conf</tt>.
48    *
49    * Example file
50    *
51    * \code
52    * [ruby]
53    * name=Ruby repository (openSUSE_10.2)
54    * type=rpm-md
55    * baseurl=http://software.opensuse.org/download/ruby/openSUSE_10.2/
56    * gpgcheck=1
57    * gpgkey=http://software.opensuse.org/openSUSE-Build-Service.asc
58    * enabled=1
59    * \endcode
60    *
61    * \note A RepoInfo is a hint about how
62    * to create a Repository.
63    */
64   class RepoInfo
65   {
66     friend std::ostream & operator<<( std::ostream & str, const RepoInfo & obj );
67
68     public:
69     RepoInfo();
70     ~RepoInfo();
71
72     /**
73      * unique identifier for this source. If not specified
74      * It should be generated from the base url.
75      *
76      * Normally, in a .repo file the section name is used
77      * ( [somerepo] )
78      */
79     std::string alias() const;
80
81     /**
82      * Same as alias(), just escaped in a way to be a valid file name.
83      */
84     std::string escaped_alias() const;
85
86     /**
87      * A Url under which the metadata are located, or a set of mirrors.
88      *
89      * This can't be empty in order the repository to be valid
90      * unless the download of the mirror list succeeds and it
91      * contains a valid url.
92      *
93      * \deprecated IMO superfluous as we provide begin/end iterator.
94      */
95     ZYPP_DEPRECATED std::set<Url> baseUrls() const;
96
97     /**
98      * \short Repository path
99      *
100      * Pathname relative to the base Url where the product/repository
101      * is located
102      *
103      * For medias containing more than one product, or repositories not
104      * located at the root of the media it is important to
105      * know the path of the media root relative to the product directory
106      * so a media verifier can be set for that media.
107      *
108      * It is not mandatory, and the default is /
109      *
110      * \note As a repository can have multiple Urls, the path is unique and
111      * the same for all Urls, so it is assumed all the Urls have the
112      * same media layout.
113      *
114      */
115     Pathname path() const;
116
117     /**
118      * Url of a file which contains a list of Urls
119      * If empty, the base url will be used.
120      */
121     Url mirrorListUrl() const;
122
123     typedef std::set<Url> url_set;
124     //typedef url_set::const_iterator urls_const_iterator;
125     typedef url_set::size_type      urls_size_type;
126     typedef transform_iterator<repo::RepoVariablesUrlReplacer, url_set::const_iterator> urls_const_iterator;
127
128     /**
129      * iterator that points at begin of repository urls
130      */
131     urls_const_iterator baseUrlsBegin() const;
132
133     /**
134      * iterator that points at end of repository urls
135      */
136     urls_const_iterator baseUrlsEnd() const;
137
138     /**
139      * number of repository urls
140      */
141     urls_size_type baseUrlsSize() const;
142
143      /**
144       * whether repository urls are available
145       */
146     bool baseUrlsEmpty() const;
147
148    /**
149      * If enabled is false, then this repository must be ignored as if does
150      * not exists, except when checking for duplicate alias.
151      */
152     bool enabled() const;
153
154     /**
155      * If true, the repostory must be refreshed before creating resolvables
156      * from it
157      */
158     bool autorefresh() const;
159
160     /**
161      * Type of repository,
162      *
163      */
164     repo::RepoType type() const;
165
166     /**
167      * \short Repository short label
168      *
169      * Short label or description of the repository, to be used on
170      * the user interface.
171      * ie: "SUSE Linux 10.2 updates"
172      */
173     std::string name() const;
174
175     /**
176      * \short File where this repo was read from
177      *
178      * \note could be an empty pathname for repo
179      * infos created in memory.
180      */
181      Pathname filepath() const;
182
183      /**
184      * \short Path where this repo metadata was read from
185      *
186      * \note could be an empty pathname for repo
187      * infos created in memory.
188      */
189      Pathname metadataPath() const;
190
191      /**
192      * \short Path where this repo packages are cached
193      */
194      Pathname packagesPath() const;
195
196      /**
197      * \short Whether to check or not this repository with gpg
198      *
199      * \note This is a just a hint to the application and can
200      * be ignored.
201      *
202      */
203     bool gpgCheck() const;
204
205     /**
206      * \short Key to use for gpg checking of this repository
207      *
208      * \param url Url to the key in ASCII armored format
209      *
210      * \note This is a just a hint to the application and can
211      * be ignored.
212      *
213      */
214      Url gpgKeyUrl() const;
215
216     /**
217      * \short Whether to keep the packages downloaded from this repository will be kept in local cache
218      */
219     bool keepPackages() const;
220
221     /**
222      * Add a base url. \see baseUrls
223      * \param url The base url for the repository.
224      *
225      * To recreate the base URLs list, use \ref setBaseUrl(const Url &) followed
226      * by addBaseUrl().
227      */
228     RepoInfo & addBaseUrl( const Url &url );
229
230     /**
231      * Clears current base URL list and adds \a url.
232      */
233     RepoInfo & setBaseUrl( const Url &url );
234
235     /**
236      * set the product path. \see path()
237      * \param path the path to the product
238      */
239     RepoInfo & setPath( const Pathname &path );
240
241     /**
242      * Set mirror list url. \see mirrorListUrl
243      * \param url The base url for the list
244      */
245     RepoInfo & setMirrorListUrl( const Url &url );
246
247     /**
248      * enable or disable the repository \see enabled
249      * \param enabled
250      */
251     RepoInfo & setEnabled( bool enabled );
252
253     /**
254      * enable or disable autorefresh \see autorefresh
255      * \param enabled
256      */
257     RepoInfo & setAutorefresh( bool autorefresh );
258
259     /**
260      * set the repository alias \see alias
261      * \param alias
262      */
263     RepoInfo & setAlias( const std::string &alias );
264
265     /**
266      * set the repository type \see type
267      * \param t
268      */
269     RepoInfo & setType( const repo::RepoType &t );
270
271     /**
272      * set the repository name \see name
273      * \param name
274      */
275     RepoInfo & setName( const std::string &name );
276
277     /**
278      * \short set the path to the .repo file
279      *
280      * The path to the .repo file where this repository
281      * was defined, or empty if nowhere.
282      *
283      * \param path File path
284      */
285     RepoInfo & setFilepath( const Pathname &filename );
286
287     /**
288      * \short set the path where the local metadata is stored
289      *
290      * The path to the metadata of this repository
291      * was defined, or empty if nowhere.
292      *
293      * \param path directory path
294      */
295     RepoInfo & setMetadataPath( const Pathname &path );
296
297     /**
298      * \short set the path where the local packages are stored
299      *
300      * \param path directory path
301      */
302     RepoInfo & setPackagesPath( const Pathname &path );
303
304     /**
305      * \short Whether to check or not this repository with gpg
306      *
307      * \param check true (check) or false (dont'check)
308      *
309      * \note This is a just a hint to the application and can
310      * be ignored.
311      *
312      */
313     RepoInfo & setGpgCheck( bool check );
314
315     /**
316      * \short Key to use for gpg checking of this repository
317      *
318      * \param url Url to the key in ASCII armored format
319      *
320      * \note This is a just a hint to the application and can
321      * be ignored.
322      *
323      */
324     RepoInfo & setGpgKeyUrl( const Url &gpgkey );
325     
326     /**
327      * \short Set if the packaqes downloaded from this repository will be kept in local cache
328      *
329      * If the setting is true, all downloaded packages from this repository will be 
330      * copied to the local raw cache.
331      *
332      * \param keep true (keep the downloaded packages) or false (delete them after installation)
333      *
334      */
335     RepoInfo & setKeepPackages( bool keep );
336
337     /**
338      * Write a human-readable representation of this RepoInfo object
339      * into the \a str stream. Useful for logging.
340      */
341     std::ostream & dumpOn( std::ostream & str ) const;
342
343     /**
344      * Write this RepoInfo object into \a str in a <tr>.repo</tt> file format.
345      */
346     std::ostream & dumpRepoOn( std::ostream & str ) const;
347
348     class Impl;
349   private:
350     /** Pointer to implementation */
351     RWCOW_pointer<Impl> _pimpl;
352   };
353   ///////////////////////////////////////////////////////////////////
354
355   /** \relates RepoInfo Stream output */
356   std::ostream & operator<<( std::ostream & str, const RepoInfo & obj );
357
358   typedef std::list<RepoInfo> RepoInfoList;
359
360   /////////////////////////////////////////////////////////////////
361 } // namespace zypp
362 ///////////////////////////////////////////////////////////////////
363 #endif // ZYPP2_REPOSITORYINFO_H