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"
17 #include "zypp/parser/xml/XmlEscape.h"
19 #include "zypp/RepoInfo.h"
20 #include "zypp/repo/RepoInfoBaseImpl.h"
23 using zypp::xml::escape;
25 ///////////////////////////////////////////////////////////////////
27 { /////////////////////////////////////////////////////////////////
29 ///////////////////////////////////////////////////////////////////
31 // CLASS NAME : RepoInfo::Impl
33 /** RepoInfo implementation. */
34 struct RepoInfo::Impl : public repo::RepoInfoBase::Impl
37 : repo::RepoInfoBase::Impl()
38 , gpgcheck(indeterminate)
39 , keeppackages(indeterminate)
40 , type(repo::RepoType::NONE_e)
47 static const unsigned defaultPriority = 99;
49 void setProbedType( const repo::RepoType & t ) const
51 if ( type == repo::RepoType::NONE
52 && t != repo::RepoType::NONE )
55 const_cast<Impl*>(this)->type = t;
65 std::set<Url> baseUrls;
68 std::string targetDistro;
69 Pathname metadatapath;
70 Pathname packagespath;
71 DefaultIntegral<unsigned,defaultPriority> priority;
75 friend Impl * rwcowClone<Impl>( const Impl * rhs );
76 /** clone for RWCOW_pointer */
78 { return new Impl( *this ); }
80 ///////////////////////////////////////////////////////////////////
82 /** \relates RepoInfo::Impl Stream output */
83 inline std::ostream & operator<<( std::ostream & str, const RepoInfo::Impl & obj )
85 return str << "RepoInfo::Impl";
88 ///////////////////////////////////////////////////////////////////
90 // CLASS NAME : RepoInfo
92 ///////////////////////////////////////////////////////////////////
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
292 { return dumpAsIniOn(str); }
294 std::ostream & RepoInfo::dumpAsIniOn( std::ostream & str ) const
296 RepoInfoBase::dumpAsIniOn(str);
298 if ( ! _pimpl->baseUrls.empty() )
300 for ( url_set::const_iterator it = _pimpl->baseUrls.begin();
301 it != _pimpl->baseUrls.end();
307 if ( ! _pimpl->path.empty() )
308 str << "path="<< path() << endl;
310 if ( ! (_pimpl->mirrorlist_url.asString().empty()) )
311 str << "mirrorlist=" << _pimpl->mirrorlist_url << endl;
313 str << "type=" << type().asString() << endl;
315 if ( priority() != defaultPriority() )
316 str << "priority=" << priority() << endl;
318 if (!indeterminate(_pimpl->gpgcheck))
319 str << "gpgcheck=" << (gpgCheck() ? "1" : "0") << endl;
320 if ( ! (gpgKeyUrl().asString().empty()) )
321 str << "gpgkey=" <<gpgKeyUrl() << endl;
323 if (!indeterminate(_pimpl->keeppackages))
324 str << "keeppackages=" << keepPackages() << endl;
326 if( ! service().empty() )
327 str << "service=" << service() << endl;
332 std::ostream & RepoInfo::dumpAsXMLOn( std::ostream & str) const
337 << " alias=\"" << escape(alias()) << "\""
338 << " name=\"" << escape(name()) << "\"";
339 if (type() != repo::RepoType::NONE)
340 str << " type=\"" << type().asString() << "\"";
342 << " enabled=\"" << enabled() << "\""
343 << " autorefresh=\"" << autorefresh() << "\""
344 << " gpgcheck=\"" << gpgCheck() << "\"";
345 if (!(tmpstr = gpgKeyUrl().asString()).empty())
346 str << " gpgkey=\"" << escape(tmpstr) << "\"";
347 if (!(tmpstr = mirrorListUrl().asString()).empty())
348 str << " mirrorlist=\"" << escape(tmpstr) << "\"";
351 for (RepoInfo::urls_const_iterator urlit = baseUrlsBegin();
352 urlit != baseUrlsEnd(); ++urlit)
353 str << "<url>" << escape(urlit->asString()) << "</url>" << endl;
355 str << "</repo>" << endl;
359 std::ostream & operator<<( std::ostream & str, const RepoInfo & obj )
361 return obj.dumpOn(str);
364 /////////////////////////////////////////////////////////////////
366 ///////////////////////////////////////////////////////////////////