1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/RepoInfo.cc
14 #include "zypp/base/Logger.h"
15 #include "zypp/base/DefaultIntegral.h"
17 #include "zypp/RepoInfo.h"
21 ///////////////////////////////////////////////////////////////////
23 { /////////////////////////////////////////////////////////////////
25 ///////////////////////////////////////////////////////////////////
27 // CLASS NAME : RepoInfo::Impl
29 /** RepoInfo implementation. */
38 type(repo::RepoType::NONE_e)
46 static const unsigned defaultPriority = 99;
56 std::set<Url> baseUrls;
59 std::string escaped_alias;
62 Pathname metadatapath;
63 Pathname packagespath;
64 DefaultIntegral<unsigned,defaultPriority> priority;
68 friend Impl * rwcowClone<Impl>( const Impl * rhs );
69 /** clone for RWCOW_pointer */
71 { return new Impl( *this ); }
73 ///////////////////////////////////////////////////////////////////
75 /** \relates RepoInfo::Impl Stream output */
76 inline std::ostream & operator<<( std::ostream & str, const RepoInfo::Impl & obj )
78 return str << "RepoInfo::Impl";
81 ///////////////////////////////////////////////////////////////////
83 // CLASS NAME : RepoInfo
85 ///////////////////////////////////////////////////////////////////
87 ///////////////////////////////////////////////////////////////////
89 // METHOD NAME : RepoInfo::RepoInfo
93 : _pimpl( new Impl() )
96 ///////////////////////////////////////////////////////////////////
98 // METHOD NAME : RepoInfo::~RepoInfo
101 RepoInfo::~RepoInfo()
106 unsigned RepoInfo::priority() const
107 { return _pimpl->priority; }
108 unsigned RepoInfo::defaultPriority()
109 { return Impl::defaultPriority; }
110 RepoInfo & RepoInfo::setPriority( unsigned newval_r )
112 _pimpl->priority = newval_r ? newval_r : Impl::defaultPriority;
117 RepoInfo & RepoInfo::setEnabled( bool enabled )
119 _pimpl->enabled = enabled;
123 RepoInfo & RepoInfo::setAutorefresh( bool autorefresh )
125 _pimpl->autorefresh = autorefresh;
129 RepoInfo & RepoInfo::setGpgCheck( bool check )
131 _pimpl->gpgcheck = check;
135 RepoInfo & RepoInfo::setMirrorListUrl( const Url &url )
137 _pimpl->mirrorlist_url = url;
141 RepoInfo & RepoInfo::setGpgKeyUrl( const Url &url )
143 _pimpl->gpgkey_url = url;
147 RepoInfo & RepoInfo::addBaseUrl( const Url &url )
149 if ( _pimpl->baseUrls.size()==0 ) //first url
151 string scheme = url.getScheme();
152 if ( scheme == "http" || scheme == "ftp" || scheme == "smb" )
153 setKeepPackages(true);
155 setKeepPackages(false);
158 _pimpl->baseUrls.insert(url);
162 RepoInfo & RepoInfo::setBaseUrl( const Url &url )
164 _pimpl->baseUrls.clear();
169 RepoInfo & RepoInfo::setPath( const Pathname &path )
175 RepoInfo & RepoInfo::setAlias( const std::string &alias )
177 _pimpl->alias = alias;
178 // replace slashes with underscores
181 std::string escaped_alias = alias;
182 size_t pos = escaped_alias.find(fnd);
183 while(pos!=string::npos)
185 escaped_alias.replace(pos,fnd.length(),rep);
186 pos = escaped_alias.find(fnd,pos+rep.length());
188 _pimpl->escaped_alias = escaped_alias;
192 RepoInfo & RepoInfo::setType( const repo::RepoType &t )
198 RepoInfo & RepoInfo::setName( const std::string &name )
204 RepoInfo & RepoInfo::setFilepath( const Pathname &filepath )
206 _pimpl->filepath = filepath;
210 RepoInfo & RepoInfo::setMetadataPath( const Pathname &path )
212 _pimpl->metadatapath = path;
216 RepoInfo & RepoInfo::setPackagesPath( const Pathname &path )
218 _pimpl->packagespath = path;
222 RepoInfo & RepoInfo::setKeepPackages( bool keep )
224 _pimpl->keeppackages = keep;
228 bool RepoInfo::enabled() const
229 { return _pimpl->enabled; }
231 bool RepoInfo::autorefresh() const
232 { return _pimpl->autorefresh; }
234 bool RepoInfo::gpgCheck() const
235 { return _pimpl->gpgcheck; }
237 std::string RepoInfo::alias() const
238 { return _pimpl->alias; }
240 std::string RepoInfo::escaped_alias() const
241 { return _pimpl->escaped_alias; }
243 std::string RepoInfo::name() const
245 if ( _pimpl->name.empty() )
250 repo::RepoVariablesStringReplacer replacer;
251 return replacer(_pimpl->name);
254 Pathname RepoInfo::filepath() const
255 { return _pimpl->filepath; }
257 Pathname RepoInfo::metadataPath() const
258 { return _pimpl->metadatapath; }
260 Pathname RepoInfo::packagesPath() const
261 { return _pimpl->packagespath; }
263 repo::RepoType RepoInfo::type() const
264 { return _pimpl->type; }
266 Url RepoInfo::mirrorListUrl() const
267 { return _pimpl->mirrorlist_url; }
269 Url RepoInfo::gpgKeyUrl() const
270 { return _pimpl->gpgkey_url; }
272 std::set<Url> RepoInfo::baseUrls() const
274 RepoInfo::url_set replaced_urls;
275 repo::RepoVariablesUrlReplacer replacer;
276 for ( url_set::const_iterator it = _pimpl->baseUrls.begin();
277 it != _pimpl->baseUrls.end();
280 replaced_urls.insert(replacer(*it));
282 return replaced_urls;
284 return _pimpl->baseUrls;
287 Pathname RepoInfo::path() const
288 { return _pimpl->path; }
290 RepoInfo::urls_const_iterator RepoInfo::baseUrlsBegin() const
292 return make_transform_iterator( _pimpl->baseUrls.begin(),
293 repo::RepoVariablesUrlReplacer() );
294 //return _pimpl->baseUrls.begin();
297 RepoInfo::urls_const_iterator RepoInfo::baseUrlsEnd() const
299 //return _pimpl->baseUrls.end();
300 return make_transform_iterator( _pimpl->baseUrls.end(),
301 repo::RepoVariablesUrlReplacer() );
304 RepoInfo::urls_size_type RepoInfo::baseUrlsSize() const
305 { return _pimpl->baseUrls.size(); }
307 bool RepoInfo::baseUrlsEmpty() const
308 { return _pimpl->baseUrls.empty(); }
310 bool RepoInfo::keepPackages() const
311 { return _pimpl->keeppackages; }
313 std::ostream & RepoInfo::dumpOn( std::ostream & str ) const
315 str << "--------------------------------------" << std::endl;
316 str << "- alias : " << alias() << std::endl;
317 for ( urls_const_iterator it = baseUrlsBegin();
321 str << "- url : " << *it << std::endl;
323 str << "- path : " << path() << std::endl;
324 str << "- type : " << type() << std::endl;
325 str << "- enabled : " << enabled() << std::endl;
326 str << "- priority : " << priority() << std::endl;
328 str << "- autorefresh : " << autorefresh() << std::endl;
329 str << "- gpgcheck : " << gpgCheck() << std::endl;
330 str << "- gpgkey : " << gpgKeyUrl() << std::endl;
331 str << "- keeppackages: " << keepPackages() << std::endl;
336 std::ostream & RepoInfo::dumpRepoOn( std::ostream & str ) const
338 // we save the original data without variable replacement
339 str << "[" << alias() << "]" << endl;
340 str << "name=" << _pimpl->name << endl;
342 if ( ! _pimpl->baseUrls.empty() )
344 for ( url_set::const_iterator it = _pimpl->baseUrls.begin();
345 it != _pimpl->baseUrls.end();
351 if ( ! _pimpl->path.empty() )
352 str << "path="<< path() << endl;
354 if ( ! (_pimpl->mirrorlist_url.asString().empty()) )
355 str << "mirrorlist=" << _pimpl->mirrorlist_url << endl;
357 str << "type=" << type().asString() << endl;
358 str << "enabled=" << (enabled() ? "1" : "0") << endl;
360 if ( priority() != defaultPriority() )
361 str << "priority=" << priority() << endl;
363 str << "autorefresh=" << (autorefresh() ? "1" : "0") << endl;
364 str << "gpgcheck=" << (gpgCheck() ? "1" : "0") << endl;
365 if ( ! (gpgKeyUrl().asString().empty()) )
366 str << "gpgkey=" <<gpgKeyUrl() << endl;
368 str << "keeppackages=" << keepPackages() << endl;
373 std::ostream & operator<<( std::ostream & str, const RepoInfo & obj )
375 return obj.dumpOn(str);
378 /////////////////////////////////////////////////////////////////
380 ///////////////////////////////////////////////////////////////////