libzypp  17.38.17
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 
380  bool triBoolFromPath( const Pathname & path_r, TriBool & ret_r ) const
381  {
382  static const Pathname truePath( "true" );
383  static const Pathname falsePath( "false" );
384  static const Pathname indeterminatePath( "indeterminate" );
385 
386  // Quiet readlink;
387  static const ssize_t bufsiz = 63;
388  static char buf[bufsiz+1];
389  ssize_t ret = ::readlink( path_r.c_str(), buf, bufsiz );
390  buf[ret == -1 ? 0 : ret] = '\0';
391 
392  Pathname linkval( buf );
393 
394  bool known = true;
395  if ( linkval == truePath )
396  ret_r = true;
397  else if ( linkval == falsePath )
398  ret_r = false;
399  else if ( linkval == indeterminatePath )
400  ret_r = indeterminate;
401  else
402  known = false;
403  return known;
404  }
405 
406  TriBool triBoolFromPath( const Pathname & path_r ) const
407  { TriBool ret(indeterminate); triBoolFromPath( path_r, ret ); return ret; }
408 
410 
411  private:
415 
416  public:
417  TriBool rawGpgCheck() const { return _rawGpgCheck; }
420 
421  void rawGpgCheck( TriBool val_r ) { _rawGpgCheck = val_r; }
422  void rawRepoGpgCheck( TriBool val_r ) { _rawRepoGpgCheck = val_r; }
423  void rawPkgGpgCheck( TriBool val_r ) { _rawPkgGpgCheck = val_r; }
424 
425  bool cfgGpgCheck() const
426  { return indeterminate(_rawGpgCheck) ? ZConfig::instance().gpgCheck() : (bool)_rawGpgCheck; }
428  { return indeterminate(_rawGpgCheck) && indeterminate(_rawRepoGpgCheck) ? ZConfig::instance().repoGpgCheck() : _rawRepoGpgCheck; }
430  { return indeterminate(_rawGpgCheck) && indeterminate(_rawPkgGpgCheck) ? ZConfig::instance().pkgGpgCheck() : _rawPkgGpgCheck; }
431 
432  private:
435 
436  private:
439  public:
443 
444  void setMirrorlistUrl( const Url & url_r ) // Raw
445  { _cfgMirrorlistUrl.raw() = url_r; }
446 
447  void setMetalinkUrl( const Url & url_r ) // Raw
448  { _cfgMetalinkUrl.raw() = url_r; }
449 
452  { return _cfgMirrorlistUrl; }
455  { return _cfgMetalinkUrl; }
456 
457  public:
460  std::string service;
461  std::string targetDistro;
462 
463  void metadataPath( Pathname new_r )
464  { _metadataPath = std::move( new_r ); }
465 
466  void packagesPath( Pathname new_r )
467  {
468  _packagesPath = std::move( new_r );
471  WAR << "systemPackagesPath " << _packagesPath << " is not user writable, may use " << *_alternatePackagesPath << endl;
472  } else {
473  _alternatePackagesPath.reset();
474  }
475  }
476 
478  { return str::hasSuffix( _metadataPath.asString(), "/%AUTO%" ); }
479 
481  {
482  if ( usesAutoMetadataPaths() )
483  return _metadataPath.dirname() / "%RAW%";
484  return _metadataPath;
485  }
486 
488  {
490  return _metadataPath.dirname() / "%PKG%";
491  return _packagesPath;
492  }
493 
495  {
497  }
498 
500  {
501  return packagesPath() / ".preload";
502  }
503 
505 
506  public:
507  std::map<std::string,std::string> _extraValues;
508 
513  TriBool isBuiltinExtraValue( std::string_view key_r ) const
514  {
515  static const std::set<std::string_view> _builtins { {
516  "repo_sigcheck_plugin",
517  } };
518  if ( _builtins.count( key_r ) )
519  return true;
520  if ( key_r.find( '=' ) == std::string::npos )
521  return false;
522  return indeterminate;
523  }
524 
525  bool hasExtraValue( const std::string & key_r ) const
526  { return _extraValues.count( key_r ); }
527 
528  std::string extraValue( const std::string & key_r ) const
529  { return _extraValues.at( key_r ); } // let it throw
530 
531  bool setExtraValue( const std::string & key_r, std::string value_r )
532  {
533  _extraValues[key_r] = std::move(value_r);
534  return bool(isBuiltinExtraValue( key_r ));
535  }
536 
538  template <typename Fnc>
539  void forDumpableExtraValues( Fnc && fnc_r ) const
540  {
541  for ( const auto & [k,v] : _extraValues ) {
542  TriBool dumpable = isBuiltinExtraValue( k );
543  if ( indeterminate(dumpable) )
544  continue;
545  if constexpr ( std::is_invocable_v<Fnc, std::string_view, std::string_view, bool> ) {
546  fnc_r( k, v, bool(dumpable) );
547  }
548  else if constexpr ( std::is_invocable_v<Fnc, std::string_view, std::string_view> ) {
549  fnc_r( k, v );
550  }
551  else {
552  static_assert( zyppng::always_false_v<Fnc>, "Lambda must accept (k, v) or (k, v, b)" );
553  }
554  }
555  }
556 
557  private:
560  std::optional<Pathname> _alternatePackagesPath;
561 
563 
565  mutable std::chrono::steady_clock::time_point _lastMirrorUrlsUpdate = std::chrono::steady_clock::time_point::min();
566  mutable std::vector<MirroredOrigin> _repoOrigins;
567 
568  mutable std::pair<FalseBool, std::set<std::string> > _keywords;
569 
571 
572  friend Impl * rwcowClone<Impl>( const Impl * rhs );
574  Impl * clone() const
575  { return new Impl( *this ); }
576  };
578 
580  inline std::ostream & operator<<( std::ostream & str, const RepoInfo::Impl & obj )
581  {
582  return str << "RepoInfo::Impl";
583  }
584 
586  //
587  // CLASS NAME : RepoInfo
588  //
590 
592 
594  : _pimpl( new Impl() )
595  {}
596 
598  {}
599 
600  unsigned RepoInfo::priority() const
601  { return _pimpl->priority; }
602 
604  { return Impl::defaultPriority; }
605 
607  { return Impl::noPriority; }
608 
609  void RepoInfo::setPriority( unsigned newval_r )
610  { _pimpl->priority = newval_r ? newval_r : Impl::defaultPriority; }
611 
612 
613  bool RepoInfo::gpgCheck() const
614  { return _pimpl->cfgGpgCheck(); }
615 
617  { _pimpl->rawGpgCheck( value_r ); }
618 
619  void RepoInfo::setGpgCheck( bool value_r ) // deprecated legacy and for squid
620  { setGpgCheck( TriBool(value_r) ); }
621 
622 
624  { return gpgCheck() || bool(_pimpl->cfgRepoGpgCheck()); }
625 
626  bool RepoInfo::repoGpgCheckIsMandatory() const // may be omitted only if cfgRepoGpgCheck is explicitly false (unsigned-ok)
627  { return ( gpgCheck() && indeterminate(_pimpl->cfgRepoGpgCheck()) ) || bool(_pimpl->cfgRepoGpgCheck()); }
628 
630  { _pimpl->rawRepoGpgCheck( value_r ); }
631 
632 
634  { return bool(_pimpl->cfgPkgGpgCheck()) || ( gpgCheck() && !bool(validRepoSignature())/*enforced*/ ) ; }
635 
637  { return bool(_pimpl->cfgPkgGpgCheck()) || ( gpgCheck() && indeterminate(_pimpl->cfgPkgGpgCheck()) && !bool(validRepoSignature())/*enforced*/ ); }
638 
640  { _pimpl->rawPkgGpgCheck( value_r ); }
641 
642 
643  void RepoInfo::getRawGpgChecks( TriBool & g_r, TriBool & r_r, TriBool & p_r ) const
644  {
645  g_r = _pimpl->rawGpgCheck();
646  r_r = _pimpl->rawRepoGpgCheck();
647  p_r = _pimpl->rawPkgGpgCheck();
648  }
649 
650 
652  {
654  if ( ret && !repoGpgCheck() ) ret = false; // invalidate any old signature if repoGpgCheck is off
655  return ret;
656  }
657 
659  { _pimpl->internalSetValidRepoSignature( value_r ); }
660 
662  namespace
663  {
664  inline bool changeGpgCheckTo( TriBool & lhs, TriBool rhs )
665  { if ( ! sameTriboolState( lhs, rhs ) ) { lhs = rhs; return true; } return false; }
666 
667  inline bool changeGpgCheckTo( TriBool ogpg[3], TriBool g, TriBool r, TriBool p )
668  {
669  bool changed = false;
670  if ( changeGpgCheckTo( ogpg[0], g ) ) changed = true;
671  if ( changeGpgCheckTo( ogpg[1], r ) ) changed = true;
672  if ( changeGpgCheckTo( ogpg[2], p ) ) changed = true;
673  return changed;
674  }
675  } // namespace
678  {
679  TriBool ogpg[3]; // Gpg RepoGpg PkgGpg
680  getRawGpgChecks( ogpg[0], ogpg[1], ogpg[2] );
681 
682  bool changed = false;
683  switch ( mode_r )
684  {
685  case GpgCheck::On:
686  changed = changeGpgCheckTo( ogpg, true, indeterminate, indeterminate );
687  break;
688  case GpgCheck::Strict:
689  changed = changeGpgCheckTo( ogpg, true, true, true );
690  break;
692  changed = changeGpgCheckTo( ogpg, true, false, false );
693  break;
695  changed = changeGpgCheckTo( ogpg, true, false, indeterminate );
696  break;
698  changed = changeGpgCheckTo( ogpg, true, indeterminate, false );
699  break;
700  case GpgCheck::Default:
701  changed = changeGpgCheckTo( ogpg, indeterminate, indeterminate, indeterminate );
702  break;
703  case GpgCheck::Off:
704  changed = changeGpgCheckTo( ogpg, false, indeterminate, indeterminate );
705  break;
706  case GpgCheck::indeterminate: // no change
707  break;
708  }
709 
710  if ( changed )
711  {
712  setGpgCheck ( ogpg[0] );
713  setRepoGpgCheck( ogpg[1] );
714  setPkgGpgCheck ( ogpg[2] );
715  }
716  return changed;
717  }
718 
719  void RepoInfo::setMirrorlistUrl( const Url & url_r ) // Raw
720  { _pimpl->setMirrorlistUrl( url_r ); }
721 
722  void RepoInfo::setMetalinkUrl( const Url & url_r ) // Raw
723  { _pimpl->setMetalinkUrl( url_r ); }
724 
726  { return _pimpl->cfgMirrorlistUrl().raw(); }
727 
729  { return _pimpl->cfgMetalinkUrl().raw(); }
730 
731 #if LEGACY(1735)
732  void RepoInfo::setMirrorListUrl( const Url & url_r ) // Raw
733  { setMirrorlistUrl( url_r ); }
734  void RepoInfo::setMirrorListUrls( url_set urls ) // Raw
735  { _pimpl->setMirrorlistUrl( urls.empty() ? Url() : urls.front() ); }
736  void RepoInfo::setMetalinkUrls( url_set urls ) // Raw
737  { _pimpl->setMetalinkUrl( urls.empty() ? Url() : urls.front() ); }
738 #endif
739 
741  { _pimpl->gpgKeyUrls().raw().swap( urls ); }
742 
743  void RepoInfo::setGpgKeyUrl( const Url & url_r )
744  {
745  _pimpl->gpgKeyUrls().raw().clear();
746  _pimpl->gpgKeyUrls().raw().push_back( url_r );
747  }
748 
749  std::string RepoInfo::repoStatusString() const
750  { return _pimpl->repoStatusString(); }
751 
752  void RepoInfo::addBaseUrl( Url url_r )
753  {
754  for ( const auto & url : _pimpl->baseUrls().raw() ) // Raw unique!
755  if ( url == url_r )
756  return;
757 
758  _pimpl->baseUrls().raw().push_back( url_r );
760  }
761 
762  void RepoInfo::setBaseUrl( Url url_r )
763  {
764  _pimpl->baseUrls().raw().clear();
766  _pimpl->baseUrls().raw().push_back( std::move(url_r) );
767  }
768 
770  {
772  _pimpl->baseUrls().raw().swap( urls );
773  }
774 
776  {
777  return _pimpl->repoOrigins();
778  }
779 
781  {
782  return ( _pimpl->baseUrls().empty () && _pimpl->mirrorUrls().empty() );
783  }
784 
785  void RepoInfo::setPath( const Pathname &path )
786  { _pimpl->_path = path.absolutename(); /* must not refer to ../ */ }
787 
789  { _pimpl->setType( t ); }
790 
792  { _pimpl->setProbedType( t ); }
793 
794 
796  { _pimpl->metadataPath( path ); }
797 
799  { _pimpl->packagesPath( path ); }
800 
802  { return _pimpl->predownloadPath(); }
803 
804  void RepoInfo::setKeepPackages( bool keep )
805  { _pimpl->keeppackages = keep; }
806 
807  void RepoInfo::setService( const std::string& name )
808  { _pimpl->service = name; }
809 
810  void RepoInfo::setTargetDistribution( const std::string & targetDistribution )
812 
814  { return indeterminate(_pimpl->keeppackages) ? false : (bool)_pimpl->keeppackages; }
815 
817  { return keepPackages() || PathInfo(packagesPath().dirname()/".keep_packages").isExist(); }
818 
820  { return _pimpl->metadataPath(); }
821 
823  { return _pimpl->systemPackagesPath(); }
824 
826  { return _pimpl->packagesPath(); }
827 
829  { return _pimpl->usesAutoMetadataPaths(); }
830 
832  { return _pimpl->type(); }
833 
834  Url RepoInfo::mirrorListUrl() const // Variables replaced!
835  { return _pimpl->mirrorListUrl().transformed(); }
836 
838  { return _pimpl->mirrorListUrl().raw(); }
839 
841  { return _pimpl->gpgKeyUrls().empty(); }
842 
844  { return _pimpl->gpgKeyUrls().size(); }
845 
846  RepoInfo::url_set RepoInfo::gpgKeyUrls() const // Variables replaced!
847  { return _pimpl->gpgKeyUrls().transformed(); }
848 
850  { return _pimpl->gpgKeyUrls().raw(); }
851 
852  Url RepoInfo::gpgKeyUrl() const // Variables replaced!
853  { return( _pimpl->gpgKeyUrls().empty() ? Url() : *_pimpl->gpgKeyUrls().transformedBegin() ); }
854 
856  { return( _pimpl->gpgKeyUrls().empty() ? Url() : *_pimpl->gpgKeyUrls().rawBegin() ) ; }
857 
858  RepoInfo::url_set RepoInfo::baseUrls() const // Variables replaced!
859  { return _pimpl->baseUrls().transformed(); }
860 
862  { return _pimpl->baseUrls().raw(); }
863 
865  { return _pimpl->_path; }
866 
867  std::string RepoInfo::service() const
868  { return _pimpl->service; }
869 
870  std::string RepoInfo::targetDistribution() const
871  { return _pimpl->targetDistro; }
872 
874  { return _pimpl->baseUrl().raw(); }
875 
877  { return _pimpl->location (); }
878 
880  { return _pimpl->baseUrls().transformedBegin(); }
881 
883  { return _pimpl->baseUrls().transformedEnd(); }
884 
886  { return _pimpl->baseUrls().size(); }
887 
889  { return _pimpl->baseUrls().empty(); }
890 
891  bool RepoInfo::baseUrlSet() const
892  { return _pimpl->baseurl2dump(); }
893 
895  {
896  return _pimpl->baseUrl().transformed();
897  }
898 
899  const std::set<std::string> & RepoInfo::contentKeywords() const
900  { return _pimpl->contentKeywords(); }
901 
902  void RepoInfo::addContent( const std::string & keyword_r )
903  { _pimpl->addContent( keyword_r ); }
904 
905  bool RepoInfo::hasContent() const
906  { return _pimpl->hasContent(); }
907 
908  bool RepoInfo::hasContent( const std::string & keyword_r ) const
909  { return _pimpl->hasContent( keyword_r ); }
910 
912 
913  bool RepoInfo::hasLicense() const
914  { return hasLicense( std::string() ); }
915 
916  bool RepoInfo::hasLicense( const std::string & name_r ) const
917  { return !_pimpl->licenseTgz( name_r ).empty(); }
918 
919 
921  { return needToAcceptLicense( std::string() ); }
922 
923  bool RepoInfo::needToAcceptLicense( const std::string & name_r ) const
924  {
925  const Pathname & licenseTgz( _pimpl->licenseTgz( name_r ) );
926  if ( licenseTgz.empty() )
927  return false; // no licenses at all
928 
930  cmd.push_back( "tar" );
931  cmd.push_back( "-t" );
932  cmd.push_back( "-z" );
933  cmd.push_back( "-f" );
934  cmd.push_back( licenseTgz.asString() );
936 
937  bool accept = true;
938  static const std::string noAcceptanceFile = "no-acceptance-needed\n";
939  for ( std::string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() )
940  {
941  if ( output == noAcceptanceFile )
942  {
943  accept = false;
944  }
945  }
946  prog.close();
947  MIL << "License(" << name_r << ") in " << name() << " has to be accepted: " << (accept?"true":"false" ) << endl;
948  return accept;
949  }
950 
951 
952  std::string RepoInfo::getLicense( const Locale & lang_r )
953  { return const_cast<const RepoInfo *>(this)->getLicense( std::string(), lang_r ); }
954 
955  std::string RepoInfo::getLicense( const Locale & lang_r ) const
956  { return getLicense( std::string(), lang_r ); }
957 
958  std::string RepoInfo::getLicense( const std::string & name_r, const Locale & lang_r ) const
959  {
960  LocaleSet avlocales( getLicenseLocales( name_r ) );
961  if ( avlocales.empty() )
962  return std::string();
963 
964  Locale getLang( Locale::bestMatch( avlocales, lang_r ) );
965  if ( !getLang && avlocales.find( Locale::noCode ) == avlocales.end() )
966  {
967  WAR << "License(" << name_r << ") in " << name() << " contains no fallback text!" << endl;
968  // Using the fist locale instead of returning no text at all.
969  // So the user might recognize that there is a license, even if they
970  // can't read it.
971  getLang = *avlocales.begin();
972  }
973 
974  // now extract the license file.
975  static const std::string licenseFileFallback( "license.txt" );
976  std::string licenseFile( !getLang ? licenseFileFallback
977  : str::form( "license.%s.txt", getLang.c_str() ) );
978 
980  cmd.push_back( "tar" );
981  cmd.push_back( "-x" );
982  cmd.push_back( "-z" );
983  cmd.push_back( "-O" );
984  cmd.push_back( "-f" );
985  cmd.push_back( _pimpl->licenseTgz( name_r ).asString() ); // if it not exists, avlocales was empty.
986  cmd.push_back( licenseFile );
987 
988  std::string ret;
990  for ( std::string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() )
991  {
992  ret += output;
993  }
994  prog.close();
995  return ret;
996  }
997 
998 
1000  { return getLicenseLocales( std::string() ); }
1001 
1002  LocaleSet RepoInfo::getLicenseLocales( const std::string & name_r ) const
1003  {
1004  const Pathname & licenseTgz( _pimpl->licenseTgz( name_r ) );
1005  if ( licenseTgz.empty() )
1006  return LocaleSet();
1007 
1009  cmd.push_back( "tar" );
1010  cmd.push_back( "-t" );
1011  cmd.push_back( "-z" );
1012  cmd.push_back( "-f" );
1013  cmd.push_back( licenseTgz.asString() );
1014 
1015  LocaleSet ret;
1017  for ( std::string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() )
1018  {
1019  static const C_Str license( "license." );
1020  static const C_Str dotTxt( ".txt\n" );
1021  if ( str::hasPrefix( output, license ) && str::hasSuffix( output, dotTxt ) )
1022  {
1023  if ( output.size() <= license.size() + dotTxt.size() ) // license.txt
1024  ret.insert( Locale() );
1025  else
1026  ret.insert( Locale( std::string( output.c_str()+license.size(), output.size()- license.size() - dotTxt.size() ) ) );
1027  }
1028  }
1029  prog.close();
1030  return ret;
1031  }
1032 
1034 
1035  std::ostream & RepoInfo::dumpOn( std::ostream & str ) const
1036  {
1038  if ( _pimpl->baseurl2dump() )
1039  {
1040  for ( const auto & url : _pimpl->baseUrls().raw() )
1041  {
1042  str << "- url : " << url << std::endl;
1043  }
1044  }
1045 
1046  // print if non empty value
1047  auto strif( [&] ( const std::string & tag_r, const std::string & value_r ) {
1048  if ( ! value_r.empty() )
1049  str << tag_r << value_r << std::endl;
1050  });
1051 
1052  strif( "- mirrorlist : ", _pimpl->cfgMirrorlistUrl().raw().asString() );
1053  strif( "- metalink : ", _pimpl->cfgMetalinkUrl().raw().asString() );
1054  strif( "- path : ", path().asString() );
1055  str << "- type : " << type() << std::endl;
1056  str << "- priority : " << priority() << std::endl;
1057 
1058  // Yes No Default(Y) Default(N)
1059 #define OUTS(T,B) ( indeterminate(T) ? (std::string("D(")+(B?"Y":"N")+")") : ((bool)T?"Y":"N") )
1060  str << "- gpgcheck : " << OUTS(_pimpl->rawGpgCheck(),gpgCheck())
1061  << " repo" << OUTS(_pimpl->rawRepoGpgCheck(),repoGpgCheck()) << (repoGpgCheckIsMandatory() ? "* ": " " )
1062  << "sig" << asString( validRepoSignature(), "?", "Y", "N" )
1063  << " pkg" << OUTS(_pimpl->rawPkgGpgCheck(),pkgGpgCheck()) << (pkgGpgCheckIsMandatory() ? "* ": " " )
1064  << std::endl;
1065 #undef OUTS
1066 
1067  for ( const auto & url : _pimpl->gpgKeyUrls().raw() )
1068  {
1069  str << "- gpgkey : " << url << std::endl;
1070  }
1071 
1072  if ( ! indeterminate(_pimpl->keeppackages) )
1073  str << "- keeppackages: " << keepPackages() << std::endl;
1074 
1075  strif( "- service : ", service() );
1076  strif( "- targetdistro: ", targetDistribution() );
1077  strif( "- filePath : ", filepath().asString() );
1078  strif( "- metadataPath: ", metadataPath().asString() );
1079  strif( "- packagesPath: ", packagesPath().asString() );
1080 
1081  _pimpl->forDumpableExtraValues( [&]( std::string_view k, std::string_view v, bool builtin_r ) {
1082  str << ( builtin_r ? "- " : "# " ) << k << ": " << v << std::endl;
1083  } );
1084  return str;
1085  }
1086 
1087  std::ostream & RepoInfo::dumpAsIniOn( std::ostream & str ) const
1088  {
1089  // libzypp/#638: Add a note to service maintained repo entries
1090  if( ! service().empty() ) {
1091  str << "# Repository '"<<alias()<<"' is maintained by the '"<<service()<<"' service." << endl;
1092  str << "# Manual changes may be overwritten by a service refresh." << endl;
1093  str << "# See also 'man zypper', section 'Services'." << endl;
1094  }
1095  RepoInfoBase::dumpAsIniOn(str);
1096 
1097  if ( _pimpl->baseurl2dump() )
1098  {
1099  str << "baseurl=";
1100  std::string indent;
1101  for ( const auto & url : _pimpl->baseUrls().raw() )
1102  {
1103  str << indent << hotfix1050625::asString( url ) << endl;
1104  if ( indent.empty() ) indent = " "; // "baseurl="
1105  }
1106  }
1107 
1108  if ( ! path().empty() )
1109  str << "path="<< path() << endl;
1110 
1111  if ( ! _pimpl->cfgMirrorlistUrl().raw().asString().empty() )
1112  str << "mirrorlist=" << hotfix1050625::asString( _pimpl->cfgMirrorlistUrl().raw() ) << endl;
1113 
1114  if ( ! _pimpl->cfgMetalinkUrl().raw().asString().empty() )
1115  str << "metalink=" << hotfix1050625::asString( _pimpl->cfgMetalinkUrl().raw() ) << endl;
1116 
1117  if ( type() != repo::RepoType::NONE )
1118  str << "type=" << type().asString() << endl;
1119 
1120  if ( priority() != defaultPriority() )
1121  str << "priority=" << priority() << endl;
1122 
1123  if ( ! indeterminate(_pimpl->rawGpgCheck()) )
1124  str << "gpgcheck=" << (_pimpl->rawGpgCheck() ? "1" : "0") << endl;
1125 
1126  if ( ! indeterminate(_pimpl->rawRepoGpgCheck()) )
1127  str << "repo_gpgcheck=" << (_pimpl->rawRepoGpgCheck() ? "1" : "0") << endl;
1128 
1129  if ( ! indeterminate(_pimpl->rawPkgGpgCheck()) )
1130  str << "pkg_gpgcheck=" << (_pimpl->rawPkgGpgCheck() ? "1" : "0") << endl;
1131 
1132  {
1133  std::string indent( "gpgkey=");
1134  for ( const auto & url : _pimpl->gpgKeyUrls().raw() )
1135  {
1136  str << indent << url << endl;
1137  if ( indent[0] != ' ' )
1138  indent = " ";
1139  }
1140  }
1141 
1142  if (!indeterminate(_pimpl->keeppackages))
1143  str << "keeppackages=" << keepPackages() << endl;
1144 
1145  if( ! service().empty() )
1146  str << "service=" << service() << endl;
1147 
1148  _pimpl->forDumpableExtraValues( [&]( std::string_view k, std::string_view v ) {
1149  str << k << "=" << v << endl;
1150  } );
1151 
1152  return str;
1153  }
1154 
1155  std::ostream & RepoInfo::dumpAsXmlOn( std::ostream & str, const std::string & content ) const
1156  {
1157  std::string tmpstr;
1158  str
1159  << "<repo"
1160  << " alias=\"" << escape(alias()) << "\""
1161  << " name=\"" << escape(name()) << "\"";
1162  if (type() != repo::RepoType::NONE)
1163  str << " type=\"" << type().asString() << "\"";
1164  str
1165  << " priority=\"" << priority() << "\""
1166  << " enabled=\"" << enabled() << "\""
1167  << " autorefresh=\"" << autorefresh() << "\""
1168  << " gpgcheck=\"" << gpgCheck() << "\""
1169  << " repo_gpgcheck=\"" << repoGpgCheck() << "\""
1170  << " pkg_gpgcheck=\"" << pkgGpgCheck() << "\"";
1171  if ( ! indeterminate(_pimpl->rawGpgCheck()) )
1172  str << " raw_gpgcheck=\"" << (_pimpl->rawGpgCheck() ? "1" : "0") << "\"";
1173  if ( ! indeterminate(_pimpl->rawRepoGpgCheck()) )
1174  str << " raw_repo_gpgcheck=\"" << (_pimpl->rawRepoGpgCheck() ? "1" : "0") << "\"";
1175  if ( ! indeterminate(_pimpl->rawPkgGpgCheck()) )
1176  str << " raw_pkg_gpgcheck=\"" << (_pimpl->rawPkgGpgCheck() ? "1" : "0") << "\"";
1177  if (!(tmpstr = gpgKeyUrl().asString()).empty())
1178  str << " gpgkey=\"" << escape(tmpstr) << "\"";
1179  if ( ! (tmpstr = _pimpl->cfgMirrorlistUrl().transformed().asString()).empty() )
1180  str << " mirrorlist=\"" << escape(tmpstr) << "\"";
1181  if ( ! (tmpstr = _pimpl->cfgMetalinkUrl().transformed().asString()).empty() )
1182  str << " metalink=\"" << escape(tmpstr) << "\"";
1183  str << ">" << endl;
1184 
1185  if ( _pimpl->baseurl2dump() )
1186  {
1187  for_( it, baseUrlsBegin(), baseUrlsEnd() ) // !transform iterator replaces variables
1188  str << "<url>" << escape((*it).asString()) << "</url>" << endl;
1189  }
1190 
1191  _pimpl->forDumpableExtraValues( [&]( std::string_view k, std::string_view v ) {
1192  str << "<extra key=\"" << escape(std::string(k)) << "\">"
1193  << escape(std::string(v))
1194  << "</extra>" << endl;
1195  } );
1196 
1197  str << "</repo>" << endl;
1198  return str;
1199  }
1200 
1201 
1202  std::ostream & operator<<( std::ostream & str, const RepoInfo & obj )
1203  {
1204  return obj.dumpOn(str);
1205  }
1206 
1207  std::ostream & operator<<( std::ostream & str, const RepoInfo::GpgCheck & obj )
1208  {
1209  switch ( obj )
1210  {
1211 #define OUTS( V ) case RepoInfo::V: return str << #V; break
1212  OUTS( GpgCheck::On );
1213  OUTS( GpgCheck::Strict );
1214  OUTS( GpgCheck::AllowUnsigned );
1215  OUTS( GpgCheck::AllowUnsignedRepo );
1216  OUTS( GpgCheck::AllowUnsignedPackage );
1218  OUTS( GpgCheck::Off );
1219  OUTS( GpgCheck::indeterminate );
1220 #undef OUTS
1221  }
1222  return str << "GpgCheck::UNKNOWN";
1223  }
1224 
1226  {
1227  // We skip the check for downloading media unless a local copy of the
1228  // media file exists and states that there is more than one medium.
1229  const auto &origins = _pimpl->repoOrigins ();
1230  bool canSkipMediaCheck = std::all_of( origins.begin(), origins.end(), []( const MirroredOrigin &origin ) { return origin.authority().url().schemeIsDownloading(); });
1231  if ( canSkipMediaCheck ) {
1232  const auto &mDataPath = metadataPath();
1233  if ( not mDataPath.empty() ) {
1234  PathInfo mediafile { mDataPath/"media.1/media" };
1235  if ( mediafile.isExist() ) {
1236  repo::SUSEMediaVerifier lverifier { mediafile.path() };
1237  if ( lverifier && lverifier.totalMedia() > 1 ) {
1238  canSkipMediaCheck = false;
1239  }
1240  }
1241  }
1242  }
1243  if ( canSkipMediaCheck )
1244  DBG << "Can SKIP media.1/media check for status calc of repo " << alias() << endl;
1245  return not canSkipMediaCheck;
1246  }
1247 
1248  bool RepoInfo::hasExtraValue( const std::string & key_r ) const
1249  { return _pimpl->hasExtraValue( key_r ); }
1250 
1251  std::string RepoInfo::extraValue( const std::string & key_r ) const
1252  { return _pimpl->extraValue( key_r ); }
1253 
1254  bool RepoInfo::setExtraValue( const std::string & key_r, std::string value_r )
1255  { return _pimpl->setExtraValue( key_r, std::move(value_r) ); }
1256 
1257 
1259 } // 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:507
const RepoVariablesReplacedUrl & mirrorListUrl() const
THE mirrorListUrl to work with (either_cfgMirrorlistUrl or _cfgMetalinkUrl)
Definition: RepoInfo.cc:441
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:451
void setBaseUrl(Url url)
Clears current base URL list and adds url.
Definition: RepoInfo.cc:762
Pathname path() const
Repository path.
Definition: RepoInfo.cc:864
unsigned priority() const
Repository priority for solver.
Definition: RepoInfo.cc:600
#define MIL
Definition: Logger.h:130
bool hasLicense() const
Whether there is a license associated with the repo.
Definition: RepoInfo.cc:913
url_set gpgKeyUrls() const
The list of gpgkey URLs defined for this repo.
Definition: RepoInfo.cc:846
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:743
static unsigned defaultPriority()
The default priority (99).
Definition: RepoInfo.cc:603
Url rawGpgKeyUrl() const
(leagcy API) The 1st raw gpgkey URL defined for this repo (no variables replaced) ...
Definition: RepoInfo.cc:855
Url rawUrl() const
Pars pro toto: The first repository raw url (no variables replaced) this is either rawBaseUrls()...
Definition: RepoInfo.cc:873
TriBool rawPkgGpgCheck() const
Definition: RepoInfo.cc:419
const std::set< std::string > & contentKeywords() const
Content keywords defined.
Definition: RepoInfo.cc:899
std::chrono::steady_clock::time_point _lastMirrorUrlsUpdate
Definition: RepoInfo.cc:565
Implementation of the traditional SUSE media verifier.
Namespace intended to collect all environment variables we use.
void packagesPath(Pathname new_r)
Definition: RepoInfo.cc:466
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:794
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:867
bool IamNotRoot()
Definition: PathInfo.h:42
bool usesAutoMetadataPaths() const
Definition: RepoInfo.cc:477
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:791
void setPriority(unsigned newval_r)
Set repository priority for solver.
Definition: RepoInfo.cc:609
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:822
void forDumpableExtraValues(Fnc &&fnc_r) const
Filter discarding not dumpable extra values.
Definition: RepoInfo.cc:539
RawConstIterator rawBegin() const
MirroredOriginSet repoOrigins() const
The repodata origins.
Definition: RepoInfo.cc:775
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:421
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: RepoInfo.h:655
Url rawCfgMetalinkUrl() const
The configured raw metalink url.
Definition: RepoInfo.cc:728
void addAuthorityEndpoint(OriginEndpoint endpoint)
Adds a single endpoint as an authority, routing it to the correct MirroredOrigin. ...
RepoVariablesReplacedUrl _cfgMirrorlistUrl
Definition: RepoInfo.cc:437
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:636
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:849
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:525
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:616
TriBool _rawPkgGpgCheck
need to check pkg sign.: Y/N/(ZConf(Y/N/gpgCheck))
Definition: RepoInfo.cc:414
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:454
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:852
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:623
bool triBoolFromPath(const Pathname &path_r, TriBool &ret_r) const
Definition: RepoInfo.cc:380
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:658
urls_const_iterator baseUrlsBegin() const
iterator that points at begin of repository urls
Definition: RepoInfo.cc:879
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:888
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:719
std::string extraValue(const std::string &key_r) const
Return extra value for key_r or throws std::out_of_range.
Definition: RepoInfo.cc:1251
Pathname _metadataPath
Definition: RepoInfo.cc:558
const std::string & asString() const
Definition: RepoType.cc:56
MirroredOriginSet repoOrigins() const
Definition: RepoInfo.cc:255
RepoVariablesReplacedUrlList _baseUrls
baseUrls as configured
Definition: RepoInfo.cc:562
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:894
Url mirrorListUrl() const
Url of a file which contains a list of repository urls.
Definition: RepoInfo.cc:834
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:813
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:840
Url rawCfgMirrorlistUrl() const
The configured raw mirrorlist url.
Definition: RepoInfo.cc:725
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:1099
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:633
bool setExtraValue(const std::string &key_r, std::string value_r)
Definition: RepoInfo.cc:531
Pathname packagesPath() const
Definition: RepoInfo.cc:494
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:626
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:629
const std::string & asString() const
String representation.
Definition: Pathname.h:94
TriBool triBoolFromPath(const Pathname &path_r) const
Definition: RepoInfo.cc:406
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:528
void addContent(const std::string &keyword_r)
Definition: RepoInfo.cc:293
bool gpgCheck() const
Turn signature checking on/off (on)
Definition: ZConfig.cc:1097
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:560
Url rawMirrorListUrl() const
The raw mirrorListUrl (no variables replaced).
Definition: RepoInfo.cc:837
void setPath(const Pathname &path)
set the product path.
Definition: RepoInfo.cc:785
TriBool validRepoSignature() const
Whether the repo metadata are signed and successfully validated or indeterminate if unsigned...
Definition: RepoInfo.cc:651
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:999
void setService(const std::string &name)
sets service which added this repository
Definition: RepoInfo.cc:807
#define WAR
Definition: Logger.h:131
RepoVariablesReplacedUrl _cfgMetalinkUrl
Definition: RepoInfo.cc:438
void setMetadataPath(const Pathname &path)
Set the path where the local metadata is stored.
Definition: RepoInfo.cc:795
bool baseUrlSet() const
Whether there are manualy configured repository urls.
Definition: RepoInfo.cc:891
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:1248
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:643
void setType(const repo::RepoType &t)
set the repository type
Definition: RepoInfo.cc:788
TriBool repoGpgCheck() const
Check repo matadata signatures (indeterminate - according to gpgcheck)
Definition: ZConfig.cc:1098
bool gpgCheck() const
Whether default signature checking should be performed.
Definition: RepoInfo.cc:613
TriBool _rawGpgCheck
default gpgcheck behavior: Y/N/ZConf
Definition: RepoInfo.cc:412
bool repoOriginsEmpty() const
whether repo origins are available
Definition: RepoInfo.cc:780
TriBool _validRepoSignature
have signed and valid repo metadata
Definition: RepoInfo.cc:433
bool hasContent() const
Check for content keywords.
Definition: RepoInfo.cc:905
std::vector< MirroredOrigin > _repoOrigins
Definition: RepoInfo.cc:566
std::pair< FalseBool, std::set< std::string > > _keywords
Definition: RepoInfo.cc:568
Pathname predownloadPath() const
Definition: RepoInfo.cc:499
void setKeepPackages(bool keep)
Set if packaqes downloaded from this repository will be kept in local cache.
Definition: RepoInfo.cc:804
std::string getLicense(const Locale &lang_r=Locale()) const
Return the best license for the current (or a specified) locale.
Definition: RepoInfo.cc:955
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:429
std::ostream & dumpOn(std::ostream &str) const override
Write a human-readable representation of this RepoInfo object into the str stream.
Definition: RepoInfo.cc:1035
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:425
TriBool _rawRepoGpgCheck
need to check repo sign.: Y/N/(ZConf(Y/N/gpgCheck))
Definition: RepoInfo.cc:413
bool requireStatusWithMediaFile() const
Returns true if this repository requires the media.1/media file to be included in the metadata status...
Definition: RepoInfo.cc:1225
Find pathnames matching a pattern.
Definition: Glob.h:57
Pathname metadataPath() const
Path where this repo metadata was read from.
Definition: RepoInfo.cc:819
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:1155
static const unsigned noPriority
Definition: RepoInfo.cc:124
repo::RepoType type() const
Definition: RepoInfo.cc:135
repo::RepoType _type
Definition: RepoInfo.cc:434
Pathname predownloadPath() const
Path where this repo packages are predownloaded.
Definition: RepoInfo.cc:801
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:513
bool usesAutoMetadataPaths() const
Whether metadataPath uses AUTO% setup.
Definition: RepoInfo.cc:828
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:798
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:722
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:740
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:422
url_set rawBaseUrls() const
The complete set of raw repository urls (no variables replaced)
Definition: RepoInfo.cc:861
Pathname absolutename() const
Return this path, adding a leading &#39;/&#39; if relative.
Definition: Pathname.h:148
void setTargetDistribution(const std::string &targetDistribution)
Sets the distribution for which is this repository meant.
Definition: RepoInfo.cc:810
bool needToAcceptLicense() const
Whether the repo license has to be accepted, e.g.
Definition: RepoInfo.cc:920
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:1087
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:876
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:752
void setMirrorlistUrl(const Url &url_r)
Definition: RepoInfo.cc:444
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
RepoVariablesReplacedUrlList _gpgKeyUrls
Definition: RepoInfo.cc:570
Typesafe passing of user data via callbacks.
Definition: UserData.h:39
TriBool rawRepoGpgCheck() const
Definition: RepoInfo.cc:418
TransformedConstIterator transformedEnd() const
DefaultIntegral< unsigned, defaultPriority > priority
Definition: RepoInfo.cc:504
std::string targetDistribution() const
Distribution for which is this repository meant.
Definition: RepoInfo.cc:870
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:825
void setBaseUrls(url_set urls)
Clears current base URL list and adds an url_set.
Definition: RepoInfo.cc:769
std::string targetDistro
Definition: RepoInfo.cc:461
Wrapper class for ::stat/::lstat.
Definition: PathInfo.h:225
~RepoInfo() override
Definition: RepoInfo.cc:597
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:749
urls_const_iterator baseUrlsEnd() const
iterator that points at end of repository urls
Definition: RepoInfo.cc:882
void addContent(const std::string &keyword_r)
Add content keywords.
Definition: RepoInfo.cc:902
void clear()
Clear the container.
void rawPkgGpgCheck(TriBool val_r)
Definition: RepoInfo.cc:423
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:885
void setMetalinkUrl(const Url &url_r)
Definition: RepoInfo.cc:447
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:843
Pathname metadataPath() const
Definition: RepoInfo.cc:480
TriBool rawGpgCheck() const
Definition: RepoInfo.cc:417
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
Pathname systemPackagesPath() const
Definition: RepoInfo.cc:487
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:564
Impl * clone() const
clone for RWCOW_pointer
Definition: RepoInfo.cc:574
static unsigned noPriority()
The least priority (unsigned(-1)).
Definition: RepoInfo.cc:606
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:858
void setPkgGpgCheck(TriBool value_r)
Set the value for pkgGpgCheck (or indeterminate to use the default).
Definition: RepoInfo.cc:639
repo::RepoType type() const
Type of repository,.
Definition: RepoInfo.cc:831
TriBool cfgRepoGpgCheck() const
Definition: RepoInfo.cc:427
const char * c_str() const
Definition: IdStringType.h:115
Pathname _packagesPath
Definition: RepoInfo.cc:559
bool effectiveKeepPackages() const
keepPackages unless the package cache itself enforces keeping the packages.
Definition: RepoInfo.cc:816
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:1254
Url manipulation class.
Definition: Url.h:92
void metadataPath(Pathname new_r)
Definition: RepoInfo.cc:463
A smart container that manages a collection of MirroredOrigin objects, automatically grouping endpoin...
#define DBG
Definition: Logger.h:129
std::string service
Definition: RepoInfo.cc:460
Repository type enumeration.
Definition: RepoType.h:28
bool hasContent(const std::string &keyword_r) const
Definition: RepoInfo.cc:341