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;
82 Pathname metadatapath;
83 Pathname packagespath;
84 DefaultIntegral<unsigned,defaultPriority> priority;
89 friend Impl * rwcowClone<Impl>( const Impl * rhs );
90 /** clone for RWCOW_pointer */
92 { return new Impl( *this ); }
94 ///////////////////////////////////////////////////////////////////
96 /** \relates RepoInfo::Impl Stream output */
97 inline std::ostream & operator<<( std::ostream & str, const RepoInfo::Impl & obj )
99 return str << "RepoInfo::Impl";
102 ///////////////////////////////////////////////////////////////////
104 // CLASS NAME : RepoInfo
106 ///////////////////////////////////////////////////////////////////
108 ///////////////////////////////////////////////////////////////////
110 // METHOD NAME : RepoInfo::RepoInfo
111 // METHOD TYPE : Ctor
114 : _pimpl( new Impl() )
117 ///////////////////////////////////////////////////////////////////
119 // METHOD NAME : RepoInfo::~RepoInfo
120 // METHOD TYPE : Dtor
122 RepoInfo::~RepoInfo()
127 unsigned RepoInfo::priority() const
128 { return _pimpl->priority; }
129 unsigned RepoInfo::defaultPriority()
130 { return Impl::defaultPriority; }
131 RepoInfo & RepoInfo::setPriority( unsigned newval_r )
133 _pimpl->priority = newval_r ? newval_r : Impl::defaultPriority;
138 RepoInfo & RepoInfo::setEnabled( bool enabled )
140 _pimpl->enabled = enabled;
141 _pimpl->flags_determined |= Impl::FLAG_ENABLED;
145 RepoInfo & RepoInfo::setAutorefresh( bool autorefresh )
147 _pimpl->autorefresh = autorefresh;
148 _pimpl->flags_determined |= Impl::FLAG_AUTOREFRESH;
152 RepoInfo & RepoInfo::setGpgCheck( bool check )
154 _pimpl->gpgcheck = check;
155 _pimpl->flags_determined |= Impl::FLAG_GPGCHECK;
159 RepoInfo & RepoInfo::setMirrorListUrl( const Url &url )
161 _pimpl->mirrorlist_url = url;
165 RepoInfo & RepoInfo::setGpgKeyUrl( const Url &url )
167 _pimpl->gpgkey_url = url;
171 RepoInfo & RepoInfo::addBaseUrl( const Url &url )
173 // set only if not already set externally (bnc #394728)
174 if (!(_pimpl->flags_determined & Impl::FLAG_KEEPPACKAGES) &&
175 _pimpl->baseUrls.empty())
177 if ( media::MediaAccess::downloads( url ) )
178 // don't do this via setKeepPackages, it would set the flags_determined
179 // for FLAG_KEEPPACKAGES
180 _pimpl->keeppackages = true;
182 _pimpl->keeppackages = false;
185 _pimpl->baseUrls.insert(url);
189 RepoInfo & RepoInfo::setBaseUrl( const Url &url )
191 _pimpl->baseUrls.clear();
196 RepoInfo & RepoInfo::setPath( const Pathname &path )
202 RepoInfo & RepoInfo::setAlias( const std::string &alias )
204 _pimpl->alias = alias;
205 // replace slashes with underscores
208 std::string escaped_alias = alias;
209 size_t pos = escaped_alias.find(fnd);
210 while(pos!=string::npos)
212 escaped_alias.replace(pos,fnd.length(),rep);
213 pos = escaped_alias.find(fnd,pos+rep.length());
215 _pimpl->escaped_alias = escaped_alias;
219 RepoInfo & RepoInfo::setType( const repo::RepoType &t )
225 void RepoInfo::setProbedType( const repo::RepoType &t ) const
226 { _pimpl->setProbedType( t ); }
228 RepoInfo & RepoInfo::setName( const std::string &name )
234 RepoInfo & RepoInfo::setFilepath( const Pathname &filepath )
236 _pimpl->filepath = filepath;
240 RepoInfo & RepoInfo::setMetadataPath( const Pathname &path )
242 _pimpl->metadatapath = path;
246 RepoInfo & RepoInfo::setPackagesPath( const Pathname &path )
248 _pimpl->packagespath = path;
252 RepoInfo & RepoInfo::setKeepPackages( bool keep )
254 _pimpl->keeppackages = keep;
255 _pimpl->flags_determined |= Impl::FLAG_KEEPPACKAGES;
259 RepoInfo & RepoInfo::setService( const std::string& name )
261 _pimpl->service = name;
265 bool RepoInfo::enabled() const
266 { return _pimpl->enabled; }
268 bool RepoInfo::autorefresh() const
269 { return _pimpl->autorefresh; }
271 bool RepoInfo::gpgCheck() const
272 { return _pimpl->gpgcheck; }
274 std::string RepoInfo::alias() const
275 { return _pimpl->alias; }
277 std::string RepoInfo::escaped_alias() const
278 { return _pimpl->escaped_alias; }
280 std::string RepoInfo::name() const
282 if ( _pimpl->name.empty() )
287 repo::RepoVariablesStringReplacer replacer;
288 return replacer(_pimpl->name);
291 Pathname RepoInfo::filepath() const
292 { return _pimpl->filepath; }
294 Pathname RepoInfo::metadataPath() const
295 { return _pimpl->metadatapath; }
297 Pathname RepoInfo::packagesPath() const
298 { return _pimpl->packagespath; }
300 repo::RepoType RepoInfo::type() const
301 { return _pimpl->type; }
303 Url RepoInfo::mirrorListUrl() const
304 { return _pimpl->mirrorlist_url; }
306 Url RepoInfo::gpgKeyUrl() const
307 { return _pimpl->gpgkey_url; }
309 std::set<Url> RepoInfo::baseUrls() const
311 RepoInfo::url_set replaced_urls;
312 repo::RepoVariablesUrlReplacer replacer;
313 for ( url_set::const_iterator it = _pimpl->baseUrls.begin();
314 it != _pimpl->baseUrls.end();
317 replaced_urls.insert(replacer(*it));
319 return replaced_urls;
321 return _pimpl->baseUrls;
324 Pathname RepoInfo::path() const
325 { return _pimpl->path; }
327 std::string RepoInfo::service() const
328 { return _pimpl->service; }
330 RepoInfo::urls_const_iterator RepoInfo::baseUrlsBegin() const
332 return make_transform_iterator( _pimpl->baseUrls.begin(),
333 repo::RepoVariablesUrlReplacer() );
334 //return _pimpl->baseUrls.begin();
337 RepoInfo::urls_const_iterator RepoInfo::baseUrlsEnd() const
339 //return _pimpl->baseUrls.end();
340 return make_transform_iterator( _pimpl->baseUrls.end(),
341 repo::RepoVariablesUrlReplacer() );
344 RepoInfo::urls_size_type RepoInfo::baseUrlsSize() const
345 { return _pimpl->baseUrls.size(); }
347 bool RepoInfo::baseUrlsEmpty() const
348 { return _pimpl->baseUrls.empty(); }
350 bool RepoInfo::keepPackages() const
351 { return _pimpl->keeppackages; }
353 std::ostream & RepoInfo::dumpOn( std::ostream & str ) const
355 str << "--------------------------------------" << std::endl;
356 str << "- alias : " << alias() << std::endl;
357 for ( urls_const_iterator it = baseUrlsBegin();
361 str << "- url : " << *it << std::endl;
363 str << "- path : " << path() << std::endl;
364 str << "- type : " << type() << std::endl;
365 str << "- enabled : " << enabled() << std::endl;
366 str << "- priority : " << priority() << std::endl;
368 str << "- autorefresh : " << autorefresh() << std::endl;
369 str << "- gpgcheck : " << gpgCheck() << std::endl;
370 str << "- gpgkey : " << gpgKeyUrl() << std::endl;
371 str << "- keeppackages: " << keepPackages() << std::endl;
372 str << "- service : " << service() << std::endl;
377 std::ostream & RepoInfo::dumpRepoOn( std::ostream & str ) const
379 // we save the original data without variable replacement
380 str << "[" << alias() << "]" << endl;
381 str << "name=" << _pimpl->name << endl;
383 if ( ! _pimpl->baseUrls.empty() )
385 for ( url_set::const_iterator it = _pimpl->baseUrls.begin();
386 it != _pimpl->baseUrls.end();
392 if ( ! _pimpl->path.empty() )
393 str << "path="<< path() << endl;
395 if ( ! (_pimpl->mirrorlist_url.asString().empty()) )
396 str << "mirrorlist=" << _pimpl->mirrorlist_url << endl;
398 str << "type=" << type().asString() << endl;
399 str << "enabled=" << (enabled() ? "1" : "0") << endl;
401 if ( priority() != defaultPriority() )
402 str << "priority=" << priority() << endl;
404 str << "autorefresh=" << (autorefresh() ? "1" : "0") << endl;
405 str << "gpgcheck=" << (gpgCheck() ? "1" : "0") << endl;
406 if ( ! (gpgKeyUrl().asString().empty()) )
407 str << "gpgkey=" <<gpgKeyUrl() << endl;
409 str << "keeppackages=" << keepPackages() << endl;
411 if( ! service().empty() )
412 str << "service=" << service() << endl;
417 std::ostream & operator<<( std::ostream & str, const RepoInfo & obj )
419 return obj.dumpOn(str);
422 /////////////////////////////////////////////////////////////////
424 ///////////////////////////////////////////////////////////////////