libzypp  15.28.6
RepoInfo.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <iostream>
13 #include <vector>
14 
15 #include "zypp/base/LogTools.h"
18 
19 #include "zypp/RepoInfo.h"
20 #include "zypp/TriBool.h"
21 #include "zypp/Pathname.h"
22 #include "zypp/ZConfig.h"
24 #include "zypp/ExternalProgram.h"
25 #include "zypp/media/MediaAccess.h"
26 
27 #include "zypp/base/IOStream.h"
28 #include "zypp/base/InputStream.h"
29 #include "zypp/parser/xml/Reader.h"
30 
31 using std::endl;
32 using zypp::xml::escape;
33 
35 namespace zypp
36 {
37 
39  //
40  // CLASS NAME : RepoInfo::Impl
41  //
44  {
45  Impl()
46  : _rawGpgCheck( indeterminate )
47  , _rawRepoGpgCheck( indeterminate )
48  , _rawPkgGpgCheck( indeterminate )
49  , _validRepoSignature( indeterminate )
50  , keeppackages(indeterminate)
52  , type(repo::RepoType::NONE_e)
53  , emptybaseurls(false)
54  {}
55 
57  {}
58 
59  public:
60  static const unsigned defaultPriority = 99;
61  static const unsigned noPriority = unsigned(-1);
62 
63  void setProbedType( const repo::RepoType & t ) const
64  {
66  && t != repo::RepoType::NONE )
67  {
68  // lazy init!
69  const_cast<Impl*>(this)->type = t;
70  }
71  }
72 
73  public:
74  Pathname licenseTgz() const
75  { return metadatapath.empty() ? Pathname() : metadatapath / path / "license.tar.gz"; }
76 
78  {
79  const Url & mlurl( _mirrorListUrl.transformed() ); // Variables replaced!
80  if ( _baseUrls.empty() && ! mlurl.asString().empty() )
81  {
82  emptybaseurls = true;
83  DBG << "MetadataPath: " << metadatapath << endl;
85  _baseUrls.raw().insert( _baseUrls.raw().end(), rmurls.getUrls().begin(), rmurls.getUrls().end() );
86  }
87  return _baseUrls;
88  }
89 
91  { return _baseUrls; }
92 
93  bool baseurl2dump() const
94  { return !emptybaseurls && !_baseUrls.empty(); }
95 
96 
98  { return _gpgKeyUrls; }
99 
101  { return _gpgKeyUrls; }
102 
103 
104  const std::set<std::string> & contentKeywords() const
105  { hasContent()/*init if not yet done*/; return _keywords.second; }
106 
107  void addContent( const std::string & keyword_r )
108  { _keywords.second.insert( keyword_r ); if ( ! hasContent() ) _keywords.first = true; }
109 
110  bool hasContent() const
111  {
112  if ( !_keywords.first && ! metadatapath.empty() )
113  {
114  // HACK directly check master index file until RepoManager offers
115  // some content probing and zypper uses it.
117  MIL << "Empty keywords...." << metadatapath << endl;
118  Pathname master;
119  if ( PathInfo( (master=metadatapath/"/repodata/repomd.xml") ).isFile() )
120  {
121  //MIL << "GO repomd.." << endl;
122  xml::Reader reader( master );
123  while ( reader.seekToNode( 2, "content" ) )
124  {
125  _keywords.second.insert( reader.nodeText().asString() );
126  reader.seekToEndNode( 2, "content" );
127  }
128  _keywords.first = true; // valid content in _keywords even if empty
129  }
130  else if ( PathInfo( (master=metadatapath/"/content") ).isFile() )
131  {
132  //MIL << "GO content.." << endl;
133  iostr::forEachLine( InputStream( master ),
134  [this]( int num_r, std::string line_r )->bool
135  {
136  if ( str::startsWith( line_r, "REPOKEYWORDS" ) )
137  {
138  std::vector<std::string> words;
139  if ( str::split( line_r, std::back_inserter(words) ) > 1
140  && words[0].length() == 12 /*"REPOKEYWORDS"*/ )
141  {
142  this->_keywords.second.insert( ++words.begin(), words.end() );
143  }
144  return true; // mult. occurrances are ok.
145  }
146  return( ! str::startsWith( line_r, "META " ) ); // no need to parse into META section.
147  } );
148  _keywords.first = true; // valid content in _keywords even if empty
149  }
151  }
152  return _keywords.first;
153  }
154 
155  bool hasContent( const std::string & keyword_r ) const
156  { return( hasContent() && _keywords.second.find( keyword_r ) != _keywords.second.end() ); }
157 
163  {
164  if ( ! indeterminate(_validRepoSignature) )
165  return _validRepoSignature;
166  // check metadata:
167  if ( ! metadatapath.empty() )
168  {
169  // A missing ".repo_gpgcheck" might be plaindir(no Downloader) or not yet refreshed signed repo!
170  TriBool linkval = triBoolFromPath( metadatapath / ".repo_gpgcheck" );
171  return linkval;
172  }
173  return indeterminate;
174  }
175 
177  {
178  if ( PathInfo(metadatapath).isDir() )
179  {
180  Pathname gpgcheckFile( metadatapath / ".repo_gpgcheck" );
181  if ( PathInfo(gpgcheckFile).isExist() )
182  {
183  TriBool linkval( indeterminate );
184  if ( triBoolFromPath( gpgcheckFile, linkval ) && linkval == value_r )
185  return; // existing symlink fits value_r
186  else
187  filesystem::unlink( gpgcheckFile ); // will write a new one
188  }
189  filesystem::symlink( asString(value_r), gpgcheckFile );
190  }
191  _validRepoSignature = value_r;
192  }
193 
199  {
200  TriBool linkval( true ); // want to see it being switched to indeterminate
201  return triBoolFromPath( metadatapath / ".repo_gpgcheck", linkval ) && indeterminate(linkval);
202  }
203 
204  bool triBoolFromPath( const Pathname & path_r, TriBool & ret_r ) const
205  {
206  static const Pathname truePath( "true" );
207  static const Pathname falsePath( "false" );
208  static const Pathname indeterminatePath( "indeterminate" );
209 
210  // Quiet readlink;
211  static const ssize_t bufsiz = 63;
212  static char buf[bufsiz+1];
213  ssize_t ret = ::readlink( path_r.c_str(), buf, bufsiz );
214  buf[ret == -1 ? 0 : ret] = '\0';
215 
216  Pathname linkval( buf );
217 
218  bool known = true;
219  if ( linkval == truePath )
220  ret_r = true;
221  else if ( linkval == falsePath )
222  ret_r = false;
223  else if ( linkval == indeterminatePath )
224  ret_r = indeterminate;
225  else
226  known = false;
227  return known;
228  }
229 
230  TriBool triBoolFromPath( const Pathname & path_r ) const
231  { TriBool ret(indeterminate); triBoolFromPath( path_r, ret ); return ret; }
232 
234 
235  private:
239 
240  public:
241  TriBool rawGpgCheck() const { return _rawGpgCheck; }
244 
245  void rawGpgCheck( TriBool val_r ) { _rawGpgCheck = val_r; }
246  void rawRepoGpgCheck( TriBool val_r ) { _rawRepoGpgCheck = val_r; }
247  void rawPkgGpgCheck( TriBool val_r ) { _rawPkgGpgCheck = val_r; }
248 
249  bool cfgGpgCheck() const
250  { return indeterminate(_rawGpgCheck) ? ZConfig::instance().gpgCheck() : (bool)_rawGpgCheck; }
252  { return indeterminate(_rawGpgCheck) && indeterminate(_rawRepoGpgCheck) ? ZConfig::instance().repoGpgCheck() : _rawRepoGpgCheck; }
254  { return indeterminate(_rawGpgCheck) && indeterminate(_rawPkgGpgCheck) ? ZConfig::instance().pkgGpgCheck() : _rawPkgGpgCheck; }
255 
256  private:
258  public:
263  Pathname path;
264  std::string service;
265  std::string targetDistro;
266  Pathname metadatapath;
267  Pathname packagespath;
269  mutable bool emptybaseurls;
271 
272  private:
274  mutable std::pair<FalseBool, std::set<std::string> > _keywords;
275 
277 
278  friend Impl * rwcowClone<Impl>( const Impl * rhs );
280  Impl * clone() const
281  { return new Impl( *this ); }
282  };
284 
286  inline std::ostream & operator<<( std::ostream & str, const RepoInfo::Impl & obj )
287  {
288  return str << "RepoInfo::Impl";
289  }
290 
292  //
293  // CLASS NAME : RepoInfo
294  //
296 
298 
300  : _pimpl( new Impl() )
301  {}
302 
304  {}
305 
306  unsigned RepoInfo::priority() const
307  { return _pimpl->priority; }
308 
310  { return Impl::defaultPriority; }
311 
313  { return Impl::noPriority; }
314 
315  void RepoInfo::setPriority( unsigned newval_r )
316  { _pimpl->priority = newval_r ? newval_r : Impl::defaultPriority; }
317 
318 
319  bool RepoInfo::gpgCheck() const
320  { return _pimpl->cfgGpgCheck(); }
321 
323  { _pimpl->rawGpgCheck( value_r ); }
324 
325  void RepoInfo::setGpgCheck( bool value_r ) // deprecated legacy and for squid
326  { setGpgCheck( TriBool(value_r) ); }
327 
328 
330  { return gpgCheck() || _pimpl->cfgRepoGpgCheck(); }
331 
333  {
334  bool ret = ( gpgCheck() && indeterminate(_pimpl->cfgRepoGpgCheck()) ) || _pimpl->cfgRepoGpgCheck();
335  if ( ret && _pimpl->internalUnsignedConfirmed() ) // relax if unsigned repo was confirmed in the past
336  ret = false;
337  return ret;
338  }
339 
341  { _pimpl->rawRepoGpgCheck( value_r ); }
342 
343 
345  { return _pimpl->cfgPkgGpgCheck() || ( gpgCheck() && !bool(validRepoSignature())/*enforced*/ ) ; }
346 
348  { return _pimpl->cfgPkgGpgCheck() || ( gpgCheck() && indeterminate(_pimpl->cfgPkgGpgCheck()) && !bool(validRepoSignature())/*enforced*/ ); }
349 
351  { _pimpl->rawPkgGpgCheck( value_r ); }
352 
353 
354  void RepoInfo::getRawGpgChecks( TriBool & g_r, TriBool & r_r, TriBool & p_r ) const
355  {
356  g_r = _pimpl->rawGpgCheck();
357  r_r = _pimpl->rawRepoGpgCheck();
358  p_r = _pimpl->rawPkgGpgCheck();
359  }
360 
361 
363  {
365  if ( ret && !repoGpgCheck() ) ret = false; // invalidate any old signature if repoGpgCheck is off
366  return ret;
367  }
368 
370  { _pimpl->internalSetValidRepoSignature( value_r ); }
371 
373  namespace
374  {
375  inline bool changeGpgCheckTo( TriBool & lhs, TriBool rhs )
376  { if ( ! sameTriboolState( lhs, rhs ) ) { lhs = rhs; return true; } return false; }
377 
378  inline bool changeGpgCheckTo( TriBool ogpg[3], TriBool g, TriBool r, TriBool p )
379  {
380  bool changed = false;
381  if ( changeGpgCheckTo( ogpg[0], g ) ) changed = true;
382  if ( changeGpgCheckTo( ogpg[1], r ) ) changed = true;
383  if ( changeGpgCheckTo( ogpg[2], p ) ) changed = true;
384  return changed;
385  }
386  } // namespace
389  {
390  TriBool ogpg[3]; // Gpg RepoGpg PkgGpg
391  getRawGpgChecks( ogpg[0], ogpg[1], ogpg[2] );
392 
393  bool changed = false;
394  switch ( mode_r.asEnum() )
395  {
396  case GpgCheck::On:
397  changed = changeGpgCheckTo( ogpg, true, indeterminate, indeterminate );
398  break;
399  case GpgCheck::Strict:
400  changed = changeGpgCheckTo( ogpg, true, true, true );
401  break;
402  case GpgCheck::AllowUnsigned:
403  changed = changeGpgCheckTo( ogpg, true, false, false );
404  break;
405  case GpgCheck::AllowUnsignedRepo:
406  changed = changeGpgCheckTo( ogpg, true, false, indeterminate );
407  break;
408  case GpgCheck::AllowUnsignedPackage:
409  changed = changeGpgCheckTo( ogpg, true, indeterminate, false );
410  break;
411  case GpgCheck::Default:
412  changed = changeGpgCheckTo( ogpg, indeterminate, indeterminate, indeterminate );
413  break;
414  case GpgCheck::Off:
415  changed = changeGpgCheckTo( ogpg, false, indeterminate, indeterminate );
416  break;
417  case GpgCheck::indeterminate: // no change
418  break;
419  }
420 
421  if ( changed )
422  {
423  setGpgCheck ( ogpg[0] );
424  setRepoGpgCheck( ogpg[1] );
425  setPkgGpgCheck ( ogpg[2] );
426  }
427  return changed;
428  }
429 
430  void RepoInfo::setMirrorListUrl( const Url & url_r ) // Raw
431  { _pimpl->_mirrorListUrl.raw() = url_r; _pimpl->_mirrorListForceMetalink = false; }
432 
433  void RepoInfo::setMetalinkUrl( const Url & url_r ) // Raw
434  { _pimpl->_mirrorListUrl.raw() = url_r; _pimpl->_mirrorListForceMetalink = true; }
435 
437  { _pimpl->gpgKeyUrls().raw().swap( urls ); }
438 
439  void RepoInfo::setGpgKeyUrl( const Url & url_r )
440  {
441  _pimpl->gpgKeyUrls().raw().clear();
442  _pimpl->gpgKeyUrls().raw().push_back( url_r );
443  }
444 
445  void RepoInfo::addBaseUrl( const Url & url_r )
446  {
447  for ( const auto & url : _pimpl->baseUrls().raw() ) // Raw unique!
448  if ( url == url_r )
449  return;
450  _pimpl->baseUrls().raw().push_back( url_r );
451  }
452 
453  void RepoInfo::setBaseUrl( const Url & url_r )
454  {
455  _pimpl->baseUrls().raw().clear();
456  _pimpl->baseUrls().raw().push_back( url_r );
457  }
458 
460  { _pimpl->baseUrls().raw().swap( urls ); }
461 
462  void RepoInfo::setPath( const Pathname &path )
463  { _pimpl->path = path; }
464 
466  { _pimpl->type = t; }
467 
469  { _pimpl->setProbedType( t ); }
470 
471 
472  void RepoInfo::setMetadataPath( const Pathname &path )
473  { _pimpl->metadatapath = path; }
474 
475  void RepoInfo::setPackagesPath( const Pathname &path )
476  { _pimpl->packagespath = path; }
477 
478  void RepoInfo::setKeepPackages( bool keep )
479  { _pimpl->keeppackages = keep; }
480 
481  void RepoInfo::setService( const std::string& name )
482  { _pimpl->service = name; }
483 
484  void RepoInfo::setTargetDistribution( const std::string & targetDistribution )
486 
488  { return indeterminate(_pimpl->keeppackages) ? false : (bool)_pimpl->keeppackages; }
489 
490  Pathname RepoInfo::metadataPath() const
491  { return _pimpl->metadatapath; }
492 
493  Pathname RepoInfo::packagesPath() const
494  { return _pimpl->packagespath; }
495 
497  { return _pimpl->type; }
498 
499  Url RepoInfo::mirrorListUrl() const // Variables replaced!
500  { return _pimpl->_mirrorListUrl.transformed(); }
501 
503  { return _pimpl->_mirrorListUrl.raw(); }
504 
506  { return _pimpl->gpgKeyUrls().empty(); }
507 
509  { return _pimpl->gpgKeyUrls().size(); }
510 
511  RepoInfo::url_set RepoInfo::gpgKeyUrls() const // Variables replaced!
512  { return _pimpl->gpgKeyUrls().transformed(); }
513 
515  { return _pimpl->gpgKeyUrls().raw(); }
516 
517  Url RepoInfo::gpgKeyUrl() const // Variables replaced!
518  { return( _pimpl->gpgKeyUrls().empty() ? Url() : *_pimpl->gpgKeyUrls().transformedBegin() ); }
519 
521  { return( _pimpl->gpgKeyUrls().empty() ? Url() : *_pimpl->gpgKeyUrls().rawBegin() ) ; }
522 
523  RepoInfo::url_set RepoInfo::baseUrls() const // Variables replaced!
524  { return _pimpl->baseUrls().transformed(); }
525 
527  { return _pimpl->baseUrls().raw(); }
528 
529  Pathname RepoInfo::path() const
530  { return _pimpl->path; }
531 
532  std::string RepoInfo::service() const
533  { return _pimpl->service; }
534 
535  std::string RepoInfo::targetDistribution() const
536  { return _pimpl->targetDistro; }
537 
539  { return( _pimpl->baseUrls().empty() ? Url() : *_pimpl->baseUrls().rawBegin() ); }
540 
542  { return _pimpl->baseUrls().transformedBegin(); }
543 
545  { return _pimpl->baseUrls().transformedEnd(); }
546 
548  { return _pimpl->baseUrls().size(); }
549 
551  { return _pimpl->baseUrls().empty(); }
552 
553  bool RepoInfo::baseUrlSet() const
554  { return _pimpl->baseurl2dump(); }
555 
556  const std::set<std::string> & RepoInfo::contentKeywords() const
557  { return _pimpl->contentKeywords(); }
558 
559  void RepoInfo::addContent( const std::string & keyword_r )
560  { _pimpl->addContent( keyword_r ); }
561 
562  bool RepoInfo::hasContent() const
563  { return _pimpl->hasContent(); }
564 
565  bool RepoInfo::hasContent( const std::string & keyword_r ) const
566  { return _pimpl->hasContent( keyword_r ); }
567 
569 
570  bool RepoInfo::hasLicense() const
571  {
572  Pathname licenseTgz( _pimpl->licenseTgz() );
573  return ! licenseTgz.empty() && PathInfo(licenseTgz).isFile();
574  }
575 
577  {
578  static const std::string noAcceptanceFile = "no-acceptance-needed\n";
579  bool accept = true;
580 
581  Pathname licenseTgz( _pimpl->licenseTgz() );
582  if ( licenseTgz.empty() || ! PathInfo( licenseTgz ).isFile() )
583  return false; // no licenses at all
584 
586  cmd.push_back( "tar" );
587  cmd.push_back( "-t" );
588  cmd.push_back( "-z" );
589  cmd.push_back( "-f" );
590  cmd.push_back( licenseTgz.asString() );
591 
593  for ( std::string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() )
594  {
595  if ( output == noAcceptanceFile )
596  {
597  accept = false;
598  }
599  }
600  prog.close();
601  MIL << "License for " << name() << " has to be accepted: " << (accept?"true":"false" ) << endl;
602  return accept;
603  }
604 
605  std::string RepoInfo::getLicense( const Locale & lang_r )
606  { return const_cast<const RepoInfo *>(this)->getLicense( lang_r ); }
607 
608  std::string RepoInfo::getLicense( const Locale & lang_r ) const
609  {
610  LocaleSet avlocales( getLicenseLocales() );
611  if ( avlocales.empty() )
612  return std::string();
613 
614  Locale getLang( Locale::bestMatch( avlocales, lang_r ) );
615  if ( !getLang && avlocales.find( Locale::noCode ) == avlocales.end() )
616  {
617  WAR << "License.tar.gz contains no fallback text! " << *this << endl;
618  // Using the fist locale instead of returning no text at all.
619  // So the user might recognize that there is a license, even if he
620  // can't read it.
621  getLang = *avlocales.begin();
622  }
623 
624  // now extract the license file.
625  static const std::string licenseFileFallback( "license.txt" );
626  std::string licenseFile( !getLang ? licenseFileFallback
627  : str::form( "license.%s.txt", getLang.c_str() ) );
628 
630  cmd.push_back( "tar" );
631  cmd.push_back( "-x" );
632  cmd.push_back( "-z" );
633  cmd.push_back( "-O" );
634  cmd.push_back( "-f" );
635  cmd.push_back( _pimpl->licenseTgz().asString() ); // if it not exists, avlocales was empty.
636  cmd.push_back( licenseFile );
637 
638  std::string ret;
640  for ( std::string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() )
641  {
642  ret += output;
643  }
644  prog.close();
645  return ret;
646  }
647 
649  {
650  Pathname licenseTgz( _pimpl->licenseTgz() );
651  if ( licenseTgz.empty() || ! PathInfo( licenseTgz ).isFile() )
652  return LocaleSet();
653 
655  cmd.push_back( "tar" );
656  cmd.push_back( "-t" );
657  cmd.push_back( "-z" );
658  cmd.push_back( "-f" );
659  cmd.push_back( licenseTgz.asString() );
660 
661  LocaleSet ret;
663  for ( std::string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() )
664  {
665  static const C_Str license( "license." );
666  static const C_Str dotTxt( ".txt\n" );
667  if ( str::hasPrefix( output, license ) && str::hasSuffix( output, dotTxt ) )
668  {
669  if ( output.size() <= license.size() + dotTxt.size() ) // license.txt
670  ret.insert( Locale() );
671  else
672  ret.insert( Locale( std::string( output.c_str()+license.size(), output.size()- license.size() - dotTxt.size() ) ) );
673  }
674  }
675  prog.close();
676  return ret;
677  }
678 
680 
681  std::ostream & RepoInfo::dumpOn( std::ostream & str ) const
682  {
684  if ( _pimpl->baseurl2dump() )
685  {
686  for ( const auto & url : _pimpl->baseUrls().raw() )
687  {
688  str << "- url : " << url << std::endl;
689  }
690  }
691 
692  // print if non empty value
693  auto strif( [&] ( const std::string & tag_r, const std::string & value_r ) {
694  if ( ! value_r.empty() )
695  str << tag_r << value_r << std::endl;
696  });
697 
698  strif( (_pimpl->_mirrorListForceMetalink ? "- metalink : " : "- mirrorlist : "), rawMirrorListUrl().asString() );
699  strif( "- path : ", path().asString() );
700  str << "- type : " << type() << std::endl;
701  str << "- priority : " << priority() << std::endl;
702 
703  // Yes No Default(Y) Default(N)
704 #define OUTS(T,B) ( indeterminate(T) ? (std::string("D(")+(B?"Y":"N")+")") : ((bool)T?"Y":"N") )
705  str << "- gpgcheck : " << OUTS(_pimpl->rawGpgCheck(),gpgCheck())
706  << " repo" << OUTS(_pimpl->rawRepoGpgCheck(),repoGpgCheck()) << (repoGpgCheckIsMandatory() ? "* ": " " )
707  << "sig" << asString( validRepoSignature(), "?", "Y", "N" )
708  << " pkg" << OUTS(_pimpl->rawPkgGpgCheck(),pkgGpgCheck()) << (pkgGpgCheckIsMandatory() ? "* ": " " )
709  << std::endl;
710 #undef OUTS
711 
712  for ( const auto & url : _pimpl->gpgKeyUrls().raw() )
713  {
714  str << "- gpgkey : " << url << std::endl;
715  }
716 
717  if ( ! indeterminate(_pimpl->keeppackages) )
718  str << "- keeppackages: " << keepPackages() << std::endl;
719 
720  strif( "- service : ", service() );
721  strif( "- targetdistro: ", targetDistribution() );
722  strif( "- metadataPath: ", metadataPath().asString() );
723  strif( "- packagesPath: ", packagesPath().asString() );
724 
725  return str;
726  }
727 
728  std::ostream & RepoInfo::dumpAsIniOn( std::ostream & str ) const
729  {
730  RepoInfoBase::dumpAsIniOn(str);
731 
732  if ( _pimpl->baseurl2dump() )
733  {
734  str << "baseurl=";
735  std::string indent;
736  for ( const auto & url : _pimpl->baseUrls().raw() )
737  {
738  str << indent << url << endl;
739  if ( indent.empty() ) indent = " "; // "baseurl="
740  }
741  }
742 
743  if ( ! _pimpl->path.empty() )
744  str << "path="<< path() << endl;
745 
746  if ( ! (rawMirrorListUrl().asString().empty()) )
747  str << (_pimpl->_mirrorListForceMetalink ? "metalink=" : "mirrorlist=") << rawMirrorListUrl() << endl;
748 
749  str << "type=" << type().asString() << endl;
750 
751  if ( priority() != defaultPriority() )
752  str << "priority=" << priority() << endl;
753 
754  if ( ! indeterminate(_pimpl->rawGpgCheck()) )
755  str << "gpgcheck=" << (_pimpl->rawGpgCheck() ? "1" : "0") << endl;
756 
757  if ( ! indeterminate(_pimpl->rawRepoGpgCheck()) )
758  str << "repo_gpgcheck=" << (_pimpl->rawRepoGpgCheck() ? "1" : "0") << endl;
759 
760  if ( ! indeterminate(_pimpl->rawPkgGpgCheck()) )
761  str << "pkg_gpgcheck=" << (_pimpl->rawPkgGpgCheck() ? "1" : "0") << endl;
762 
763  {
764  std::string indent( "gpgkey=");
765  for ( const auto & url : _pimpl->gpgKeyUrls().raw() )
766  {
767  str << indent << url << endl;
768  if ( indent[0] != ' ' )
769  indent = " ";
770  }
771  }
772 
773  if (!indeterminate(_pimpl->keeppackages))
774  str << "keeppackages=" << keepPackages() << endl;
775 
776  if( ! service().empty() )
777  str << "service=" << service() << endl;
778 
779  return str;
780  }
781 
782  std::ostream & RepoInfo::dumpAsXmlOn( std::ostream & str, const std::string & content ) const
783  {
784  std::string tmpstr;
785  str
786  << "<repo"
787  << " alias=\"" << escape(alias()) << "\""
788  << " name=\"" << escape(name()) << "\"";
789  if (type() != repo::RepoType::NONE)
790  str << " type=\"" << type().asString() << "\"";
791  str
792  << " priority=\"" << priority() << "\""
793  << " enabled=\"" << enabled() << "\""
794  << " autorefresh=\"" << autorefresh() << "\""
795  << " gpgcheck=\"" << gpgCheck() << "\""
796  << " repo_gpgcheck=\"" << repoGpgCheck() << "\""
797  << " pkg_gpgcheck=\"" << pkgGpgCheck() << "\"";
798  if (!(tmpstr = gpgKeyUrl().asString()).empty())
799  str << " gpgkey=\"" << escape(tmpstr) << "\"";
800  if (!(tmpstr = mirrorListUrl().asString()).empty())
801  str << (_pimpl->_mirrorListForceMetalink ? " metalink=\"" : " mirrorlist=\"") << escape(tmpstr) << "\"";
802  str << ">" << endl;
803 
804  if ( _pimpl->baseurl2dump() )
805  {
806  for_( it, baseUrlsBegin(), baseUrlsEnd() ) // !transform iterator replaces variables
807  str << "<url>" << escape((*it).asString()) << "</url>" << endl;
808  }
809 
810  str << "</repo>" << endl;
811  return str;
812  }
813 
814 
815  std::ostream & operator<<( std::ostream & str, const RepoInfo & obj )
816  {
817  return obj.dumpOn(str);
818  }
819 
820  std::ostream & operator<<( std::ostream & str, const RepoInfo::GpgCheck & obj )
821  {
822  switch ( obj.asEnum() )
823  {
824 #define OUTS( V ) case RepoInfo::V: return str << #V; break
825  OUTS( GpgCheck::On );
826  OUTS( GpgCheck::Strict );
827  OUTS( GpgCheck::AllowUnsigned );
828  OUTS( GpgCheck::AllowUnsignedRepo );
829  OUTS( GpgCheck::AllowUnsignedPackage );
830  OUTS( GpgCheck::Default );
831  OUTS( GpgCheck::Off );
832  OUTS( GpgCheck::indeterminate );
833 #undef OUTS
834  }
835  return str << "GpgCheck::UNKNOWN";
836  }
837 
839 } // namespace zypp
std::string asString(const Patch::Category &obj)
Definition: Patch.cc:117
static const Locale noCode
Empty code.
Definition: Locale.h:74
LocaleSet getLicenseLocales() const
Return the locales the license is available for.
Definition: RepoInfo.cc:648
TriBool internalValidRepoSignature() const
Signature check result needs to be stored/retrieved from _metadatapath.
Definition: RepoInfo.cc:162
std::string name() const
Repository name.
std::string targetDistribution() const
Distribution for which is this repository meant.
Definition: RepoInfo.cc:535
bool gpgKeyUrlsEmpty() const
Whether gpgkey URLs are defined.
Definition: RepoInfo.cc:505
#define MIL
Definition: Logger.h:64
void setGpgKeyUrl(const Url &gpgkey)
(leagcy API) Set the gpgkey URL defined for this repo
Definition: RepoInfo.cc:439
static unsigned defaultPriority()
The default priority (99).
Definition: RepoInfo.cc:309
std::string alias() const
unique identifier for this source.
TriBool repoGpgCheck() const
Check repo matadata signatures (indeterminate - according to gpgcheck)
Definition: ZConfig.cc:993
Url rawUrl() const
Pars pro toto: The first repository raw url (no variables replaced)
Definition: RepoInfo.cc:538
virtual std::ostream & dumpAsIniOn(std::ostream &str) const
Write this RepoInfo object into str in a .repo file format.
Definition: RepoInfo.cc:728
bool _mirrorListForceMetalink
Definition: RepoInfo.cc:261
static ZConfig & instance()
Singleton ctor.
Definition: Resolver.cc:125
void setPriority(unsigned newval_r)
Set repository priority for solver.
Definition: RepoInfo.cc:315
int readlink(const Pathname &symlink_r, Pathname &target_r)
Like 'readlink'.
Definition: PathInfo.cc:856
void rawGpgCheck(TriBool val_r)
Definition: RepoInfo.cc:245
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: RepoInfo.h:514
url_set gpgKeyUrls() const
The list of gpgkey URLs defined for this repo.
Definition: RepoInfo.cc:511
void setMirrorListUrl(const Url &url)
Set mirror list url.
Definition: RepoInfo.cc:430
repo::RepoVariablesUrlReplacer replacer
Definition: RepoInfo.cc:270
urls_const_iterator baseUrlsBegin() const
iterator that points at begin of repository urls
Definition: RepoInfo.cc:541
std::string escape(const C_Str &str_r, const char sep_r)
Escape desired character c using a backslash.
Definition: String.cc:369
std::ostream & dumpOn(std::ostream &str, const zypp::shared_ptr< void > &obj)
Definition: PtrTypes.h:151
Pathname metadataPath() const
Path where this repo metadata was read from.
Definition: RepoInfo.cc:490
std::ostream & operator<<(std::ostream &str, const RepoInfo::Impl &obj)
Definition: RepoInfo.cc:286
Pathname metadatapath
Definition: RepoInfo.cc:266
bool pkgGpgCheck() const
Whether the signature of rpm packages should be checked for this repo.
Definition: RepoInfo.cc:344
std::list< Url > url_set
Definition: RepoInfo.h:104
void setProbedType(const repo::RepoType &t) const
This allows to adjust the RepoType lazy, from NONE to some probed value, even for const objects...
Definition: RepoInfo.cc:468
TriBool rawPkgGpgCheck() const
Definition: RepoInfo.cc:243
What is known about a repository.
Definition: RepoInfo.h:72
void getRawGpgChecks(TriBool &g_r, TriBool &r_r, TriBool &p_r) const
Raw values for RepoManager.
Definition: RepoInfo.cc:354
void setGpgCheck(TriBool value_r)
Set the value for gpgCheck (or indeterminate to use the default).
Definition: RepoInfo.cc:322
TriBool _rawPkgGpgCheck
need to check pkg sign.: Y/N/(ZConf(Y/N/gpgCheck))
Definition: RepoInfo.cc:238
Helper to create and pass std::istream.
Definition: InputStream.h:56
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:27
void setBaseUrl(const Url &url)
Clears current base URL list and adds url.
Definition: RepoInfo.cc:453
bool enabled() const
If enabled is false, then this repository must be ignored as if does not exists, except when checking...
urls_const_iterator baseUrlsEnd() const
iterator that points at end of repository urls
Definition: RepoInfo.cc:544
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition: String.cc:36
void internalSetValidRepoSignature(TriBool value_r)
Definition: RepoInfo.cc:176
Pathname packagesPath() const
Path where this repo packages are cached.
Definition: RepoInfo.cc:493
base::ValueTransform< Url, repo::RepoVariablesUrlReplacer > RepoVariablesReplacedUrl
unsigned priority() const
Repository priority for solver.
Definition: RepoInfo.cc:306
#define OUTS(T, B)
TriBool triBoolFromPath(const Pathname &path_r) const
Definition: RepoInfo.cc:230
void setValidRepoSignature(TriBool value_r)
Set the value for validRepoSignature (or indeterminate if unsigned).
Definition: RepoInfo.cc:369
std::vector< std::string > Arguments
bool repoGpgCheck() const
Whether the signature of repo metadata should be checked for this repo.
Definition: RepoInfo.cc:329
bool seekToNode(int depth_r, const std::string &name_r)
Definition: Reader.cc:212
url_set rawGpgKeyUrls() const
The list of raw gpgkey URLs defined for this repo (no variables replaced)
Definition: RepoInfo.cc:514
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
Definition: String.h:30
transform_iterator< repo::RepoVariablesUrlReplacer, url_set::const_iterator > urls_const_iterator
Definition: RepoInfo.h:106
bool pkgGpgCheckIsMandatory() const
Mandatory check (pkgGpgCheck is not off) must ask to confirm using unsigned packages.
Definition: RepoInfo.cc:347
bool cfgGpgCheck() const
Definition: RepoInfo.cc:249
RepoVariablesReplacedUrlList _baseUrls
Definition: RepoInfo.cc:273
static Locale bestMatch(const LocaleSet &avLocales_r, Locale requested_r=Locale())
Return the best match for Locale requested_r within the available avLocales_r.
Definition: Locale.cc:213
RepoInfo implementation.
Definition: RepoInfo.cc:43
bool keepPackages() const
Whether packages downloaded from this repository will be kept in local cache.
Definition: RepoInfo.cc:487
bool needToAcceptLicense() const
Whether the repo license has to be accepted, e.g.
Definition: RepoInfo.cc:576
Url rawMirrorListUrl() const
The raw mirrorListUrl (no variables replaced).
Definition: RepoInfo.cc:502
unsigned split(const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=" \t")
Split line_r into words.
Definition: String.h:518
virtual ~RepoInfo()
Definition: RepoInfo.cc:303
bool gpgCheck() const
Turn signature checking on/off (on)
Definition: ZConfig.cc:992
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:120
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
int unlink(const Pathname &path)
Like 'unlink'.
Definition: PathInfo.cc:662
RepoVariablesReplacedUrlList & baseUrls()
Definition: RepoInfo.cc:90
void setRepoGpgCheck(TriBool value_r)
Set the value for repoGpgCheck (or indeterminate to use the default).
Definition: RepoInfo.cc:340
Url mirrorListUrl() const
Url of a file which contains a list of repository urls.
Definition: RepoInfo.cc:499
bool hasContent() const
Definition: RepoInfo.cc:110
void addContent(const std::string &keyword_r)
Definition: RepoInfo.cc:107
bool internalUnsignedConfirmed() const
We definitely have a symlink pointing to "indeterminate" (for repoGpgCheckIsMandatory)? I.e.
Definition: RepoInfo.cc:198
Convenience char* constructible from std::string and char*, it maps (char*)0 to an empty string...
Definition: String.h:90
int forEachLine(std::istream &str_r, function< bool(int, std::string)> consume_r)
Simple lineparser: Call functor consume_r for each line.
Definition: IOStream.cc:100
TriBool pkgGpgCheck() const
Check rpm package signatures (indeterminate - according to gpgcheck)
Definition: ZConfig.cc:994
void setPath(const Pathname &path)
set the product path.
Definition: RepoInfo.cc:462
bool hasContent() const
Check for content keywords.
Definition: RepoInfo.cc:562
void setService(const std::string &name)
sets service which added this repository
Definition: RepoInfo.cc:481
#define WAR
Definition: Logger.h:65
void setMetadataPath(const Pathname &path)
set the path where the local metadata is stored
Definition: RepoInfo.cc:472
bool gpgCheck() const
Whether default signature checking should be performed.
Definition: RepoInfo.cc:319
RepoVariablesReplacedUrlList & gpgKeyUrls()
Definition: RepoInfo.cc:100
urls_size_type gpgKeyUrlsSize() const
Number of gpgkey URLs defined.
Definition: RepoInfo.cc:508
bool startsWith(const C_Str &str_r, const C_Str &prefix_r)
alias for hasPrefix
Definition: String.h:1066
void setType(const repo::RepoType &t)
set the repository type
Definition: RepoInfo.cc:465
TriBool _rawGpgCheck
default gpgcheck behavior: Y/N/ZConf
Definition: RepoInfo.cc:236
TriBool _validRepoSignature
have signed and valid repo metadata
Definition: RepoInfo.cc:257
bool baseUrlSet() const
Whether there are manualy configured repository urls.
Definition: RepoInfo.cc:553
Impl * clone() const
clone for RWCOW_pointer
Definition: RepoInfo.cc:280
std::pair< FalseBool, std::set< std::string > > _keywords
Definition: RepoInfo.cc:274
void setKeepPackages(bool keep)
Set if packaqes downloaded from this repository will be kept in local cache.
Definition: RepoInfo.cc:478
std::string service() const
Gets name of the service to which this repository belongs or empty string if it has been added manual...
Definition: RepoInfo.cc:532
bool baseurl2dump() const
Definition: RepoInfo.cc:93
const std::string & asString() const
Definition: RepoType.cc:56
TriBool cfgRepoGpgCheck() const
Definition: RepoInfo.cc:251
bool seekToEndNode(int depth_r, const std::string &name_r)
Definition: Reader.cc:232
int symlink(const Pathname &oldpath, const Pathname &newpath)
Like 'symlink'.
Definition: PathInfo.cc:789
void addBaseUrl(const Url &url)
Add a base url.
Definition: RepoInfo.cc:445
std::string receiveLine()
Read one line from the input stream.
TriBool _rawRepoGpgCheck
need to check repo sign.: Y/N/(ZConf(Y/N/gpgCheck))
Definition: RepoInfo.cc:237
static const RepoType NONE
Definition: RepoType.h:32
static const unsigned noPriority
Definition: RepoInfo.cc:61
base::ContainerTransform< std::list< Url >, repo::RepoVariablesUrlReplacer > RepoVariablesReplacedUrlList
void setPackagesPath(const Pathname &path)
set the path where the local packages are stored
Definition: RepoInfo.cc:475
url_set baseUrls() const
The complete set of repository urls.
Definition: RepoInfo.cc:523
const std::vector< Url > & getUrls() const
url_set rawBaseUrls() const
The complete set of raw repository urls (no variables replaced)
Definition: RepoInfo.cc:526
std::string asString() const
Explicit conversion to std::string.
Definition: XmlString.h:77
'Language[_Country]' codes.
Definition: Locale.h:49
int close()
Wait for the progamm to complete.
void setMetalinkUrl(const Url &url)
Like setMirrorListUrl but expect metalink format.
Definition: RepoInfo.cc:433
bool baseUrlsEmpty() const
whether repository urls are available
Definition: RepoInfo.cc:550
void setGpgKeyUrls(url_set urls)
Set a list of gpgkey URLs defined for this repo.
Definition: RepoInfo.cc:436
repo::RepoType type() const
Type of repository,.
Definition: RepoInfo.cc:496
void setProbedType(const repo::RepoType &t) const
Definition: RepoInfo.cc:63
bool triBoolFromPath(const Pathname &path_r, TriBool &ret_r) const
Definition: RepoInfo.cc:204
const char * c_str() const
Definition: IdStringType.h:105
Pathname licenseTgz() const
Definition: RepoInfo.cc:74
url_set::size_type urls_size_type
Definition: RepoInfo.h:105
bool hasSuffix(const C_Str &str_r, const C_Str &suffix_r)
Return whether str_r has suffix suffix_r.
Definition: String.h:1044
void rawRepoGpgCheck(TriBool val_r)
Definition: RepoInfo.cc:246
const std::set< std::string > & contentKeywords() const
Definition: RepoInfo.cc:104
void setTargetDistribution(const std::string &targetDistribution)
Sets the distribution for which is this repository meant.
Definition: RepoInfo.cc:484
std::string getLicense(const Locale &lang_r=Locale()) const
Return the best license for the current (or a specified) locale.
Definition: RepoInfo.cc:608
bool autorefresh() const
If true, the repostory must be refreshed before creating resolvables from it.
XmlString nodeText()
If the curent node is not empty, advances the reader to the next node, and returns the value...
Definition: Reader.cc:140
Pathname packagespath
Definition: RepoInfo.cc:267
bool hasLicense() const
Whether there is a license associated with the repo.
Definition: RepoInfo.cc:570
RepoVariablesReplacedUrlList _gpgKeyUrls
Definition: RepoInfo.cc:276
bool hasContent(const std::string &keyword_r) const
Definition: RepoInfo.cc:155
bool repoGpgCheckIsMandatory() const
Mandatory check (repoGpgCheck is on) must ask to confirm using unsigned repos.
Definition: RepoInfo.cc:332
Url gpgKeyUrl() const
(leagcy API) The 1st gpgkey URL defined for this repo
Definition: RepoInfo.cc:517
RepoVariablesReplacedUrl _mirrorListUrl
Definition: RepoInfo.cc:260
DefaultIntegral< unsigned, defaultPriority > priority
Definition: RepoInfo.cc:268
Url url() const
Pars pro toto: The first repository url.
Definition: RepoInfo.h:132
const std::set< std::string > & contentKeywords() const
Content keywords defined.
Definition: RepoInfo.cc:556
void setBaseUrls(url_set urls)
Clears current base URL list and adds an url_set.
Definition: RepoInfo.cc:459
std::string targetDistro
Definition: RepoInfo.cc:265
static const RepoInfo noRepo
Represents no Repository (one with an empty alias).
Definition: RepoInfo.h:81
base::EnumClass< GpgCheckDef > GpgCheck
'enum class GpgCheck'
Definition: RepoInfo.h:357
void addContent(const std::string &keyword_r)
Add content keywords.
Definition: RepoInfo.cc:559
void rawPkgGpgCheck(TriBool val_r)
Definition: RepoInfo.cc:247
size_type size() const
Definition: String.h:105
virtual std::ostream & dumpAsXmlOn(std::ostream &str, const std::string &content="") const
Write an XML representation of this RepoInfo object.
Definition: RepoInfo.cc:782
repo::RepoType type
Definition: RepoInfo.cc:262
TriBool validRepoSignature() const
Whether the repo metadata are signed and successfully validated or indeterminate if unsigned...
Definition: RepoInfo.cc:362
Functor replacing repository variables.
urls_size_type baseUrlsSize() const
number of repository urls
Definition: RepoInfo.cc:547
TriBool rawRepoGpgCheck() const
Definition: RepoInfo.cc:242
static const unsigned defaultPriority
Definition: RepoInfo.cc:60
const RepoVariablesReplacedUrlList & gpgKeyUrls() const
Definition: RepoInfo.cc:97
static unsigned noPriority()
The least priority (unsigned(-1)).
Definition: RepoInfo.cc:312
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
Definition: String.h:1036
TriBool rawGpgCheck() const
Definition: RepoInfo.cc:241
const RepoVariablesReplacedUrlList & baseUrls() const
Definition: RepoInfo.cc:77
void setPkgGpgCheck(TriBool value_r)
Set the value for pkgGpgCheck (or indeterminate to use the default).
Definition: RepoInfo.cc:350
std::unordered_set< Locale > LocaleSet
Definition: Locale.h:27
Url rawGpgKeyUrl() const
(leagcy API) The 1st raw gpgkey URL defined for this repo (no variables replaced) ...
Definition: RepoInfo.cc:520
TriBool cfgPkgGpgCheck() const
Definition: RepoInfo.cc:253
Url manipulation class.
Definition: Url.h:87
Pathname path() const
Repository path.
Definition: RepoInfo.cc:529
virtual std::ostream & dumpOn(std::ostream &str) const
Write a human-readable representation of this RepoInfo object into the str stream.
Definition: RepoInfo.cc:681
#define DBG
Definition: Logger.h:63
std::string service
Definition: RepoInfo.cc:264
detail::EscapedString escape(const std::string &in_r)
Escape xml special charaters (& -> &; from IoBind library).
Definition: XmlEscape.h:51
Repository type enumeration.
Definition: RepoType.h:27
xmlTextReader based interface to iterate xml streams.
Definition: Reader.h:95