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 const RepoInfo RepoInfo::noRepo;
96 ///////////////////////////////////////////////////////////////////
98 // METHOD NAME : RepoInfo::RepoInfo
102 : _pimpl( new Impl() )
105 ///////////////////////////////////////////////////////////////////
107 // METHOD NAME : RepoInfo::~RepoInfo
108 // METHOD TYPE : Dtor
110 RepoInfo::~RepoInfo()
115 unsigned RepoInfo::priority() const
116 { return _pimpl->priority; }
117 unsigned RepoInfo::defaultPriority()
118 { return Impl::defaultPriority; }
119 void RepoInfo::setPriority( unsigned newval_r )
121 _pimpl->priority = newval_r ? newval_r : Impl::defaultPriority;
124 void RepoInfo::setGpgCheck( bool check )
126 _pimpl->gpgcheck = check;
129 void RepoInfo::setMirrorListUrl( const Url &url )
131 _pimpl->mirrorlist_url = url;
134 void RepoInfo::setGpgKeyUrl( const Url &url )
136 _pimpl->gpgkey_url = url;
139 void RepoInfo::addBaseUrl( const Url &url )
141 _pimpl->baseUrls.insert(url);
144 void RepoInfo::setBaseUrl( const Url &url )
146 _pimpl->baseUrls.clear();
150 void RepoInfo::setPath( const Pathname &path )
155 void RepoInfo::setType( const repo::RepoType &t )
160 void RepoInfo::setProbedType( const repo::RepoType &t ) const
161 { _pimpl->setProbedType( t ); }
164 void RepoInfo::setMetadataPath( const Pathname &path )
166 _pimpl->metadatapath = path;
169 void RepoInfo::setPackagesPath( const Pathname &path )
171 _pimpl->packagespath = path;
174 void RepoInfo::setKeepPackages( bool keep )
176 _pimpl->keeppackages = keep;
179 void RepoInfo::setService( const std::string& name )
181 _pimpl->service = name;
184 void RepoInfo::setTargetDistribution(
185 const std::string & targetDistribution)
187 _pimpl->targetDistro = targetDistribution;
190 bool RepoInfo::gpgCheck() const
191 { return indeterminate(_pimpl->gpgcheck) ? true : (bool) _pimpl->gpgcheck; }
193 Pathname RepoInfo::metadataPath() const
194 { return _pimpl->metadatapath; }
196 Pathname RepoInfo::packagesPath() const
197 { return _pimpl->packagespath; }
199 repo::RepoType RepoInfo::type() const
200 { return _pimpl->type; }
202 Url RepoInfo::mirrorListUrl() const
203 { return _pimpl->mirrorlist_url; }
205 Url RepoInfo::gpgKeyUrl() const
206 { return _pimpl->gpgkey_url; }
208 std::set<Url> RepoInfo::baseUrls() const
210 RepoInfo::url_set replaced_urls;
211 repo::RepoVariablesUrlReplacer replacer;
212 for ( url_set::const_iterator it = _pimpl->baseUrls.begin();
213 it != _pimpl->baseUrls.end();
216 replaced_urls.insert(replacer(*it));
218 return replaced_urls;
220 return _pimpl->baseUrls;
223 Pathname RepoInfo::path() const
224 { return _pimpl->path; }
226 std::string RepoInfo::service() const
227 { return _pimpl->service; }
229 std::string RepoInfo::targetDistribution() const
230 { return _pimpl->targetDistro; }
232 RepoInfo::urls_const_iterator RepoInfo::baseUrlsBegin() const
234 return make_transform_iterator( _pimpl->baseUrls.begin(),
235 repo::RepoVariablesUrlReplacer() );
236 //return _pimpl->baseUrls.begin();
239 RepoInfo::urls_const_iterator RepoInfo::baseUrlsEnd() const
241 //return _pimpl->baseUrls.end();
242 return make_transform_iterator( _pimpl->baseUrls.end(),
243 repo::RepoVariablesUrlReplacer() );
246 RepoInfo::urls_size_type RepoInfo::baseUrlsSize() const
247 { return _pimpl->baseUrls.size(); }
249 bool RepoInfo::baseUrlsEmpty() const
250 { return _pimpl->baseUrls.empty(); }
252 // false by default (if not set by setKeepPackages)
253 bool RepoInfo::keepPackages() const
255 if (indeterminate(_pimpl->keeppackages))
257 if (_pimpl->baseUrls.empty())
259 else if ( media::MediaAccess::downloads( *baseUrlsBegin() ) )
265 return (bool) _pimpl->keeppackages;
269 std::ostream & RepoInfo::dumpOn( std::ostream & str ) const
271 RepoInfoBase::dumpOn(str);
272 for ( urls_const_iterator it = baseUrlsBegin();
276 str << "- url : " << *it << std::endl;
278 str << "- path : " << path() << std::endl;
279 str << "- type : " << type() << std::endl;
280 str << "- priority : " << priority() << std::endl;
282 str << "- gpgcheck : " << gpgCheck() << std::endl;
283 str << "- gpgkey : " << gpgKeyUrl() << std::endl;
284 str << "- keeppackages: " << keepPackages() << std::endl;
285 str << "- service : " << service() << std::endl;
287 if (!targetDistribution().empty())
288 str << "- targetdistro: " << targetDistribution() << std::endl;
293 std::ostream & RepoInfo::dumpRepoOn( std::ostream & str ) const
294 { return dumpAsIniOn(str); }
296 std::ostream & RepoInfo::dumpAsIniOn( std::ostream & str ) const
298 RepoInfoBase::dumpAsIniOn(str);
300 if ( ! _pimpl->baseUrls.empty() )
302 for ( url_set::const_iterator it = _pimpl->baseUrls.begin();
303 it != _pimpl->baseUrls.end();
309 if ( ! _pimpl->path.empty() )
310 str << "path="<< path() << endl;
312 if ( ! (_pimpl->mirrorlist_url.asString().empty()) )
313 str << "mirrorlist=" << _pimpl->mirrorlist_url << endl;
315 str << "type=" << type().asString() << endl;
317 if ( priority() != defaultPriority() )
318 str << "priority=" << priority() << endl;
320 if (!indeterminate(_pimpl->gpgcheck))
321 str << "gpgcheck=" << (gpgCheck() ? "1" : "0") << endl;
322 if ( ! (gpgKeyUrl().asString().empty()) )
323 str << "gpgkey=" <<gpgKeyUrl() << endl;
325 if (!indeterminate(_pimpl->keeppackages))
326 str << "keeppackages=" << keepPackages() << endl;
328 if( ! service().empty() )
329 str << "service=" << service() << endl;
334 std::ostream & RepoInfo::dumpAsXMLOn( std::ostream & str) const
335 { return dumpAsXMLOn(str, ""); }
337 std::ostream & RepoInfo::dumpAsXMLOn( std::ostream & str, const std::string & content) const
342 << " alias=\"" << escape(alias()) << "\""
343 << " name=\"" << escape(name()) << "\"";
344 if (type() != repo::RepoType::NONE)
345 str << " type=\"" << type().asString() << "\"";
347 << " enabled=\"" << enabled() << "\""
348 << " autorefresh=\"" << autorefresh() << "\""
349 << " gpgcheck=\"" << gpgCheck() << "\"";
350 if (!(tmpstr = gpgKeyUrl().asString()).empty())
351 str << " gpgkey=\"" << escape(tmpstr) << "\"";
352 if (!(tmpstr = mirrorListUrl().asString()).empty())
353 str << " mirrorlist=\"" << escape(tmpstr) << "\"";
356 for (RepoInfo::urls_const_iterator urlit = baseUrlsBegin();
357 urlit != baseUrlsEnd(); ++urlit)
358 str << "<url>" << escape(urlit->asString()) << "</url>" << endl;
360 str << "</repo>" << endl;
365 std::ostream & operator<<( std::ostream & str, const RepoInfo & obj )
367 return obj.dumpOn(str);
371 /////////////////////////////////////////////////////////////////
373 ///////////////////////////////////////////////////////////////////