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