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