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/Glob.h"
21 #include "zypp/TriBool.h"
22 #include "zypp/Pathname.h"
23 #include "zypp/ZConfig.h"
24 #include "zypp/repo/RepoMirrorList.h"
25 #include "zypp/ExternalProgram.h"
26 #include "zypp/media/MediaAccess.h"
28 #include "zypp/base/IOStream.h"
29 #include "zypp/base/InputStream.h"
30 #include "zypp/parser/xml/Reader.h"
33 using zypp::xml::escape;
35 ///////////////////////////////////////////////////////////////////
37 { /////////////////////////////////////////////////////////////////
39 ///////////////////////////////////////////////////////////////////
41 // CLASS NAME : RepoInfo::Impl
43 /** RepoInfo implementation. */
47 : _rawGpgCheck( indeterminate )
48 , _rawRepoGpgCheck( indeterminate )
49 , _rawPkgGpgCheck( indeterminate )
50 , _validRepoSignature( indeterminate )
51 , keeppackages(indeterminate)
52 , _mirrorListForceMetalink(false)
53 , type(repo::RepoType::NONE_e)
54 , emptybaseurls(false)
61 static const unsigned defaultPriority = 99;
62 static const unsigned noPriority = unsigned(-1);
64 void setProbedType( const repo::RepoType & t ) const
66 if ( type == repo::RepoType::NONE
67 && t != repo::RepoType::NONE )
70 const_cast<Impl*>(this)->type = t;
75 /** Path to a license tarball in case it exists in the repo. */
76 Pathname licenseTgz( const std::string & name_r ) const
79 if ( !metadataPath().empty() )
81 std::string licenseStem( "license" );
82 if ( !name_r.empty() )
85 licenseStem += name_r;
89 // TODO: REPOMD: this assumes we know the name of the tarball. In fact
90 // we'd need to get the file from repomd.xml (<data type="license[-name_r]">)
91 g.add( metadataPath() / path / ("repodata/*"+licenseStem+".tar.gz") );
93 g.add( metadataPath() / path / (licenseStem+".tar.gz") );
101 const RepoVariablesReplacedUrlList & baseUrls() const
103 const Url & mlurl( _mirrorListUrl.transformed() ); // Variables replaced!
104 if ( _baseUrls.empty() && ! mlurl.asString().empty() )
106 emptybaseurls = true;
107 DBG << "MetadataPath: " << metadataPath() << endl;
108 repo::RepoMirrorList rmurls( mlurl, metadataPath(), _mirrorListForceMetalink );
109 _baseUrls.raw().insert( _baseUrls.raw().end(), rmurls.getUrls().begin(), rmurls.getUrls().end() );
114 RepoVariablesReplacedUrlList & baseUrls()
115 { return _baseUrls; }
117 bool baseurl2dump() const
118 { return !emptybaseurls && !_baseUrls.empty(); }
121 const RepoVariablesReplacedUrlList & gpgKeyUrls() const
122 { return _gpgKeyUrls; }
124 RepoVariablesReplacedUrlList & gpgKeyUrls()
125 { return _gpgKeyUrls; }
128 const std::set<std::string> & contentKeywords() const
129 { hasContent()/*init if not yet done*/; return _keywords.second; }
131 void addContent( const std::string & keyword_r )
132 { _keywords.second.insert( keyword_r ); if ( ! hasContent() ) _keywords.first = true; }
134 bool hasContent() const
136 if ( !_keywords.first && ! metadataPath().empty() )
138 // HACK directly check master index file until RepoManager offers
139 // some content probing and zypper uses it.
140 /////////////////////////////////////////////////////////////////
141 MIL << "Empty keywords...." << metadataPath() << endl;
143 if ( PathInfo( (master=metadataPath()/"/repodata/repomd.xml") ).isFile() )
145 //MIL << "GO repomd.." << endl;
146 xml::Reader reader( master );
147 while ( reader.seekToNode( 2, "content" ) )
149 _keywords.second.insert( reader.nodeText().asString() );
150 reader.seekToEndNode( 2, "content" );
152 _keywords.first = true; // valid content in _keywords even if empty
154 else if ( PathInfo( (master=metadataPath()/"/content") ).isFile() )
156 //MIL << "GO content.." << endl;
157 iostr::forEachLine( InputStream( master ),
158 [this]( int num_r, std::string line_r )->bool
160 if ( str::startsWith( line_r, "REPOKEYWORDS" ) )
162 std::vector<std::string> words;
163 if ( str::split( line_r, std::back_inserter(words) ) > 1
164 && words[0].length() == 12 /*"REPOKEYWORDS"*/ )
166 this->_keywords.second.insert( ++words.begin(), words.end() );
168 return true; // mult. occurrances are ok.
170 return( ! str::startsWith( line_r, "META " ) ); // no need to parse into META section.
172 _keywords.first = true; // valid content in _keywords even if empty
174 /////////////////////////////////////////////////////////////////
176 return _keywords.first;
179 bool hasContent( const std::string & keyword_r ) const
180 { return( hasContent() && _keywords.second.find( keyword_r ) != _keywords.second.end() ); }
182 /** Signature check result needs to be stored/retrieved from _metadataPath.
183 * Don't call them from outside validRepoSignature/setValidRepoSignature
186 TriBool internalValidRepoSignature() const
188 if ( ! indeterminate(_validRepoSignature) )
189 return _validRepoSignature;
191 if ( ! metadataPath().empty() )
193 // A missing ".repo_gpgcheck" might be plaindir(no Downloader) or not yet refreshed signed repo!
194 TriBool linkval = triBoolFromPath( metadataPath() / ".repo_gpgcheck" );
197 return indeterminate;
200 void internalSetValidRepoSignature( TriBool value_r )
202 if ( PathInfo(metadataPath()).isDir() )
204 Pathname gpgcheckFile( metadataPath() / ".repo_gpgcheck" );
205 if ( PathInfo(gpgcheckFile).isExist() )
207 TriBool linkval( indeterminate );
208 if ( triBoolFromPath( gpgcheckFile, linkval ) && linkval == value_r )
209 return; // existing symlink fits value_r
211 filesystem::unlink( gpgcheckFile ); // will write a new one
213 filesystem::symlink( asString(value_r), gpgcheckFile );
215 _validRepoSignature = value_r;
218 /** We definitely have a symlink pointing to "indeterminate" (for repoGpgCheckIsMandatory)?
219 * I.e. user accepted the unsigned repo in Downloader. A test whether `internalValidRepoSignature`
220 * is indeterminate would include not yet checked repos, which is unwanted here.
222 bool internalUnsignedConfirmed() const
224 TriBool linkval( true ); // want to see it being switched to indeterminate
225 return triBoolFromPath( metadataPath() / ".repo_gpgcheck", linkval ) && indeterminate(linkval);
228 bool triBoolFromPath( const Pathname & path_r, TriBool & ret_r ) const
230 static const Pathname truePath( "true" );
231 static const Pathname falsePath( "false" );
232 static const Pathname indeterminatePath( "indeterminate" );
235 static const ssize_t bufsiz = 63;
236 static char buf[bufsiz+1];
237 ssize_t ret = ::readlink( path_r.c_str(), buf, bufsiz );
238 buf[ret == -1 ? 0 : ret] = '\0';
240 Pathname linkval( buf );
243 if ( linkval == truePath )
245 else if ( linkval == falsePath )
247 else if ( linkval == indeterminatePath )
248 ret_r = indeterminate;
254 TriBool triBoolFromPath( const Pathname & path_r ) const
255 { TriBool ret(indeterminate); triBoolFromPath( path_r, ret ); return ret; }
260 TriBool _rawGpgCheck; ///< default gpgcheck behavior: Y/N/ZConf
261 TriBool _rawRepoGpgCheck; ///< need to check repo sign.: Y/N/(ZConf(Y/N/gpgCheck))
262 TriBool _rawPkgGpgCheck; ///< need to check pkg sign.: Y/N/(ZConf(Y/N/gpgCheck))
265 TriBool rawGpgCheck() const { return _rawGpgCheck; }
266 TriBool rawRepoGpgCheck() const { return _rawRepoGpgCheck; }
267 TriBool rawPkgGpgCheck() const { return _rawPkgGpgCheck; }
269 void rawGpgCheck( TriBool val_r ) { _rawGpgCheck = val_r; }
270 void rawRepoGpgCheck( TriBool val_r ) { _rawRepoGpgCheck = val_r; }
271 void rawPkgGpgCheck( TriBool val_r ) { _rawPkgGpgCheck = val_r; }
273 bool cfgGpgCheck() const
274 { return indeterminate(_rawGpgCheck) ? ZConfig::instance().gpgCheck() : (bool)_rawGpgCheck; }
275 TriBool cfgRepoGpgCheck() const
276 { return indeterminate(_rawGpgCheck) && indeterminate(_rawRepoGpgCheck) ? ZConfig::instance().repoGpgCheck() : _rawRepoGpgCheck; }
277 TriBool cfgPkgGpgCheck() const
278 { return indeterminate(_rawGpgCheck) && indeterminate(_rawPkgGpgCheck) ? ZConfig::instance().pkgGpgCheck() : _rawPkgGpgCheck; }
281 TriBool _validRepoSignature;///< have signed and valid repo metadata
283 TriBool keeppackages;
284 RepoVariablesReplacedUrl _mirrorListUrl;
285 bool _mirrorListForceMetalink;
289 std::string targetDistro;
291 void metadataPath( Pathname new_r )
292 { _metadataPath = std::move( new_r ); }
294 void packagesPath( Pathname new_r )
295 { _packagesPath = std::move( new_r ); }
297 bool usesAutoMethadataPaths() const
298 { return str::hasSuffix( _metadataPath.asString(), "/%AUTO%" ); }
300 Pathname metadataPath() const
302 if ( usesAutoMethadataPaths() )
303 return _metadataPath.dirname() / "%RAW%";
304 return _metadataPath;
307 Pathname packagesPath() const
309 if ( _packagesPath.empty() && usesAutoMethadataPaths() )
310 return _metadataPath.dirname() / "%PKG%";
311 return _packagesPath;
314 DefaultIntegral<unsigned,defaultPriority> priority;
315 mutable bool emptybaseurls;
318 Pathname _metadataPath;
319 Pathname _packagesPath;
321 mutable RepoVariablesReplacedUrlList _baseUrls;
322 mutable std::pair<FalseBool, std::set<std::string> > _keywords;
324 RepoVariablesReplacedUrlList _gpgKeyUrls;
326 friend Impl * rwcowClone<Impl>( const Impl * rhs );
327 /** clone for RWCOW_pointer */
329 { return new Impl( *this ); }
331 ///////////////////////////////////////////////////////////////////
333 /** \relates RepoInfo::Impl Stream output */
334 inline std::ostream & operator<<( std::ostream & str, const RepoInfo::Impl & obj )
336 return str << "RepoInfo::Impl";
339 ///////////////////////////////////////////////////////////////////
341 // CLASS NAME : RepoInfo
343 ///////////////////////////////////////////////////////////////////
345 const RepoInfo RepoInfo::noRepo;
348 : _pimpl( new Impl() )
351 RepoInfo::~RepoInfo()
354 unsigned RepoInfo::priority() const
355 { return _pimpl->priority; }
357 unsigned RepoInfo::defaultPriority()
358 { return Impl::defaultPriority; }
360 unsigned RepoInfo::noPriority()
361 { return Impl::noPriority; }
363 void RepoInfo::setPriority( unsigned newval_r )
364 { _pimpl->priority = newval_r ? newval_r : Impl::defaultPriority; }
367 bool RepoInfo::gpgCheck() const
368 { return _pimpl->cfgGpgCheck(); }
370 void RepoInfo::setGpgCheck( TriBool value_r )
371 { _pimpl->rawGpgCheck( value_r ); }
373 void RepoInfo::setGpgCheck( bool value_r ) // deprecated legacy and for squid
374 { setGpgCheck( TriBool(value_r) ); }
377 bool RepoInfo::repoGpgCheck() const
378 { return gpgCheck() || _pimpl->cfgRepoGpgCheck(); }
380 bool RepoInfo::repoGpgCheckIsMandatory() const
382 bool ret = ( gpgCheck() && indeterminate(_pimpl->cfgRepoGpgCheck()) ) || _pimpl->cfgRepoGpgCheck();
383 if ( ret && _pimpl->internalUnsignedConfirmed() ) // relax if unsigned repo was confirmed in the past
388 void RepoInfo::setRepoGpgCheck( TriBool value_r )
389 { _pimpl->rawRepoGpgCheck( value_r ); }
392 bool RepoInfo::pkgGpgCheck() const
393 { return _pimpl->cfgPkgGpgCheck() || ( gpgCheck() && !bool(validRepoSignature())/*enforced*/ ) ; }
395 bool RepoInfo::pkgGpgCheckIsMandatory() const
396 { return _pimpl->cfgPkgGpgCheck() || ( gpgCheck() && indeterminate(_pimpl->cfgPkgGpgCheck()) && !bool(validRepoSignature())/*enforced*/ ); }
398 void RepoInfo::setPkgGpgCheck( TriBool value_r )
399 { _pimpl->rawPkgGpgCheck( value_r ); }
402 void RepoInfo::getRawGpgChecks( TriBool & g_r, TriBool & r_r, TriBool & p_r ) const
404 g_r = _pimpl->rawGpgCheck();
405 r_r = _pimpl->rawRepoGpgCheck();
406 p_r = _pimpl->rawPkgGpgCheck();
410 TriBool RepoInfo::validRepoSignature() const
412 TriBool ret( _pimpl->internalValidRepoSignature() );
413 if ( ret && !repoGpgCheck() ) ret = false; // invalidate any old signature if repoGpgCheck is off
417 void RepoInfo::setValidRepoSignature( TriBool value_r )
418 { _pimpl->internalSetValidRepoSignature( value_r ); }
420 ///////////////////////////////////////////////////////////////////
423 inline bool changeGpgCheckTo( TriBool & lhs, TriBool rhs )
424 { if ( ! sameTriboolState( lhs, rhs ) ) { lhs = rhs; return true; } return false; }
426 inline bool changeGpgCheckTo( TriBool ogpg[3], TriBool g, TriBool r, TriBool p )
428 bool changed = false;
429 if ( changeGpgCheckTo( ogpg[0], g ) ) changed = true;
430 if ( changeGpgCheckTo( ogpg[1], r ) ) changed = true;
431 if ( changeGpgCheckTo( ogpg[2], p ) ) changed = true;
435 ///////////////////////////////////////////////////////////////////
436 bool RepoInfo::setGpgCheck( GpgCheck mode_r )
438 TriBool ogpg[3]; // Gpg RepoGpg PkgGpg
439 getRawGpgChecks( ogpg[0], ogpg[1], ogpg[2] );
441 bool changed = false;
445 changed = changeGpgCheckTo( ogpg, true, indeterminate, indeterminate );
447 case GpgCheck::Strict:
448 changed = changeGpgCheckTo( ogpg, true, true, true );
450 case GpgCheck::AllowUnsigned:
451 changed = changeGpgCheckTo( ogpg, true, false, false );
453 case GpgCheck::AllowUnsignedRepo:
454 changed = changeGpgCheckTo( ogpg, true, false, indeterminate );
456 case GpgCheck::AllowUnsignedPackage:
457 changed = changeGpgCheckTo( ogpg, true, indeterminate, false );
459 case GpgCheck::Default:
460 changed = changeGpgCheckTo( ogpg, indeterminate, indeterminate, indeterminate );
463 changed = changeGpgCheckTo( ogpg, false, indeterminate, indeterminate );
465 case GpgCheck::indeterminate: // no change
471 setGpgCheck ( ogpg[0] );
472 setRepoGpgCheck( ogpg[1] );
473 setPkgGpgCheck ( ogpg[2] );
478 void RepoInfo::setMirrorListUrl( const Url & url_r ) // Raw
479 { _pimpl->_mirrorListUrl.raw() = url_r; _pimpl->_mirrorListForceMetalink = false; }
481 void RepoInfo::setMetalinkUrl( const Url & url_r ) // Raw
482 { _pimpl->_mirrorListUrl.raw() = url_r; _pimpl->_mirrorListForceMetalink = true; }
484 void RepoInfo::setGpgKeyUrls( url_set urls )
485 { _pimpl->gpgKeyUrls().raw().swap( urls ); }
487 void RepoInfo::setGpgKeyUrl( const Url & url_r )
489 _pimpl->gpgKeyUrls().raw().clear();
490 _pimpl->gpgKeyUrls().raw().push_back( url_r );
493 void RepoInfo::addBaseUrl( const Url & url_r )
495 for ( const auto & url : _pimpl->baseUrls().raw() ) // Raw unique!
498 _pimpl->baseUrls().raw().push_back( url_r );
501 void RepoInfo::setBaseUrl( const Url & url_r )
503 _pimpl->baseUrls().raw().clear();
504 _pimpl->baseUrls().raw().push_back( url_r );
507 void RepoInfo::setBaseUrls( url_set urls )
508 { _pimpl->baseUrls().raw().swap( urls ); }
510 void RepoInfo::setPath( const Pathname &path )
511 { _pimpl->path = path; }
513 void RepoInfo::setType( const repo::RepoType &t )
514 { _pimpl->type = t; }
516 void RepoInfo::setProbedType( const repo::RepoType &t ) const
517 { _pimpl->setProbedType( t ); }
520 void RepoInfo::setMetadataPath( const Pathname &path )
521 { _pimpl->metadataPath( path ); }
523 void RepoInfo::setPackagesPath( const Pathname &path )
524 { _pimpl->packagesPath( path ); }
526 void RepoInfo::setKeepPackages( bool keep )
527 { _pimpl->keeppackages = keep; }
529 void RepoInfo::setService( const std::string& name )
530 { _pimpl->service = name; }
532 void RepoInfo::setTargetDistribution( const std::string & targetDistribution )
533 { _pimpl->targetDistro = targetDistribution; }
535 bool RepoInfo::keepPackages() const
536 { return indeterminate(_pimpl->keeppackages) ? false : (bool)_pimpl->keeppackages; }
538 Pathname RepoInfo::metadataPath() const
539 { return _pimpl->metadataPath(); }
541 Pathname RepoInfo::packagesPath() const
542 { return _pimpl->packagesPath(); }
544 bool RepoInfo::usesAutoMethadataPaths() const
545 { return _pimpl->usesAutoMethadataPaths(); }
547 repo::RepoType RepoInfo::type() const
548 { return _pimpl->type; }
550 Url RepoInfo::mirrorListUrl() const // Variables replaced!
551 { return _pimpl->_mirrorListUrl.transformed(); }
553 Url RepoInfo::rawMirrorListUrl() const // Raw
554 { return _pimpl->_mirrorListUrl.raw(); }
556 bool RepoInfo::gpgKeyUrlsEmpty() const
557 { return _pimpl->gpgKeyUrls().empty(); }
559 RepoInfo::urls_size_type RepoInfo::gpgKeyUrlsSize() const
560 { return _pimpl->gpgKeyUrls().size(); }
562 RepoInfo::url_set RepoInfo::gpgKeyUrls() const // Variables replaced!
563 { return _pimpl->gpgKeyUrls().transformed(); }
565 RepoInfo::url_set RepoInfo::rawGpgKeyUrls() const // Raw
566 { return _pimpl->gpgKeyUrls().raw(); }
568 Url RepoInfo::gpgKeyUrl() const // Variables replaced!
569 { return( _pimpl->gpgKeyUrls().empty() ? Url() : *_pimpl->gpgKeyUrls().transformedBegin() ); }
571 Url RepoInfo::rawGpgKeyUrl() const // Raw
572 { return( _pimpl->gpgKeyUrls().empty() ? Url() : *_pimpl->gpgKeyUrls().rawBegin() ) ; }
574 RepoInfo::url_set RepoInfo::baseUrls() const // Variables replaced!
575 { return _pimpl->baseUrls().transformed(); }
577 RepoInfo::url_set RepoInfo::rawBaseUrls() const // Raw
578 { return _pimpl->baseUrls().raw(); }
580 Pathname RepoInfo::path() const
581 { return _pimpl->path; }
583 std::string RepoInfo::service() const
584 { return _pimpl->service; }
586 std::string RepoInfo::targetDistribution() const
587 { return _pimpl->targetDistro; }
589 Url RepoInfo::rawUrl() const
590 { return( _pimpl->baseUrls().empty() ? Url() : *_pimpl->baseUrls().rawBegin() ); }
592 RepoInfo::urls_const_iterator RepoInfo::baseUrlsBegin() const
593 { return _pimpl->baseUrls().transformedBegin(); }
595 RepoInfo::urls_const_iterator RepoInfo::baseUrlsEnd() const
596 { return _pimpl->baseUrls().transformedEnd(); }
598 RepoInfo::urls_size_type RepoInfo::baseUrlsSize() const
599 { return _pimpl->baseUrls().size(); }
601 bool RepoInfo::baseUrlsEmpty() const
602 { return _pimpl->baseUrls().empty(); }
604 bool RepoInfo::baseUrlSet() const
605 { return _pimpl->baseurl2dump(); }
607 const std::set<std::string> & RepoInfo::contentKeywords() const
608 { return _pimpl->contentKeywords(); }
610 void RepoInfo::addContent( const std::string & keyword_r )
611 { _pimpl->addContent( keyword_r ); }
613 bool RepoInfo::hasContent() const
614 { return _pimpl->hasContent(); }
616 bool RepoInfo::hasContent( const std::string & keyword_r ) const
617 { return _pimpl->hasContent( keyword_r ); }
619 ///////////////////////////////////////////////////////////////////
621 bool RepoInfo::hasLicense() const
622 { return hasLicense( std::string() ); }
624 bool RepoInfo::hasLicense( const std::string & name_r ) const
625 { return !_pimpl->licenseTgz( name_r ).empty(); }
628 bool RepoInfo::needToAcceptLicense() const
629 { return needToAcceptLicense( std::string() ); }
631 bool RepoInfo::needToAcceptLicense( const std::string & name_r ) const
633 const Pathname & licenseTgz( _pimpl->licenseTgz( name_r ) );
634 if ( licenseTgz.empty() )
635 return false; // no licenses at all
637 ExternalProgram::Arguments cmd;
638 cmd.push_back( "tar" );
639 cmd.push_back( "-t" );
640 cmd.push_back( "-z" );
641 cmd.push_back( "-f" );
642 cmd.push_back( licenseTgz.asString() );
643 ExternalProgram prog( cmd, ExternalProgram::Stderr_To_Stdout );
646 static const std::string noAcceptanceFile = "no-acceptance-needed\n";
647 for ( std::string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() )
649 if ( output == noAcceptanceFile )
654 MIL << "License(" << name_r << ") in " << name() << " has to be accepted: " << (accept?"true":"false" ) << endl;
659 std::string RepoInfo::getLicense( const Locale & lang_r )
660 { return const_cast<const RepoInfo *>(this)->getLicense( std::string(), lang_r ); }
662 std::string RepoInfo::getLicense( const Locale & lang_r ) const
663 { return getLicense( std::string(), lang_r ); }
665 std::string RepoInfo::getLicense( const std::string & name_r, const Locale & lang_r ) const
667 LocaleSet avlocales( getLicenseLocales( name_r ) );
668 if ( avlocales.empty() )
669 return std::string();
671 Locale getLang( Locale::bestMatch( avlocales, lang_r ) );
672 if ( !getLang && avlocales.find( Locale::noCode ) == avlocales.end() )
674 WAR << "License(" << name_r << ") in " << name() << " contains no fallback text!" << endl;
675 // Using the fist locale instead of returning no text at all.
676 // So the user might recognize that there is a license, even if he
678 getLang = *avlocales.begin();
681 // now extract the license file.
682 static const std::string licenseFileFallback( "license.txt" );
683 std::string licenseFile( !getLang ? licenseFileFallback
684 : str::form( "license.%s.txt", getLang.c_str() ) );
686 ExternalProgram::Arguments cmd;
687 cmd.push_back( "tar" );
688 cmd.push_back( "-x" );
689 cmd.push_back( "-z" );
690 cmd.push_back( "-O" );
691 cmd.push_back( "-f" );
692 cmd.push_back( _pimpl->licenseTgz( name_r ).asString() ); // if it not exists, avlocales was empty.
693 cmd.push_back( licenseFile );
696 ExternalProgram prog( cmd, ExternalProgram::Discard_Stderr );
697 for ( std::string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() )
706 LocaleSet RepoInfo::getLicenseLocales() const
707 { return getLicenseLocales( std::string() ); }
709 LocaleSet RepoInfo::getLicenseLocales( const std::string & name_r ) const
711 const Pathname & licenseTgz( _pimpl->licenseTgz( name_r ) );
712 if ( licenseTgz.empty() )
715 ExternalProgram::Arguments cmd;
716 cmd.push_back( "tar" );
717 cmd.push_back( "-t" );
718 cmd.push_back( "-z" );
719 cmd.push_back( "-f" );
720 cmd.push_back( licenseTgz.asString() );
723 ExternalProgram prog( cmd, ExternalProgram::Stderr_To_Stdout );
724 for ( std::string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() )
726 static const C_Str license( "license." );
727 static const C_Str dotTxt( ".txt\n" );
728 if ( str::hasPrefix( output, license ) && str::hasSuffix( output, dotTxt ) )
730 if ( output.size() <= license.size() + dotTxt.size() ) // license.txt
731 ret.insert( Locale() );
733 ret.insert( Locale( std::string( output.c_str()+license.size(), output.size()- license.size() - dotTxt.size() ) ) );
740 ///////////////////////////////////////////////////////////////////
742 std::ostream & RepoInfo::dumpOn( std::ostream & str ) const
744 RepoInfoBase::dumpOn(str);
745 if ( _pimpl->baseurl2dump() )
747 for ( const auto & url : _pimpl->baseUrls().raw() )
749 str << "- url : " << url << std::endl;
753 // print if non empty value
754 auto strif( [&] ( const std::string & tag_r, const std::string & value_r ) {
755 if ( ! value_r.empty() )
756 str << tag_r << value_r << std::endl;
759 strif( (_pimpl->_mirrorListForceMetalink ? "- metalink : " : "- mirrorlist : "), rawMirrorListUrl().asString() );
760 strif( "- path : ", path().asString() );
761 str << "- type : " << type() << std::endl;
762 str << "- priority : " << priority() << std::endl;
764 // Yes No Default(Y) Default(N)
765 #define OUTS(T,B) ( indeterminate(T) ? (std::string("D(")+(B?"Y":"N")+")") : ((bool)T?"Y":"N") )
766 str << "- gpgcheck : " << OUTS(_pimpl->rawGpgCheck(),gpgCheck())
767 << " repo" << OUTS(_pimpl->rawRepoGpgCheck(),repoGpgCheck()) << (repoGpgCheckIsMandatory() ? "* ": " " )
768 << "sig" << asString( validRepoSignature(), "?", "Y", "N" )
769 << " pkg" << OUTS(_pimpl->rawPkgGpgCheck(),pkgGpgCheck()) << (pkgGpgCheckIsMandatory() ? "* ": " " )
773 for ( const auto & url : _pimpl->gpgKeyUrls().raw() )
775 str << "- gpgkey : " << url << std::endl;
778 if ( ! indeterminate(_pimpl->keeppackages) )
779 str << "- keeppackages: " << keepPackages() << std::endl;
781 strif( "- service : ", service() );
782 strif( "- targetdistro: ", targetDistribution() );
783 strif( "- filePath: ", filepath().asString() );
784 strif( "- metadataPath: ", metadataPath().asString() );
785 strif( "- packagesPath: ", packagesPath().asString() );
790 std::ostream & RepoInfo::dumpAsIniOn( std::ostream & str ) const
792 RepoInfoBase::dumpAsIniOn(str);
794 if ( _pimpl->baseurl2dump() )
798 for ( const auto & url : _pimpl->baseUrls().raw() )
800 str << indent << url << endl;
801 if ( indent.empty() ) indent = " "; // "baseurl="
805 if ( ! _pimpl->path.empty() )
806 str << "path="<< path() << endl;
808 if ( ! (rawMirrorListUrl().asString().empty()) )
809 str << (_pimpl->_mirrorListForceMetalink ? "metalink=" : "mirrorlist=") << rawMirrorListUrl() << endl;
811 str << "type=" << type().asString() << endl;
813 if ( priority() != defaultPriority() )
814 str << "priority=" << priority() << endl;
816 if ( ! indeterminate(_pimpl->rawGpgCheck()) )
817 str << "gpgcheck=" << (_pimpl->rawGpgCheck() ? "1" : "0") << endl;
819 if ( ! indeterminate(_pimpl->rawRepoGpgCheck()) )
820 str << "repo_gpgcheck=" << (_pimpl->rawRepoGpgCheck() ? "1" : "0") << endl;
822 if ( ! indeterminate(_pimpl->rawPkgGpgCheck()) )
823 str << "pkg_gpgcheck=" << (_pimpl->rawPkgGpgCheck() ? "1" : "0") << endl;
826 std::string indent( "gpgkey=");
827 for ( const auto & url : _pimpl->gpgKeyUrls().raw() )
829 str << indent << url << endl;
830 if ( indent[0] != ' ' )
835 if (!indeterminate(_pimpl->keeppackages))
836 str << "keeppackages=" << keepPackages() << endl;
838 if( ! service().empty() )
839 str << "service=" << service() << endl;
844 std::ostream & RepoInfo::dumpAsXmlOn( std::ostream & str, const std::string & content ) const
849 << " alias=\"" << escape(alias()) << "\""
850 << " name=\"" << escape(name()) << "\"";
851 if (type() != repo::RepoType::NONE)
852 str << " type=\"" << type().asString() << "\"";
854 << " priority=\"" << priority() << "\""
855 << " enabled=\"" << enabled() << "\""
856 << " autorefresh=\"" << autorefresh() << "\""
857 << " gpgcheck=\"" << gpgCheck() << "\""
858 << " repo_gpgcheck=\"" << repoGpgCheck() << "\""
859 << " pkg_gpgcheck=\"" << pkgGpgCheck() << "\"";
860 if (!(tmpstr = gpgKeyUrl().asString()).empty())
861 str << " gpgkey=\"" << escape(tmpstr) << "\"";
862 if (!(tmpstr = mirrorListUrl().asString()).empty())
863 str << (_pimpl->_mirrorListForceMetalink ? " metalink=\"" : " mirrorlist=\"") << escape(tmpstr) << "\"";
866 if ( _pimpl->baseurl2dump() )
868 for_( it, baseUrlsBegin(), baseUrlsEnd() ) // !transform iterator replaces variables
869 str << "<url>" << escape((*it).asString()) << "</url>" << endl;
872 str << "</repo>" << endl;
877 std::ostream & operator<<( std::ostream & str, const RepoInfo & obj )
879 return obj.dumpOn(str);
882 std::ostream & operator<<( std::ostream & str, const RepoInfo::GpgCheck & obj )
886 #define OUTS( V ) case RepoInfo::V: return str << #V; break
887 OUTS( GpgCheck::On );
888 OUTS( GpgCheck::Strict );
889 OUTS( GpgCheck::AllowUnsigned );
890 OUTS( GpgCheck::AllowUnsignedRepo );
891 OUTS( GpgCheck::AllowUnsignedPackage );
892 OUTS( GpgCheck::Default );
893 OUTS( GpgCheck::Off );
894 OUTS( GpgCheck::indeterminate );
897 return str << "GpgCheck::UNKNOWN";
900 /////////////////////////////////////////////////////////////////
902 ///////////////////////////////////////////////////////////////////