1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/RepoInfo.cc
14 #include "zypp/base/Logger.h"
15 #include "zypp/base/DefaultIntegral.h"
16 #include "zypp/media/MediaAccess.h"
18 #include "zypp/RepoInfo.h"
19 #include "zypp/repo/RepoInfoBaseImpl.h"
23 ///////////////////////////////////////////////////////////////////
25 { /////////////////////////////////////////////////////////////////
27 ///////////////////////////////////////////////////////////////////
29 // CLASS NAME : RepoInfo::Impl
31 /** RepoInfo implementation. */
32 struct RepoInfo::Impl : public repo::RepoInfoBase::Impl
35 : repo::RepoInfoBase::Impl()
36 , gpgcheck(indeterminate)
37 , keeppackages(indeterminate)
38 , type(repo::RepoType::NONE_e)
45 static const unsigned defaultPriority = 99;
47 void setProbedType( const repo::RepoType & t ) const
49 if ( type == repo::RepoType::NONE
50 && t != repo::RepoType::NONE )
53 const_cast<Impl*>(this)->type = t;
63 std::set<Url> baseUrls;
66 std::string targetDistro;
67 Pathname metadatapath;
68 Pathname packagespath;
69 DefaultIntegral<unsigned,defaultPriority> priority;
73 friend Impl * rwcowClone<Impl>( const Impl * rhs );
74 /** clone for RWCOW_pointer */
76 { return new Impl( *this ); }
78 ///////////////////////////////////////////////////////////////////
80 /** \relates RepoInfo::Impl Stream output */
81 inline std::ostream & operator<<( std::ostream & str, const RepoInfo::Impl & obj )
83 return str << "RepoInfo::Impl";
86 ///////////////////////////////////////////////////////////////////
88 // CLASS NAME : RepoInfo
90 ///////////////////////////////////////////////////////////////////
92 IMPL_PTR_TYPE(RepoInfo);
94 ///////////////////////////////////////////////////////////////////
96 // METHOD NAME : RepoInfo::RepoInfo
100 : _pimpl( new Impl() )
103 ///////////////////////////////////////////////////////////////////
105 // METHOD NAME : RepoInfo::~RepoInfo
106 // METHOD TYPE : Dtor
108 RepoInfo::~RepoInfo()
113 unsigned RepoInfo::priority() const
114 { return _pimpl->priority; }
115 unsigned RepoInfo::defaultPriority()
116 { return Impl::defaultPriority; }
117 void RepoInfo::setPriority( unsigned newval_r )
119 _pimpl->priority = newval_r ? newval_r : Impl::defaultPriority;
122 void RepoInfo::setGpgCheck( bool check )
124 _pimpl->gpgcheck = check;
127 void RepoInfo::setMirrorListUrl( const Url &url )
129 _pimpl->mirrorlist_url = url;
132 void RepoInfo::setGpgKeyUrl( const Url &url )
134 _pimpl->gpgkey_url = url;
137 void RepoInfo::addBaseUrl( const Url &url )
139 _pimpl->baseUrls.insert(url);
142 void RepoInfo::setBaseUrl( const Url &url )
144 _pimpl->baseUrls.clear();
148 void RepoInfo::setPath( const Pathname &path )
153 void RepoInfo::setType( const repo::RepoType &t )
158 void RepoInfo::setProbedType( const repo::RepoType &t ) const
159 { _pimpl->setProbedType( t ); }
162 void RepoInfo::setMetadataPath( const Pathname &path )
164 _pimpl->metadatapath = path;
167 void RepoInfo::setPackagesPath( const Pathname &path )
169 _pimpl->packagespath = path;
172 void RepoInfo::setKeepPackages( bool keep )
174 _pimpl->keeppackages = keep;
177 void RepoInfo::setService( const std::string& name )
179 _pimpl->service = name;
182 void RepoInfo::setTargetDistribution(
183 const std::string & targetDistribution)
185 _pimpl->targetDistro = targetDistribution;
188 bool RepoInfo::gpgCheck() const
189 { return indeterminate(_pimpl->gpgcheck) ? true : (bool) _pimpl->gpgcheck; }
191 Pathname RepoInfo::metadataPath() const
192 { return _pimpl->metadatapath; }
194 Pathname RepoInfo::packagesPath() const
195 { return _pimpl->packagespath; }
197 repo::RepoType RepoInfo::type() const
198 { return _pimpl->type; }
200 Url RepoInfo::mirrorListUrl() const
201 { return _pimpl->mirrorlist_url; }
203 Url RepoInfo::gpgKeyUrl() const
204 { return _pimpl->gpgkey_url; }
206 std::set<Url> RepoInfo::baseUrls() const
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();
214 replaced_urls.insert(replacer(*it));
216 return replaced_urls;
218 return _pimpl->baseUrls;
221 Pathname RepoInfo::path() const
222 { return _pimpl->path; }
224 std::string RepoInfo::service() const
225 { return _pimpl->service; }
227 std::string RepoInfo::targetDistribution() const
228 { return _pimpl->targetDistro; }
230 RepoInfo::urls_const_iterator RepoInfo::baseUrlsBegin() const
232 return make_transform_iterator( _pimpl->baseUrls.begin(),
233 repo::RepoVariablesUrlReplacer() );
234 //return _pimpl->baseUrls.begin();
237 RepoInfo::urls_const_iterator RepoInfo::baseUrlsEnd() const
239 //return _pimpl->baseUrls.end();
240 return make_transform_iterator( _pimpl->baseUrls.end(),
241 repo::RepoVariablesUrlReplacer() );
244 RepoInfo::urls_size_type RepoInfo::baseUrlsSize() const
245 { return _pimpl->baseUrls.size(); }
247 bool RepoInfo::baseUrlsEmpty() const
248 { return _pimpl->baseUrls.empty(); }
250 // false by default (if not set by setKeepPackages)
251 bool RepoInfo::keepPackages() const
253 if (indeterminate(_pimpl->keeppackages))
255 if (_pimpl->baseUrls.empty())
257 else if ( media::MediaAccess::downloads( *baseUrlsBegin() ) )
263 return (bool) _pimpl->keeppackages;
267 std::ostream & RepoInfo::dumpOn( std::ostream & str ) const
269 RepoInfoBase::dumpOn(str);
270 for ( urls_const_iterator it = baseUrlsBegin();
274 str << "- url : " << *it << std::endl;
276 str << "- path : " << path() << std::endl;
277 str << "- type : " << type() << std::endl;
278 str << "- priority : " << priority() << std::endl;
280 str << "- gpgcheck : " << gpgCheck() << std::endl;
281 str << "- gpgkey : " << gpgKeyUrl() << std::endl;
282 str << "- keeppackages: " << keepPackages() << std::endl;
283 str << "- service : " << service() << std::endl;
285 if (!targetDistribution().empty())
286 str << "- targetdistro: " << targetDistribution() << std::endl;
291 std::ostream & RepoInfo::dumpRepoOn( std::ostream & str ) const
293 RepoInfoBase::dumpAsIniOn(str);
295 if ( ! _pimpl->baseUrls.empty() )
297 for ( url_set::const_iterator it = _pimpl->baseUrls.begin();
298 it != _pimpl->baseUrls.end();
304 if ( ! _pimpl->path.empty() )
305 str << "path="<< path() << endl;
307 if ( ! (_pimpl->mirrorlist_url.asString().empty()) )
308 str << "mirrorlist=" << _pimpl->mirrorlist_url << endl;
310 str << "type=" << type().asString() << endl;
312 if ( priority() != defaultPriority() )
313 str << "priority=" << priority() << endl;
315 if (!indeterminate(_pimpl->gpgcheck))
316 str << "gpgcheck=" << (gpgCheck() ? "1" : "0") << endl;
317 if ( ! (gpgKeyUrl().asString().empty()) )
318 str << "gpgkey=" <<gpgKeyUrl() << endl;
320 if (!indeterminate(_pimpl->keeppackages))
321 str << "keeppackages=" << keepPackages() << endl;
323 if( ! service().empty() )
324 str << "service=" << service() << endl;
329 std::ostream & operator<<( std::ostream & str, const RepoInfo & obj )
331 return obj.dumpOn(str);
334 /////////////////////////////////////////////////////////////////
336 ///////////////////////////////////////////////////////////////////