152264c27f26dfc2a8280a9472ac63e84c30225d
[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    * priority=10
60    * \endcode
61    *
62    * \note A RepoInfo is a hint about how
63    * to create a Repository.
64    */
65   class RepoInfo
66   {
67     friend std::ostream & operator<<( std::ostream & str, const RepoInfo & obj );
68
69     public:
70     static unsigned defaultPrioity();
71
72     public:
73     RepoInfo();
74     ~RepoInfo();
75
76     /**
77      * unique identifier for this source. If not specified
78      * It should be generated from the base url.
79      *
80      * Normally, in a .repo file the section name is used
81      * ( [somerepo] )
82      */
83     std::string alias() const;
84
85     /**
86      * Same as alias(), just escaped in a way to be a valid file name.
87      */
88     std::string escaped_alias() const;
89
90     /**
91      * Repository priority for solver.
92      * Some number between \c 1 (highest priority) and \c 99 (\ref defaultPriority).
93      */
94     unsigned priority() const;
95     /**
96      * The default priority (\c 99).
97      */
98     static unsigned defaultPriority();
99     /**
100      * Set repository priority for solver.
101      * A \c newval_r of \c 0 sets the default priority.
102      * \see \ref priority.
103      */
104     RepoInfo & setPriority( unsigned newval_r );
105
106     /**
107      * A Url under which the metadata are located, or a set of mirrors.
108      *
109      * This can't be empty in order the repository to be valid
110      * unless the download of the mirror list succeeds and it
111      * contains a valid url.
112      *
113      * \deprecated IMO superfluous as we provide begin/end iterator.
114      */
115     ZYPP_DEPRECATED std::set<Url> baseUrls() const;
116
117     /**
118      * \short Repository path
119      *
120      * Pathname relative to the base Url where the product/repository
121      * is located
122      *
123      * For medias containing more than one product, or repositories not
124      * located at the root of the media it is important to
125      * know the path of the media root relative to the product directory
126      * so a media verifier can be set for that media.
127      *
128      * It is not mandatory, and the default is /
129      *
130      * \note As a repository can have multiple Urls, the path is unique and
131      * the same for all Urls, so it is assumed all the Urls have the
132      * same media layout.
133      *
134      */
135     Pathname path() const;
136
137     /**
138      * Url of a file which contains a list of Urls
139      * If empty, the base url will be used.
140      */
141     Url mirrorListUrl() const;
142
143     typedef std::set<Url> url_set;
144     //typedef url_set::const_iterator urls_const_iterator;
145     typedef url_set::size_type      urls_size_type;
146     typedef transform_iterator<repo::RepoVariablesUrlReplacer, url_set::const_iterator> urls_const_iterator;
147
148     /**
149      * iterator that points at begin of repository urls
150      */
151     urls_const_iterator baseUrlsBegin() const;
152
153     /**
154      * iterator that points at end of repository urls
155      */
156     urls_const_iterator baseUrlsEnd() const;
157
158     /**
159      * number of repository urls
160      */
161     urls_size_type baseUrlsSize() const;
162
163      /**
164       * whether repository urls are available
165       */
166     bool baseUrlsEmpty() const;
167
168    /**
169      * If enabled is false, then this repository must be ignored as if does
170      * not exists, except when checking for duplicate alias.
171      */
172     bool enabled() const;
173
174     /**
175      * If true, the repostory must be refreshed before creating resolvables
176      * from it
177      */
178     bool autorefresh() const;
179
180     /**
181      * Type of repository,
182      *
183      */
184     repo::RepoType type() const;
185
186     /**
187      * \short Repository short label
188      *
189      * Short label or description of the repository, to be used on
190      * the user interface.
191      * ie: "SUSE Linux 10.2 updates"
192      */
193     std::string name() const;
194
195     /**
196      * \short File where this repo was read from
197      *
198      * \note could be an empty pathname for repo
199      * infos created in memory.
200      */
201      Pathname filepath() const;
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      /**
212      * \short Path where this repo packages are cached
213      */
214      Pathname packagesPath() const;
215
216      /**
217      * \short Whether to check or not this repository with gpg
218      *
219      * \note This is a just a hint to the application and can
220      * be ignored.
221      *
222      */
223     bool gpgCheck() const;
224
225     /**
226      * \short Key to use for gpg checking of this repository
227      *
228      * \param url Url to the key in ASCII armored format
229      *
230      * \note This is a just a hint to the application and can
231      * be ignored.
232      *
233      */
234      Url gpgKeyUrl() const;
235
236     /**
237      * \short Whether to keep the packages downloaded from this repository will be kept in local cache
238      */
239     bool keepPackages() const;
240
241     /**
242      * Gets name of the service to which this repository belongs or empty string
243      * if it has been added manually.
244      */
245     std::string service() const;
246
247     public:
248     /**
249      * Add a base url. \see baseUrls
250      * \param url The base url for the repository.
251      * \note can change keepPackages,so change it after this call
252      *
253      * To recreate the base URLs list, use \ref setBaseUrl(const Url &) followed
254      * by addBaseUrl().
255      */
256     RepoInfo & addBaseUrl( const Url &url );
257
258     /**
259      * Clears current base URL list and adds \a url.
260      * \note can change keepPackages,so change it after this call
261      */
262     RepoInfo & setBaseUrl( const Url &url );
263
264     /**
265      * set the product path. \see path()
266      * \param path the path to the product
267      */
268     RepoInfo & setPath( const Pathname &path );
269
270     /**
271      * Set mirror list url. \see mirrorListUrl
272      * \param url The base url for the list
273      */
274     RepoInfo & setMirrorListUrl( const Url &url );
275
276     /**
277      * enable or disable the repository \see enabled
278      * \param enabled
279      */
280     RepoInfo & setEnabled( bool enabled );
281
282     /**
283      * enable or disable autorefresh \see autorefresh
284      * \param enabled
285      */
286     RepoInfo & setAutorefresh( bool autorefresh );
287
288     /**
289      * set the repository alias \see alias
290      * \param alias
291      */
292     RepoInfo & setAlias( const std::string &alias );
293
294     /**
295      * set the repository type \see type
296      * \param t
297      */
298     RepoInfo & setType( const repo::RepoType &t );
299
300     /**
301      * This allows to adjust the \ref  RepoType lazy, from \c NONE to
302      * some probed value, even for const objects.
303      *
304      * This is a NOOP if the current type is not \c NONE.
305      */
306     void setProbedType( const repo::RepoType &t ) const;
307
308     /**
309      * set the repository name \see name
310      * \param name
311      */
312     RepoInfo & setName( const std::string &name );
313
314     /**
315      * \short set the path to the .repo file
316      *
317      * The path to the .repo file where this repository
318      * was defined, or empty if nowhere.
319      *
320      * \param path File path
321      */
322     RepoInfo & setFilepath( const Pathname &filename );
323
324     /**
325      * \short set the path where the local metadata is stored
326      *
327      * The path to the metadata of this repository
328      * was defined, or empty if nowhere.
329      *
330      * \param path directory path
331      */
332     RepoInfo & setMetadataPath( const Pathname &path );
333
334     /**
335      * \short set the path where the local packages are stored
336      *
337      * \param path directory path
338      */
339     RepoInfo & setPackagesPath( const Pathname &path );
340
341     /**
342      * \short Whether to check or not this repository with gpg
343      *
344      * \param check true (check) or false (dont'check)
345      *
346      * \note This is a just a hint to the application and can
347      * be ignored.
348      *
349      */
350     RepoInfo & setGpgCheck( bool check );
351
352     /**
353      * \short Key to use for gpg checking of this repository
354      *
355      * \param url Url to the key in ASCII armored format
356      *
357      * \note This is a just a hint to the application and can
358      * be ignored.
359      *
360      */
361     RepoInfo & setGpgKeyUrl( const Url &gpgkey );
362
363     /**
364      * \short Set if the packaqes downloaded from this repository will be kept in local cache
365      *
366      * If the setting is true, all downloaded packages from this repository will be
367      * copied to the local raw cache.
368      *
369      * \param keep true (keep the downloaded packages) or false (delete them after installation)
370      *
371      */
372     RepoInfo & setKeepPackages( bool keep );
373
374     /**
375      * sets service which added this repository
376      */
377     RepoInfo & setService( const std::string& name );
378
379     /**
380      * Write a human-readable representation of this RepoInfo object
381      * into the \a str stream. Useful for logging.
382      */
383     std::ostream & dumpOn( std::ostream & str ) const;
384
385     /**
386      * Write this RepoInfo object into \a str in a <tr>.repo</tt> file format.
387      */
388     std::ostream & dumpRepoOn( std::ostream & str ) const;
389
390     class Impl;
391   private:
392     /** Pointer to implementation */
393     RWCOW_pointer<Impl> _pimpl;
394   };
395   ///////////////////////////////////////////////////////////////////
396
397   /** \relates RepoInfo Stream output */
398   std::ostream & operator<<( std::ostream & str, const RepoInfo & obj );
399
400   inline bool operator<( const RepoInfo& lhs, const RepoInfo & rhs )
401   { return lhs.alias() < rhs.alias(); }
402
403   typedef std::list<RepoInfo> RepoInfoList;
404
405   /////////////////////////////////////////////////////////////////
406 } // namespace zypp
407 ///////////////////////////////////////////////////////////////////
408 #endif // ZYPP2_REPOSITORYINFO_H