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"
19 #include "zypp/repo/RepoInfoBaseImpl.h"
23 ///////////////////////////////////////////////////////////////////
25 { /////////////////////////////////////////////////////////////////
27 ///////////////////////////////////////////////////////////////////
29 // CLASS NAME : RepoInfo::Impl
31 /** RepoInfo implementation. */
32 struct RepoInfo::Impl : public repo::RepoInfoBase::Impl
35 : repo::RepoInfoBase::Impl()
36 , gpgcheck(indeterminate)
37 , keeppackages(indeterminate)
38 , type(repo::RepoType::NONE_e)
45 static const unsigned defaultPriority = 99;
47 void setProbedType( const repo::RepoType & t ) const
49 if ( type == repo::RepoType::NONE
50 && t != repo::RepoType::NONE )
53 const_cast<Impl*>(this)->type = t;
63 std::set<Url> baseUrls;
66 Pathname metadatapath;
67 Pathname packagespath;
68 DefaultIntegral<unsigned,defaultPriority> priority;
72 friend Impl * rwcowClone<Impl>( const Impl * rhs );
73 /** clone for RWCOW_pointer */
75 { return new Impl( *this ); }
77 ///////////////////////////////////////////////////////////////////
79 /** \relates RepoInfo::Impl Stream output */
80 inline std::ostream & operator<<( std::ostream & str, const RepoInfo::Impl & obj )
82 return str << "RepoInfo::Impl";
85 ///////////////////////////////////////////////////////////////////
87 // CLASS NAME : RepoInfo
89 ///////////////////////////////////////////////////////////////////
91 ///////////////////////////////////////////////////////////////////
93 // METHOD NAME : RepoInfo::RepoInfo
97 : _pimpl( new Impl() )
100 ///////////////////////////////////////////////////////////////////
102 // METHOD NAME : RepoInfo::~RepoInfo
103 // METHOD TYPE : Dtor
105 RepoInfo::~RepoInfo()
110 unsigned RepoInfo::priority() const
111 { return _pimpl->priority; }
112 unsigned RepoInfo::defaultPriority()
113 { return Impl::defaultPriority; }
114 RepoInfo & RepoInfo::setPriority( unsigned newval_r )
116 _pimpl->priority = newval_r ? newval_r : Impl::defaultPriority;
120 RepoInfo & RepoInfo::setGpgCheck( bool check )
122 _pimpl->gpgcheck = check;
126 RepoInfo & RepoInfo::setMirrorListUrl( const Url &url )
128 _pimpl->mirrorlist_url = url;
132 RepoInfo & RepoInfo::setGpgKeyUrl( const Url &url )
134 _pimpl->gpgkey_url = url;
138 RepoInfo & RepoInfo::addBaseUrl( const Url &url )
140 _pimpl->baseUrls.insert(url);
144 RepoInfo & RepoInfo::setBaseUrl( const Url &url )
146 _pimpl->baseUrls.clear();
151 RepoInfo & RepoInfo::setPath( const Pathname &path )
157 RepoInfo & RepoInfo::setType( const repo::RepoType &t )
163 void RepoInfo::setProbedType( const repo::RepoType &t ) const
164 { _pimpl->setProbedType( t ); }
167 RepoInfo & RepoInfo::setMetadataPath( const Pathname &path )
169 _pimpl->metadatapath = path;
173 RepoInfo & RepoInfo::setPackagesPath( const Pathname &path )
175 _pimpl->packagespath = path;
179 RepoInfo & RepoInfo::setKeepPackages( bool keep )
181 _pimpl->keeppackages = keep;
185 RepoInfo & RepoInfo::setService( const std::string& name )
187 _pimpl->service = name;
191 bool RepoInfo::gpgCheck() const
192 { return indeterminate(_pimpl->gpgcheck) ? true : (bool) _pimpl->gpgcheck; }
194 Pathname RepoInfo::metadataPath() const
195 { return _pimpl->metadatapath; }
197 Pathname RepoInfo::packagesPath() const
198 { return _pimpl->packagespath; }
200 repo::RepoType RepoInfo::type() const
201 { return _pimpl->type; }
203 Url RepoInfo::mirrorListUrl() const
204 { return _pimpl->mirrorlist_url; }
206 Url RepoInfo::gpgKeyUrl() const
207 { return _pimpl->gpgkey_url; }
209 std::set<Url> RepoInfo::baseUrls() const
211 RepoInfo::url_set replaced_urls;
212 repo::RepoVariablesUrlReplacer replacer;
213 for ( url_set::const_iterator it = _pimpl->baseUrls.begin();
214 it != _pimpl->baseUrls.end();
217 replaced_urls.insert(replacer(*it));
219 return replaced_urls;
221 return _pimpl->baseUrls;
224 Pathname RepoInfo::path() const
225 { return _pimpl->path; }
227 std::string RepoInfo::service() const
228 { return _pimpl->service; }
230 RepoInfo::urls_const_iterator RepoInfo::baseUrlsBegin() const
232 return make_transform_iterator( _pimpl->baseUrls.begin(),
233 repo::RepoVariablesUrlReplacer() );
234 //return _pimpl->baseUrls.begin();
237 RepoInfo::urls_const_iterator RepoInfo::baseUrlsEnd() const
239 //return _pimpl->baseUrls.end();
240 return make_transform_iterator( _pimpl->baseUrls.end(),
241 repo::RepoVariablesUrlReplacer() );
244 RepoInfo::urls_size_type RepoInfo::baseUrlsSize() const
245 { return _pimpl->baseUrls.size(); }
247 bool RepoInfo::baseUrlsEmpty() const
248 { return _pimpl->baseUrls.empty(); }
250 // false by default (if not set by setKeepPackages)
251 bool RepoInfo::keepPackages() const
253 if (indeterminate(_pimpl->keeppackages))
255 if (_pimpl->baseUrls.empty())
257 else if ( media::MediaAccess::downloads( *baseUrlsBegin() ) )
263 return (bool) _pimpl->keeppackages;
267 std::ostream & RepoInfo::dumpOn( std::ostream & str ) const
269 RepoInfoBase::dumpOn(str);
270 for ( urls_const_iterator it = baseUrlsBegin();
274 str << "- url : " << *it << std::endl;
276 str << "- path : " << path() << std::endl;
277 str << "- type : " << type() << std::endl;
278 str << "- priority : " << priority() << std::endl;
280 str << "- gpgcheck : " << gpgCheck() << std::endl;
281 str << "- gpgkey : " << gpgKeyUrl() << std::endl;
282 str << "- keeppackages: " << keepPackages() << std::endl;
283 str << "- service : " << service() << std::endl;
288 std::ostream & RepoInfo::dumpRepoOn( std::ostream & str ) const
290 RepoInfoBase::dumpAsIniOn(str);
292 if ( ! _pimpl->baseUrls.empty() )
294 for ( url_set::const_iterator it = _pimpl->baseUrls.begin();
295 it != _pimpl->baseUrls.end();
301 if ( ! _pimpl->path.empty() )
302 str << "path="<< path() << endl;
304 if ( ! (_pimpl->mirrorlist_url.asString().empty()) )
305 str << "mirrorlist=" << _pimpl->mirrorlist_url << endl;
307 str << "type=" << type().asString() << endl;
309 if ( priority() != defaultPriority() )
310 str << "priority=" << priority() << endl;
312 if (!indeterminate(_pimpl->gpgcheck))
313 str << "gpgcheck=" << (gpgCheck() ? "1" : "0") << endl;
314 if ( ! (gpgKeyUrl().asString().empty()) )
315 str << "gpgkey=" <<gpgKeyUrl() << endl;
317 if (!indeterminate(_pimpl->keeppackages))
318 str << "keeppackages=" << keepPackages() << endl;
320 if( ! service().empty() )
321 str << "service=" << service() << endl;
326 std::ostream & operator<<( std::ostream & str, const RepoInfo & obj )
328 return obj.dumpOn(str);
331 /////////////////////////////////////////////////////////////////
333 ///////////////////////////////////////////////////////////////////