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"
18 #include "zypp/RepoInfo.h"
22 ///////////////////////////////////////////////////////////////////
24 { /////////////////////////////////////////////////////////////////
26 ///////////////////////////////////////////////////////////////////
28 // CLASS NAME : RepoInfo::Impl
30 /** RepoInfo implementation. */
39 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;
67 std::set<Url> baseUrls;
70 std::string escaped_alias;
73 Pathname metadatapath;
74 Pathname packagespath;
75 DefaultIntegral<unsigned,defaultPriority> priority;
79 friend Impl * rwcowClone<Impl>( const Impl * rhs );
80 /** clone for RWCOW_pointer */
82 { return new Impl( *this ); }
84 ///////////////////////////////////////////////////////////////////
86 /** \relates RepoInfo::Impl Stream output */
87 inline std::ostream & operator<<( std::ostream & str, const RepoInfo::Impl & obj )
89 return str << "RepoInfo::Impl";
92 ///////////////////////////////////////////////////////////////////
94 // CLASS NAME : RepoInfo
96 ///////////////////////////////////////////////////////////////////
98 ///////////////////////////////////////////////////////////////////
100 // METHOD NAME : RepoInfo::RepoInfo
101 // METHOD TYPE : Ctor
104 : _pimpl( new Impl() )
107 ///////////////////////////////////////////////////////////////////
109 // METHOD NAME : RepoInfo::~RepoInfo
110 // METHOD TYPE : Dtor
112 RepoInfo::~RepoInfo()
117 unsigned RepoInfo::priority() const
118 { return _pimpl->priority; }
119 unsigned RepoInfo::defaultPriority()
120 { return Impl::defaultPriority; }
121 RepoInfo & RepoInfo::setPriority( unsigned newval_r )
123 _pimpl->priority = newval_r ? newval_r : Impl::defaultPriority;
128 RepoInfo & RepoInfo::setEnabled( bool enabled )
130 _pimpl->enabled = enabled;
134 RepoInfo & RepoInfo::setAutorefresh( bool autorefresh )
136 _pimpl->autorefresh = autorefresh;
140 RepoInfo & RepoInfo::setGpgCheck( bool check )
142 _pimpl->gpgcheck = check;
146 RepoInfo & RepoInfo::setMirrorListUrl( const Url &url )
148 _pimpl->mirrorlist_url = url;
152 RepoInfo & RepoInfo::setGpgKeyUrl( const Url &url )
154 _pimpl->gpgkey_url = url;
158 RepoInfo & RepoInfo::addBaseUrl( const Url &url )
160 if ( _pimpl->baseUrls.size()==0 ) //first url
162 if ( media::MediaAccess::downloads( url ) )
163 setKeepPackages(true);
165 setKeepPackages(false);
168 _pimpl->baseUrls.insert(url);
172 RepoInfo & RepoInfo::setBaseUrl( const Url &url )
174 _pimpl->baseUrls.clear();
179 RepoInfo & RepoInfo::setPath( const Pathname &path )
185 RepoInfo & RepoInfo::setAlias( const std::string &alias )
187 _pimpl->alias = alias;
188 // replace slashes with underscores
191 std::string escaped_alias = alias;
192 size_t pos = escaped_alias.find(fnd);
193 while(pos!=string::npos)
195 escaped_alias.replace(pos,fnd.length(),rep);
196 pos = escaped_alias.find(fnd,pos+rep.length());
198 _pimpl->escaped_alias = escaped_alias;
202 RepoInfo & RepoInfo::setType( const repo::RepoType &t )
208 void RepoInfo::setProbedType( const repo::RepoType &t ) const
209 { _pimpl->setProbedType( t ); }
211 RepoInfo & RepoInfo::setName( const std::string &name )
217 RepoInfo & RepoInfo::setFilepath( const Pathname &filepath )
219 _pimpl->filepath = filepath;
223 RepoInfo & RepoInfo::setMetadataPath( const Pathname &path )
225 _pimpl->metadatapath = path;
229 RepoInfo & RepoInfo::setPackagesPath( const Pathname &path )
231 _pimpl->packagespath = path;
235 RepoInfo & RepoInfo::setKeepPackages( bool keep )
237 _pimpl->keeppackages = keep;
241 bool RepoInfo::enabled() const
242 { return _pimpl->enabled; }
244 bool RepoInfo::autorefresh() const
245 { return _pimpl->autorefresh; }
247 bool RepoInfo::gpgCheck() const
248 { return _pimpl->gpgcheck; }
250 std::string RepoInfo::alias() const
251 { return _pimpl->alias; }
253 std::string RepoInfo::escaped_alias() const
254 { return _pimpl->escaped_alias; }
256 std::string RepoInfo::name() const
258 if ( _pimpl->name.empty() )
263 repo::RepoVariablesStringReplacer replacer;
264 return replacer(_pimpl->name);
267 Pathname RepoInfo::filepath() const
268 { return _pimpl->filepath; }
270 Pathname RepoInfo::metadataPath() const
271 { return _pimpl->metadatapath; }
273 Pathname RepoInfo::packagesPath() const
274 { return _pimpl->packagespath; }
276 repo::RepoType RepoInfo::type() const
277 { return _pimpl->type; }
279 Url RepoInfo::mirrorListUrl() const
280 { return _pimpl->mirrorlist_url; }
282 Url RepoInfo::gpgKeyUrl() const
283 { return _pimpl->gpgkey_url; }
285 std::set<Url> RepoInfo::baseUrls() const
287 RepoInfo::url_set replaced_urls;
288 repo::RepoVariablesUrlReplacer replacer;
289 for ( url_set::const_iterator it = _pimpl->baseUrls.begin();
290 it != _pimpl->baseUrls.end();
293 replaced_urls.insert(replacer(*it));
295 return replaced_urls;
297 return _pimpl->baseUrls;
300 Pathname RepoInfo::path() const
301 { return _pimpl->path; }
303 RepoInfo::urls_const_iterator RepoInfo::baseUrlsBegin() const
305 return make_transform_iterator( _pimpl->baseUrls.begin(),
306 repo::RepoVariablesUrlReplacer() );
307 //return _pimpl->baseUrls.begin();
310 RepoInfo::urls_const_iterator RepoInfo::baseUrlsEnd() const
312 //return _pimpl->baseUrls.end();
313 return make_transform_iterator( _pimpl->baseUrls.end(),
314 repo::RepoVariablesUrlReplacer() );
317 RepoInfo::urls_size_type RepoInfo::baseUrlsSize() const
318 { return _pimpl->baseUrls.size(); }
320 bool RepoInfo::baseUrlsEmpty() const
321 { return _pimpl->baseUrls.empty(); }
323 bool RepoInfo::keepPackages() const
324 { return _pimpl->keeppackages; }
326 std::ostream & RepoInfo::dumpOn( std::ostream & str ) const
328 str << "--------------------------------------" << std::endl;
329 str << "- alias : " << alias() << std::endl;
330 for ( urls_const_iterator it = baseUrlsBegin();
334 str << "- url : " << *it << std::endl;
336 str << "- path : " << path() << std::endl;
337 str << "- type : " << type() << std::endl;
338 str << "- enabled : " << enabled() << std::endl;
339 str << "- priority : " << priority() << std::endl;
341 str << "- autorefresh : " << autorefresh() << std::endl;
342 str << "- gpgcheck : " << gpgCheck() << std::endl;
343 str << "- gpgkey : " << gpgKeyUrl() << std::endl;
344 str << "- keeppackages: " << keepPackages() << std::endl;
349 std::ostream & RepoInfo::dumpRepoOn( std::ostream & str ) const
351 // we save the original data without variable replacement
352 str << "[" << alias() << "]" << endl;
353 str << "name=" << _pimpl->name << endl;
355 if ( ! _pimpl->baseUrls.empty() )
357 for ( url_set::const_iterator it = _pimpl->baseUrls.begin();
358 it != _pimpl->baseUrls.end();
364 if ( ! _pimpl->path.empty() )
365 str << "path="<< path() << endl;
367 if ( ! (_pimpl->mirrorlist_url.asString().empty()) )
368 str << "mirrorlist=" << _pimpl->mirrorlist_url << endl;
370 str << "type=" << type().asString() << endl;
371 str << "enabled=" << (enabled() ? "1" : "0") << endl;
373 if ( priority() != defaultPriority() )
374 str << "priority=" << priority() << endl;
376 str << "autorefresh=" << (autorefresh() ? "1" : "0") << endl;
377 str << "gpgcheck=" << (gpgCheck() ? "1" : "0") << endl;
378 if ( ! (gpgKeyUrl().asString().empty()) )
379 str << "gpgkey=" <<gpgKeyUrl() << endl;
381 str << "keeppackages=" << keepPackages() << endl;
386 std::ostream & operator<<( std::ostream & str, const RepoInfo & obj )
388 return obj.dumpOn(str);
391 /////////////////////////////////////////////////////////////////
393 ///////////////////////////////////////////////////////////////////