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. */
36 type(repo::RepoType::NONE_e)
50 std::set<Url> baseUrls;
55 Pathname metadatapath;
59 friend Impl * rwcowClone<Impl>( const Impl * rhs );
60 /** clone for RWCOW_pointer */
62 { return new Impl( *this ); }
64 ///////////////////////////////////////////////////////////////////
66 /** \relates RepoInfo::Impl Stream output */
67 inline std::ostream & operator<<( std::ostream & str, const RepoInfo::Impl & obj )
69 return str << "RepoInfo::Impl";
72 ///////////////////////////////////////////////////////////////////
74 // CLASS NAME : RepoInfo
76 ///////////////////////////////////////////////////////////////////
78 ///////////////////////////////////////////////////////////////////
80 // METHOD NAME : RepoInfo::RepoInfo
84 : _pimpl( new Impl() )
87 ///////////////////////////////////////////////////////////////////
89 // METHOD NAME : RepoInfo::~RepoInfo
97 RepoInfo & RepoInfo::setEnabled( bool enabled )
99 _pimpl->enabled = enabled;
103 RepoInfo & RepoInfo::setAutorefresh( bool autorefresh )
105 _pimpl->autorefresh = autorefresh;
109 RepoInfo & RepoInfo::setGpgCheck( bool check )
111 _pimpl->gpgcheck = check;
115 RepoInfo & RepoInfo::setMirrorListUrl( const Url &url )
117 _pimpl->mirrorlist_url = url;
121 RepoInfo & RepoInfo::setGpgKeyUrl( const Url &url )
123 _pimpl->gpgkey_url = url;
127 RepoInfo & RepoInfo::addBaseUrl( const Url &url )
129 _pimpl->baseUrls.insert(url);
133 RepoInfo & RepoInfo::setBaseUrl( const Url &url )
135 _pimpl->baseUrls.clear();
140 RepoInfo & RepoInfo::setPath( const Pathname &path )
146 RepoInfo & RepoInfo::setAlias( const std::string &alias )
148 _pimpl->alias = alias;
152 RepoInfo & RepoInfo::setType( const repo::RepoType &t )
158 RepoInfo & RepoInfo::setName( const std::string &name )
164 RepoInfo & RepoInfo::setFilepath( const Pathname &filepath )
166 _pimpl->filepath = filepath;
170 RepoInfo & RepoInfo::setMetadataPath( const Pathname &path )
172 _pimpl->metadatapath = path;
176 bool RepoInfo::enabled() const
177 { return _pimpl->enabled; }
179 bool RepoInfo::autorefresh() const
180 { return _pimpl->autorefresh; }
182 bool RepoInfo::gpgCheck() const
183 { return _pimpl->gpgcheck; }
185 std::string RepoInfo::alias() const
186 { return _pimpl->alias; }
188 std::string RepoInfo::name() const
190 if ( _pimpl->name.empty() )
195 repo::RepoVariablesStringReplacer replacer;
196 return replacer(_pimpl->name);
199 Pathname RepoInfo::filepath() const
200 { return _pimpl->filepath; }
202 Pathname RepoInfo::metadataPath() const
203 { return _pimpl->metadatapath; }
205 repo::RepoType RepoInfo::type() const
206 { return _pimpl->type; }
208 Url RepoInfo::mirrorListUrl() const
209 { return _pimpl->mirrorlist_url; }
211 Url RepoInfo::gpgKeyUrl() const
212 { return _pimpl->gpgkey_url; }
214 std::set<Url> RepoInfo::baseUrls() const
216 RepoInfo::url_set replaced_urls;
217 repo::RepoVariablesUrlReplacer replacer;
218 for ( url_set::const_iterator it = _pimpl->baseUrls.begin();
219 it != _pimpl->baseUrls.end();
222 replaced_urls.insert(replacer(*it));
224 return replaced_urls;
226 return _pimpl->baseUrls;
229 Pathname RepoInfo::path() const
230 { return _pimpl->path; }
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 std::ostream & RepoInfo::dumpOn( std::ostream & str ) const
254 str << "--------------------------------------" << std::endl;
255 str << "- alias : " << alias() << std::endl;
256 for ( urls_const_iterator it = baseUrlsBegin();
260 str << "- url : " << *it << std::endl;
262 str << "- path : " << path() << std::endl;
263 str << "- type : " << type() << std::endl;
264 str << "- enabled : " << enabled() << std::endl;
266 str << "- autorefresh : " << autorefresh() << std::endl;
267 str << "- gpgcheck : " << gpgCheck() << std::endl;
268 str << "- gpgkey : " << gpgKeyUrl() << std::endl;
273 std::ostream & RepoInfo::dumpRepoOn( std::ostream & str ) const
275 // we save the original data without variable replacement
276 str << "[" << alias() << "]" << endl;
277 str << "name=" << _pimpl->name << endl;
279 if ( ! _pimpl->baseUrls.empty() )
281 for ( url_set::const_iterator it = _pimpl->baseUrls.begin();
282 it != _pimpl->baseUrls.end();
288 if ( ! _pimpl->path.empty() )
289 str << "path="<< path() << endl;
291 if ( ! (_pimpl->mirrorlist_url.asString().empty()) )
292 str << "mirrorlist=" << _pimpl->mirrorlist_url << endl;
294 str << "type=" << type().asString() << endl;
295 str << "enabled=" << (enabled() ? "1" : "0") << endl;
296 str << "autorefresh=" << (autorefresh() ? "1" : "0") << endl;
297 str << "gpgcheck=" << (gpgCheck() ? "1" : "0") << endl;
298 if ( ! (gpgKeyUrl().asString().empty()) )
299 str << "gpgkey=" <<gpgKeyUrl() << endl;
304 std::ostream & operator<<( std::ostream & str, const RepoInfo & obj )
306 return obj.dumpOn(str);
309 /////////////////////////////////////////////////////////////////
311 ///////////////////////////////////////////////////////////////////