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