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