- RepoInfo{Base} setters made void
[platform/upstream/libzypp.git] / zypp / RepoInfo.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/RepoInfo.cc
10  *
11 */
12 #include <iostream>
13
14 #include "zypp/base/Logger.h"
15 #include "zypp/base/DefaultIntegral.h"
16 #include "zypp/media/MediaAccess.h"
17
18 #include "zypp/RepoInfo.h"
19 #include "zypp/repo/RepoInfoBaseImpl.h"
20
21 using namespace std;
22
23 ///////////////////////////////////////////////////////////////////
24 namespace zypp
25 { /////////////////////////////////////////////////////////////////
26
27   ///////////////////////////////////////////////////////////////////
28   //
29   //    CLASS NAME : RepoInfo::Impl
30   //
31   /** RepoInfo implementation. */
32   struct RepoInfo::Impl : public repo::RepoInfoBase::Impl
33   {
34     Impl()
35       : repo::RepoInfoBase::Impl()
36       , gpgcheck(indeterminate)
37       , keeppackages(indeterminate)
38       , type(repo::RepoType::NONE_e)
39     {}
40
41     ~Impl()
42     {}
43
44   public:
45     static const unsigned defaultPriority = 99;
46
47     void setProbedType( const repo::RepoType & t ) const
48     {
49       if ( type == repo::RepoType::NONE
50            && t != repo::RepoType::NONE )
51       {
52         // lazy init!
53         const_cast<Impl*>(this)->type = t;
54       }
55     }
56
57   public:
58     TriBool gpgcheck;
59     TriBool keeppackages;
60     Url gpgkey_url;
61     repo::RepoType type;
62     Url mirrorlist_url;
63     std::set<Url> baseUrls;
64     Pathname path;
65     std::string service;
66     std::string targetDistro;
67     Pathname metadatapath;
68     Pathname packagespath;
69     DefaultIntegral<unsigned,defaultPriority> priority;
70   public:
71
72   private:
73     friend Impl * rwcowClone<Impl>( const Impl * rhs );
74     /** clone for RWCOW_pointer */
75     Impl * clone() const
76     { return new Impl( *this ); }
77   };
78   ///////////////////////////////////////////////////////////////////
79
80   /** \relates RepoInfo::Impl Stream output */
81   inline std::ostream & operator<<( std::ostream & str, const RepoInfo::Impl & obj )
82   {
83     return str << "RepoInfo::Impl";
84   }
85
86   ///////////////////////////////////////////////////////////////////
87   //
88   //    CLASS NAME : RepoInfo
89   //
90   ///////////////////////////////////////////////////////////////////
91
92   IMPL_PTR_TYPE(RepoInfo);
93
94   ///////////////////////////////////////////////////////////////////
95   //
96   //    METHOD NAME : RepoInfo::RepoInfo
97   //    METHOD TYPE : Ctor
98   //
99   RepoInfo::RepoInfo()
100   : _pimpl( new Impl() )
101   {}
102
103   ///////////////////////////////////////////////////////////////////
104   //
105   //    METHOD NAME : RepoInfo::~RepoInfo
106   //    METHOD TYPE : Dtor
107   //
108   RepoInfo::~RepoInfo()
109   {
110     //MIL << std::endl;
111   }
112
113   unsigned RepoInfo::priority() const
114   { return _pimpl->priority; }
115   unsigned RepoInfo::defaultPriority()
116   { return Impl::defaultPriority; }
117   void RepoInfo::setPriority( unsigned newval_r )
118   {
119     _pimpl->priority = newval_r ? newval_r : Impl::defaultPriority;
120   }
121
122   void RepoInfo::setGpgCheck( bool check )
123   {
124     _pimpl->gpgcheck = check;
125   }
126
127   void RepoInfo::setMirrorListUrl( const Url &url )
128   {
129     _pimpl->mirrorlist_url = url;
130   }
131
132   void RepoInfo::setGpgKeyUrl( const Url &url )
133   {
134     _pimpl->gpgkey_url = url;
135   }
136
137   void RepoInfo::addBaseUrl( const Url &url )
138   {
139     _pimpl->baseUrls.insert(url);
140   }
141
142   void RepoInfo::setBaseUrl( const Url &url )
143   {
144     _pimpl->baseUrls.clear();
145     addBaseUrl(url);
146   }
147
148   void RepoInfo::setPath( const Pathname &path )
149   {
150     _pimpl->path = path;
151   }
152
153   void RepoInfo::setType( const repo::RepoType &t )
154   {
155     _pimpl->type = t;
156   }
157
158   void RepoInfo::setProbedType( const repo::RepoType &t ) const
159   { _pimpl->setProbedType( t ); }
160
161
162   void RepoInfo::setMetadataPath( const Pathname &path )
163   {
164     _pimpl->metadatapath = path;
165   }
166
167   void RepoInfo::setPackagesPath( const Pathname &path )
168   {
169     _pimpl->packagespath = path;
170   }
171
172   void RepoInfo::setKeepPackages( bool keep )
173   {
174     _pimpl->keeppackages = keep;
175   }
176
177   void RepoInfo::setService( const std::string& name )
178   {
179     _pimpl->service = name;
180   }
181   
182   void RepoInfo::setTargetDistribution(
183       const std::string & targetDistribution)
184   {
185     _pimpl->targetDistro = targetDistribution;
186   }
187
188   bool RepoInfo::gpgCheck() const
189   { return indeterminate(_pimpl->gpgcheck) ? true : (bool) _pimpl->gpgcheck; }
190
191   Pathname RepoInfo::metadataPath() const
192   { return _pimpl->metadatapath; }
193
194   Pathname RepoInfo::packagesPath() const
195   { return _pimpl->packagespath; }
196
197   repo::RepoType RepoInfo::type() const
198   { return _pimpl->type; }
199
200   Url RepoInfo::mirrorListUrl() const
201   { return _pimpl->mirrorlist_url; }
202
203   Url RepoInfo::gpgKeyUrl() const
204   { return _pimpl->gpgkey_url; }
205
206   std::set<Url> RepoInfo::baseUrls() const
207   {
208     RepoInfo::url_set replaced_urls;
209     repo::RepoVariablesUrlReplacer replacer;
210     for ( url_set::const_iterator it = _pimpl->baseUrls.begin();
211           it != _pimpl->baseUrls.end();
212           ++it )
213     {
214       replaced_urls.insert(replacer(*it));
215     }
216     return replaced_urls;
217
218     return _pimpl->baseUrls;
219   }
220
221   Pathname RepoInfo::path() const
222   { return _pimpl->path; }
223
224   std::string RepoInfo::service() const
225   { return _pimpl->service; }
226   
227   std::string RepoInfo::targetDistribution() const
228   { return _pimpl->targetDistro; }
229
230   RepoInfo::urls_const_iterator RepoInfo::baseUrlsBegin() const
231   {
232     return make_transform_iterator( _pimpl->baseUrls.begin(),
233                                     repo::RepoVariablesUrlReplacer() );
234     //return _pimpl->baseUrls.begin();
235   }
236
237   RepoInfo::urls_const_iterator RepoInfo::baseUrlsEnd() const
238   {
239     //return _pimpl->baseUrls.end();
240     return make_transform_iterator( _pimpl->baseUrls.end(),
241                                     repo::RepoVariablesUrlReplacer() );
242   }
243
244   RepoInfo::urls_size_type RepoInfo::baseUrlsSize() const
245   { return _pimpl->baseUrls.size(); }
246
247   bool RepoInfo::baseUrlsEmpty() const
248   { return _pimpl->baseUrls.empty(); }
249
250   // false by default (if not set by setKeepPackages)
251   bool RepoInfo::keepPackages() const
252   {
253     if (indeterminate(_pimpl->keeppackages))
254     {
255       if (_pimpl->baseUrls.empty())
256         return false;
257       else if ( media::MediaAccess::downloads( *baseUrlsBegin() ) )
258         return true;
259       else
260         return false;
261     }
262
263     return (bool) _pimpl->keeppackages;
264   }
265
266
267   std::ostream & RepoInfo::dumpOn( std::ostream & str ) const
268   {
269     RepoInfoBase::dumpOn(str);
270     for ( urls_const_iterator it = baseUrlsBegin();
271           it != baseUrlsEnd();
272           ++it )
273     {
274       str << "- url         : " << *it << std::endl;
275     }
276     str << "- path        : " << path() << std::endl;
277     str << "- type        : " << type() << std::endl;
278     str << "- priority    : " << priority() << std::endl;
279
280     str << "- gpgcheck    : " << gpgCheck() << std::endl;
281     str << "- gpgkey      : " << gpgKeyUrl() << std::endl;
282     str << "- keeppackages: " << keepPackages() << std::endl;
283     str << "- service     : " << service() << std::endl;
284
285     if (!targetDistribution().empty())
286       str << "- targetdistro: " << targetDistribution() << std::endl;
287
288     return str;
289   }
290
291   std::ostream & RepoInfo::dumpRepoOn( std::ostream & str ) const
292   {
293     RepoInfoBase::dumpAsIniOn(str);
294
295     if ( ! _pimpl->baseUrls.empty() )
296       str << "baseurl=";
297     for ( url_set::const_iterator it = _pimpl->baseUrls.begin();
298           it != _pimpl->baseUrls.end();
299           ++it )
300     {
301       str << *it << endl;
302     }
303
304     if ( ! _pimpl->path.empty() )
305       str << "path="<< path() << endl;
306
307     if ( ! (_pimpl->mirrorlist_url.asString().empty()) )
308       str << "mirrorlist=" << _pimpl->mirrorlist_url << endl;
309
310     str << "type=" << type().asString() << endl;
311
312     if ( priority() != defaultPriority() )
313       str << "priority=" << priority() << endl;
314
315     if (!indeterminate(_pimpl->gpgcheck))
316       str << "gpgcheck=" << (gpgCheck() ? "1" : "0") << endl;
317     if ( ! (gpgKeyUrl().asString().empty()) )
318       str << "gpgkey=" <<gpgKeyUrl() << endl;
319
320     if (!indeterminate(_pimpl->keeppackages))
321       str << "keeppackages=" << keepPackages() << endl;
322
323     if( ! service().empty() )
324       str << "service=" << service() << endl;
325
326     return str;
327   }
328
329   std::ostream & operator<<( std::ostream & str, const RepoInfo & obj )
330   {
331     return obj.dumpOn(str);
332   }
333
334   /////////////////////////////////////////////////////////////////
335 } // namespace zypp
336 ///////////////////////////////////////////////////////////////////