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. */
33 enum FlagsDeterminedState
46 type(repo::RepoType::NONE_e),
55 static const unsigned defaultPriority = 99;
57 void setProbedType( const repo::RepoType & t ) const
59 if ( type == repo::RepoType::NONE
60 && t != repo::RepoType::NONE )
63 const_cast<Impl*>(this)->type = t;
75 std::set<Url> baseUrls;
78 std::string escaped_alias;
81 Pathname metadatapath;
82 Pathname packagespath;
83 DefaultIntegral<unsigned,defaultPriority> priority;
88 friend Impl * rwcowClone<Impl>( const Impl * rhs );
89 /** clone for RWCOW_pointer */
91 { return new Impl( *this ); }
93 ///////////////////////////////////////////////////////////////////
95 /** \relates RepoInfo::Impl Stream output */
96 inline std::ostream & operator<<( std::ostream & str, const RepoInfo::Impl & obj )
98 return str << "RepoInfo::Impl";
101 ///////////////////////////////////////////////////////////////////
103 // CLASS NAME : RepoInfo
105 ///////////////////////////////////////////////////////////////////
107 ///////////////////////////////////////////////////////////////////
109 // METHOD NAME : RepoInfo::RepoInfo
110 // METHOD TYPE : Ctor
113 : _pimpl( new Impl() )
116 ///////////////////////////////////////////////////////////////////
118 // METHOD NAME : RepoInfo::~RepoInfo
119 // METHOD TYPE : Dtor
121 RepoInfo::~RepoInfo()
126 unsigned RepoInfo::priority() const
127 { return _pimpl->priority; }
128 unsigned RepoInfo::defaultPriority()
129 { return Impl::defaultPriority; }
130 RepoInfo & RepoInfo::setPriority( unsigned newval_r )
132 _pimpl->priority = newval_r ? newval_r : Impl::defaultPriority;
137 RepoInfo & RepoInfo::setEnabled( bool enabled )
139 _pimpl->enabled = enabled;
140 _pimpl->flags_determined |= Impl::FLAG_ENABLED;
144 RepoInfo & RepoInfo::setAutorefresh( bool autorefresh )
146 _pimpl->autorefresh = autorefresh;
147 _pimpl->flags_determined |= Impl::FLAG_AUTOREFRESH;
151 RepoInfo & RepoInfo::setGpgCheck( bool check )
153 _pimpl->gpgcheck = check;
154 _pimpl->flags_determined |= Impl::FLAG_GPGCHECK;
158 RepoInfo & RepoInfo::setMirrorListUrl( const Url &url )
160 _pimpl->mirrorlist_url = url;
164 RepoInfo & RepoInfo::setGpgKeyUrl( const Url &url )
166 _pimpl->gpgkey_url = url;
170 RepoInfo & RepoInfo::addBaseUrl( const Url &url )
172 // set only if not already set (bnc #394728)
173 if (!(_pimpl->flags_determined & Impl::FLAG_KEEPPACKAGES))
175 if ( media::MediaAccess::downloads( url ) )
176 setKeepPackages(true);
178 setKeepPackages(false);
181 _pimpl->baseUrls.insert(url);
185 RepoInfo & RepoInfo::setBaseUrl( const Url &url )
187 _pimpl->baseUrls.clear();
192 RepoInfo & RepoInfo::setPath( const Pathname &path )
198 RepoInfo & RepoInfo::setAlias( const std::string &alias )
200 _pimpl->alias = alias;
201 // replace slashes with underscores
204 std::string escaped_alias = alias;
205 size_t pos = escaped_alias.find(fnd);
206 while(pos!=string::npos)
208 escaped_alias.replace(pos,fnd.length(),rep);
209 pos = escaped_alias.find(fnd,pos+rep.length());
211 _pimpl->escaped_alias = escaped_alias;
215 RepoInfo & RepoInfo::setType( const repo::RepoType &t )
221 void RepoInfo::setProbedType( const repo::RepoType &t ) const
222 { _pimpl->setProbedType( t ); }
224 RepoInfo & RepoInfo::setName( const std::string &name )
230 RepoInfo & RepoInfo::setFilepath( const Pathname &filepath )
232 _pimpl->filepath = filepath;
236 RepoInfo & RepoInfo::setMetadataPath( const Pathname &path )
238 _pimpl->metadatapath = path;
242 RepoInfo & RepoInfo::setPackagesPath( const Pathname &path )
244 _pimpl->packagespath = path;
248 RepoInfo & RepoInfo::setKeepPackages( bool keep )
250 _pimpl->keeppackages = keep;
251 _pimpl->flags_determined |= Impl::FLAG_KEEPPACKAGES;
255 bool RepoInfo::enabled() const
256 { return _pimpl->enabled; }
258 bool RepoInfo::autorefresh() const
259 { return _pimpl->autorefresh; }
261 bool RepoInfo::gpgCheck() const
262 { return _pimpl->gpgcheck; }
264 std::string RepoInfo::alias() const
265 { return _pimpl->alias; }
267 std::string RepoInfo::escaped_alias() const
268 { return _pimpl->escaped_alias; }
270 std::string RepoInfo::name() const
272 if ( _pimpl->name.empty() )
277 repo::RepoVariablesStringReplacer replacer;
278 return replacer(_pimpl->name);
281 Pathname RepoInfo::filepath() const
282 { return _pimpl->filepath; }
284 Pathname RepoInfo::metadataPath() const
285 { return _pimpl->metadatapath; }
287 Pathname RepoInfo::packagesPath() const
288 { return _pimpl->packagespath; }
290 repo::RepoType RepoInfo::type() const
291 { return _pimpl->type; }
293 Url RepoInfo::mirrorListUrl() const
294 { return _pimpl->mirrorlist_url; }
296 Url RepoInfo::gpgKeyUrl() const
297 { return _pimpl->gpgkey_url; }
299 std::set<Url> RepoInfo::baseUrls() const
301 RepoInfo::url_set replaced_urls;
302 repo::RepoVariablesUrlReplacer replacer;
303 for ( url_set::const_iterator it = _pimpl->baseUrls.begin();
304 it != _pimpl->baseUrls.end();
307 replaced_urls.insert(replacer(*it));
309 return replaced_urls;
311 return _pimpl->baseUrls;
314 Pathname RepoInfo::path() const
315 { return _pimpl->path; }
317 RepoInfo::urls_const_iterator RepoInfo::baseUrlsBegin() const
319 return make_transform_iterator( _pimpl->baseUrls.begin(),
320 repo::RepoVariablesUrlReplacer() );
321 //return _pimpl->baseUrls.begin();
324 RepoInfo::urls_const_iterator RepoInfo::baseUrlsEnd() const
326 //return _pimpl->baseUrls.end();
327 return make_transform_iterator( _pimpl->baseUrls.end(),
328 repo::RepoVariablesUrlReplacer() );
331 RepoInfo::urls_size_type RepoInfo::baseUrlsSize() const
332 { return _pimpl->baseUrls.size(); }
334 bool RepoInfo::baseUrlsEmpty() const
335 { return _pimpl->baseUrls.empty(); }
337 bool RepoInfo::keepPackages() const
338 { return _pimpl->keeppackages; }
340 std::ostream & RepoInfo::dumpOn( std::ostream & str ) const
342 str << "--------------------------------------" << std::endl;
343 str << "- alias : " << alias() << std::endl;
344 for ( urls_const_iterator it = baseUrlsBegin();
348 str << "- url : " << *it << std::endl;
350 str << "- path : " << path() << std::endl;
351 str << "- type : " << type() << std::endl;
352 str << "- enabled : " << enabled() << std::endl;
353 str << "- priority : " << priority() << std::endl;
355 str << "- autorefresh : " << autorefresh() << std::endl;
356 str << "- gpgcheck : " << gpgCheck() << std::endl;
357 str << "- gpgkey : " << gpgKeyUrl() << std::endl;
358 str << "- keeppackages: " << keepPackages() << std::endl;
363 std::ostream & RepoInfo::dumpRepoOn( std::ostream & str ) const
365 // we save the original data without variable replacement
366 str << "[" << alias() << "]" << endl;
367 str << "name=" << _pimpl->name << endl;
369 if ( ! _pimpl->baseUrls.empty() )
371 for ( url_set::const_iterator it = _pimpl->baseUrls.begin();
372 it != _pimpl->baseUrls.end();
378 if ( ! _pimpl->path.empty() )
379 str << "path="<< path() << endl;
381 if ( ! (_pimpl->mirrorlist_url.asString().empty()) )
382 str << "mirrorlist=" << _pimpl->mirrorlist_url << endl;
384 str << "type=" << type().asString() << endl;
385 str << "enabled=" << (enabled() ? "1" : "0") << endl;
387 if ( priority() != defaultPriority() )
388 str << "priority=" << priority() << endl;
390 str << "autorefresh=" << (autorefresh() ? "1" : "0") << endl;
391 str << "gpgcheck=" << (gpgCheck() ? "1" : "0") << endl;
392 if ( ! (gpgKeyUrl().asString().empty()) )
393 str << "gpgkey=" <<gpgKeyUrl() << endl;
395 str << "keeppackages=" << keepPackages() << endl;
400 std::ostream & operator<<( std::ostream & str, const RepoInfo & obj )
402 return obj.dumpOn(str);
405 /////////////////////////////////////////////////////////////////
407 ///////////////////////////////////////////////////////////////////