1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/RepoInfo.cc
15 #include "zypp/base/LogTools.h"
16 #include "zypp/base/DefaultIntegral.h"
17 #include "zypp/parser/xml/XmlEscape.h"
19 #include "zypp/RepoInfo.h"
20 #include "zypp/TriBool.h"
21 #include "zypp/Pathname.h"
22 #include "zypp/ZConfig.h"
23 #include "zypp/repo/RepoMirrorList.h"
24 #include "zypp/ExternalProgram.h"
25 #include "zypp/media/MediaAccess.h"
27 #include "zypp/base/IOStream.h"
28 #include "zypp/base/InputStream.h"
29 #include "zypp/parser/xml/Reader.h"
32 using zypp::xml::escape;
34 ///////////////////////////////////////////////////////////////////
36 { /////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////
40 // CLASS NAME : RepoInfo::Impl
42 /** RepoInfo implementation. */
46 : _rawGpgCheck( indeterminate )
47 , _rawRepoGpgCheck( indeterminate )
48 , _rawPkgGpgCheck( indeterminate )
49 , _validRepoSignature( indeterminate )
50 , keeppackages(indeterminate)
51 , type(repo::RepoType::NONE_e)
52 , emptybaseurls(false)
59 static const unsigned defaultPriority = 99;
61 void setProbedType( const repo::RepoType & t ) const
63 if ( type == repo::RepoType::NONE
64 && t != repo::RepoType::NONE )
67 const_cast<Impl*>(this)->type = t;
72 Pathname licenseTgz() const
73 { return metadatapath.empty() ? Pathname() : metadatapath / path / "license.tar.gz"; }
75 const RepoVariablesReplacedUrlList & baseUrls() const
77 const Url & mlurl( _mirrorListUrl.transformed() ); // Variables replaced!
78 if ( _baseUrls.empty() && ! mlurl.asString().empty() )
81 DBG << "MetadataPath: " << metadatapath << endl;
82 repo::RepoMirrorList rmurls( mlurl, metadatapath );
83 _baseUrls.raw().insert( _baseUrls.raw().end(), rmurls.getUrls().begin(), rmurls.getUrls().end() );
88 RepoVariablesReplacedUrlList & baseUrls()
91 bool baseurl2dump() const
92 { return !emptybaseurls && !_baseUrls.empty(); }
95 const RepoVariablesReplacedUrlList & gpgKeyUrls() const
96 { return _gpgKeyUrls; }
98 RepoVariablesReplacedUrlList & gpgKeyUrls()
99 { return _gpgKeyUrls; }
101 void addContent( const std::string & keyword_r )
102 { _keywords.insert( keyword_r ); }
104 bool hasContent( const std::string & keyword_r ) const
106 if ( _keywords.empty() && ! metadatapath.empty() )
108 // HACK directly check master index file until RepoManager offers
109 // some content probing ans zypepr uses it.
110 /////////////////////////////////////////////////////////////////
111 MIL << "Empty keywords...." << metadatapath << endl;
113 if ( PathInfo( (master=metadatapath/"/repodata/repomd.xml") ).isFile() )
115 //MIL << "GO repomd.." << endl;
116 xml::Reader reader( master );
117 while ( reader.seekToNode( 2, "content" ) )
119 _keywords.insert( reader.nodeText().asString() );
120 reader.seekToEndNode( 2, "content" );
122 _keywords.insert( "" ); // valid content in _keywords even if empty
124 else if ( PathInfo( (master=metadatapath/"/content") ).isFile() )
126 //MIL << "GO content.." << endl;
127 iostr::forEachLine( InputStream( master ),
128 [this]( int num_r, std::string line_r )->bool
130 if ( str::startsWith( line_r, "REPOKEYWORDS" ) )
132 std::vector<std::string> words;
133 if ( str::split( line_r, std::back_inserter(words) ) > 1
134 && words[0].length() == 12 /*"REPOKEYWORDS"*/ )
136 this->_keywords.insert( ++words.begin(), words.end() );
138 return true; // mult. occurrances are ok.
140 return( ! str::startsWith( line_r, "META " ) ); // no need to parse into META section.
142 _keywords.insert( "" );
144 /////////////////////////////////////////////////////////////////
146 return( _keywords.find( keyword_r ) != _keywords.end() );
149 /** Signature check result needs to be stored/retrieved from _metadatapath.
150 * Don't call them from outside validRepoSignature/setValidRepoSignature
153 TriBool internalValidRepoSignature() const
155 if ( ! indeterminate(_validRepoSignature) )
156 return _validRepoSignature;
158 if ( ! metadatapath.empty() )
160 // A missing ".repo_gpgcheck" might be plaindir(no Downloader) or not yet refreshed signed repo!
161 TriBool linkval = triBoolFromPath( metadatapath / ".repo_gpgcheck" );
164 return indeterminate;
167 void internalSetValidRepoSignature( TriBool value_r )
169 if ( PathInfo(metadatapath).isDir() )
171 Pathname gpgcheckFile( metadatapath / ".repo_gpgcheck" );
172 if ( PathInfo(gpgcheckFile).isExist() )
174 TriBool linkval( indeterminate );
175 if ( triBoolFromPath( gpgcheckFile, linkval ) && linkval == value_r )
176 return; // existing symlink fits value_r
178 filesystem::unlink( gpgcheckFile ); // will write a new one
180 filesystem::symlink( asString(value_r), gpgcheckFile );
182 _validRepoSignature = value_r;
185 /** We definitely have a symlink pointing to "indeterminate" (for repoGpgCheckIsMandatory)?
186 * I.e. user accepted the unsigned repo in Downloader. A test whether `internalValidRepoSignature`
187 * is indeterminate would include not yet checked repos, which is unwanted here.
189 bool internalUnsignedConfirmed() const
191 TriBool linkval( true ); // want to see it being switched to indeterminate
192 return triBoolFromPath( metadatapath / ".repo_gpgcheck", linkval ) && indeterminate(linkval);
195 bool triBoolFromPath( const Pathname & path_r, TriBool & ret_r ) const
197 static const Pathname truePath( "true" );
198 static const Pathname falsePath( "false" );
199 static const Pathname indeterminatePath( "indeterminate" );
202 static const ssize_t bufsiz = 63;
203 static char buf[bufsiz+1];
204 ssize_t ret = ::readlink( path_r.c_str(), buf, bufsiz );
205 buf[ret == -1 ? 0 : ret] = '\0';
207 Pathname linkval( buf );
210 if ( linkval == truePath )
212 else if ( linkval == falsePath )
214 else if ( linkval == indeterminatePath )
215 ret_r = indeterminate;
221 TriBool triBoolFromPath( const Pathname & path_r ) const
222 { TriBool ret(indeterminate); triBoolFromPath( path_r, ret ); return ret; }
227 TriBool _rawGpgCheck; ///< default gpgcheck behavior: Y/N/ZConf
228 TriBool _rawRepoGpgCheck; ///< need to check repo sign.: Y/N/(ZConf(Y/N/gpgCheck))
229 TriBool _rawPkgGpgCheck; ///< need to check pkg sign.: Y/N/(ZConf(Y/N/gpgCheck))
232 TriBool rawGpgCheck() const { return _rawGpgCheck; }
233 TriBool rawRepoGpgCheck() const { return _rawRepoGpgCheck; }
234 TriBool rawPkgGpgCheck() const { return _rawPkgGpgCheck; }
236 void rawGpgCheck( TriBool val_r ) { _rawGpgCheck = val_r; }
237 void rawRepoGpgCheck( TriBool val_r ) { _rawRepoGpgCheck = val_r; }
238 void rawPkgGpgCheck( TriBool val_r ) { _rawPkgGpgCheck = val_r; }
240 bool cfgGpgCheck() const
241 { return indeterminate(_rawGpgCheck) ? ZConfig::instance().gpgCheck() : (bool)_rawGpgCheck; }
242 TriBool cfgRepoGpgCheck() const
243 { return indeterminate(_rawGpgCheck) && indeterminate(_rawRepoGpgCheck) ? ZConfig::instance().repoGpgCheck() : _rawRepoGpgCheck; }
244 TriBool cfgPkgGpgCheck() const
245 { return indeterminate(_rawGpgCheck) && indeterminate(_rawPkgGpgCheck) ? ZConfig::instance().pkgGpgCheck() : _rawPkgGpgCheck; }
248 TriBool _validRepoSignature;///< have signed and valid repo metadata
250 TriBool keeppackages;
251 RepoVariablesReplacedUrl _mirrorListUrl;
255 std::string targetDistro;
256 Pathname metadatapath;
257 Pathname packagespath;
258 DefaultIntegral<unsigned,defaultPriority> priority;
259 mutable bool emptybaseurls;
260 repo::RepoVariablesUrlReplacer replacer;
263 mutable RepoVariablesReplacedUrlList _baseUrls;
264 mutable std::set<std::string> _keywords;
266 RepoVariablesReplacedUrlList _gpgKeyUrls;
268 friend Impl * rwcowClone<Impl>( const Impl * rhs );
269 /** clone for RWCOW_pointer */
271 { return new Impl( *this ); }
273 ///////////////////////////////////////////////////////////////////
275 /** \relates RepoInfo::Impl Stream output */
276 inline std::ostream & operator<<( std::ostream & str, const RepoInfo::Impl & obj )
278 return str << "RepoInfo::Impl";
281 ///////////////////////////////////////////////////////////////////
283 // CLASS NAME : RepoInfo
285 ///////////////////////////////////////////////////////////////////
287 const RepoInfo RepoInfo::noRepo;
290 : _pimpl( new Impl() )
293 RepoInfo::~RepoInfo()
296 unsigned RepoInfo::priority() const
297 { return _pimpl->priority; }
299 unsigned RepoInfo::defaultPriority()
300 { return Impl::defaultPriority; }
302 void RepoInfo::setPriority( unsigned newval_r )
303 { _pimpl->priority = newval_r ? newval_r : Impl::defaultPriority; }
306 bool RepoInfo::gpgCheck() const
307 { return _pimpl->cfgGpgCheck(); }
309 void RepoInfo::setGpgCheck( TriBool value_r )
310 { _pimpl->rawGpgCheck( value_r ); }
312 void RepoInfo::setGpgCheck( bool value_r ) // deprecated legacy and for squid
313 { setGpgCheck( TriBool(value_r) ); }
316 bool RepoInfo::repoGpgCheck() const
317 { return gpgCheck() || _pimpl->cfgRepoGpgCheck(); }
319 bool RepoInfo::repoGpgCheckIsMandatory() const
321 bool ret = ( gpgCheck() && indeterminate(_pimpl->cfgRepoGpgCheck()) ) || _pimpl->cfgRepoGpgCheck();
322 if ( ret && _pimpl->internalUnsignedConfirmed() ) // relax if unsigned repo was confirmed in the past
327 void RepoInfo::setRepoGpgCheck( TriBool value_r )
328 { _pimpl->rawRepoGpgCheck( value_r ); }
331 bool RepoInfo::pkgGpgCheck() const
332 { return _pimpl->cfgPkgGpgCheck() || ( gpgCheck() && !bool(validRepoSignature())/*enforced*/ ) ; }
334 bool RepoInfo::pkgGpgCheckIsMandatory() const
335 { return _pimpl->cfgPkgGpgCheck() || ( gpgCheck() && indeterminate(_pimpl->cfgPkgGpgCheck()) && !bool(validRepoSignature())/*enforced*/ ); }
337 void RepoInfo::setPkgGpgCheck( TriBool value_r )
338 { _pimpl->rawPkgGpgCheck( value_r ); }
341 void RepoInfo::getRawGpgChecks( TriBool & g_r, TriBool & r_r, TriBool & p_r ) const
343 g_r = _pimpl->rawGpgCheck();
344 r_r = _pimpl->rawRepoGpgCheck();
345 p_r = _pimpl->rawPkgGpgCheck();
349 TriBool RepoInfo::validRepoSignature() const
351 TriBool ret( _pimpl->internalValidRepoSignature() );
352 if ( ret && !repoGpgCheck() ) ret = false; // invalidate any old signature if repoGpgCheck is off
356 void RepoInfo::setValidRepoSignature( TriBool value_r )
357 { _pimpl->internalSetValidRepoSignature( value_r ); }
359 ///////////////////////////////////////////////////////////////////
362 inline bool changeGpgCheckTo( TriBool & lhs, TriBool rhs )
363 { if ( ! sameTriboolState( lhs, rhs ) ) { lhs = rhs; return true; } return false; }
365 inline bool changeGpgCheckTo( TriBool ogpg[3], TriBool g, TriBool r, TriBool p )
367 bool changed = false;
368 if ( changeGpgCheckTo( ogpg[0], g ) ) changed = true;
369 if ( changeGpgCheckTo( ogpg[1], r ) ) changed = true;
370 if ( changeGpgCheckTo( ogpg[2], p ) ) changed = true;
374 ///////////////////////////////////////////////////////////////////
375 bool RepoInfo::setGpgCheck( GpgCheck mode_r )
377 TriBool ogpg[3]; // Gpg RepoGpg PkgGpg
378 getRawGpgChecks( ogpg[0], ogpg[1], ogpg[2] );
380 bool changed = false;
381 switch ( mode_r.asEnum() )
384 changed = changeGpgCheckTo( ogpg, true, indeterminate, indeterminate );
386 case GpgCheck::Strict:
387 changed = changeGpgCheckTo( ogpg, true, true, true );
389 case GpgCheck::AllowUnsigned:
390 changed = changeGpgCheckTo( ogpg, true, false, false );
392 case GpgCheck::AllowUnsignedRepo:
393 changed = changeGpgCheckTo( ogpg, true, false, indeterminate );
395 case GpgCheck::AllowUnsignedPackage:
396 changed = changeGpgCheckTo( ogpg, true, indeterminate, false );
398 case GpgCheck::Default:
399 changed = changeGpgCheckTo( ogpg, indeterminate, indeterminate, indeterminate );
402 changed = changeGpgCheckTo( ogpg, false, indeterminate, indeterminate );
404 case GpgCheck::indeterminate: // no change
410 setGpgCheck ( ogpg[0] );
411 setRepoGpgCheck( ogpg[1] );
412 setPkgGpgCheck ( ogpg[2] );
417 void RepoInfo::setMirrorListUrl( const Url & url_r ) // Raw
418 { _pimpl->_mirrorListUrl.raw() = url_r; }
420 void RepoInfo::setGpgKeyUrls( url_set urls )
421 { _pimpl->gpgKeyUrls().raw().swap( urls ); }
423 void RepoInfo::setGpgKeyUrl( const Url & url_r )
425 _pimpl->gpgKeyUrls().raw().clear();
426 _pimpl->gpgKeyUrls().raw().push_back( url_r );
429 void RepoInfo::addBaseUrl( const Url & url_r )
431 for ( const auto & url : _pimpl->baseUrls().raw() ) // Raw unique!
434 _pimpl->baseUrls().raw().push_back( url_r );
437 void RepoInfo::setBaseUrl( const Url & url_r )
439 _pimpl->baseUrls().raw().clear();
440 _pimpl->baseUrls().raw().push_back( url_r );
443 void RepoInfo::setBaseUrls( url_set urls )
444 { _pimpl->baseUrls().raw().swap( urls ); }
446 void RepoInfo::setPath( const Pathname &path )
447 { _pimpl->path = path; }
449 void RepoInfo::setType( const repo::RepoType &t )
450 { _pimpl->type = t; }
452 void RepoInfo::setProbedType( const repo::RepoType &t ) const
453 { _pimpl->setProbedType( t ); }
456 void RepoInfo::setMetadataPath( const Pathname &path )
457 { _pimpl->metadatapath = path; }
459 void RepoInfo::setPackagesPath( const Pathname &path )
460 { _pimpl->packagespath = path; }
462 void RepoInfo::setKeepPackages( bool keep )
463 { _pimpl->keeppackages = keep; }
465 void RepoInfo::setService( const std::string& name )
466 { _pimpl->service = name; }
468 void RepoInfo::setTargetDistribution( const std::string & targetDistribution )
469 { _pimpl->targetDistro = targetDistribution; }
471 bool RepoInfo::keepPackages() const
472 { return indeterminate(_pimpl->keeppackages) ? false : (bool)_pimpl->keeppackages; }
474 Pathname RepoInfo::metadataPath() const
475 { return _pimpl->metadatapath; }
477 Pathname RepoInfo::packagesPath() const
478 { return _pimpl->packagespath; }
480 repo::RepoType RepoInfo::type() const
481 { return _pimpl->type; }
483 Url RepoInfo::mirrorListUrl() const // Variables replaced!
484 { return _pimpl->_mirrorListUrl.transformed(); }
486 Url RepoInfo::rawMirrorListUrl() const // Raw
487 { return _pimpl->_mirrorListUrl.raw(); }
489 bool RepoInfo::gpgKeyUrlsEmpty() const
490 { return _pimpl->gpgKeyUrls().empty(); }
492 RepoInfo::urls_size_type RepoInfo::gpgKeyUrlsSize() const
493 { return _pimpl->gpgKeyUrls().size(); }
495 RepoInfo::url_set RepoInfo::gpgKeyUrls() const // Variables replaced!
496 { return _pimpl->gpgKeyUrls().transformed(); }
498 RepoInfo::url_set RepoInfo::rawGpgKeyUrls() const // Raw
499 { return _pimpl->gpgKeyUrls().raw(); }
501 Url RepoInfo::gpgKeyUrl() const // Variables replaced!
502 { return( _pimpl->gpgKeyUrls().empty() ? Url() : *_pimpl->gpgKeyUrls().transformedBegin() ); }
504 Url RepoInfo::rawGpgKeyUrl() const // Raw
505 { return( _pimpl->gpgKeyUrls().empty() ? Url() : *_pimpl->gpgKeyUrls().rawBegin() ) ; }
507 RepoInfo::url_set RepoInfo::baseUrls() const // Variables replaced!
508 { return _pimpl->baseUrls().transformed(); }
510 RepoInfo::url_set RepoInfo::rawBaseUrls() const // Raw
511 { return _pimpl->baseUrls().raw(); }
513 Pathname RepoInfo::path() const
514 { return _pimpl->path; }
516 std::string RepoInfo::service() const
517 { return _pimpl->service; }
519 std::string RepoInfo::targetDistribution() const
520 { return _pimpl->targetDistro; }
522 Url RepoInfo::rawUrl() const
523 { return( _pimpl->baseUrls().empty() ? Url() : *_pimpl->baseUrls().rawBegin() ); }
525 RepoInfo::urls_const_iterator RepoInfo::baseUrlsBegin() const
526 { return _pimpl->baseUrls().transformedBegin(); }
528 RepoInfo::urls_const_iterator RepoInfo::baseUrlsEnd() const
529 { return _pimpl->baseUrls().transformedEnd(); }
531 RepoInfo::urls_size_type RepoInfo::baseUrlsSize() const
532 { return _pimpl->baseUrls().size(); }
534 bool RepoInfo::baseUrlsEmpty() const
535 { return _pimpl->baseUrls().empty(); }
537 bool RepoInfo::baseUrlSet() const
538 { return _pimpl->baseurl2dump(); }
541 void RepoInfo::addContent( const std::string & keyword_r )
542 { _pimpl->addContent( keyword_r ); }
544 bool RepoInfo::hasContent( const std::string & keyword_r ) const
545 { return _pimpl->hasContent( keyword_r ); }
547 ///////////////////////////////////////////////////////////////////
549 bool RepoInfo::hasLicense() const
551 Pathname licenseTgz( _pimpl->licenseTgz() );
552 return ! licenseTgz.empty() && PathInfo(licenseTgz).isFile();
555 bool RepoInfo::needToAcceptLicense() const
557 static const std::string noAcceptanceFile = "no-acceptance-needed\n";
560 Pathname licenseTgz( _pimpl->licenseTgz() );
561 if ( licenseTgz.empty() || ! PathInfo( licenseTgz ).isFile() )
562 return false; // no licenses at all
564 ExternalProgram::Arguments cmd;
565 cmd.push_back( "tar" );
566 cmd.push_back( "-t" );
567 cmd.push_back( "-z" );
568 cmd.push_back( "-f" );
569 cmd.push_back( licenseTgz.asString() );
571 ExternalProgram prog( cmd, ExternalProgram::Stderr_To_Stdout );
572 for ( std::string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() )
574 if ( output == noAcceptanceFile )
580 MIL << "License for " << name() << " has to be accepted: " << (accept?"true":"false" ) << endl;
584 std::string RepoInfo::getLicense( const Locale & lang_r )
585 { return const_cast<const RepoInfo *>(this)->getLicense( lang_r ); }
587 std::string RepoInfo::getLicense( const Locale & lang_r ) const
589 LocaleSet avlocales( getLicenseLocales() );
590 if ( avlocales.empty() )
591 return std::string();
593 Locale getLang( Locale::bestMatch( avlocales, lang_r ) );
594 if ( getLang == Locale::noCode
595 && avlocales.find( Locale::noCode ) == avlocales.end() )
597 WAR << "License.tar.gz contains no fallback text! " << *this << endl;
598 // Using the fist locale instead of returning no text at all.
599 // So the user might recognize that there is a license, even if he
601 getLang = *avlocales.begin();
604 // now extract the license file.
605 static const std::string licenseFileFallback( "license.txt" );
606 std::string licenseFile( getLang == Locale::noCode
607 ? licenseFileFallback
608 : str::form( "license.%s.txt", getLang.code().c_str() ) );
610 ExternalProgram::Arguments cmd;
611 cmd.push_back( "tar" );
612 cmd.push_back( "-x" );
613 cmd.push_back( "-z" );
614 cmd.push_back( "-O" );
615 cmd.push_back( "-f" );
616 cmd.push_back( _pimpl->licenseTgz().asString() ); // if it not exists, avlocales was empty.
617 cmd.push_back( licenseFile );
620 ExternalProgram prog( cmd, ExternalProgram::Discard_Stderr );
621 for ( std::string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() )
629 LocaleSet RepoInfo::getLicenseLocales() const
631 Pathname licenseTgz( _pimpl->licenseTgz() );
632 if ( licenseTgz.empty() || ! PathInfo( licenseTgz ).isFile() )
635 ExternalProgram::Arguments cmd;
636 cmd.push_back( "tar" );
637 cmd.push_back( "-t" );
638 cmd.push_back( "-z" );
639 cmd.push_back( "-f" );
640 cmd.push_back( licenseTgz.asString() );
643 ExternalProgram prog( cmd, ExternalProgram::Stderr_To_Stdout );
644 for ( std::string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() )
646 static const C_Str license( "license." );
647 static const C_Str dotTxt( ".txt\n" );
648 if ( str::hasPrefix( output, license ) && str::hasSuffix( output, dotTxt ) )
650 if ( output.size() <= license.size() + dotTxt.size() ) // license.txt
651 ret.insert( Locale() );
653 ret.insert( Locale( std::string( output.c_str()+license.size(), output.size()- license.size() - dotTxt.size() ) ) );
660 ///////////////////////////////////////////////////////////////////
662 std::ostream & RepoInfo::dumpOn( std::ostream & str ) const
664 RepoInfoBase::dumpOn(str);
665 if ( _pimpl->baseurl2dump() )
667 for ( const auto & url : _pimpl->baseUrls().raw() )
669 str << "- url : " << url << std::endl;
673 // print if non empty value
674 auto strif( [&] ( const std::string & tag_r, const std::string & value_r ) {
675 if ( ! value_r.empty() )
676 str << tag_r << value_r << std::endl;
679 strif( "- mirrorlist : ", rawMirrorListUrl().asString() );
680 strif( "- path : ", path().asString() );
681 str << "- type : " << type() << std::endl;
682 str << "- priority : " << priority() << std::endl;
684 // Yes No Default(Y) Default(N)
685 #define OUTS(T,B) ( indeterminate(T) ? (std::string("D(")+(B?"Y":"N")+")") : ((bool)T?"Y":"N") )
686 str << "- gpgcheck : " << OUTS(_pimpl->rawGpgCheck(),gpgCheck())
687 << " repo" << OUTS(_pimpl->rawRepoGpgCheck(),repoGpgCheck()) << (repoGpgCheckIsMandatory() ? "* ": " " )
688 << "sig" << asString( validRepoSignature(), "?", "Y", "N" )
689 << " pkg" << OUTS(_pimpl->rawPkgGpgCheck(),pkgGpgCheck()) << (pkgGpgCheckIsMandatory() ? "* ": " " )
693 for ( const auto & url : _pimpl->gpgKeyUrls().raw() )
695 str << "- gpgkey : " << url << std::endl;
698 if ( ! indeterminate(_pimpl->keeppackages) )
699 str << "- keeppackages: " << keepPackages() << std::endl;
701 strif( "- service : ", service() );
702 strif( "- targetdistro: ", targetDistribution() );
703 strif( "- metadataPath: ", metadataPath().asString() );
704 strif( "- packagesPath: ", packagesPath().asString() );
709 std::ostream & RepoInfo::dumpAsIniOn( std::ostream & str ) const
711 RepoInfoBase::dumpAsIniOn(str);
713 if ( _pimpl->baseurl2dump() )
717 for ( const auto & url : _pimpl->baseUrls().raw() )
719 str << indent << url << endl;
720 if ( indent.empty() ) indent = " "; // "baseurl="
724 if ( ! _pimpl->path.empty() )
725 str << "path="<< path() << endl;
727 if ( ! (rawMirrorListUrl().asString().empty()) )
728 str << "mirrorlist=" << rawMirrorListUrl() << endl;
730 str << "type=" << type().asString() << endl;
732 if ( priority() != defaultPriority() )
733 str << "priority=" << priority() << endl;
735 if ( ! indeterminate(_pimpl->rawGpgCheck()) )
736 str << "gpgcheck=" << (_pimpl->rawGpgCheck() ? "1" : "0") << endl;
738 if ( ! indeterminate(_pimpl->rawRepoGpgCheck()) )
739 str << "repo_gpgcheck=" << (_pimpl->rawRepoGpgCheck() ? "1" : "0") << endl;
741 if ( ! indeterminate(_pimpl->rawPkgGpgCheck()) )
742 str << "pkg_gpgcheck=" << (_pimpl->rawPkgGpgCheck() ? "1" : "0") << endl;
745 std::string indent( "gpgkey=");
746 for ( const auto & url : _pimpl->gpgKeyUrls().raw() )
748 str << indent << url << endl;
749 if ( indent[0] != ' ' )
754 if (!indeterminate(_pimpl->keeppackages))
755 str << "keeppackages=" << keepPackages() << endl;
757 if( ! service().empty() )
758 str << "service=" << service() << endl;
763 std::ostream & RepoInfo::dumpAsXmlOn( std::ostream & str, const std::string & content ) const
768 << " alias=\"" << escape(alias()) << "\""
769 << " name=\"" << escape(name()) << "\"";
770 if (type() != repo::RepoType::NONE)
771 str << " type=\"" << type().asString() << "\"";
773 << " priority=\"" << priority() << "\""
774 << " enabled=\"" << enabled() << "\""
775 << " autorefresh=\"" << autorefresh() << "\""
776 << " gpgcheck=\"" << gpgCheck() << "\""
777 << " repo_gpgcheck=\"" << repoGpgCheck() << "\""
778 << " pkg_gpgcheck=\"" << pkgGpgCheck() << "\"";
779 if (!(tmpstr = gpgKeyUrl().asString()).empty())
780 str << " gpgkey=\"" << escape(tmpstr) << "\"";
781 if (!(tmpstr = mirrorListUrl().asString()).empty())
782 str << " mirrorlist=\"" << escape(tmpstr) << "\"";
785 if ( _pimpl->baseurl2dump() )
787 for_( it, baseUrlsBegin(), baseUrlsEnd() ) // !transform iterator replaces variables
788 str << "<url>" << escape((*it).asString()) << "</url>" << endl;
791 str << "</repo>" << endl;
796 std::ostream & operator<<( std::ostream & str, const RepoInfo & obj )
798 return obj.dumpOn(str);
801 std::ostream & operator<<( std::ostream & str, const RepoInfo::GpgCheck & obj )
803 switch ( obj.asEnum() )
805 #define OUTS( V ) case RepoInfo::V: return str << #V; break
806 OUTS( GpgCheck::On );
807 OUTS( GpgCheck::Strict );
808 OUTS( GpgCheck::AllowUnsigned );
809 OUTS( GpgCheck::AllowUnsignedRepo );
810 OUTS( GpgCheck::AllowUnsignedPackage );
811 OUTS( GpgCheck::Default );
812 OUTS( GpgCheck::Off );
813 OUTS( GpgCheck::indeterminate );
816 return str << "GpgCheck::UNKNOWN";
819 /////////////////////////////////////////////////////////////////
821 ///////////////////////////////////////////////////////////////////