1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/RepoInfo.cc
14 #include "zypp/base/Logger.h"
16 #include "zypp/RepoInfo.h"
20 ///////////////////////////////////////////////////////////////////
22 { /////////////////////////////////////////////////////////////////
24 ///////////////////////////////////////////////////////////////////
26 // CLASS NAME : RepoInfo::Impl
28 /** RepoInfo implementation. */
37 type(repo::RepoType::NONE_e)
52 std::set<Url> baseUrls;
55 std::string escaped_alias;
58 Pathname metadatapath;
59 Pathname packagespath;
63 friend Impl * rwcowClone<Impl>( const Impl * rhs );
64 /** clone for RWCOW_pointer */
66 { return new Impl( *this ); }
68 ///////////////////////////////////////////////////////////////////
70 /** \relates RepoInfo::Impl Stream output */
71 inline std::ostream & operator<<( std::ostream & str, const RepoInfo::Impl & obj )
73 return str << "RepoInfo::Impl";
76 ///////////////////////////////////////////////////////////////////
78 // CLASS NAME : RepoInfo
80 ///////////////////////////////////////////////////////////////////
82 ///////////////////////////////////////////////////////////////////
84 // METHOD NAME : RepoInfo::RepoInfo
88 : _pimpl( new Impl() )
91 ///////////////////////////////////////////////////////////////////
93 // METHOD NAME : RepoInfo::~RepoInfo
101 RepoInfo & RepoInfo::setEnabled( bool enabled )
103 _pimpl->enabled = enabled;
107 RepoInfo & RepoInfo::setAutorefresh( bool autorefresh )
109 _pimpl->autorefresh = autorefresh;
113 RepoInfo & RepoInfo::setGpgCheck( bool check )
115 _pimpl->gpgcheck = check;
119 RepoInfo & RepoInfo::setMirrorListUrl( const Url &url )
121 _pimpl->mirrorlist_url = url;
125 RepoInfo & RepoInfo::setGpgKeyUrl( const Url &url )
127 _pimpl->gpgkey_url = url;
131 RepoInfo & RepoInfo::addBaseUrl( const Url &url )
133 _pimpl->baseUrls.insert(url);
137 RepoInfo & RepoInfo::setBaseUrl( const Url &url )
139 _pimpl->baseUrls.clear();
144 RepoInfo & RepoInfo::setPath( const Pathname &path )
150 RepoInfo & RepoInfo::setAlias( const std::string &alias )
152 _pimpl->alias = alias;
153 // replace slashes with underscores
156 std::string escaped_alias = alias;
157 size_t pos = escaped_alias.find(fnd);
158 while(pos!=string::npos)
160 escaped_alias.replace(pos,fnd.length(),rep);
161 pos = escaped_alias.find(fnd,pos+rep.length());
163 _pimpl->escaped_alias = escaped_alias;
167 RepoInfo & RepoInfo::setType( const repo::RepoType &t )
173 RepoInfo & RepoInfo::setName( const std::string &name )
179 RepoInfo & RepoInfo::setFilepath( const Pathname &filepath )
181 _pimpl->filepath = filepath;
185 RepoInfo & RepoInfo::setMetadataPath( const Pathname &path )
187 _pimpl->metadatapath = path;
191 RepoInfo & RepoInfo::setPackagesPath( const Pathname &path )
193 _pimpl->packagespath = path;
197 RepoInfo & RepoInfo::setKeepPackages( bool keep )
199 _pimpl->keeppackages = keep;
203 bool RepoInfo::enabled() const
204 { return _pimpl->enabled; }
206 bool RepoInfo::autorefresh() const
207 { return _pimpl->autorefresh; }
209 bool RepoInfo::gpgCheck() const
210 { return _pimpl->gpgcheck; }
212 std::string RepoInfo::alias() const
213 { return _pimpl->alias; }
215 std::string RepoInfo::escaped_alias() const
216 { return _pimpl->escaped_alias; }
218 std::string RepoInfo::name() const
220 if ( _pimpl->name.empty() )
225 repo::RepoVariablesStringReplacer replacer;
226 return replacer(_pimpl->name);
229 Pathname RepoInfo::filepath() const
230 { return _pimpl->filepath; }
232 Pathname RepoInfo::metadataPath() const
233 { return _pimpl->metadatapath; }
235 Pathname RepoInfo::packagesPath() const
236 { return _pimpl->packagespath; }
238 repo::RepoType RepoInfo::type() const
239 { return _pimpl->type; }
241 Url RepoInfo::mirrorListUrl() const
242 { return _pimpl->mirrorlist_url; }
244 Url RepoInfo::gpgKeyUrl() const
245 { return _pimpl->gpgkey_url; }
247 std::set<Url> RepoInfo::baseUrls() const
249 RepoInfo::url_set replaced_urls;
250 repo::RepoVariablesUrlReplacer replacer;
251 for ( url_set::const_iterator it = _pimpl->baseUrls.begin();
252 it != _pimpl->baseUrls.end();
255 replaced_urls.insert(replacer(*it));
257 return replaced_urls;
259 return _pimpl->baseUrls;
262 Pathname RepoInfo::path() const
263 { return _pimpl->path; }
265 RepoInfo::urls_const_iterator RepoInfo::baseUrlsBegin() const
267 return make_transform_iterator( _pimpl->baseUrls.begin(),
268 repo::RepoVariablesUrlReplacer() );
269 //return _pimpl->baseUrls.begin();
272 RepoInfo::urls_const_iterator RepoInfo::baseUrlsEnd() const
274 //return _pimpl->baseUrls.end();
275 return make_transform_iterator( _pimpl->baseUrls.end(),
276 repo::RepoVariablesUrlReplacer() );
279 RepoInfo::urls_size_type RepoInfo::baseUrlsSize() const
280 { return _pimpl->baseUrls.size(); }
282 bool RepoInfo::baseUrlsEmpty() const
283 { return _pimpl->baseUrls.empty(); }
285 bool RepoInfo::keepPackages() const
286 { return _pimpl->keeppackages; }
288 std::ostream & RepoInfo::dumpOn( std::ostream & str ) const
290 str << "--------------------------------------" << std::endl;
291 str << "- alias : " << alias() << std::endl;
292 for ( urls_const_iterator it = baseUrlsBegin();
296 str << "- url : " << *it << std::endl;
298 str << "- path : " << path() << std::endl;
299 str << "- type : " << type() << std::endl;
300 str << "- enabled : " << enabled() << std::endl;
302 str << "- autorefresh : " << autorefresh() << std::endl;
303 str << "- gpgcheck : " << gpgCheck() << std::endl;
304 str << "- gpgkey : " << gpgKeyUrl() << std::endl;
305 str << "- keeppackages : " << keepPackages() << std::endl;
310 std::ostream & RepoInfo::dumpRepoOn( std::ostream & str ) const
312 // we save the original data without variable replacement
313 str << "[" << alias() << "]" << endl;
314 str << "name=" << _pimpl->name << endl;
316 if ( ! _pimpl->baseUrls.empty() )
318 for ( url_set::const_iterator it = _pimpl->baseUrls.begin();
319 it != _pimpl->baseUrls.end();
325 if ( ! _pimpl->path.empty() )
326 str << "path="<< path() << endl;
328 if ( ! (_pimpl->mirrorlist_url.asString().empty()) )
329 str << "mirrorlist=" << _pimpl->mirrorlist_url << endl;
331 str << "type=" << type().asString() << endl;
332 str << "enabled=" << (enabled() ? "1" : "0") << endl;
333 str << "autorefresh=" << (autorefresh() ? "1" : "0") << endl;
334 str << "gpgcheck=" << (gpgCheck() ? "1" : "0") << endl;
335 if ( ! (gpgKeyUrl().asString().empty()) )
336 str << "gpgkey=" <<gpgKeyUrl() << endl;
338 str << "keeppackages=" << keepPackages() << endl;
343 std::ostream & operator<<( std::ostream & str, const RepoInfo & obj )
345 return obj.dumpOn(str);
348 /////////////////////////////////////////////////////////////////
350 ///////////////////////////////////////////////////////////////////