libzypp  17.38.8
RepoInfo.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <type_traits>
13 #include <iostream>
14 #include <vector>
15 #include <map>
16 #include <string_view>
17 
18 #include <zypp-core/base/Gettext.h>
20 #include <zypp-core/base/DefaultIntegral>
23 
24 #include <zypp/ManagedFile.h>
25 #include <zypp-common/PublicKey.h>
26 #include <zypp/MediaSetAccess.h>
27 #include <zypp/RepoInfo.h>
28 #include <zypp/Glob.h>
29 #include <zypp-core/TriBool.h>
30 #include <zypp-core/Pathname.h>
31 #include <zypp/ZConfig.h>
35 
37 #include <zypp-core/base/InputStream>
38 #include <zypp/parser/xml/Reader.h>
39 
40 
41 #include <zypp/base/StrMatcher.h>
42 #include <zypp/KeyRing.h>
43 #include <zypp/TmpPath.h>
44 #include <zypp/ZYppFactory.h>
45 #include <zypp/ZYppCallbacks.h>
46 
49 
51 
52 using std::endl;
53 using zypp::xml::escape;
54 
56 namespace zypp
57 {
58 
59  namespace
60  {
61  repo::RepoType probeCache( const Pathname & path_r )
62  {
63  repo::RepoType ret = repo::RepoType::NONE;
64  if ( PathInfo(path_r).isDir() )
65  {
66  if ( PathInfo(path_r/"/repodata/repomd.xml").isFile() )
67  { ret = repo::RepoType::RPMMD; }
68  else if ( PathInfo(path_r/"/content").isFile() )
69  { ret = repo::RepoType::YAST2; }
70  else if ( PathInfo(path_r/"/cookie").isFile() )
72  }
73  DBG << "Probed cached type " << ret << " at " << path_r << endl;
74  return ret;
75  }
76  } // namespace
77 
78  namespace repo {
79  namespace env {
84  {
86  const char * envp = getenv( "XDG_CACHE_HOME" );
87  if ( envp && *envp )
88  ret = envp;
89  else
90  {
91  ret = getenv( "HOME" );
92  ret /= ".cache";
93  }
94  return ret;
95  }
96  }
97  }
98 
100  //
101  // CLASS NAME : RepoInfo::Impl
102  //
105  {
107  : _rawGpgCheck( indeterminate )
108  , _rawRepoGpgCheck( indeterminate )
109  , _rawPkgGpgCheck( indeterminate )
110  , _validRepoSignature( indeterminate )
111  , _type(repo::RepoType::NONE_e)
112  , keeppackages(indeterminate)
113  {}
114 
115  Impl(const Impl &) = default;
116  Impl(Impl &&) = delete;
117  Impl &operator=(const Impl &) = delete;
118  Impl &operator=(Impl &&) = delete;
119 
120  ~Impl() {}
121 
122  public:
123  static const unsigned defaultPriority = 99;
124  static const unsigned noPriority = unsigned(-1);
125 
126  void setType( const repo::RepoType & t )
127  { _type = t; }
128 
129  void setProbedType( const repo::RepoType & t ) const
130  {
132  { const_cast<Impl*>(this)->_type = t; }
133  }
134 
136  {
137  if ( _type == repo::RepoType::NONE && not metadataPath().empty() )
138  setProbedType( probeCache( metadataPath() / path ) );
139  return _type;
140  }
141 
142  public:
144  Pathname licenseTgz( const std::string & name_r ) const
145  {
146  Pathname ret;
147  if ( !metadataPath().empty() )
148  {
149  std::string licenseStem( "license" );
150  if ( !name_r.empty() )
151  {
152  licenseStem += "-";
153  licenseStem += name_r;
154  }
155 
157  // TODO: REPOMD: this assumes we know the name of the tarball. In fact
158  // we'd need to get the file from repomd.xml (<data type="license[-name_r]">)
159  g.add( metadataPath() / path / ("repodata/*"+licenseStem+".tar.gz") );
160  if ( g.empty() )
161  g.add( metadataPath() / path / (licenseStem+".tar.gz") );
162 
163  if ( !g.empty() )
164  ret = *g.begin();
165  }
166  return ret;
167  }
168 
170  if ( !_baseUrls.empty() ) {
172  }
173  if ( !mirrorUrls().empty() ){
175  }
176  return RepoVariablesReplacedUrl();
177  }
178 
180  {
181  return _baseUrls;
182  }
183 
184  Url location() const {
185  if ( !_baseUrls.empty() )
186  return *_baseUrls.transformedBegin ();
187  return mirrorListUrl().transformed();
188  }
189 
190  void resetMirrorUrls() const {
191  _mirrorUrls.clear ();
192  _lastMirrorUrlsUpdate = std::chrono::steady_clock::time_point::min();
193  }
194 
201  {
202  // do not change order of calculation, using std::chrono::steady_clock::now() - _lastMirrorUrlsUpdate
203  // will overflow the internal counter if _lastMirrorUrlsUpdate is still time_point::min and result
204  // in a negative value.
205  if ( ( std::chrono::steady_clock::now() - std::chrono::hours(1) ) < _lastMirrorUrlsUpdate )
206  return _mirrorUrls;
207 
208  _mirrorUrls.clear();
209  _lastMirrorUrlsUpdate = std::chrono::steady_clock::now();
210 
211  bool isAutoMirrorList = false; // bsc#1243901 Allows mirrorlist parsing to fail if automatically switched on
212 
213  Url mlurl( mirrorListUrl().transformed() ); // Variables replaced!
214  if ( mlurl.asString().empty()
215  && _baseUrls.raw().size() == 1
217 
218  mlurl = *_baseUrls.transformedBegin ();
219  if ( !path.emptyOrRoot () )
220  mlurl.setPathName(path);
221  mlurl.pathNameSetTrailingSlash();
222  mlurl.setQueryParam("mirrorlist", std::string() );
223 
224  MIL << "Detected opensuse.org baseUrl with no mirrors, requesting them from : " << mlurl.asString() << std::endl;
225  isAutoMirrorList = true;
226  }
227 
228  if ( !mlurl.asString().empty() ) {
229  try {
230  DBG << "MetadataPath: " << metadataPath() << endl;
231  repo::RepoMirrorList rmurls( mlurl, metadataPath() );
232 
233  // propagate internally used URL params like 'proxy' to the mirrors
234  const auto &tf = [urlTemplate =mirrorListUrl().transformed()]( const zypp::Url &in ){
235  return internal::propagateQueryParams ( in , urlTemplate );
236  };
237 
238  _mirrorUrls.raw().insert( _mirrorUrls.raw().end(), make_transform_iterator( rmurls.getUrls().begin(), tf ), make_transform_iterator( rmurls.getUrls().end(), tf ) );
239  } catch ( const zypp::Exception & e ) {
240  // failed to fetch the mirrorlist/metalink, if we still have a baseUrl we can go on, otherwise this is a error
241  MIL << "Mirrorlist failed, repo either returns invalid data or has no mirrors at all!" << std::endl;
242  if ( !isAutoMirrorList ) {
244  data.set("error", e );
245  JobReport::warning( _("Failed to fetch mirrorlist/metalink data."), data );
246 
247  // in case of error, we want to try again asap
248  _lastMirrorUrlsUpdate = std::chrono::steady_clock::time_point::min();
249  }
250  }
251  }
252  return _mirrorUrls;
253  }
254 
256  {
257  MirroredOriginSet origins;
258  std::for_each( _baseUrls.transformedBegin(), _baseUrls.transformedEnd(), [&]( OriginEndpoint ep ) {
259  origins.addAuthorityEndpoint( std::move(ep) );
260  });
261 
262  const auto &mirrs = mirrorUrls ();
263  origins.addEndpoints( mirrs.transformedBegin(), mirrs.transformedEnd() );
264 
265  return origins;
266  }
267 
269  { return _baseUrls; }
270 
271  bool baseurl2dump() const
272  { return !_baseUrls.empty(); }
273 
274 
276  { return _gpgKeyUrls; }
277 
279  { return _gpgKeyUrls; }
280 
281  std::string repoStatusString() const
282  {
283  if ( mirrorListUrl().transformed().isValid() )
284  return mirrorListUrl().transformed().asString();
285  if ( !baseUrls().empty() )
286  return (*baseUrls().transformedBegin()).asString();
287  return std::string();
288  }
289 
290  const std::set<std::string> & contentKeywords() const
291  { hasContent()/*init if not yet done*/; return _keywords.second; }
292 
293  void addContent( const std::string & keyword_r )
294  { _keywords.second.insert( keyword_r ); if ( ! hasContent() ) _keywords.first = true; }
295 
296  bool hasContent() const
297  {
298  if ( !_keywords.first && ! metadataPath().empty() )
299  {
300  // HACK directly check master index file until RepoManager offers
301  // some content probing and zypper uses it.
303  MIL << "Empty keywords...." << metadataPath() << endl;
304  Pathname master;
305  if ( PathInfo( (master=metadataPath()/"/repodata/repomd.xml") ).isFile() )
306  {
307  //MIL << "GO repomd.." << endl;
308  xml::Reader reader( master );
309  while ( reader.seekToNode( 2, "content" ) )
310  {
311  _keywords.second.insert( reader.nodeText().asString() );
312  reader.seekToEndNode( 2, "content" );
313  }
314  _keywords.first = true; // valid content in _keywords even if empty
315  }
316  else if ( PathInfo( (master=metadataPath()/"/content") ).isFile() )
317  {
318  //MIL << "GO content.." << endl;
319  iostr::forEachLine( InputStream( master ),
320  [this]( int num_r, const std::string& line_r )->bool
321  {
322  if ( str::startsWith( line_r, "REPOKEYWORDS" ) )
323  {
324  std::vector<std::string> words;
325  if ( str::split( line_r, std::back_inserter(words) ) > 1
326  && words[0].length() == 12 /*"REPOKEYWORDS"*/ )
327  {
328  this->_keywords.second.insert( ++words.begin(), words.end() );
329  }
330  return true; // mult. occurrances are ok.
331  }
332  return( ! str::startsWith( line_r, "META " ) ); // no need to parse into META section.
333  } );
334  _keywords.first = true; // valid content in _keywords even if empty
335  }
337  }
338  return _keywords.first;
339  }
340 
341  bool hasContent( const std::string & keyword_r ) const
342  { return( hasContent() && _keywords.second.find( keyword_r ) != _keywords.second.end() ); }
343 
349  {
350  if ( ! indeterminate(_validRepoSignature) )
351  return _validRepoSignature;
352  // check metadata:
353  if ( ! metadataPath().empty() )
354  {
355  // A missing ".repo_gpgcheck" might be plaindir(no Downloader) or not yet refreshed signed repo!
356  TriBool linkval = triBoolFromPath( metadataPath() / ".repo_gpgcheck" );
357  return linkval;
358  }
359  return indeterminate;
360  }
361 
363  {
364  if ( PathInfo(metadataPath()).isDir() )
365  {
366  Pathname gpgcheckFile( metadataPath() / ".repo_gpgcheck" );
367  if ( PathInfo(gpgcheckFile).isExist() )
368  {
369  TriBool linkval( indeterminate );
370  if ( triBoolFromPath( gpgcheckFile, linkval ) && linkval == value_r )
371  return; // existing symlink fits value_r
372  else
373  filesystem::unlink( gpgcheckFile ); // will write a new one
374  }
375  filesystem::symlink( asString(value_r), gpgcheckFile );
376  }
377  _validRepoSignature = value_r;
378  }
379 
385  {
386  TriBool linkval( true ); // want to see it being switched to indeterminate
387  return triBoolFromPath( metadataPath() / ".repo_gpgcheck", linkval ) && indeterminate(linkval);
388  }
389 
390  bool triBoolFromPath( const Pathname & path_r, TriBool & ret_r ) const
391  {
392  static const Pathname truePath( "true" );
393  static const Pathname falsePath( "false" );
394  static const Pathname indeterminatePath( "indeterminate" );
395 
396  // Quiet readlink;
397  static const ssize_t bufsiz = 63;
398  static char buf[bufsiz+1];
399  ssize_t ret = ::readlink( path_r.c_str(), buf, bufsiz );
400  buf[ret == -1 ? 0 : ret] = '\0';
401 
402  Pathname linkval( buf );
403 
404  bool known = true;
405  if ( linkval == truePath )
406  ret_r = true;
407  else if ( linkval == falsePath )
408  ret_r = false;
409  else if ( linkval == indeterminatePath )
410  ret_r = indeterminate;
411  else
412  known = false;
413  return known;
414  }
415 
416  TriBool triBoolFromPath( const Pathname & path_r ) const
417  { TriBool ret(indeterminate); triBoolFromPath( path_r, ret ); return ret; }
418 
420 
421  private:
425 
426  public:
427  TriBool rawGpgCheck() const { return _rawGpgCheck; }
430 
431  void rawGpgCheck( TriBool val_r ) { _rawGpgCheck = val_r; }
432  void rawRepoGpgCheck( TriBool val_r ) { _rawRepoGpgCheck = val_r; }
433  void rawPkgGpgCheck( TriBool val_r ) { _rawPkgGpgCheck = val_r; }
434 
435  bool cfgGpgCheck() const
436  { return indeterminate(_rawGpgCheck) ? ZConfig::instance().gpgCheck() : (bool)_rawGpgCheck; }
438  { return indeterminate(_rawGpgCheck) && indeterminate(_rawRepoGpgCheck) ? ZConfig::instance().repoGpgCheck() : _rawRepoGpgCheck; }
440  { return indeterminate(_rawGpgCheck) && indeterminate(_rawPkgGpgCheck) ? ZConfig::instance().pkgGpgCheck() : _rawPkgGpgCheck; }
441 
442  private:
445 
446  private:
449  public:
453 
454  void setMirrorlistUrl( const Url & url_r ) // Raw
455  { _cfgMirrorlistUrl.raw() = url_r; }
456 
457  void setMetalinkUrl( const Url & url_r ) // Raw
458  { _cfgMetalinkUrl.raw() = url_r; }
459 
462  { return _cfgMirrorlistUrl; }
465  { return _cfgMetalinkUrl; }
466 
467  public:
470  std::string service;
471  std::string targetDistro;
472 
473  void metadataPath( Pathname new_r )
474  { _metadataPath = std::move( new_r ); }
475 
476  void packagesPath( Pathname new_r )
477  {
478  _packagesPath = std::move( new_r );
481  WAR << "systemPackagesPath " << _packagesPath << " is not user writable, may use " << *_alternatePackagesPath << endl;
482  } else {
483  _alternatePackagesPath.reset();
484  }
485  }
486 
488  { return str::hasSuffix( _metadataPath.asString(), "/%AUTO%" ); }
489 
491  {
492  if ( usesAutoMetadataPaths() )
493  return _metadataPath.dirname() / "%RAW%";
494  return _metadataPath;
495  }
496 
498  {
500  return _metadataPath.dirname() / "%PKG%";
501  return _packagesPath;
502  }
503 
505  {
507  }
508 
510  {
511  return packagesPath() / ".preload";
512  }
513 
515 
516  public:
517  std::map<std::string,std::string> _extraValues;
518 
523  TriBool isBuiltinExtraValue( std::string_view key_r ) const
524  {
525  static const std::set<std::string_view> _builtins { {
526  "repo_sigcheck_plugin",
527  } };
528  if ( _builtins.count( key_r ) )
529  return true;
530  if ( key_r.find( '=' ) == std::string::npos )
531  return false;
532  return indeterminate;
533  }
534 
535  bool hasExtraValue( const std::string & key_r ) const
536  { return _extraValues.count( key_r ); }
537 
538  std::string extraValue( const std::string & key_r ) const
539  { return _extraValues.at( key_r ); } // let it throw
540 
541  bool setExtraValue( const std::string & key_r, std::string value_r )
542  {
543  _extraValues[key_r] = std::move(value_r);
544  return bool(isBuiltinExtraValue( key_r ));
545  }
546 
548  template <typename Fnc>
549  void forDumpableExtraValues( Fnc && fnc_r ) const
550  {
551  for ( const auto & [k,v] : _extraValues ) {
552  TriBool dumpable = isBuiltinExtraValue( k );
553  if ( indeterminate(dumpable) )
554  continue;
555  if constexpr ( std::is_invocable_v<Fnc, std::string_view, std::string_view, bool> ) {
556  fnc_r( k, v, bool(dumpable) );
557  }
558  else if constexpr ( std::is_invocable_v<Fnc, std::string_view, std::string_view> ) {
559  fnc_r( k, v );
560  }
561  else {
562  static_assert( zyppng::always_false_v<Fnc>, "Lambda must accept (k, v) or (k, v, b)" );
563  }
564  }
565  }
566 
567  private:
570  std::optional<Pathname> _alternatePackagesPath;
571 
573 
575  mutable std::chrono::steady_clock::time_point _lastMirrorUrlsUpdate = std::chrono::steady_clock::time_point::min();
576  mutable std::vector<MirroredOrigin> _repoOrigins;
577 
578  mutable std::pair<FalseBool, std::set<std::string> > _keywords;
579 
581 
582  friend Impl * rwcowClone<Impl>( const Impl * rhs );
584  Impl * clone() const
585  { return new Impl( *this ); }
586  };
588 
590  inline std::ostream & operator<<( std::ostream & str, const RepoInfo::Impl & obj )
591  {
592  return str << "RepoInfo::Impl";
593  }
594 
596  //
597  // CLASS NAME : RepoInfo
598  //
600 
602 
604  : _pimpl( new Impl() )
605  {}
606 
608  {}
609 
610  unsigned RepoInfo::priority() const
611  { return _pimpl->priority; }
612 
614  { return Impl::defaultPriority; }
615 
617  { return Impl::noPriority; }
618 
619  void RepoInfo::setPriority( unsigned newval_r )
620  { _pimpl->priority = newval_r ? newval_r : Impl::defaultPriority; }
621 
622 
623  bool RepoInfo::gpgCheck() const
624  { return _pimpl->cfgGpgCheck(); }
625 
627  { _pimpl->rawGpgCheck( value_r ); }
628 
629  void RepoInfo::setGpgCheck( bool value_r ) // deprecated legacy and for squid
630  { setGpgCheck( TriBool(value_r) ); }
631 
632 
634  { return gpgCheck() || bool(_pimpl->cfgRepoGpgCheck()); }
635 
637  {
638  bool ret = ( gpgCheck() && indeterminate(_pimpl->cfgRepoGpgCheck()) ) || bool(_pimpl->cfgRepoGpgCheck());
639  if ( ret && _pimpl->internalUnsignedConfirmed() ) // relax if unsigned repo was confirmed in the past
640  ret = false;
641  return ret;
642  }
643 
645  { _pimpl->rawRepoGpgCheck( value_r ); }
646 
647 
649  { return bool(_pimpl->cfgPkgGpgCheck()) || ( gpgCheck() && !bool(validRepoSignature())/*enforced*/ ) ; }
650 
652  { return bool(_pimpl->cfgPkgGpgCheck()) || ( gpgCheck() && indeterminate(_pimpl->cfgPkgGpgCheck()) && !bool(validRepoSignature())/*enforced*/ ); }
653 
655  { _pimpl->rawPkgGpgCheck( value_r ); }
656 
657 
658  void RepoInfo::getRawGpgChecks( TriBool & g_r, TriBool & r_r, TriBool & p_r ) const
659  {
660  g_r = _pimpl->rawGpgCheck();
661  r_r = _pimpl->rawRepoGpgCheck();
662  p_r = _pimpl->rawPkgGpgCheck();
663  }
664 
665 
667  {
669  if ( ret && !repoGpgCheck() ) ret = false; // invalidate any old signature if repoGpgCheck is off
670  return ret;
671  }
672 
674  { _pimpl->internalSetValidRepoSignature( value_r ); }
675 
677  namespace
678  {
679  inline bool changeGpgCheckTo( TriBool & lhs, TriBool rhs )
680  { if ( ! sameTriboolState( lhs, rhs ) ) { lhs = rhs; return true; } return false; }
681 
682  inline bool changeGpgCheckTo( TriBool ogpg[3], TriBool g, TriBool r, TriBool p )
683  {
684  bool changed = false;
685  if ( changeGpgCheckTo( ogpg[0], g ) ) changed = true;
686  if ( changeGpgCheckTo( ogpg[1], r ) ) changed = true;
687  if ( changeGpgCheckTo( ogpg[2], p ) ) changed = true;
688  return changed;
689  }
690  } // namespace
693  {
694  TriBool ogpg[3]; // Gpg RepoGpg PkgGpg
695  getRawGpgChecks( ogpg[0], ogpg[1], ogpg[2] );
696 
697  bool changed = false;
698  switch ( mode_r )
699  {
700  case GpgCheck::On:
701  changed = changeGpgCheckTo( ogpg, true, indeterminate, indeterminate );
702  break;
703  case GpgCheck::Strict:
704  changed = changeGpgCheckTo( ogpg, true, true, true );
705  break;
707  changed = changeGpgCheckTo( ogpg, true, false, false );
708  break;
710  changed = changeGpgCheckTo( ogpg, true, false, indeterminate );
711  break;
713  changed = changeGpgCheckTo( ogpg, true, indeterminate, false );
714  break;
715  case GpgCheck::Default:
716  changed = changeGpgCheckTo( ogpg, indeterminate, indeterminate, indeterminate );
717  break;
718  case GpgCheck::Off:
719  changed = changeGpgCheckTo( ogpg, false, indeterminate, indeterminate );
720  break;
721  case GpgCheck::indeterminate: // no change
722  break;
723  }
724 
725  if ( changed )
726  {
727  setGpgCheck ( ogpg[0] );
728  setRepoGpgCheck( ogpg[1] );
729  setPkgGpgCheck ( ogpg[2] );
730  }
731  return changed;
732  }
733 
734  void RepoInfo::setMirrorlistUrl( const Url & url_r ) // Raw
735  { _pimpl->setMirrorlistUrl( url_r ); }
736 
737  void RepoInfo::setMetalinkUrl( const Url & url_r ) // Raw
738  { _pimpl->setMetalinkUrl( url_r ); }
739 
741  { return _pimpl->cfgMirrorlistUrl().raw(); }
742 
744  { return _pimpl->cfgMetalinkUrl().raw(); }
745 
746 #if LEGACY(1735)
747  void RepoInfo::setMirrorListUrl( const Url & url_r ) // Raw
748  { setMirrorlistUrl( url_r ); }
749  void RepoInfo::setMirrorListUrls( url_set urls ) // Raw
750  { _pimpl->setMirrorlistUrl( urls.empty() ? Url() : urls.front() ); }
751  void RepoInfo::setMetalinkUrls( url_set urls ) // Raw
752  { _pimpl->setMetalinkUrl( urls.empty() ? Url() : urls.front() ); }
753 #endif
754 
756  { _pimpl->gpgKeyUrls().raw().swap( urls ); }
757 
758  void RepoInfo::setGpgKeyUrl( const Url & url_r )
759  {
760  _pimpl->gpgKeyUrls().raw().clear();
761  _pimpl->gpgKeyUrls().raw().push_back( url_r );
762  }
763 
764  std::string RepoInfo::repoStatusString() const
765  { return _pimpl->repoStatusString(); }
766 
767  void RepoInfo::addBaseUrl( Url url_r )
768  {
769  for ( const auto & url : _pimpl->baseUrls().raw() ) // Raw unique!
770  if ( url == url_r )
771  return;
772 
773  _pimpl->baseUrls().raw().push_back( url_r );
775  }
776 
777  void RepoInfo::setBaseUrl( Url url_r )
778  {
779  _pimpl->baseUrls().raw().clear();
781  _pimpl->baseUrls().raw().push_back( std::move(url_r) );
782  }
783 
785  {
787  _pimpl->baseUrls().raw().swap( urls );
788  }
789 
791  {
792  return _pimpl->repoOrigins();
793  }
794 
796  {
797  return ( _pimpl->baseUrls().empty () && _pimpl->mirrorUrls().empty() );
798  }
799 
800  void RepoInfo::setPath( const Pathname &path )
801  { _pimpl->path = path; }
802 
804  { _pimpl->setType( t ); }
805 
807  { _pimpl->setProbedType( t ); }
808 
809 
811  { _pimpl->metadataPath( path ); }
812 
814  { _pimpl->packagesPath( path ); }
815 
817  { return _pimpl->predownloadPath(); }
818 
819  void RepoInfo::setKeepPackages( bool keep )
820  { _pimpl->keeppackages = keep; }
821 
822  void RepoInfo::setService( const std::string& name )
823  { _pimpl->service = name; }
824 
825  void RepoInfo::setTargetDistribution( const std::string & targetDistribution )
827 
829  { return indeterminate(_pimpl->keeppackages) ? false : (bool)_pimpl->keeppackages; }
830 
832  { return keepPackages() || PathInfo(packagesPath().dirname()/".keep_packages").isExist(); }
833 
835  { return _pimpl->metadataPath(); }
836 
838  { return _pimpl->systemPackagesPath(); }
839 
841  { return _pimpl->packagesPath(); }
842 
844  { return _pimpl->usesAutoMetadataPaths(); }
845 
847  { return _pimpl->type(); }
848 
849  Url RepoInfo::mirrorListUrl() const // Variables replaced!
850  { return _pimpl->mirrorListUrl().transformed(); }
851 
853  { return _pimpl->mirrorListUrl().raw(); }
854 
856  { return _pimpl->gpgKeyUrls().empty(); }
857 
859  { return _pimpl->gpgKeyUrls().size(); }
860 
861  RepoInfo::url_set RepoInfo::gpgKeyUrls() const // Variables replaced!
862  { return _pimpl->gpgKeyUrls().transformed(); }
863 
865  { return _pimpl->gpgKeyUrls().raw(); }
866 
867  Url RepoInfo::gpgKeyUrl() const // Variables replaced!
868  { return( _pimpl->gpgKeyUrls().empty() ? Url() : *_pimpl->gpgKeyUrls().transformedBegin() ); }
869 
871  { return( _pimpl->gpgKeyUrls().empty() ? Url() : *_pimpl->gpgKeyUrls().rawBegin() ) ; }
872 
873  RepoInfo::url_set RepoInfo::baseUrls() const // Variables replaced!
874  { return _pimpl->baseUrls().transformed(); }
875 
877  { return _pimpl->baseUrls().raw(); }
878 
880  { return _pimpl->path; }
881 
882  std::string RepoInfo::service() const
883  { return _pimpl->service; }
884 
885  std::string RepoInfo::targetDistribution() const
886  { return _pimpl->targetDistro; }
887 
889  { return _pimpl->baseUrl().raw(); }
890 
892  { return _pimpl->location (); }
893 
895  { return _pimpl->baseUrls().transformedBegin(); }
896 
898  { return _pimpl->baseUrls().transformedEnd(); }
899 
901  { return _pimpl->baseUrls().size(); }
902 
904  { return _pimpl->baseUrls().empty(); }
905 
906  bool RepoInfo::baseUrlSet() const
907  { return _pimpl->baseurl2dump(); }
908 
910  {
911  return _pimpl->baseUrl().transformed();
912  }
913 
914  const std::set<std::string> & RepoInfo::contentKeywords() const
915  { return _pimpl->contentKeywords(); }
916 
917  void RepoInfo::addContent( const std::string & keyword_r )
918  { _pimpl->addContent( keyword_r ); }
919 
920  bool RepoInfo::hasContent() const
921  { return _pimpl->hasContent(); }
922 
923  bool RepoInfo::hasContent( const std::string & keyword_r ) const
924  { return _pimpl->hasContent( keyword_r ); }
925 
927 
928  bool RepoInfo::hasLicense() const
929  { return hasLicense( std::string() ); }
930 
931  bool RepoInfo::hasLicense( const std::string & name_r ) const
932  { return !_pimpl->licenseTgz( name_r ).empty(); }
933 
934 
936  { return needToAcceptLicense( std::string() ); }
937 
938  bool RepoInfo::needToAcceptLicense( const std::string & name_r ) const
939  {
940  const Pathname & licenseTgz( _pimpl->licenseTgz( name_r ) );
941  if ( licenseTgz.empty() )
942  return false; // no licenses at all
943 
945  cmd.push_back( "tar" );
946  cmd.push_back( "-t" );
947  cmd.push_back( "-z" );
948  cmd.push_back( "-f" );
949  cmd.push_back( licenseTgz.asString() );
951 
952  bool accept = true;
953  static const std::string noAcceptanceFile = "no-acceptance-needed\n";
954  for ( std::string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() )
955  {
956  if ( output == noAcceptanceFile )
957  {
958  accept = false;
959  }
960  }
961  prog.close();
962  MIL << "License(" << name_r << ") in " << name() << " has to be accepted: " << (accept?"true":"false" ) << endl;
963  return accept;
964  }
965 
966 
967  std::string RepoInfo::getLicense( const Locale & lang_r )
968  { return const_cast<const RepoInfo *>(this)->getLicense( std::string(), lang_r ); }
969 
970  std::string RepoInfo::getLicense( const Locale & lang_r ) const
971  { return getLicense( std::string(), lang_r ); }
972 
973  std::string RepoInfo::getLicense( const std::string & name_r, const Locale & lang_r ) const
974  {
975  LocaleSet avlocales( getLicenseLocales( name_r ) );
976  if ( avlocales.empty() )
977  return std::string();
978 
979  Locale getLang( Locale::bestMatch( avlocales, lang_r ) );
980  if ( !getLang && avlocales.find( Locale::noCode ) == avlocales.end() )
981  {
982  WAR << "License(" << name_r << ") in " << name() << " contains no fallback text!" << endl;
983  // Using the fist locale instead of returning no text at all.
984  // So the user might recognize that there is a license, even if they
985  // can't read it.
986  getLang = *avlocales.begin();
987  }
988 
989  // now extract the license file.
990  static const std::string licenseFileFallback( "license.txt" );
991  std::string licenseFile( !getLang ? licenseFileFallback
992  : str::form( "license.%s.txt", getLang.c_str() ) );
993 
995  cmd.push_back( "tar" );
996  cmd.push_back( "-x" );
997  cmd.push_back( "-z" );
998  cmd.push_back( "-O" );
999  cmd.push_back( "-f" );
1000  cmd.push_back( _pimpl->licenseTgz( name_r ).asString() ); // if it not exists, avlocales was empty.
1001  cmd.push_back( licenseFile );
1002 
1003  std::string ret;
1005  for ( std::string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() )
1006  {
1007  ret += output;
1008  }
1009  prog.close();
1010  return ret;
1011  }
1012 
1013 
1015  { return getLicenseLocales( std::string() ); }
1016 
1017  LocaleSet RepoInfo::getLicenseLocales( const std::string & name_r ) const
1018  {
1019  const Pathname & licenseTgz( _pimpl->licenseTgz( name_r ) );
1020  if ( licenseTgz.empty() )
1021  return LocaleSet();
1022 
1024  cmd.push_back( "tar" );
1025  cmd.push_back( "-t" );
1026  cmd.push_back( "-z" );
1027  cmd.push_back( "-f" );
1028  cmd.push_back( licenseTgz.asString() );
1029 
1030  LocaleSet ret;
1032  for ( std::string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() )
1033  {
1034  static const C_Str license( "license." );
1035  static const C_Str dotTxt( ".txt\n" );
1036  if ( str::hasPrefix( output, license ) && str::hasSuffix( output, dotTxt ) )
1037  {
1038  if ( output.size() <= license.size() + dotTxt.size() ) // license.txt
1039  ret.insert( Locale() );
1040  else
1041  ret.insert( Locale( std::string( output.c_str()+license.size(), output.size()- license.size() - dotTxt.size() ) ) );
1042  }
1043  }
1044  prog.close();
1045  return ret;
1046  }
1047 
1049 
1050  std::ostream & RepoInfo::dumpOn( std::ostream & str ) const
1051  {
1053  if ( _pimpl->baseurl2dump() )
1054  {
1055  for ( const auto & url : _pimpl->baseUrls().raw() )
1056  {
1057  str << "- url : " << url << std::endl;
1058  }
1059  }
1060 
1061  // print if non empty value
1062  auto strif( [&] ( const std::string & tag_r, const std::string & value_r ) {
1063  if ( ! value_r.empty() )
1064  str << tag_r << value_r << std::endl;
1065  });
1066 
1067  strif( "- mirrorlist : ", _pimpl->cfgMirrorlistUrl().raw().asString() );
1068  strif( "- metalink : ", _pimpl->cfgMetalinkUrl().raw().asString() );
1069  strif( "- path : ", path().asString() );
1070  str << "- type : " << type() << std::endl;
1071  str << "- priority : " << priority() << std::endl;
1072 
1073  // Yes No Default(Y) Default(N)
1074 #define OUTS(T,B) ( indeterminate(T) ? (std::string("D(")+(B?"Y":"N")+")") : ((bool)T?"Y":"N") )
1075  str << "- gpgcheck : " << OUTS(_pimpl->rawGpgCheck(),gpgCheck())
1076  << " repo" << OUTS(_pimpl->rawRepoGpgCheck(),repoGpgCheck()) << (repoGpgCheckIsMandatory() ? "* ": " " )
1077  << "sig" << asString( validRepoSignature(), "?", "Y", "N" )
1078  << " pkg" << OUTS(_pimpl->rawPkgGpgCheck(),pkgGpgCheck()) << (pkgGpgCheckIsMandatory() ? "* ": " " )
1079  << std::endl;
1080 #undef OUTS
1081 
1082  for ( const auto & url : _pimpl->gpgKeyUrls().raw() )
1083  {
1084  str << "- gpgkey : " << url << std::endl;
1085  }
1086 
1087  if ( ! indeterminate(_pimpl->keeppackages) )
1088  str << "- keeppackages: " << keepPackages() << std::endl;
1089 
1090  strif( "- service : ", service() );
1091  strif( "- targetdistro: ", targetDistribution() );
1092  strif( "- filePath : ", filepath().asString() );
1093  strif( "- metadataPath: ", metadataPath().asString() );
1094  strif( "- packagesPath: ", packagesPath().asString() );
1095 
1096  _pimpl->forDumpableExtraValues( [&]( std::string_view k, std::string_view v, bool builtin_r ) {
1097  str << ( builtin_r ? "- " : "# " ) << k << ": " << v << std::endl;
1098  } );
1099  return str;
1100  }
1101 
1102  std::ostream & RepoInfo::dumpAsIniOn( std::ostream & str ) const
1103  {
1104  // libzypp/#638: Add a note to service maintained repo entries
1105  if( ! service().empty() ) {
1106  str << "# Repository '"<<alias()<<"' is maintained by the '"<<service()<<"' service." << endl;
1107  str << "# Manual changes may be overwritten by a service refresh." << endl;
1108  str << "# See also 'man zypper', section 'Services'." << endl;
1109  }
1110  RepoInfoBase::dumpAsIniOn(str);
1111 
1112  if ( _pimpl->baseurl2dump() )
1113  {
1114  str << "baseurl=";
1115  std::string indent;
1116  for ( const auto & url : _pimpl->baseUrls().raw() )
1117  {
1118  str << indent << hotfix1050625::asString( url ) << endl;
1119  if ( indent.empty() ) indent = " "; // "baseurl="
1120  }
1121  }
1122 
1123  if ( ! _pimpl->path.empty() )
1124  str << "path="<< path() << endl;
1125 
1126  if ( ! _pimpl->cfgMirrorlistUrl().raw().asString().empty() )
1127  str << "mirrorlist=" << hotfix1050625::asString( _pimpl->cfgMirrorlistUrl().raw() ) << endl;
1128 
1129  if ( ! _pimpl->cfgMetalinkUrl().raw().asString().empty() )
1130  str << "metalink=" << hotfix1050625::asString( _pimpl->cfgMetalinkUrl().raw() ) << endl;
1131 
1132  if ( type() != repo::RepoType::NONE )
1133  str << "type=" << type().asString() << endl;
1134 
1135  if ( priority() != defaultPriority() )
1136  str << "priority=" << priority() << endl;
1137 
1138  if ( ! indeterminate(_pimpl->rawGpgCheck()) )
1139  str << "gpgcheck=" << (_pimpl->rawGpgCheck() ? "1" : "0") << endl;
1140 
1141  if ( ! indeterminate(_pimpl->rawRepoGpgCheck()) )
1142  str << "repo_gpgcheck=" << (_pimpl->rawRepoGpgCheck() ? "1" : "0") << endl;
1143 
1144  if ( ! indeterminate(_pimpl->rawPkgGpgCheck()) )
1145  str << "pkg_gpgcheck=" << (_pimpl->rawPkgGpgCheck() ? "1" : "0") << endl;
1146 
1147  {
1148  std::string indent( "gpgkey=");
1149  for ( const auto & url : _pimpl->gpgKeyUrls().raw() )
1150  {
1151  str << indent << url << endl;
1152  if ( indent[0] != ' ' )
1153  indent = " ";
1154  }
1155  }
1156 
1157  if (!indeterminate(_pimpl->keeppackages))
1158  str << "keeppackages=" << keepPackages() << endl;
1159 
1160  if( ! service().empty() )
1161  str << "service=" << service() << endl;
1162 
1163  _pimpl->forDumpableExtraValues( [&]( std::string_view k, std::string_view v ) {
1164  str << k << "=" << v << endl;
1165  } );
1166 
1167  return str;
1168  }
1169 
1170  std::ostream & RepoInfo::dumpAsXmlOn( std::ostream & str, const std::string & content ) const
1171  {
1172  std::string tmpstr;
1173  str
1174  << "<repo"
1175  << " alias=\"" << escape(alias()) << "\""
1176  << " name=\"" << escape(name()) << "\"";
1177  if (type() != repo::RepoType::NONE)
1178  str << " type=\"" << type().asString() << "\"";
1179  str
1180  << " priority=\"" << priority() << "\""
1181  << " enabled=\"" << enabled() << "\""
1182  << " autorefresh=\"" << autorefresh() << "\""
1183  << " gpgcheck=\"" << gpgCheck() << "\""
1184  << " repo_gpgcheck=\"" << repoGpgCheck() << "\""
1185  << " pkg_gpgcheck=\"" << pkgGpgCheck() << "\"";
1186  if ( ! indeterminate(_pimpl->rawGpgCheck()) )
1187  str << " raw_gpgcheck=\"" << (_pimpl->rawGpgCheck() ? "1" : "0") << "\"";
1188  if ( ! indeterminate(_pimpl->rawRepoGpgCheck()) )
1189  str << " raw_repo_gpgcheck=\"" << (_pimpl->rawRepoGpgCheck() ? "1" : "0") << "\"";
1190  if ( ! indeterminate(_pimpl->rawPkgGpgCheck()) )
1191  str << " raw_pkg_gpgcheck=\"" << (_pimpl->rawPkgGpgCheck() ? "1" : "0") << "\"";
1192  if (!(tmpstr = gpgKeyUrl().asString()).empty())
1193  str << " gpgkey=\"" << escape(tmpstr) << "\"";
1194  if ( ! (tmpstr = _pimpl->cfgMirrorlistUrl().transformed().asString()).empty() )
1195  str << " mirrorlist=\"" << escape(tmpstr) << "\"";
1196  if ( ! (tmpstr = _pimpl->cfgMetalinkUrl().transformed().asString()).empty() )
1197  str << " metalink=\"" << escape(tmpstr) << "\"";
1198  str << ">" << endl;
1199 
1200  if ( _pimpl->baseurl2dump() )
1201  {
1202  for_( it, baseUrlsBegin(), baseUrlsEnd() ) // !transform iterator replaces variables
1203  str << "<url>" << escape((*it).asString()) << "</url>" << endl;
1204  }
1205 
1206  _pimpl->forDumpableExtraValues( [&]( std::string_view k, std::string_view v ) {
1207  str << "<extra key=\"" << escape(std::string(k)) << "\">"
1208  << escape(std::string(v))
1209  << "</extra>" << endl;
1210  } );
1211 
1212  str << "</repo>" << endl;
1213  return str;
1214  }
1215 
1216 
1217  std::ostream & operator<<( std::ostream & str, const RepoInfo & obj )
1218  {
1219  return obj.dumpOn(str);
1220  }
1221 
1222  std::ostream & operator<<( std::ostream & str, const RepoInfo::GpgCheck & obj )
1223  {
1224  switch ( obj )
1225  {
1226 #define OUTS( V ) case RepoInfo::V: return str << #V; break
1227  OUTS( GpgCheck::On );
1228  OUTS( GpgCheck::Strict );
1229  OUTS( GpgCheck::AllowUnsigned );
1230  OUTS( GpgCheck::AllowUnsignedRepo );
1231  OUTS( GpgCheck::AllowUnsignedPackage );
1233  OUTS( GpgCheck::Off );
1234  OUTS( GpgCheck::indeterminate );
1235 #undef OUTS
1236  }
1237  return str << "GpgCheck::UNKNOWN";
1238  }
1239 
1241  {
1242  // We skip the check for downloading media unless a local copy of the
1243  // media file exists and states that there is more than one medium.
1244  const auto &origins = _pimpl->repoOrigins ();
1245  bool canSkipMediaCheck = std::all_of( origins.begin(), origins.end(), []( const MirroredOrigin &origin ) { return origin.authority().url().schemeIsDownloading(); });
1246  if ( canSkipMediaCheck ) {
1247  const auto &mDataPath = metadataPath();
1248  if ( not mDataPath.empty() ) {
1249  PathInfo mediafile { mDataPath/"media.1/media" };
1250  if ( mediafile.isExist() ) {
1251  repo::SUSEMediaVerifier lverifier { mediafile.path() };
1252  if ( lverifier && lverifier.totalMedia() > 1 ) {
1253  canSkipMediaCheck = false;
1254  }
1255  }
1256  }
1257  }
1258  if ( canSkipMediaCheck )
1259  DBG << "Can SKIP media.1/media check for status calc of repo " << alias() << endl;
1260  return not canSkipMediaCheck;
1261  }
1262 
1263  bool RepoInfo::hasExtraValue( const std::string & key_r ) const
1264  { return _pimpl->hasExtraValue( key_r ); }
1265 
1266  std::string RepoInfo::extraValue( const std::string & key_r ) const
1267  { return _pimpl->extraValue( key_r ); }
1268 
1269  bool RepoInfo::setExtraValue( const std::string & key_r, std::string value_r )
1270  { return _pimpl->setExtraValue( key_r, std::move(value_r) ); }
1271 
1272 
1274 } // namespace zypp
static const Locale noCode
Empty code.
Definition: Locale.h:75
std::map< std::string, std::string > _extraValues
Basically raw .repo file key-value lines.
Definition: RepoInfo.cc:517
const RepoVariablesReplacedUrl & mirrorListUrl() const
THE mirrorListUrl to work with (either_cfgMirrorlistUrl or _cfgMetalinkUrl)
Definition: RepoInfo.cc:451
Pathname filepath() const
File where this repo was read from.
static const ContentType repoRefreshMirrorlist
const RepoVariablesReplacedUrl & cfgMirrorlistUrl() const
Config file writing needs to tell them appart.
Definition: RepoInfo.cc:461
void setBaseUrl(Url url)
Clears current base URL list and adds url.
Definition: RepoInfo.cc:777
Pathname path() const
Repository path.
Definition: RepoInfo.cc:879
unsigned priority() const
Repository priority for solver.
Definition: RepoInfo.cc:610
#define MIL
Definition: Logger.h:103
bool hasLicense() const
Whether there is a license associated with the repo.
Definition: RepoInfo.cc:928
url_set gpgKeyUrls() const
The list of gpgkey URLs defined for this repo.
Definition: RepoInfo.cc:861
ZYPP_API detail::EscapedString escape(const std::string &in_r)
Escape xml special charaters (& -> &; from IoBind library).
Definition: XmlEscape.h:51
void setGpgKeyUrl(const Url &gpgkey)
(leagcy API) Set the gpgkey URL defined for this repo
Definition: RepoInfo.cc:758
static unsigned defaultPriority()
The default priority (99).
Definition: RepoInfo.cc:613
Url rawGpgKeyUrl() const
(leagcy API) The 1st raw gpgkey URL defined for this repo (no variables replaced) ...
Definition: RepoInfo.cc:870
Url rawUrl() const
Pars pro toto: The first repository raw url (no variables replaced) this is either rawBaseUrls()...
Definition: RepoInfo.cc:888
TriBool rawPkgGpgCheck() const
Definition: RepoInfo.cc:429
const std::set< std::string > & contentKeywords() const
Content keywords defined.
Definition: RepoInfo.cc:914
std::chrono::steady_clock::time_point _lastMirrorUrlsUpdate
Definition: RepoInfo.cc:575
Implementation of the traditional SUSE media verifier.
Namespace intended to collect all environment variables we use.
void packagesPath(Pathname new_r)
Definition: RepoInfo.cc:476
void setQueryParam(const std::string &param, const std::string &value)
Set or add value for the specified query parameter.
Definition: Url.cc:903
zypp::RepoInfo RepoInfo
Definition: repomanager.h:38
static ZConfig & instance()
Singleton ctor.
Definition: ZConfig.cc:756
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:882
bool IamNotRoot()
Definition: PathInfo.h:42
bool usesAutoMetadataPaths() const
Definition: RepoInfo.cc:487
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:806
void setPriority(unsigned newval_r)
Set repository priority for solver.
Definition: RepoInfo.cc:619
zypp::Url propagateQueryParams(zypp::Url url_r, const zypp::Url &template_r)
Definition: curlhelper.cc:432
Pathname systemPackagesPath() const
Returns a path to the system-defined package cache.
Definition: RepoInfo.cc:837
void forDumpableExtraValues(Fnc &&fnc_r) const
Filter discarding not dumpable extra values.
Definition: RepoInfo.cc:549
RawConstIterator rawBegin() const
MirroredOriginSet repoOrigins() const
The repodata origins.
Definition: RepoInfo.cc:790
int readlink(const Pathname &symlink_r, Pathname &target_r)
Like &#39;readlink&#39;.
Definition: PathInfo.cc:943
std::string asString(const Patch::Category &obj)
relates: Patch::Category string representation.
Definition: Patch.cc:122
void rawGpgCheck(TriBool val_r)
Definition: RepoInfo.cc:431
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: RepoInfo.h:655
Url rawCfgMetalinkUrl() const
The configured raw metalink url.
Definition: RepoInfo.cc:743
void addAuthorityEndpoint(OriginEndpoint endpoint)
Adds a single endpoint as an authority, routing it to the correct MirroredOrigin. ...
RepoVariablesReplacedUrl _cfgMirrorlistUrl
Definition: RepoInfo.cc:447
std::unordered_set< Locale > LocaleSet
Definition: Locale.h:29
const char * c_str() const
String representation.
Definition: Pathname.h:113
bool pkgGpgCheckIsMandatory() const
Mandatory check (pkgGpgCheck is not off) must ask to confirm using unsigned packages.
Definition: RepoInfo.cc:651
int forEachLine(std::istream &str_r, const function< bool(int, std::string)> &consume_r)
Simple lineparser: Call functor consume_r for each line.
Definition: IOStream.cc:100
url_set rawGpgKeyUrls() const
The list of raw gpgkey URLs defined for this repo (no variables replaced)
Definition: RepoInfo.cc:864
String related utilities and Regular expression matching.
bool hasContent() const
Definition: RepoInfo.cc:296
What is known about a repository.
Definition: RepoInfo.h:71
bool hasExtraValue(const std::string &key_r) const
Definition: RepoInfo.cc:535
static bool warning(const std::string &msg_r, const UserData &userData_r=UserData())
send warning text
void setGpgCheck(TriBool value_r)
Set the value for gpgCheck (or indeterminate to use the default).
Definition: RepoInfo.cc:626
TriBool _rawPkgGpgCheck
need to check pkg sign.: Y/N/(ZConf(Y/N/gpgCheck))
Definition: RepoInfo.cc:424
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
std::string receiveLine()
Read one line from the input stream.
Request the standard behavior (as defined in zypp.conf or &#39;Job&#39;)
std::string basename() const
Return the last component of this path.
Definition: Pathname.h:137
const RepoVariablesReplacedUrl & cfgMetalinkUrl() const
Config file writing needs to tell them appart.
Definition: RepoInfo.cc:464
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition: String.cc:39
bool enabled() const
If enabled is false, then this repository must be ignored as if does not exists, except when checking...
void internalSetValidRepoSignature(TriBool value_r)
Definition: RepoInfo.cc:362
Url gpgKeyUrl() const
(leagcy API) The 1st gpgkey URL defined for this repo
Definition: RepoInfo.cc:867
RepoVariablesReplacedUrl baseUrl() const
Definition: RepoInfo.cc:169
TriBool internalValidRepoSignature() const
Signature check result needs to be stored/retrieved from _metadataPath.
Definition: RepoInfo.cc:348
#define OUTS(T, B)
const Transformator & transformator() const
Return the transformator.
bool repoGpgCheck() const
Whether the signature of repo metadata should be checked for this repo.
Definition: RepoInfo.cc:633
bool triBoolFromPath(const Pathname &path_r, TriBool &ret_r) const
Definition: RepoInfo.cc:390
const_iterator begin() const
Iterator pointing to the first result.
Definition: Glob.h:197
void setValidRepoSignature(TriBool value_r)
Set the value for validRepoSignature (or indeterminate if unsigned).
Definition: RepoInfo.cc:673
urls_const_iterator baseUrlsBegin() const
iterator that points at begin of repository urls
Definition: RepoInfo.cc:894
bool seekToNode(int depth_r, const std::string &name_r)
Definition: Reader.cc:194
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
Definition: String.h:31
bool baseUrlsEmpty() const
whether repository urls are available
Definition: RepoInfo.cc:903
bool emptyOrRoot() const
Test for "" or "/".
Definition: Pathname.h:127
size_type size() const
Definition: String.h:109
void setMirrorlistUrl(const Url &url)
Set the raw mirrorlist url.
Definition: RepoInfo.cc:734
std::string extraValue(const std::string &key_r) const
Return extra value for key_r or throws std::out_of_range.
Definition: RepoInfo.cc:1266
Pathname _metadataPath
Definition: RepoInfo.cc:568
const std::string & asString() const
Definition: RepoType.cc:56
MirroredOriginSet repoOrigins() const
Definition: RepoInfo.cc:255
RepoVariablesReplacedUrlList _baseUrls
baseUrls as configured
Definition: RepoInfo.cc:572
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:215
Url url() const
Pars pro toto: The first repository url, this is either baseUrls().front() or if no baseUrl is define...
Definition: RepoInfo.cc:909
Url mirrorListUrl() const
Url of a file which contains a list of repository urls.
Definition: RepoInfo.cc:849
RepoInfo implementation.
Definition: RepoInfo.cc:104
bool empty() const
Test for an empty path.
Definition: Pathname.h:117
void setPathName(const std::string &path, EEncoding eflag=zypp::url::E_DECODED)
Set the path name.
Definition: Url.cc:791
bool keepPackages() const
Whether packages downloaded from this repository will be kept in local cache.
Definition: RepoInfo.cc:828
unsigned split(const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=" \, const Trim trim_r=NO_TRIM)
Split line_r into words.
Definition: String.h:602
std::string asString() const
Returns a default string representation of the Url object.
Definition: Url.cc:524
const Container & raw() const
Get the raw value.
void resetMirrorUrls() const
Definition: RepoInfo.cc:190
bool gpgKeyUrlsEmpty() const
Whether gpgkey URLs are defined.
Definition: RepoInfo.cc:855
Url rawCfgMirrorlistUrl() const
The configured raw mirrorlist url.
Definition: RepoInfo.cc:740
filesystem::Pathname XDG_CACHE_HOME()
XDG_CACHE_HOME: base directory relative to which user specific non-essential data files should be sto...
Definition: RepoInfo.cc:83
GpgCheck
Some predefined settings.
Definition: RepoInfo.h:422
TriBool pkgGpgCheck() const
Check rpm package signatures (indeterminate - according to gpgcheck)
Definition: ZConfig.cc:1058
std::string repoStatusString() const
Definition: RepoInfo.cc:281
bool pkgGpgCheck() const
Whether the signature of rpm packages should be checked for this repo.
Definition: RepoInfo.cc:648
bool setExtraValue(const std::string &key_r, std::string value_r)
Definition: RepoInfo.cc:541
Pathname packagesPath() const
Definition: RepoInfo.cc:504
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
bool set(const std::string &key_r, AnyType val_r)
Set the value for key (nonconst version always returns true).
Definition: UserData.h:119
bool repoGpgCheckIsMandatory() const
Mandatory check (repoGpgCheck is on) must ask to confirm using unsigned repos.
Definition: RepoInfo.cc:636
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
RepoVariablesReplacedUrlList & baseUrls()
Definition: RepoInfo.cc:268
void setRepoGpgCheck(TriBool value_r)
Set the value for repoGpgCheck (or indeterminate to use the default).
Definition: RepoInfo.cc:644
const std::string & asString() const
String representation.
Definition: Pathname.h:94
TriBool triBoolFromPath(const Pathname &path_r) const
Definition: RepoInfo.cc:416
std::string alias() const
unique identifier for this source.
bool isExist() const
Return whether valid stat info exists.
Definition: PathInfo.h:286
std::string escape(const C_Str &str_r, const char sep_r)
Escape desired character c using a backslash.
Definition: String.cc:374
std::string extraValue(const std::string &key_r) const
Definition: RepoInfo.cc:538
void addContent(const std::string &keyword_r)
Definition: RepoInfo.cc:293
bool gpgCheck() const
Turn signature checking on/off (on)
Definition: ZConfig.cc:1056
Convenience char* constructible from std::string and char*, it maps (char*)0 to an empty string...
Definition: String.h:91
std::optional< Pathname > _alternatePackagesPath
in case _packagesPath is not writable
Definition: RepoInfo.cc:570
Url rawMirrorListUrl() const
The raw mirrorListUrl (no variables replaced).
Definition: RepoInfo.cc:852
void setPath(const Pathname &path)
set the product path.
Definition: RepoInfo.cc:800
TriBool validRepoSignature() const
Whether the repo metadata are signed and successfully validated or indeterminate if unsigned...
Definition: RepoInfo.cc:666
Pathname dirname() const
Return all but the last component od this path.
Definition: Pathname.h:133
LocaleSet getLicenseLocales() const
Return the locales the license is available for.
Definition: RepoInfo.cc:1014
void setService(const std::string &name)
sets service which added this repository
Definition: RepoInfo.cc:822
#define WAR
Definition: Logger.h:104
RepoVariablesReplacedUrl _cfgMetalinkUrl
Definition: RepoInfo.cc:448
void setMetadataPath(const Pathname &path)
Set the path where the local metadata is stored.
Definition: RepoInfo.cc:810
bool baseUrlSet() const
Whether there are manualy configured repository urls.
Definition: RepoInfo.cc:906
RepoVariablesReplacedUrlList & gpgKeyUrls()
Definition: RepoInfo.cc:278
bool hasExtraValue(const std::string &key_r) const
Whether an extra value for key_r is set.
Definition: RepoInfo.cc:1263
bool startsWith(const C_Str &str_r, const C_Str &prefix_r)
alias for hasPrefix
Definition: String.h:1156
int close() override
Wait for the progamm to complete.
void getRawGpgChecks(TriBool &g_r, TriBool &r_r, TriBool &p_r) const
Raw values for RepoManager.
Definition: RepoInfo.cc:658
void setType(const repo::RepoType &t)
set the repository type
Definition: RepoInfo.cc:803
TriBool repoGpgCheck() const
Check repo matadata signatures (indeterminate - according to gpgcheck)
Definition: ZConfig.cc:1057
bool gpgCheck() const
Whether default signature checking should be performed.
Definition: RepoInfo.cc:623
TriBool _rawGpgCheck
default gpgcheck behavior: Y/N/ZConf
Definition: RepoInfo.cc:422
bool repoOriginsEmpty() const
whether repo origins are available
Definition: RepoInfo.cc:795
TriBool _validRepoSignature
have signed and valid repo metadata
Definition: RepoInfo.cc:443
bool hasContent() const
Check for content keywords.
Definition: RepoInfo.cc:920
std::vector< MirroredOrigin > _repoOrigins
Definition: RepoInfo.cc:576
std::pair< FalseBool, std::set< std::string > > _keywords
Definition: RepoInfo.cc:578
Pathname predownloadPath() const
Definition: RepoInfo.cc:509
void setKeepPackages(bool keep)
Set if packaqes downloaded from this repository will be kept in local cache.
Definition: RepoInfo.cc:819
std::string getLicense(const Locale &lang_r=Locale()) const
Return the best license for the current (or a specified) locale.
Definition: RepoInfo.cc:970
bool baseurl2dump() const
Definition: RepoInfo.cc:271
bool empty() const
Whether matches were found.
Definition: Glob.h:189
Container transformed() const
Return copy with transformed variables (expensive)
TransformedType transformed() const
Return a transformed copy of the raw value.
std::string asString(const Url &url_r)
Definition: Url.cc:957
url_set::size_type urls_size_type
Definition: RepoInfo.h:109
bool seekToEndNode(int depth_r, const std::string &name_r)
Definition: Reader.cc:214
const RepoVariablesReplacedUrlList & baseUrls() const
Definition: RepoInfo.cc:179
#define _(MSG)
Definition: Gettext.h:39
TriBool cfgPkgGpgCheck() const
Definition: RepoInfo.cc:439
std::ostream & dumpOn(std::ostream &str) const override
Write a human-readable representation of this RepoInfo object into the str stream.
Definition: RepoInfo.cc:1050
std::list< Url > url_set
Definition: RepoInfo.h:108
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
relates: Capability Detailed stream output
Definition: Capability.cc:589
bool cfgGpgCheck() const
Definition: RepoInfo.cc:435
TriBool _rawRepoGpgCheck
need to check repo sign.: Y/N/(ZConf(Y/N/gpgCheck))
Definition: RepoInfo.cc:423
bool requireStatusWithMediaFile() const
Returns true if this repository requires the media.1/media file to be included in the metadata status...
Definition: RepoInfo.cc:1240
Find pathnames matching a pattern.
Definition: Glob.h:57
Pathname metadataPath() const
Path where this repo metadata was read from.
Definition: RepoInfo.cc:834
std::vector< std::string > Arguments
transform_iterator< repo::RepoVariablesUrlReplacer, url_set::const_iterator > urls_const_iterator
Definition: RepoInfo.h:110
int unlink(const Pathname &path)
Like &#39;unlink&#39;.
Definition: PathInfo.cc:719
static const RepoType NONE
Definition: RepoType.h:33
std::ostream & dumpAsXmlOn(std::ostream &str, const std::string &content="") const override
Write an XML representation of this RepoInfo object.
Definition: RepoInfo.cc:1170
static const unsigned noPriority
Definition: RepoInfo.cc:124
repo::RepoType type() const
Definition: RepoInfo.cc:135
repo::RepoType _type
Definition: RepoInfo.cc:444
Pathname predownloadPath() const
Path where this repo packages are predownloaded.
Definition: RepoInfo.cc:816
TriBool isBuiltinExtraValue(std::string_view key_r) const
Return bool whether a dumpable key_r is known; indeterminate if the key must not be dumped...
Definition: RepoInfo.cc:523
bool usesAutoMetadataPaths() const
Whether metadataPath uses AUTO% setup.
Definition: RepoInfo.cc:843
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:813
void addEndpoints(InputIterator first, InputIterator last)
A convenience method to add multiple endpoints from a range.
zypp::Url Url
Definition: url.h:15
&#39;Language[_Country]&#39; codes.
Definition: Locale.h:50
static bool urlSupportsMirrorLink(const zypp::Url &url)
void setMetalinkUrl(const Url &url)
Set the raw metalink url.
Definition: RepoInfo.cc:737
static const RepoType RPMMD
Definition: RepoType.h:30
void setGpgKeyUrls(url_set urls)
Set a list of gpgkey URLs defined for this repo.
Definition: RepoInfo.cc:755
const std::set< std::string > & contentKeywords() const
Definition: RepoInfo.cc:290
int symlink(const Pathname &oldpath, const Pathname &newpath)
Like &#39;symlink&#39;.
Definition: PathInfo.cc:874
void setProbedType(const repo::RepoType &t) const
Definition: RepoInfo.cc:129
static const RepoType YAST2
Definition: RepoType.h:31
bool hasSuffix(const C_Str &str_r, const C_Str &suffix_r)
Return whether str_r has suffix suffix_r.
Definition: String.h:1112
void rawRepoGpgCheck(TriBool val_r)
Definition: RepoInfo.cc:432
url_set rawBaseUrls() const
The complete set of raw repository urls (no variables replaced)
Definition: RepoInfo.cc:876
void setTargetDistribution(const std::string &targetDistribution)
Sets the distribution for which is this repository meant.
Definition: RepoInfo.cc:825
bool needToAcceptLicense() const
Whether the repo license has to be accepted, e.g.
Definition: RepoInfo.cc:935
const RawType & raw() const
Get the raw value.
Base class for Exception.
Definition: Exception.h:152
std::ostream & dumpAsIniOn(std::ostream &str) const override
Write this RepoInfo object into str in a .repo file format.
Definition: RepoInfo.cc:1102
Impl & operator=(const Impl &)=delete
Url location() const
Returns the location URL for the repository, this is either the first configured baseUrl or a configu...
Definition: RepoInfo.cc:891
XmlString nodeText()
If the current node is not empty, advances the reader to the next node, and returns the value...
Definition: Reader.cc:122
void addBaseUrl(Url url)
Add a base url.
Definition: RepoInfo.cc:767
void setMirrorlistUrl(const Url &url_r)
Definition: RepoInfo.cc:454
const RepoVariablesReplacedUrlList & gpgKeyUrls() const
Definition: RepoInfo.cc:275
bool sameTriboolState(tribool lhs, tribool rhs)
relates: TriBool whether 2 tribool have the same state (this is NOT ==)
Definition: TriBool.h:74
std::string name() const
Repository name.
void pathNameSetTrailingSlash(bool apply_r=true)
Apply or remove a trailing &#39;/&#39; from pathName.
Definition: Url.cc:838
std::string asString() const
Explicit conversion to std::string.
Definition: XmlString.h:77
Pathname licenseTgz(const std::string &name_r) const
Path to a license tarball in case it exists in the repo.
Definition: RepoInfo.cc:144
bool userMayWriteOrCreateDir(const Pathname &path_r)
Returns whether path_r denotes an existing directory with write permission for the current user or an...
Definition: PathInfo.cc:306
TransformedConstIterator transformedBegin() const
void setType(const repo::RepoType &t)
Definition: RepoInfo.cc:126
bool internalUnsignedConfirmed() const
We definitely have a symlink pointing to "indeterminate" (for repoGpgCheckIsMandatory)? I.e.
Definition: RepoInfo.cc:384
RepoVariablesReplacedUrlList _gpgKeyUrls
Definition: RepoInfo.cc:580
Typesafe passing of user data via callbacks.
Definition: UserData.h:39
TriBool rawRepoGpgCheck() const
Definition: RepoInfo.cc:428
TransformedConstIterator transformedEnd() const
DefaultIntegral< unsigned, defaultPriority > priority
Definition: RepoInfo.cc:514
std::string targetDistribution() const
Distribution for which is this repository meant.
Definition: RepoInfo.cc:885
base::ValueTransform< Url, repo::RepoVariablesUrlReplacer > RepoVariablesReplacedUrl
relates: RepoVariablesUrlReplacer Helper managing repo variables replaced urls
Pathname packagesPath() const
packagesPath Checks if the effective user is allowed to write into the system package cache...
Definition: RepoInfo.cc:840
void setBaseUrls(url_set urls)
Clears current base URL list and adds an url_set.
Definition: RepoInfo.cc:784
std::string targetDistro
Definition: RepoInfo.cc:471
Wrapper class for ::stat/::lstat.
Definition: PathInfo.h:225
~RepoInfo() override
Definition: RepoInfo.cc:607
static const RepoInfo noRepo
Represents no Repository (one with an empty alias).
Definition: RepoInfo.h:85
std::string repoStatusString() const
A string value to track changes requiring a refresh.
Definition: RepoInfo.cc:764
urls_const_iterator baseUrlsEnd() const
iterator that points at end of repository urls
Definition: RepoInfo.cc:897
void addContent(const std::string &keyword_r)
Add content keywords.
Definition: RepoInfo.cc:917
void clear()
Clear the container.
void rawPkgGpgCheck(TriBool val_r)
Definition: RepoInfo.cc:433
static const RepoType RPMPLAINDIR
Definition: RepoType.h:32
bool autorefresh() const
If true, the repostory must be refreshed before creating resolvables from it.
urls_size_type baseUrlsSize() const
number of repository urls
Definition: RepoInfo.cc:900
void setMetalinkUrl(const Url &url_r)
Definition: RepoInfo.cc:457
std::ostream & operator<<(std::ostream &str, const Capabilities &obj)
relates: Capabilities Stream output
Definition: Capabilities.cc:65
const std::vector< Url > & getUrls() const
urls_size_type gpgKeyUrlsSize() const
Number of gpgkey URLs defined.
Definition: RepoInfo.cc:858
Pathname metadataPath() const
Definition: RepoInfo.cc:490
TriBool rawGpgCheck() const
Definition: RepoInfo.cc:427
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
Pathname systemPackagesPath() const
Definition: RepoInfo.cc:497
Represents a single, configurable network endpoint, combining a URL with specific access settings...
static const unsigned defaultPriority
Definition: RepoInfo.cc:123
RepoVariablesReplacedUrlList _mirrorUrls
possible mirrors as fetched via mirrorlist or metalink
Definition: RepoInfo.cc:574
Impl * clone() const
clone for RWCOW_pointer
Definition: RepoInfo.cc:584
static unsigned noPriority()
The least priority (unsigned(-1)).
Definition: RepoInfo.cc:616
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
Definition: String.h:1098
RepoVariablesReplacedUrlList & mirrorUrls() const
Fetch the repo mirrors from the server.
Definition: RepoInfo.cc:200
url_set baseUrls() const
The complete set of repository urls as configured.
Definition: RepoInfo.cc:873
void setPkgGpgCheck(TriBool value_r)
Set the value for pkgGpgCheck (or indeterminate to use the default).
Definition: RepoInfo.cc:654
repo::RepoType type() const
Type of repository,.
Definition: RepoInfo.cc:846
TriBool cfgRepoGpgCheck() const
Definition: RepoInfo.cc:437
const char * c_str() const
Definition: IdStringType.h:115
Pathname _packagesPath
Definition: RepoInfo.cc:569
bool effectiveKeepPackages() const
keepPackages unless the package cache itself enforces keeping the packages.
Definition: RepoInfo.cc:831
Url location() const
Definition: RepoInfo.cc:184
bool setExtraValue(const std::string &key_r, std::string value_r)
Remember extra value_r for key_r.
Definition: RepoInfo.cc:1269
Url manipulation class.
Definition: Url.h:92
void metadataPath(Pathname new_r)
Definition: RepoInfo.cc:473
A smart container that manages a collection of MirroredOrigin objects, automatically grouping endpoin...
#define DBG
Definition: Logger.h:102
std::string service
Definition: RepoInfo.cc:470
Repository type enumeration.
Definition: RepoType.h:28
bool hasContent(const std::string &keyword_r) const
Definition: RepoInfo.cc:341