libzypp  17.25.1
RepoManager.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
13 #include <cstdlib>
14 #include <iostream>
15 #include <fstream>
16 #include <sstream>
17 #include <list>
18 #include <map>
19 #include <algorithm>
20 
21 #include <solv/solvversion.h>
22 
23 #include <zypp/base/InputStream.h>
24 #include <zypp/base/LogTools.h>
25 #include <zypp/base/Gettext.h>
27 #include <zypp/base/Function.h>
28 #include <zypp/base/Regex.h>
29 #include <zypp/PathInfo.h>
30 #include <zypp/TmpPath.h>
31 
32 #include <zypp/ServiceInfo.h>
34 #include <zypp/RepoManager.h>
35 
38 #include <zypp/MediaSetAccess.h>
39 #include <zypp/ExternalProgram.h>
40 #include <zypp/ManagedFile.h>
41 
44 #include <zypp/repo/ServiceRepos.h>
48 
49 #include <zypp/Target.h> // for Target::targetDistribution() for repo index services
50 #include <zypp/ZYppFactory.h> // to get the Target from ZYpp instance
51 #include <zypp/HistoryLog.h> // to write history :O)
52 
53 #include <zypp/ZYppCallbacks.h>
54 
55 #include "sat/Pool.h"
56 
57 using std::endl;
58 using std::string;
59 using namespace zypp::repo;
60 
61 #define OPT_PROGRESS const ProgressData::ReceiverFnc & = ProgressData::ReceiverFnc()
62 
64 namespace zypp
65 {
66 
68  namespace env
69  {
72  {
73  const char * env = getenv("ZYPP_PLUGIN_APPDATA_FORCE_COLLECT");
74  return( env && str::strToBool( env, true ) );
75  }
76  } // namespace env
78 
80  namespace
81  {
103  class UrlCredentialExtractor
104  {
105  public:
106  UrlCredentialExtractor( Pathname & root_r )
107  : _root( root_r )
108  {}
109 
110  ~UrlCredentialExtractor()
111  { if ( _cmPtr ) _cmPtr->save(); }
112 
114  bool collect( const Url & url_r )
115  {
116  bool ret = url_r.hasCredentialsInAuthority();
117  if ( ret )
118  {
119  if ( !_cmPtr ) _cmPtr.reset( new media::CredentialManager( _root ) );
120  _cmPtr->addUserCred( url_r );
121  }
122  return ret;
123  }
125  template<class TContainer>
126  bool collect( const TContainer & urls_r )
127  { bool ret = false; for ( const Url & url : urls_r ) { if ( collect( url ) && !ret ) ret = true; } return ret; }
128 
130  bool extract( Url & url_r )
131  {
132  bool ret = collect( url_r );
133  if ( ret )
134  url_r.setPassword( std::string() );
135  return ret;
136  }
138  template<class TContainer>
139  bool extract( TContainer & urls_r )
140  { bool ret = false; for ( Url & url : urls_r ) { if ( extract( url ) && !ret ) ret = true; } return ret; }
141 
142  private:
143  const Pathname & _root;
144  scoped_ptr<media::CredentialManager> _cmPtr;
145  };
146  } // namespace
148 
150  namespace
151  {
155  class MediaMounter
156  {
157  public:
159  MediaMounter( const Url & url_r )
160  {
161  media::MediaManager mediamanager;
162  _mid = mediamanager.open( url_r );
163  mediamanager.attach( _mid );
164  }
165 
167  ~MediaMounter()
168  {
169  media::MediaManager mediamanager;
170  mediamanager.release( _mid );
171  mediamanager.close( _mid );
172  }
173 
178  Pathname getPathName( const Pathname & path_r = Pathname() ) const
179  {
180  media::MediaManager mediamanager;
181  return mediamanager.localPath( _mid, path_r );
182  }
183 
184  private:
186  };
188 
190  template <class Iterator>
191  inline bool foundAliasIn( const std::string & alias_r, Iterator begin_r, Iterator end_r )
192  {
193  for_( it, begin_r, end_r )
194  if ( it->alias() == alias_r )
195  return true;
196  return false;
197  }
199  template <class Container>
200  inline bool foundAliasIn( const std::string & alias_r, const Container & cont_r )
201  { return foundAliasIn( alias_r, cont_r.begin(), cont_r.end() ); }
202 
204  template <class Iterator>
205  inline Iterator findAlias( const std::string & alias_r, Iterator begin_r, Iterator end_r )
206  {
207  for_( it, begin_r, end_r )
208  if ( it->alias() == alias_r )
209  return it;
210  return end_r;
211  }
213  template <class Container>
214  inline typename Container::iterator findAlias( const std::string & alias_r, Container & cont_r )
215  { return findAlias( alias_r, cont_r.begin(), cont_r.end() ); }
217  template <class Container>
218  inline typename Container::const_iterator findAlias( const std::string & alias_r, const Container & cont_r )
219  { return findAlias( alias_r, cont_r.begin(), cont_r.end() ); }
220 
221 
223  inline std::string filenameFromAlias( const std::string & alias_r, const std::string & stem_r )
224  {
225  std::string filename( alias_r );
226  // replace slashes with underscores
227  str::replaceAll( filename, "/", "_" );
228 
229  filename = Pathname(filename).extend("."+stem_r).asString();
230  MIL << "generating filename for " << stem_r << " [" << alias_r << "] : '" << filename << "'" << endl;
231  return filename;
232  }
233 
249  struct RepoCollector : private base::NonCopyable
250  {
251  RepoCollector()
252  {}
253 
254  RepoCollector(const std::string & targetDistro_)
255  : targetDistro(targetDistro_)
256  {}
257 
258  bool collect( const RepoInfo &repo )
259  {
260  // skip repositories meant for other distros than specified
261  if (!targetDistro.empty()
262  && !repo.targetDistribution().empty()
263  && repo.targetDistribution() != targetDistro)
264  {
265  MIL
266  << "Skipping repository meant for '" << repo.targetDistribution()
267  << "' distribution (current distro is '"
268  << targetDistro << "')." << endl;
269 
270  return true;
271  }
272 
273  repos.push_back(repo);
274  return true;
275  }
276 
277  RepoInfoList repos;
278  std::string targetDistro;
279  };
281 
287  std::list<RepoInfo> repositories_in_file( const Pathname & file )
288  {
289  MIL << "repo file: " << file << endl;
290  RepoCollector collector;
291  parser::RepoFileReader parser( file, bind( &RepoCollector::collect, &collector, _1 ) );
292  return std::move(collector.repos);
293  }
294 
296 
305  std::list<RepoInfo> repositories_in_dir( const Pathname &dir )
306  {
307  MIL << "directory " << dir << endl;
308  std::list<RepoInfo> repos;
309  bool nonroot( geteuid() != 0 );
310  if ( nonroot && ! PathInfo(dir).userMayRX() )
311  {
312  JobReport::warning( str::Format(_("Cannot read repo directory '%1%': Permission denied")) % dir );
313  }
314  else
315  {
316  std::list<Pathname> entries;
317  if ( filesystem::readdir( entries, dir, false ) != 0 )
318  {
319  // TranslatorExplanation '%s' is a pathname
320  ZYPP_THROW(Exception(str::form(_("Failed to read directory '%s'"), dir.c_str())));
321  }
322 
323  str::regex allowedRepoExt("^\\.repo(_[0-9]+)?$");
324  for ( std::list<Pathname>::const_iterator it = entries.begin(); it != entries.end(); ++it )
325  {
326  if ( str::regex_match(it->extension(), allowedRepoExt) )
327  {
328  if ( nonroot && ! PathInfo(*it).userMayR() )
329  {
330  JobReport::warning( str::Format(_("Cannot read repo file '%1%': Permission denied")) % *it );
331  }
332  else
333  {
334  const std::list<RepoInfo> & tmp( repositories_in_file( *it ) );
335  repos.insert( repos.end(), tmp.begin(), tmp.end() );
336  }
337  }
338  }
339  }
340  return repos;
341  }
342 
344 
345  inline void assert_alias( const RepoInfo & info )
346  {
347  if ( info.alias().empty() )
348  ZYPP_THROW( RepoNoAliasException( info ) );
349  // bnc #473834. Maybe we can match the alias against a regex to define
350  // and check for valid aliases
351  if ( info.alias()[0] == '.')
353  info, _("Repository alias cannot start with dot.")));
354  }
355 
356  inline void assert_alias( const ServiceInfo & info )
357  {
358  if ( info.alias().empty() )
360  // bnc #473834. Maybe we can match the alias against a regex to define
361  // and check for valid aliases
362  if ( info.alias()[0] == '.')
364  info, _("Service alias cannot start with dot.")));
365  }
366 
368 
369  inline void assert_urls( const RepoInfo & info )
370  {
371  if ( info.baseUrlsEmpty() )
372  ZYPP_THROW( RepoNoUrlException( info ) );
373  }
374 
375  inline void assert_url( const ServiceInfo & info )
376  {
377  if ( ! info.url().isValid() )
379  }
380 
382 
384  namespace
385  {
387  inline bool isTmpRepo( const RepoInfo & info_r )
388  { return( info_r.filepath().empty() && info_r.usesAutoMethadataPaths() ); }
389  } // namespace
391 
396  inline Pathname rawcache_path_for_repoinfo( const RepoManagerOptions &opt, const RepoInfo &info )
397  {
398  assert_alias(info);
399  return isTmpRepo( info ) ? info.metadataPath() : opt.repoRawCachePath / info.escaped_alias();
400  }
401 
410  inline Pathname rawproductdata_path_for_repoinfo( const RepoManagerOptions &opt, const RepoInfo &info )
411  { return rawcache_path_for_repoinfo( opt, info ) / info.path(); }
412 
416  inline Pathname packagescache_path_for_repoinfo( const RepoManagerOptions &opt, const RepoInfo &info )
417  {
418  assert_alias(info);
419  return isTmpRepo( info ) ? info.packagesPath() : opt.repoPackagesCachePath / info.escaped_alias();
420  }
421 
425  inline Pathname solv_path_for_repoinfo( const RepoManagerOptions &opt, const RepoInfo &info )
426  {
427  assert_alias(info);
428  return isTmpRepo( info ) ? info.metadataPath().dirname() / "%SLV%" : opt.repoSolvCachePath / info.escaped_alias();
429  }
430 
432 
434  class ServiceCollector
435  {
436  public:
437  typedef std::set<ServiceInfo> ServiceSet;
438 
439  ServiceCollector( ServiceSet & services_r )
440  : _services( services_r )
441  {}
442 
443  bool operator()( const ServiceInfo & service_r ) const
444  {
445  _services.insert( service_r );
446  return true;
447  }
448 
449  private:
450  ServiceSet & _services;
451  };
453 
454  } // namespace
456 
457  std::list<RepoInfo> readRepoFile( const Url & repo_file )
458  {
460 
461  DBG << "reading repo file " << repo_file << ", local path: " << local << endl;
462 
463  return repositories_in_file(local);
464  }
465 
467  //
468  // class RepoManagerOptions
469  //
471 
473  {
474  repoCachePath = Pathname::assertprefix( root_r, ZConfig::instance().repoCachePath() );
475  repoRawCachePath = Pathname::assertprefix( root_r, ZConfig::instance().repoMetadataPath() );
476  repoSolvCachePath = Pathname::assertprefix( root_r, ZConfig::instance().repoSolvfilesPath() );
477  repoPackagesCachePath = Pathname::assertprefix( root_r, ZConfig::instance().repoPackagesPath() );
478  knownReposPath = Pathname::assertprefix( root_r, ZConfig::instance().knownReposPath() );
479  knownServicesPath = Pathname::assertprefix( root_r, ZConfig::instance().knownServicesPath() );
480  pluginsPath = Pathname::assertprefix( root_r, ZConfig::instance().pluginsPath() );
481  probe = ZConfig::instance().repo_add_probe();
482 
483  rootDir = root_r;
484  }
485 
487  {
488  RepoManagerOptions ret;
489  ret.repoCachePath = root_r;
490  ret.repoRawCachePath = root_r/"raw";
491  ret.repoSolvCachePath = root_r/"solv";
492  ret.repoPackagesCachePath = root_r/"packages";
493  ret.knownReposPath = root_r/"repos.d";
494  ret.knownServicesPath = root_r/"services.d";
495  ret.pluginsPath = root_r/"plugins";
496  ret.rootDir = root_r;
497  return ret;
498  }
499 
500  std:: ostream & operator<<( std::ostream & str, const RepoManagerOptions & obj )
501  {
502 #define OUTS(X) str << " " #X "\t" << obj.X << endl
503  str << "RepoManagerOptions (" << obj.rootDir << ") {" << endl;
504  OUTS( repoRawCachePath );
505  OUTS( repoSolvCachePath );
506  OUTS( repoPackagesCachePath );
507  OUTS( knownReposPath );
508  OUTS( knownServicesPath );
509  OUTS( pluginsPath );
510  str << "}" << endl;
511 #undef OUTS
512  return str;
513  }
514 
521  {
522  public:
523  Impl( const RepoManagerOptions &opt )
524  : _options(opt)
525  {
526  init_knownServices();
527  init_knownRepositories();
528  }
529 
531  {
532  // trigger appdata refresh if some repos change
533  if ( ( _reposDirty || env::ZYPP_PLUGIN_APPDATA_FORCE_COLLECT() )
534  && geteuid() == 0 && ( _options.rootDir.empty() || _options.rootDir == "/" ) )
535  {
536  try {
537  std::list<Pathname> entries;
538  filesystem::readdir( entries, _options.pluginsPath/"appdata", false );
539  if ( ! entries.empty() )
540  {
542  cmd.push_back( "<" ); // discard stdin
543  cmd.push_back( ">" ); // discard stdout
544  cmd.push_back( "PROGRAM" ); // [2] - fix index below if changing!
545  for ( const auto & rinfo : repos() )
546  {
547  if ( ! rinfo.enabled() )
548  continue;
549  cmd.push_back( "-R" );
550  cmd.push_back( rinfo.alias() );
551  cmd.push_back( "-t" );
552  cmd.push_back( rinfo.type().asString() );
553  cmd.push_back( "-p" );
554  cmd.push_back( rinfo.metadataPath().asString() );
555  }
556 
557  for_( it, entries.begin(), entries.end() )
558  {
559  PathInfo pi( *it );
560  //DBG << "/tmp/xx ->" << pi << endl;
561  if ( pi.isFile() && pi.userMayRX() )
562  {
563  // trigger plugin
564  cmd[2] = pi.asString(); // [2] - PROGRAM
566  }
567  }
568  }
569  }
570  catch (...) {} // no throw in dtor
571  }
572  }
573 
574  public:
575  bool repoEmpty() const { return repos().empty(); }
576  RepoSizeType repoSize() const { return repos().size(); }
577  RepoConstIterator repoBegin() const { return repos().begin(); }
578  RepoConstIterator repoEnd() const { return repos().end(); }
579 
580  bool hasRepo( const std::string & alias ) const
581  { return foundAliasIn( alias, repos() ); }
582 
583  RepoInfo getRepo( const std::string & alias ) const
584  {
585  RepoConstIterator it( findAlias( alias, repos() ) );
586  return it == repos().end() ? RepoInfo::noRepo : *it;
587  }
588 
589  public:
590  Pathname metadataPath( const RepoInfo & info ) const
591  { return rawcache_path_for_repoinfo( _options, info ); }
592 
593  Pathname packagesPath( const RepoInfo & info ) const
594  { return packagescache_path_for_repoinfo( _options, info ); }
595 
596  RepoStatus metadataStatus( const RepoInfo & info ) const;
597 
598  RefreshCheckStatus checkIfToRefreshMetadata( const RepoInfo & info, const Url & url, RawMetadataRefreshPolicy policy );
599 
600  void refreshMetadata( const RepoInfo & info, RawMetadataRefreshPolicy policy, OPT_PROGRESS );
601 
602  void cleanMetadata( const RepoInfo & info, OPT_PROGRESS );
603 
604  void cleanPackages( const RepoInfo & info, OPT_PROGRESS );
605 
606  void buildCache( const RepoInfo & info, CacheBuildPolicy policy, OPT_PROGRESS );
607 
608  repo::RepoType probe( const Url & url, const Pathname & path = Pathname() ) const;
609  repo::RepoType probeCache( const Pathname & path_r ) const;
610 
611  void cleanCacheDirGarbage( OPT_PROGRESS );
612 
613  void cleanCache( const RepoInfo & info, OPT_PROGRESS );
614 
615  bool isCached( const RepoInfo & info ) const
616  { return PathInfo(solv_path_for_repoinfo( _options, info ) / "solv").isExist(); }
617 
618  RepoStatus cacheStatus( const RepoInfo & info ) const
619  { return RepoStatus::fromCookieFile(solv_path_for_repoinfo(_options, info) / "cookie"); }
620 
621  void loadFromCache( const RepoInfo & info, OPT_PROGRESS );
622 
623  void addRepository( const RepoInfo & info, OPT_PROGRESS );
624 
625  void addRepositories( const Url & url, OPT_PROGRESS );
626 
627  void removeRepository( const RepoInfo & info, OPT_PROGRESS );
628 
629  void modifyRepository( const std::string & alias, const RepoInfo & newinfo_r, OPT_PROGRESS );
630 
631  RepoInfo getRepositoryInfo( const std::string & alias, OPT_PROGRESS );
632  RepoInfo getRepositoryInfo( const Url & url, const url::ViewOption & urlview, OPT_PROGRESS );
633 
634  public:
635  bool serviceEmpty() const { return _services.empty(); }
636  ServiceSizeType serviceSize() const { return _services.size(); }
637  ServiceConstIterator serviceBegin() const { return _services.begin(); }
638  ServiceConstIterator serviceEnd() const { return _services.end(); }
639 
640  bool hasService( const std::string & alias ) const
641  { return foundAliasIn( alias, _services ); }
642 
643  ServiceInfo getService( const std::string & alias ) const
644  {
645  ServiceConstIterator it( findAlias( alias, _services ) );
646  return it == _services.end() ? ServiceInfo::noService : *it;
647  }
648 
649  public:
650  void addService( const ServiceInfo & service );
651  void addService( const std::string & alias, const Url & url )
652  { addService( ServiceInfo( alias, url ) ); }
653 
654  void removeService( const std::string & alias );
655  void removeService( const ServiceInfo & service )
656  { removeService( service.alias() ); }
657 
658  void refreshServices( const RefreshServiceOptions & options_r );
659 
660  void refreshService( const std::string & alias, const RefreshServiceOptions & options_r );
661  void refreshService( const ServiceInfo & service, const RefreshServiceOptions & options_r )
662  { refreshService( service.alias(), options_r ); }
663 
664  void modifyService( const std::string & oldAlias, const ServiceInfo & newService );
665 
666  repo::ServiceType probeService( const Url & url ) const;
667 
668  private:
669  void saveService( ServiceInfo & service ) const;
670 
671  Pathname generateNonExistingName( const Pathname & dir, const std::string & basefilename ) const;
672 
673  std::string generateFilename( const RepoInfo & info ) const
674  { return filenameFromAlias( info.alias(), "repo" ); }
675 
676  std::string generateFilename( const ServiceInfo & info ) const
677  { return filenameFromAlias( info.alias(), "service" ); }
678 
679  void setCacheStatus( const RepoInfo & info, const RepoStatus & status )
680  {
681  Pathname base = solv_path_for_repoinfo( _options, info );
683  status.saveToCookieFile( base / "cookie" );
684  }
685 
686  void touchIndexFile( const RepoInfo & info );
687 
688  template<typename OutputIterator>
689  void getRepositoriesInService( const std::string & alias, OutputIterator out ) const
690  {
691  MatchServiceAlias filter( alias );
692  std::copy( boost::make_filter_iterator( filter, repos().begin(), repos().end() ),
693  boost::make_filter_iterator( filter, repos().end(), repos().end() ),
694  out);
695  }
696 
697  private:
698  void init_knownServices();
699  void init_knownRepositories();
700 
701  const RepoSet & repos() const { return _reposX; }
702  RepoSet & reposManip() { if ( ! _reposDirty ) _reposDirty = true; return _reposX; }
703 
704  private:
708 
710 
711  private:
712  friend Impl * rwcowClone<Impl>( const Impl * rhs );
714  Impl * clone() const
715  { return new Impl( *this ); }
716  };
718 
720  inline std::ostream & operator<<( std::ostream & str, const RepoManager::Impl & obj )
721  { return str << "RepoManager::Impl"; }
722 
724 
726  {
727  filesystem::assert_dir( _options.knownServicesPath );
728  Pathname servfile = generateNonExistingName( _options.knownServicesPath,
729  generateFilename( service ) );
730  service.setFilepath( servfile );
731 
732  MIL << "saving service in " << servfile << endl;
733 
734  std::ofstream file( servfile.c_str() );
735  if ( !file )
736  {
737  // TranslatorExplanation '%s' is a filename
738  ZYPP_THROW( Exception(str::form( _("Can't open file '%s' for writing."), servfile.c_str() )));
739  }
740  service.dumpAsIniOn( file );
741  MIL << "done" << endl;
742  }
743 
760  const std::string & basefilename ) const
761  {
762  std::string final_filename = basefilename;
763  int counter = 1;
764  while ( PathInfo(dir + final_filename).isExist() )
765  {
766  final_filename = basefilename + "_" + str::numstring(counter);
767  ++counter;
768  }
769  return dir + Pathname(final_filename);
770  }
771 
773 
775  {
776  Pathname dir = _options.knownServicesPath;
777  std::list<Pathname> entries;
778  if (PathInfo(dir).isExist())
779  {
780  if ( filesystem::readdir( entries, dir, false ) != 0 )
781  {
782  // TranslatorExplanation '%s' is a pathname
783  ZYPP_THROW(Exception(str::form(_("Failed to read directory '%s'"), dir.c_str())));
784  }
785 
786  //str::regex allowedServiceExt("^\\.service(_[0-9]+)?$");
787  for_(it, entries.begin(), entries.end() )
788  {
789  parser::ServiceFileReader(*it, ServiceCollector(_services));
790  }
791  }
792 
793  repo::PluginServices(_options.pluginsPath/"services", ServiceCollector(_services));
794  }
795 
797  namespace {
803  inline void cleanupNonRepoMetadtaFolders( const Pathname & cachePath_r,
804  const Pathname & defaultCachePath_r,
805  const std::list<std::string> & repoEscAliases_r )
806  {
807  if ( cachePath_r != defaultCachePath_r )
808  return;
809 
810  std::list<std::string> entries;
811  if ( filesystem::readdir( entries, cachePath_r, false ) == 0 )
812  {
813  entries.sort();
814  std::set<std::string> oldfiles;
815  set_difference( entries.begin(), entries.end(), repoEscAliases_r.begin(), repoEscAliases_r.end(),
816  std::inserter( oldfiles, oldfiles.end() ) );
817  for ( const std::string & old : oldfiles )
818  {
819  if ( old == Repository::systemRepoAlias() ) // don't remove the @System solv file
820  continue;
821  filesystem::recursive_rmdir( cachePath_r / old );
822  }
823  }
824  }
825  } // namespace
828  {
829  MIL << "start construct known repos" << endl;
830 
831  if ( PathInfo(_options.knownReposPath).isExist() )
832  {
833  std::list<std::string> repoEscAliases;
834  std::list<RepoInfo> orphanedRepos;
835  for ( RepoInfo & repoInfo : repositories_in_dir(_options.knownReposPath) )
836  {
837  // set the metadata path for the repo
838  repoInfo.setMetadataPath( rawcache_path_for_repoinfo(_options, repoInfo) );
839  // set the downloaded packages path for the repo
840  repoInfo.setPackagesPath( packagescache_path_for_repoinfo(_options, repoInfo) );
841  // remember it
842  _reposX.insert( repoInfo ); // direct access via _reposX in ctor! no reposManip.
843 
844  // detect orphaned repos belonging to a deleted service
845  const std::string & serviceAlias( repoInfo.service() );
846  if ( ! ( serviceAlias.empty() || hasService( serviceAlias ) ) )
847  {
848  WAR << "Schedule orphaned service repo for deletion: " << repoInfo << endl;
849  orphanedRepos.push_back( repoInfo );
850  continue; // don't remember it in repoEscAliases
851  }
852 
853  repoEscAliases.push_back(repoInfo.escaped_alias());
854  }
855 
856  // Cleanup orphanded service repos:
857  if ( ! orphanedRepos.empty() )
858  {
859  for ( const auto & repoInfo : orphanedRepos )
860  {
861  MIL << "Delete orphaned service repo " << repoInfo.alias() << endl;
862  // translators: Cleanup a repository previously owned by a meanwhile unknown (deleted) service.
863  // %1% = service name
864  // %2% = repository name
865  JobReport::warning( str::Format(_("Unknown service '%1%': Removing orphaned service repository '%2%'"))
866  % repoInfo.service()
867  % repoInfo.alias() );
868  try {
869  removeRepository( repoInfo );
870  }
871  catch ( const Exception & caugth )
872  {
873  JobReport::error( caugth.asUserHistory() );
874  }
875  }
876  }
877 
878  // delete metadata folders without corresponding repo (e.g. old tmp directories)
879  //
880  // bnc#891515: Auto-cleanup only zypp.conf default locations. Otherwise
881  // we'd need somemagic file to identify zypp cache directories. Without this
882  // we may easily remove user data (zypper --pkg-cache-dir . download ...)
883  repoEscAliases.sort();
884  RepoManagerOptions defaultCache( _options.rootDir );
885  cleanupNonRepoMetadtaFolders( _options.repoRawCachePath, defaultCache.repoRawCachePath, repoEscAliases );
886  cleanupNonRepoMetadtaFolders( _options.repoSolvCachePath, defaultCache.repoSolvCachePath, repoEscAliases );
887  cleanupNonRepoMetadtaFolders( _options.repoPackagesCachePath, defaultCache.repoPackagesCachePath, repoEscAliases );
888  }
889  MIL << "end construct known repos" << endl;
890  }
891 
893 
895  {
896  Pathname mediarootpath = rawcache_path_for_repoinfo( _options, info );
897  Pathname productdatapath = rawproductdata_path_for_repoinfo( _options, info );
898 
899  RepoType repokind = info.type();
900  // If unknown, probe the local metadata
901  if ( repokind == RepoType::NONE )
902  repokind = probeCache( productdatapath );
903 
904  RepoStatus status;
905  switch ( repokind.toEnum() )
906  {
907  case RepoType::RPMMD_e :
908  status = RepoStatus( productdatapath/"repodata/repomd.xml") && RepoStatus( mediarootpath/"media.1/media" );
909  break;
910 
911  case RepoType::YAST2_e :
912  status = RepoStatus( productdatapath/"content" ) && RepoStatus( mediarootpath/"media.1/media" );
913  break;
914 
916  status = RepoStatus::fromCookieFile( productdatapath/"cookie" );
917  break;
918 
919  case RepoType::NONE_e :
920  // Return default RepoStatus in case of RepoType::NONE
921  // indicating it should be created?
922  // ZYPP_THROW(RepoUnknownTypeException());
923  break;
924  }
925  return status;
926  }
927 
928 
930  {
931  Pathname productdatapath = rawproductdata_path_for_repoinfo( _options, info );
932 
933  RepoType repokind = info.type();
934  if ( repokind.toEnum() == RepoType::NONE_e )
935  // unknown, probe the local metadata
936  repokind = probeCache( productdatapath );
937  // if still unknown, just return
938  if (repokind == RepoType::NONE_e)
939  return;
940 
941  Pathname p;
942  switch ( repokind.toEnum() )
943  {
944  case RepoType::RPMMD_e :
945  p = Pathname(productdatapath + "/repodata/repomd.xml");
946  break;
947 
948  case RepoType::YAST2_e :
949  p = Pathname(productdatapath + "/content");
950  break;
951 
953  p = Pathname(productdatapath + "/cookie");
954  break;
955 
956  case RepoType::NONE_e :
957  default:
958  break;
959  }
960 
961  // touch the file, ignore error (they are logged anyway)
963  }
964 
965 
967  {
968  assert_alias(info);
969  try
970  {
971  MIL << "Going to try to check whether refresh is needed for " << url << " (" << info.type() << ")" << endl;
972 
973  // first check old (cached) metadata
974  Pathname mediarootpath = rawcache_path_for_repoinfo( _options, info );
975  filesystem::assert_dir( mediarootpath );
976  RepoStatus oldstatus = metadataStatus( info );
977  if ( oldstatus.empty() )
978  {
979  MIL << "No cached metadata, going to refresh" << endl;
980  return REFRESH_NEEDED;
981  }
982 
983  if ( url.schemeIsVolatile() )
984  {
985  MIL << "Never refresh CD/DVD" << endl;
986  return REPO_UP_TO_DATE;
987  }
988 
989  if ( policy == RefreshForced )
990  {
991  MIL << "Forced refresh!" << endl;
992  return REFRESH_NEEDED;
993  }
994 
995  if ( url.schemeIsLocal() )
996  {
997  policy = RefreshIfNeededIgnoreDelay;
998  }
999 
1000  // now we've got the old (cached) status, we can decide repo.refresh.delay
1001  if ( policy != RefreshIfNeededIgnoreDelay )
1002  {
1003  // difference in seconds
1004  double diff = difftime(
1006  (Date::ValueType)oldstatus.timestamp()) / 60;
1007 
1008  DBG << "oldstatus: " << (Date::ValueType)oldstatus.timestamp() << endl;
1009  DBG << "current time: " << (Date::ValueType)Date::now() << endl;
1010  DBG << "last refresh = " << diff << " minutes ago" << endl;
1011 
1012  if ( diff < ZConfig::instance().repo_refresh_delay() )
1013  {
1014  if ( diff < 0 )
1015  {
1016  WAR << "Repository '" << info.alias() << "' was refreshed in the future!" << endl;
1017  }
1018  else
1019  {
1020  MIL << "Repository '" << info.alias()
1021  << "' has been refreshed less than repo.refresh.delay ("
1023  << ") minutes ago. Advising to skip refresh" << endl;
1024  return REPO_CHECK_DELAYED;
1025  }
1026  }
1027  }
1028 
1029  repo::RepoType repokind = info.type();
1030  // if unknown: probe it
1031  if ( repokind == RepoType::NONE )
1032  repokind = probe( url, info.path() );
1033 
1034  // retrieve newstatus
1035  RepoStatus newstatus;
1036  switch ( repokind.toEnum() )
1037  {
1038  case RepoType::RPMMD_e:
1039  {
1040  MediaSetAccess media( url );
1041  newstatus = yum::Downloader( info, mediarootpath ).status( media );
1042  }
1043  break;
1044 
1045  case RepoType::YAST2_e:
1046  {
1047  MediaSetAccess media( url );
1048  newstatus = susetags::Downloader( info, mediarootpath ).status( media );
1049  }
1050  break;
1051 
1053  newstatus = RepoStatus( MediaMounter(url).getPathName(info.path()) ); // dir status
1054  break;
1055 
1056  default:
1057  case RepoType::NONE_e:
1059  break;
1060  }
1061 
1062  // check status
1063  if ( oldstatus == newstatus )
1064  {
1065  MIL << "repo has not changed" << endl;
1066  touchIndexFile( info );
1067  return REPO_UP_TO_DATE;
1068  }
1069  else // includes newstatus.empty() if e.g. repo format changed
1070  {
1071  MIL << "repo has changed, going to refresh" << endl;
1072  return REFRESH_NEEDED;
1073  }
1074  }
1075  catch ( const Exception &e )
1076  {
1077  ZYPP_CAUGHT(e);
1078  ERR << "refresh check failed for " << url << endl;
1079  ZYPP_RETHROW(e);
1080  }
1081 
1082  return REFRESH_NEEDED; // default
1083  }
1084 
1085 
1087  {
1088  assert_alias(info);
1089  assert_urls(info);
1090 
1091  // we will throw this later if no URL checks out fine
1092  RepoException rexception( info, PL_("Valid metadata not found at specified URL",
1093  "Valid metadata not found at specified URLs",
1094  info.baseUrlsSize() ) );
1095 
1096  // Suppress (interactive) media::MediaChangeReport if we in have multiple basurls (>1)
1098  // try urls one by one
1099  for ( RepoInfo::urls_const_iterator it = info.baseUrlsBegin(); it != info.baseUrlsEnd(); ++it )
1100  {
1101  try
1102  {
1103  Url url(*it);
1104 
1105  // check whether to refresh metadata
1106  // if the check fails for this url, it throws, so another url will be checked
1107  if (checkIfToRefreshMetadata(info, url, policy)!=REFRESH_NEEDED)
1108  return;
1109 
1110  MIL << "Going to refresh metadata from " << url << endl;
1111 
1112  // bsc#1048315: Always re-probe in case of repo format change.
1113  // TODO: Would be sufficient to verify the type and re-probe
1114  // if verification failed (or type is RepoType::NONE)
1115  repo::RepoType repokind = info.type();
1116  {
1117  repo::RepoType probed = probe( *it, info.path() );
1118  if ( repokind != probed )
1119  {
1120  repokind = probed;
1121  // update probed type only for repos in system
1122  for_( it, repoBegin(), repoEnd() )
1123  {
1124  if ( info.alias() == (*it).alias() )
1125  {
1126  RepoInfo modifiedrepo = *it;
1127  modifiedrepo.setType( repokind );
1128  // don't modify .repo in refresh.
1129  // modifyRepository( info.alias(), modifiedrepo );
1130  break;
1131  }
1132  }
1133  // Adjust the probed type in RepoInfo
1134  info.setProbedType( repokind ); // lazy init!
1135  }
1136  // no need to continue with an unknown type
1137  if ( repokind.toEnum() == RepoType::NONE_e )
1139  }
1140 
1141  Pathname mediarootpath = rawcache_path_for_repoinfo( _options, info );
1142  if( filesystem::assert_dir(mediarootpath) )
1143  {
1144  Exception ex(str::form( _("Can't create %s"), mediarootpath.c_str()) );
1145  ZYPP_THROW(ex);
1146  }
1147 
1148  // create temp dir as sibling of mediarootpath
1149  filesystem::TmpDir tmpdir( filesystem::TmpDir::makeSibling( mediarootpath ) );
1150  if( tmpdir.path().empty() )
1151  {
1152  Exception ex(_("Can't create metadata cache directory."));
1153  ZYPP_THROW(ex);
1154  }
1155 
1156  if ( ( repokind.toEnum() == RepoType::RPMMD_e ) ||
1157  ( repokind.toEnum() == RepoType::YAST2_e ) )
1158  {
1159  MediaSetAccess media(url);
1160  shared_ptr<repo::Downloader> downloader_ptr;
1161 
1162  MIL << "Creating downloader for [ " << info.alias() << " ]" << endl;
1163 
1164  if ( repokind.toEnum() == RepoType::RPMMD_e )
1165  downloader_ptr.reset(new yum::Downloader(info, mediarootpath));
1166  else
1167  downloader_ptr.reset( new susetags::Downloader(info, mediarootpath) );
1168 
1175  for_( it, repoBegin(), repoEnd() )
1176  {
1177  Pathname cachepath(rawcache_path_for_repoinfo( _options, *it ));
1178  if ( PathInfo(cachepath).isExist() )
1179  downloader_ptr->addCachePath(cachepath);
1180  }
1181 
1182  downloader_ptr->download( media, tmpdir.path() );
1183  }
1184  else if ( repokind.toEnum() == RepoType::RPMPLAINDIR_e )
1185  {
1186  MediaMounter media( url );
1187  RepoStatus newstatus = RepoStatus( media.getPathName( info.path() ) ); // dir status
1188 
1189  Pathname productpath( tmpdir.path() / info.path() );
1190  filesystem::assert_dir( productpath );
1191  newstatus.saveToCookieFile( productpath/"cookie" );
1192  }
1193  else
1194  {
1196  }
1197 
1198  // ok we have the metadata, now exchange
1199  // the contents
1200  filesystem::exchange( tmpdir.path(), mediarootpath );
1201  if ( ! isTmpRepo( info ) )
1202  reposManip(); // remember to trigger appdata refresh
1203 
1204  // we are done.
1205  return;
1206  }
1207  catch ( const Exception &e )
1208  {
1209  ZYPP_CAUGHT(e);
1210  ERR << "Trying another url..." << endl;
1211 
1212  // remember the exception caught for the *first URL*
1213  // if all other URLs fail, the rexception will be thrown with the
1214  // cause of the problem of the first URL remembered
1215  if (it == info.baseUrlsBegin())
1216  rexception.remember(e);
1217  else
1218  rexception.addHistory( e.asUserString() );
1219 
1220  }
1221  } // for every url
1222  ERR << "No more urls..." << endl;
1223  ZYPP_THROW(rexception);
1224  }
1225 
1227 
1228  void RepoManager::Impl::cleanMetadata( const RepoInfo & info, const ProgressData::ReceiverFnc & progressfnc )
1229  {
1230  ProgressData progress(100);
1231  progress.sendTo(progressfnc);
1232 
1233  filesystem::recursive_rmdir(rawcache_path_for_repoinfo(_options, info));
1234  progress.toMax();
1235  }
1236 
1237 
1238  void RepoManager::Impl::cleanPackages( const RepoInfo & info, const ProgressData::ReceiverFnc & progressfnc )
1239  {
1240  ProgressData progress(100);
1241  progress.sendTo(progressfnc);
1242 
1243  filesystem::recursive_rmdir(packagescache_path_for_repoinfo(_options, info));
1244  progress.toMax();
1245  }
1246 
1247 
1248  void RepoManager::Impl::buildCache( const RepoInfo & info, CacheBuildPolicy policy, const ProgressData::ReceiverFnc & progressrcv )
1249  {
1250  assert_alias(info);
1251  Pathname mediarootpath = rawcache_path_for_repoinfo( _options, info );
1252  Pathname productdatapath = rawproductdata_path_for_repoinfo( _options, info );
1253 
1254  if( filesystem::assert_dir(_options.repoCachePath) )
1255  {
1256  Exception ex(str::form( _("Can't create %s"), _options.repoCachePath.c_str()) );
1257  ZYPP_THROW(ex);
1258  }
1259  RepoStatus raw_metadata_status = metadataStatus(info);
1260  if ( raw_metadata_status.empty() )
1261  {
1262  /* if there is no cache at this point, we refresh the raw
1263  in case this is the first time - if it's !autorefresh,
1264  we may still refresh */
1265  refreshMetadata(info, RefreshIfNeeded, progressrcv );
1266  raw_metadata_status = metadataStatus(info);
1267  }
1268 
1269  bool needs_cleaning = false;
1270  if ( isCached( info ) )
1271  {
1272  MIL << info.alias() << " is already cached." << endl;
1273  RepoStatus cache_status = cacheStatus(info);
1274 
1275  if ( cache_status == raw_metadata_status )
1276  {
1277  MIL << info.alias() << " cache is up to date with metadata." << endl;
1278  if ( policy == BuildIfNeeded )
1279  {
1280  // On the fly add missing solv.idx files for bash completion.
1281  const Pathname & base = solv_path_for_repoinfo( _options, info);
1282  if ( ! PathInfo(base/"solv.idx").isExist() )
1283  sat::updateSolvFileIndex( base/"solv" );
1284 
1285  return;
1286  }
1287  else {
1288  MIL << info.alias() << " cache rebuild is forced" << endl;
1289  }
1290  }
1291 
1292  needs_cleaning = true;
1293  }
1294 
1295  ProgressData progress(100);
1297  progress.sendTo( ProgressReportAdaptor( progressrcv, report ) );
1298  progress.name(str::form(_("Building repository '%s' cache"), info.label().c_str()));
1299  progress.toMin();
1300 
1301  if (needs_cleaning)
1302  {
1303  cleanCache(info);
1304  }
1305 
1306  MIL << info.alias() << " building cache..." << info.type() << endl;
1307 
1308  Pathname base = solv_path_for_repoinfo( _options, info);
1309 
1310  if( filesystem::assert_dir(base) )
1311  {
1312  Exception ex(str::form( _("Can't create %s"), base.c_str()) );
1313  ZYPP_THROW(ex);
1314  }
1315 
1316  if( ! PathInfo(base).userMayW() )
1317  {
1318  Exception ex(str::form( _("Can't create cache at %s - no writing permissions."), base.c_str()) );
1319  ZYPP_THROW(ex);
1320  }
1321  Pathname solvfile = base / "solv";
1322 
1323  // do we have type?
1324  repo::RepoType repokind = info.type();
1325 
1326  // if the type is unknown, try probing.
1327  switch ( repokind.toEnum() )
1328  {
1329  case RepoType::NONE_e:
1330  // unknown, probe the local metadata
1331  repokind = probeCache( productdatapath );
1332  break;
1333  default:
1334  break;
1335  }
1336 
1337  MIL << "repo type is " << repokind << endl;
1338 
1339  switch ( repokind.toEnum() )
1340  {
1341  case RepoType::RPMMD_e :
1342  case RepoType::YAST2_e :
1344  {
1345  // Take care we unlink the solvfile on exception
1346  ManagedFile guard( solvfile, filesystem::unlink );
1347  scoped_ptr<MediaMounter> forPlainDirs;
1348 
1350  cmd.push_back( PathInfo( "/usr/bin/repo2solv" ).isFile() ? "repo2solv" : "repo2solv.sh" );
1351  // repo2solv expects -o as 1st arg!
1352  cmd.push_back( "-o" );
1353  cmd.push_back( solvfile.asString() );
1354  cmd.push_back( "-X" ); // autogenerate pattern from pattern-package
1355  // bsc#1104415: no more application support // cmd.push_back( "-A" ); // autogenerate application pseudo packages
1356 
1357  if ( repokind == RepoType::RPMPLAINDIR )
1358  {
1359  forPlainDirs.reset( new MediaMounter( info.url() ) );
1360  // recusive for plaindir as 2nd arg!
1361  cmd.push_back( "-R" );
1362  // FIXME this does only work form dir: URLs
1363  cmd.push_back( forPlainDirs->getPathName( info.path() ).c_str() );
1364  }
1365  else
1366  cmd.push_back( productdatapath.asString() );
1367 
1369  std::string errdetail;
1370 
1371  for ( std::string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() ) {
1372  WAR << " " << output;
1373  if ( errdetail.empty() ) {
1374  errdetail = prog.command();
1375  errdetail += '\n';
1376  }
1377  errdetail += output;
1378  }
1379 
1380  int ret = prog.close();
1381  if ( ret != 0 )
1382  {
1383  RepoException ex(str::form( _("Failed to cache repo (%d)."), ret ));
1384  ex.remember( errdetail );
1385  ZYPP_THROW(ex);
1386  }
1387 
1388  // We keep it.
1389  guard.resetDispose();
1390  sat::updateSolvFileIndex( solvfile ); // content digest for zypper bash completion
1391  }
1392  break;
1393  default:
1394  ZYPP_THROW(RepoUnknownTypeException( info, _("Unhandled repository type") ));
1395  break;
1396  }
1397  // update timestamp and checksum
1398  setCacheStatus(info, raw_metadata_status);
1399  MIL << "Commit cache.." << endl;
1400  progress.toMax();
1401  }
1402 
1404 
1405 
1412  repo::RepoType RepoManager::Impl::probe( const Url & url, const Pathname & path ) const
1413  {
1414  MIL << "going to probe the repo type at " << url << " (" << path << ")" << endl;
1415 
1416  if ( url.getScheme() == "dir" && ! PathInfo( url.getPathName()/path ).isDir() )
1417  {
1418  // Handle non existing local directory in advance, as
1419  // MediaSetAccess does not support it.
1420  MIL << "Probed type NONE (not exists) at " << url << " (" << path << ")" << endl;
1421  return repo::RepoType::NONE;
1422  }
1423 
1424  // prepare exception to be thrown if the type could not be determined
1425  // due to a media exception. We can't throw right away, because of some
1426  // problems with proxy servers returning an incorrect error
1427  // on ftp file-not-found(bnc #335906). Instead we'll check another types
1428  // before throwing.
1429 
1430  // TranslatorExplanation '%s' is an URL
1431  RepoException enew(str::form( _("Error trying to read from '%s'"), url.asString().c_str() ));
1432  bool gotMediaException = false;
1433  try
1434  {
1435  MediaSetAccess access(url);
1436  try
1437  {
1438  if ( access.doesFileExist(path/"/repodata/repomd.xml") )
1439  {
1440  MIL << "Probed type RPMMD at " << url << " (" << path << ")" << endl;
1441  return repo::RepoType::RPMMD;
1442  }
1443  }
1444  catch ( const media::MediaException &e )
1445  {
1446  ZYPP_CAUGHT(e);
1447  DBG << "problem checking for repodata/repomd.xml file" << endl;
1448  enew.remember(e);
1449  gotMediaException = true;
1450  }
1451 
1452  try
1453  {
1454  if ( access.doesFileExist(path/"/content") )
1455  {
1456  MIL << "Probed type YAST2 at " << url << " (" << path << ")" << endl;
1457  return repo::RepoType::YAST2;
1458  }
1459  }
1460  catch ( const media::MediaException &e )
1461  {
1462  ZYPP_CAUGHT(e);
1463  DBG << "problem checking for content file" << endl;
1464  enew.remember(e);
1465  gotMediaException = true;
1466  }
1467 
1468  // if it is a non-downloading URL denoting a directory
1469  if ( ! url.schemeIsDownloading() )
1470  {
1471  MediaMounter media( url );
1472  if ( PathInfo(media.getPathName()/path).isDir() )
1473  {
1474  // allow empty dirs for now
1475  MIL << "Probed type RPMPLAINDIR at " << url << " (" << path << ")" << endl;
1477  }
1478  }
1479  }
1480  catch ( const Exception &e )
1481  {
1482  ZYPP_CAUGHT(e);
1483  // TranslatorExplanation '%s' is an URL
1484  Exception enew(str::form( _("Unknown error reading from '%s'"), url.asString().c_str() ));
1485  enew.remember(e);
1486  ZYPP_THROW(enew);
1487  }
1488 
1489  if (gotMediaException)
1490  ZYPP_THROW(enew);
1491 
1492  MIL << "Probed type NONE at " << url << " (" << path << ")" << endl;
1493  return repo::RepoType::NONE;
1494  }
1495 
1502  {
1503  MIL << "going to probe the cached repo at " << path_r << endl;
1504 
1506 
1507  if ( PathInfo(path_r/"/repodata/repomd.xml").isFile() )
1508  { ret = repo::RepoType::RPMMD; }
1509  else if ( PathInfo(path_r/"/content").isFile() )
1510  { ret = repo::RepoType::YAST2; }
1511  else if ( PathInfo(path_r).isDir() )
1512  { ret = repo::RepoType::RPMPLAINDIR; }
1513 
1514  MIL << "Probed cached type " << ret << " at " << path_r << endl;
1515  return ret;
1516  }
1517 
1519 
1521  {
1522  MIL << "Going to clean up garbage in cache dirs" << endl;
1523 
1524  ProgressData progress(300);
1525  progress.sendTo(progressrcv);
1526  progress.toMin();
1527 
1528  std::list<Pathname> cachedirs;
1529  cachedirs.push_back(_options.repoRawCachePath);
1530  cachedirs.push_back(_options.repoPackagesCachePath);
1531  cachedirs.push_back(_options.repoSolvCachePath);
1532 
1533  for_( dir, cachedirs.begin(), cachedirs.end() )
1534  {
1535  if ( PathInfo(*dir).isExist() )
1536  {
1537  std::list<Pathname> entries;
1538  if ( filesystem::readdir( entries, *dir, false ) != 0 )
1539  // TranslatorExplanation '%s' is a pathname
1540  ZYPP_THROW(Exception(str::form(_("Failed to read directory '%s'"), dir->c_str())));
1541 
1542  unsigned sdircount = entries.size();
1543  unsigned sdircurrent = 1;
1544  for_( subdir, entries.begin(), entries.end() )
1545  {
1546  // if it does not belong known repo, make it disappear
1547  bool found = false;
1548  for_( r, repoBegin(), repoEnd() )
1549  if ( subdir->basename() == r->escaped_alias() )
1550  { found = true; break; }
1551 
1552  if ( ! found && ( Date::now()-PathInfo(*subdir).mtime() > Date::day ) )
1553  filesystem::recursive_rmdir( *subdir );
1554 
1555  progress.set( progress.val() + sdircurrent * 100 / sdircount );
1556  ++sdircurrent;
1557  }
1558  }
1559  else
1560  progress.set( progress.val() + 100 );
1561  }
1562  progress.toMax();
1563  }
1564 
1566 
1567  void RepoManager::Impl::cleanCache( const RepoInfo & info, const ProgressData::ReceiverFnc & progressrcv )
1568  {
1569  ProgressData progress(100);
1570  progress.sendTo(progressrcv);
1571  progress.toMin();
1572 
1573  MIL << "Removing raw metadata cache for " << info.alias() << endl;
1574  filesystem::recursive_rmdir(solv_path_for_repoinfo(_options, info));
1575 
1576  progress.toMax();
1577  }
1578 
1580 
1581  void RepoManager::Impl::loadFromCache( const RepoInfo & info, const ProgressData::ReceiverFnc & progressrcv )
1582  {
1583  assert_alias(info);
1584  Pathname solvfile = solv_path_for_repoinfo(_options, info) / "solv";
1585 
1586  if ( ! PathInfo(solvfile).isExist() )
1588 
1589  sat::Pool::instance().reposErase( info.alias() );
1590  try
1591  {
1592  Repository repo = sat::Pool::instance().addRepoSolv( solvfile, info );
1593  // test toolversion in order to rebuild solv file in case
1594  // it was written by a different libsolv-tool parser.
1595  const std::string & toolversion( sat::LookupRepoAttr( sat::SolvAttr::repositoryToolVersion, repo ).begin().asString() );
1596  if ( toolversion != LIBSOLV_TOOLVERSION )
1597  {
1598  repo.eraseFromPool();
1599  ZYPP_THROW(Exception(str::Str() << "Solv-file was created by '"<<toolversion<<"'-parser (want "<<LIBSOLV_TOOLVERSION<<")."));
1600  }
1601  }
1602  catch ( const Exception & exp )
1603  {
1604  ZYPP_CAUGHT( exp );
1605  MIL << "Try to handle exception by rebuilding the solv-file" << endl;
1606  cleanCache( info, progressrcv );
1607  buildCache( info, BuildIfNeeded, progressrcv );
1608 
1609  sat::Pool::instance().addRepoSolv( solvfile, info );
1610  }
1611  }
1612 
1614 
1615  void RepoManager::Impl::addRepository( const RepoInfo & info, const ProgressData::ReceiverFnc & progressrcv )
1616  {
1617  assert_alias(info);
1618 
1619  ProgressData progress(100);
1621  progress.sendTo( ProgressReportAdaptor( progressrcv, report ) );
1622  progress.name(str::form(_("Adding repository '%s'"), info.label().c_str()));
1623  progress.toMin();
1624 
1625  MIL << "Try adding repo " << info << endl;
1626 
1627  RepoInfo tosave = info;
1628  if ( repos().find(tosave) != repos().end() )
1630 
1631  // check the first url for now
1632  if ( _options.probe )
1633  {
1634  DBG << "unknown repository type, probing" << endl;
1635  assert_urls(tosave);
1636 
1637  RepoType probedtype( probe( tosave.url(), info.path() ) );
1638  if ( probedtype == RepoType::NONE )
1640  else
1641  tosave.setType(probedtype);
1642  }
1643 
1644  progress.set(50);
1645 
1646  // assert the directory exists
1647  filesystem::assert_dir(_options.knownReposPath);
1648 
1649  Pathname repofile = generateNonExistingName(
1650  _options.knownReposPath, generateFilename(tosave));
1651  // now we have a filename that does not exists
1652  MIL << "Saving repo in " << repofile << endl;
1653 
1654  std::ofstream file(repofile.c_str());
1655  if (!file)
1656  {
1657  // TranslatorExplanation '%s' is a filename
1658  ZYPP_THROW( Exception(str::form( _("Can't open file '%s' for writing."), repofile.c_str() )));
1659  }
1660 
1661  tosave.dumpAsIniOn(file);
1662  tosave.setFilepath(repofile);
1663  tosave.setMetadataPath( rawcache_path_for_repoinfo( _options, tosave ) );
1664  tosave.setPackagesPath( packagescache_path_for_repoinfo( _options, tosave ) );
1665  {
1666  // We should fix the API as we must inject those paths
1667  // into the repoinfo in order to keep it usable.
1668  RepoInfo & oinfo( const_cast<RepoInfo &>(info) );
1669  oinfo.setFilepath(repofile);
1670  oinfo.setMetadataPath( rawcache_path_for_repoinfo( _options, tosave ) );
1671  oinfo.setPackagesPath( packagescache_path_for_repoinfo( _options, tosave ) );
1672  }
1673  reposManip().insert(tosave);
1674 
1675  progress.set(90);
1676 
1677  // check for credentials in Urls
1678  UrlCredentialExtractor( _options.rootDir ).collect( tosave.baseUrls() );
1679 
1680  HistoryLog(_options.rootDir).addRepository(tosave);
1681 
1682  progress.toMax();
1683  MIL << "done" << endl;
1684  }
1685 
1686 
1688  {
1689  std::list<RepoInfo> repos = readRepoFile(url);
1690  for ( std::list<RepoInfo>::const_iterator it = repos.begin();
1691  it != repos.end();
1692  ++it )
1693  {
1694  // look if the alias is in the known repos.
1695  for_ ( kit, repoBegin(), repoEnd() )
1696  {
1697  if ( (*it).alias() == (*kit).alias() )
1698  {
1699  ERR << "To be added repo " << (*it).alias() << " conflicts with existing repo " << (*kit).alias() << endl;
1701  }
1702  }
1703  }
1704 
1705  std::string filename = Pathname(url.getPathName()).basename();
1706 
1707  if ( filename == Pathname() )
1708  {
1709  // TranslatorExplanation '%s' is an URL
1710  ZYPP_THROW(RepoException(str::form( _("Invalid repo file name at '%s'"), url.asString().c_str() )));
1711  }
1712 
1713  // assert the directory exists
1714  filesystem::assert_dir(_options.knownReposPath);
1715 
1716  Pathname repofile = generateNonExistingName(_options.knownReposPath, filename);
1717  // now we have a filename that does not exists
1718  MIL << "Saving " << repos.size() << " repo" << ( repos.size() ? "s" : "" ) << " in " << repofile << endl;
1719 
1720  std::ofstream file(repofile.c_str());
1721  if (!file)
1722  {
1723  // TranslatorExplanation '%s' is a filename
1724  ZYPP_THROW( Exception(str::form( _("Can't open file '%s' for writing."), repofile.c_str() )));
1725  }
1726 
1727  for ( std::list<RepoInfo>::iterator it = repos.begin();
1728  it != repos.end();
1729  ++it )
1730  {
1731  MIL << "Saving " << (*it).alias() << endl;
1732  it->dumpAsIniOn(file);
1733  it->setFilepath(repofile);
1734  it->setMetadataPath( rawcache_path_for_repoinfo( _options, *it ) );
1735  it->setPackagesPath( packagescache_path_for_repoinfo( _options, *it ) );
1736  reposManip().insert(*it);
1737 
1738  HistoryLog(_options.rootDir).addRepository(*it);
1739  }
1740 
1741  MIL << "done" << endl;
1742  }
1743 
1745 
1747  {
1748  ProgressData progress;
1750  progress.sendTo( ProgressReportAdaptor( progressrcv, report ) );
1751  progress.name(str::form(_("Removing repository '%s'"), info.label().c_str()));
1752 
1753  MIL << "Going to delete repo " << info.alias() << endl;
1754 
1755  for_( it, repoBegin(), repoEnd() )
1756  {
1757  // they can be the same only if the provided is empty, that means
1758  // the provided repo has no alias
1759  // then skip
1760  if ( (!info.alias().empty()) && ( info.alias() != (*it).alias() ) )
1761  continue;
1762 
1763  // TODO match by url
1764 
1765  // we have a matcing repository, now we need to know
1766  // where it does come from.
1767  RepoInfo todelete = *it;
1768  if (todelete.filepath().empty())
1769  {
1770  ZYPP_THROW(RepoException( todelete, _("Can't figure out where the repo is stored.") ));
1771  }
1772  else
1773  {
1774  // figure how many repos are there in the file:
1775  std::list<RepoInfo> filerepos = repositories_in_file(todelete.filepath());
1776  if ( filerepos.size() == 0 // bsc#984494: file may have already been deleted
1777  ||(filerepos.size() == 1 && filerepos.front().alias() == todelete.alias() ) )
1778  {
1779  // easy: file does not exist, contains no or only the repo to delete: delete the file
1780  int ret = filesystem::unlink( todelete.filepath() );
1781  if ( ! ( ret == 0 || ret == ENOENT ) )
1782  {
1783  // TranslatorExplanation '%s' is a filename
1784  ZYPP_THROW(RepoException( todelete, str::form( _("Can't delete '%s'"), todelete.filepath().c_str() )));
1785  }
1786  MIL << todelete.alias() << " successfully deleted." << endl;
1787  }
1788  else
1789  {
1790  // there are more repos in the same file
1791  // write them back except the deleted one.
1792  //TmpFile tmp;
1793  //std::ofstream file(tmp.path().c_str());
1794 
1795  // assert the directory exists
1796  filesystem::assert_dir(todelete.filepath().dirname());
1797 
1798  std::ofstream file(todelete.filepath().c_str());
1799  if (!file)
1800  {
1801  // TranslatorExplanation '%s' is a filename
1802  ZYPP_THROW( Exception(str::form( _("Can't open file '%s' for writing."), todelete.filepath().c_str() )));
1803  }
1804  for ( std::list<RepoInfo>::const_iterator fit = filerepos.begin();
1805  fit != filerepos.end();
1806  ++fit )
1807  {
1808  if ( (*fit).alias() != todelete.alias() )
1809  (*fit).dumpAsIniOn(file);
1810  }
1811  }
1812 
1813  CombinedProgressData cSubprogrcv(progress, 20);
1814  CombinedProgressData mSubprogrcv(progress, 40);
1815  CombinedProgressData pSubprogrcv(progress, 40);
1816  // now delete it from cache
1817  if ( isCached(todelete) )
1818  cleanCache( todelete, cSubprogrcv);
1819  // now delete metadata (#301037)
1820  cleanMetadata( todelete, mSubprogrcv );
1821  cleanPackages( todelete, pSubprogrcv );
1822  reposManip().erase(todelete);
1823  MIL << todelete.alias() << " successfully deleted." << endl;
1824  HistoryLog(_options.rootDir).removeRepository(todelete);
1825  return;
1826  } // else filepath is empty
1827 
1828  }
1829  // should not be reached on a sucess workflow
1831  }
1832 
1834 
1835  void RepoManager::Impl::modifyRepository( const std::string & alias, const RepoInfo & newinfo_r, const ProgressData::ReceiverFnc & progressrcv )
1836  {
1837  RepoInfo toedit = getRepositoryInfo(alias);
1838  RepoInfo newinfo( newinfo_r ); // need writable copy to upadte housekeeping data
1839 
1840  // check if the new alias already exists when renaming the repo
1841  if ( alias != newinfo.alias() && hasRepo( newinfo.alias() ) )
1842  {
1844  }
1845 
1846  if (toedit.filepath().empty())
1847  {
1848  ZYPP_THROW(RepoException( toedit, _("Can't figure out where the repo is stored.") ));
1849  }
1850  else
1851  {
1852  // figure how many repos are there in the file:
1853  std::list<RepoInfo> filerepos = repositories_in_file(toedit.filepath());
1854 
1855  // there are more repos in the same file
1856  // write them back except the deleted one.
1857  //TmpFile tmp;
1858  //std::ofstream file(tmp.path().c_str());
1859 
1860  // assert the directory exists
1862 
1863  std::ofstream file(toedit.filepath().c_str());
1864  if (!file)
1865  {
1866  // TranslatorExplanation '%s' is a filename
1867  ZYPP_THROW( Exception(str::form( _("Can't open file '%s' for writing."), toedit.filepath().c_str() )));
1868  }
1869  for ( std::list<RepoInfo>::const_iterator fit = filerepos.begin();
1870  fit != filerepos.end();
1871  ++fit )
1872  {
1873  // if the alias is different, dump the original
1874  // if it is the same, dump the provided one
1875  if ( (*fit).alias() != toedit.alias() )
1876  (*fit).dumpAsIniOn(file);
1877  else
1878  newinfo.dumpAsIniOn(file);
1879  }
1880 
1881  if ( toedit.enabled() && !newinfo.enabled() )
1882  {
1883  // On the fly remove solv.idx files for bash completion if a repo gets disabled.
1884  const Pathname & solvidx = solv_path_for_repoinfo(_options, newinfo)/"solv.idx";
1885  if ( PathInfo(solvidx).isExist() )
1886  filesystem::unlink( solvidx );
1887  }
1888 
1889  newinfo.setFilepath(toedit.filepath());
1890  newinfo.setMetadataPath( rawcache_path_for_repoinfo( _options, newinfo ) );
1891  newinfo.setPackagesPath( packagescache_path_for_repoinfo( _options, newinfo ) );
1892  {
1893  // We should fix the API as we must inject those paths
1894  // into the repoinfo in order to keep it usable.
1895  RepoInfo & oinfo( const_cast<RepoInfo &>(newinfo_r) );
1896  oinfo.setFilepath(toedit.filepath());
1897  oinfo.setMetadataPath( rawcache_path_for_repoinfo( _options, newinfo ) );
1898  oinfo.setPackagesPath( packagescache_path_for_repoinfo( _options, newinfo ) );
1899  }
1900  reposManip().erase(toedit);
1901  reposManip().insert(newinfo);
1902  // check for credentials in Urls
1903  UrlCredentialExtractor( _options.rootDir ).collect( newinfo.baseUrls() );
1904  HistoryLog(_options.rootDir).modifyRepository(toedit, newinfo);
1905  MIL << "repo " << alias << " modified" << endl;
1906  }
1907  }
1908 
1910 
1911  RepoInfo RepoManager::Impl::getRepositoryInfo( const std::string & alias, const ProgressData::ReceiverFnc & progressrcv )
1912  {
1913  RepoConstIterator it( findAlias( alias, repos() ) );
1914  if ( it != repos().end() )
1915  return *it;
1916  RepoInfo info;
1917  info.setAlias( alias );
1919  }
1920 
1921 
1922  RepoInfo RepoManager::Impl::getRepositoryInfo( const Url & url, const url::ViewOption & urlview, const ProgressData::ReceiverFnc & progressrcv )
1923  {
1924  for_( it, repoBegin(), repoEnd() )
1925  {
1926  for_( urlit, (*it).baseUrlsBegin(), (*it).baseUrlsEnd() )
1927  {
1928  if ( (*urlit).asString(urlview) == url.asString(urlview) )
1929  return *it;
1930  }
1931  }
1932  RepoInfo info;
1933  info.setBaseUrl( url );
1935  }
1936 
1938  //
1939  // Services
1940  //
1942 
1944  {
1945  assert_alias( service );
1946 
1947  // check if service already exists
1948  if ( hasService( service.alias() ) )
1950 
1951  // Writable ServiceInfo is needed to save the location
1952  // of the .service file. Finaly insert into the service list.
1953  ServiceInfo toSave( service );
1954  saveService( toSave );
1955  _services.insert( toSave );
1956 
1957  // check for credentials in Url
1958  UrlCredentialExtractor( _options.rootDir ).collect( toSave.url() );
1959 
1960  MIL << "added service " << toSave.alias() << endl;
1961  }
1962 
1964 
1965  void RepoManager::Impl::removeService( const std::string & alias )
1966  {
1967  MIL << "Going to delete service " << alias << endl;
1968 
1969  const ServiceInfo & service = getService( alias );
1970 
1971  Pathname location = service.filepath();
1972  if( location.empty() )
1973  {
1974  ZYPP_THROW(ServiceException( service, _("Can't figure out where the service is stored.") ));
1975  }
1976 
1977  ServiceSet tmpSet;
1978  parser::ServiceFileReader( location, ServiceCollector(tmpSet) );
1979 
1980  // only one service definition in the file
1981  if ( tmpSet.size() == 1 )
1982  {
1983  if ( filesystem::unlink(location) != 0 )
1984  {
1985  // TranslatorExplanation '%s' is a filename
1986  ZYPP_THROW(ServiceException( service, str::form( _("Can't delete '%s'"), location.c_str() ) ));
1987  }
1988  MIL << alias << " successfully deleted." << endl;
1989  }
1990  else
1991  {
1992  filesystem::assert_dir(location.dirname());
1993 
1994  std::ofstream file(location.c_str());
1995  if( !file )
1996  {
1997  // TranslatorExplanation '%s' is a filename
1998  ZYPP_THROW( Exception(str::form( _("Can't open file '%s' for writing."), location.c_str() )));
1999  }
2000 
2001  for_(it, tmpSet.begin(), tmpSet.end())
2002  {
2003  if( it->alias() != alias )
2004  it->dumpAsIniOn(file);
2005  }
2006 
2007  MIL << alias << " successfully deleted from file " << location << endl;
2008  }
2009 
2010  // now remove all repositories added by this service
2011  RepoCollector rcollector;
2012  getRepositoriesInService( alias,
2013  boost::make_function_output_iterator( bind( &RepoCollector::collect, &rcollector, _1 ) ) );
2014  // cannot do this directly in getRepositoriesInService - would invalidate iterators
2015  for_(rit, rcollector.repos.begin(), rcollector.repos.end())
2016  removeRepository(*rit);
2017  }
2018 
2020 
2022  {
2023  // copy the set of services since refreshService
2024  // can eventually invalidate the iterator
2025  ServiceSet services( serviceBegin(), serviceEnd() );
2026  for_( it, services.begin(), services.end() )
2027  {
2028  if ( !it->enabled() )
2029  continue;
2030 
2031  try {
2032  refreshService(*it, options_r);
2033  }
2034  catch ( const repo::ServicePluginInformalException & e )
2035  { ;/* ignore ServicePluginInformalException */ }
2036  }
2037  }
2038 
2039  void RepoManager::Impl::refreshService( const std::string & alias, const RefreshServiceOptions & options_r )
2040  {
2041  ServiceInfo service( getService( alias ) );
2042  assert_alias( service );
2043  assert_url( service );
2044  MIL << "Going to refresh service '" << service.alias() << "', url: " << service.url() << ", opts: " << options_r << endl;
2045 
2046  if ( service.ttl() && !( options_r.testFlag( RefreshService_forceRefresh) || options_r.testFlag( RefreshService_restoreStatus ) ) )
2047  {
2048  // Service defines a TTL; maybe we can re-use existing data without refresh.
2049  Date lrf = service.lrf();
2050  if ( lrf )
2051  {
2052  Date now( Date::now() );
2053  if ( lrf <= now )
2054  {
2055  if ( (lrf+=service.ttl()) > now ) // lrf+= !
2056  {
2057  MIL << "Skip: '" << service.alias() << "' metadata valid until " << lrf << endl;
2058  return;
2059  }
2060  }
2061  else
2062  WAR << "Force: '" << service.alias() << "' metadata last refresh in the future: " << lrf << endl;
2063  }
2064  }
2065 
2066  // NOTE: It might be necessary to modify and rewrite the service info.
2067  // Either when probing the type, or when adjusting the repositories
2068  // enable/disable state.:
2069  bool serviceModified = false;
2070 
2072 
2073  // if the type is unknown, try probing.
2074  if ( service.type() == repo::ServiceType::NONE )
2075  {
2076  repo::ServiceType type = probeService( service.url() );
2077  if ( type != ServiceType::NONE )
2078  {
2079  service.setProbedType( type ); // lazy init!
2080  serviceModified = true;
2081  }
2082  }
2083 
2084  // get target distro identifier
2085  std::string servicesTargetDistro = _options.servicesTargetDistro;
2086  if ( servicesTargetDistro.empty() )
2087  {
2088  servicesTargetDistro = Target::targetDistribution( Pathname() );
2089  }
2090  DBG << "ServicesTargetDistro: " << servicesTargetDistro << endl;
2091 
2092  // parse it
2093  Date::Duration origTtl = service.ttl(); // FIXME Ugly hack: const service.ttl modified when parsing
2094  RepoCollector collector(servicesTargetDistro);
2095  // FIXME Ugly hack: ServiceRepos may throw ServicePluginInformalException
2096  // which is actually a notification. Using an exception for this
2097  // instead of signal/callback is bad. Needs to be fixed here, in refreshServices()
2098  // and in zypper.
2099  std::pair<DefaultIntegral<bool,false>, repo::ServicePluginInformalException> uglyHack;
2100  try {
2101  // FIXME bsc#1080693: Shortcoming of (plugin)services (and repos as well) is that they
2102  // are not aware of the RepoManagers rootDir. The service url, as created in known_services,
2103  // contains the full path to the script. The script however has to be executed chrooted.
2104  // Repos would need to know the RepoMangers rootDir to use the correct vars.d to replace
2105  // repos variables. Until RepoInfoBase is aware if the rootDir, we need to explicitly pass it
2106  // to ServiceRepos.
2107  ServiceRepos( _options.rootDir, service, bind( &RepoCollector::collect, &collector, _1 ) );
2108  }
2109  catch ( const repo::ServicePluginInformalException & e )
2110  {
2111  /* ignore ServicePluginInformalException and throw later */
2112  uglyHack.first = true;
2113  uglyHack.second = e;
2114  }
2115  if ( service.ttl() != origTtl ) // repoindex.xml changed ttl
2116  {
2117  if ( !service.ttl() )
2118  service.setLrf( Date() ); // don't need lrf when zero ttl
2119  serviceModified = true;
2120  }
2122  // On the fly remember the new repo states as defined the reopoindex.xml.
2123  // Move into ServiceInfo later.
2124  ServiceInfo::RepoStates newRepoStates;
2125 
2126  // set service alias and base url for all collected repositories
2127  for_( it, collector.repos.begin(), collector.repos.end() )
2128  {
2129  // First of all: Prepend service alias:
2130  it->setAlias( str::form( "%s:%s", service.alias().c_str(), it->alias().c_str() ) );
2131  // set reference to the parent service
2132  it->setService( service.alias() );
2133 
2134  // remember the new parsed repo state
2135  newRepoStates[it->alias()] = *it;
2136 
2137  // - If the repo url was not set by the repoindex parser, set service's url.
2138  // - Libzypp currently has problem with separate url + path handling so just
2139  // append a path, if set, to the baseurls
2140  // - Credentials in the url authority will be extracted later, either if the
2141  // repository is added or if we check for changed urls.
2142  Pathname path;
2143  if ( !it->path().empty() )
2144  {
2145  if ( it->path() != "/" )
2146  path = it->path();
2147  it->setPath("");
2148  }
2149 
2150  if ( it->baseUrlsEmpty() )
2151  {
2152  Url url( service.rawUrl() );
2153  if ( !path.empty() )
2154  url.setPathName( url.getPathName() / path );
2155  it->setBaseUrl( std::move(url) );
2156  }
2157  else if ( !path.empty() )
2158  {
2159  RepoInfo::url_set urls( it->rawBaseUrls() );
2160  for ( Url & url : urls )
2161  {
2162  url.setPathName( url.getPathName() / path );
2163  }
2164  it->setBaseUrls( std::move(urls) );
2165  }
2166  }
2167 
2169  // Now compare collected repos with the ones in the system...
2170  //
2171  RepoInfoList oldRepos;
2172  getRepositoriesInService( service.alias(), std::back_inserter( oldRepos ) );
2173 
2175  // find old repositories to remove...
2176  for_( oldRepo, oldRepos.begin(), oldRepos.end() )
2177  {
2178  if ( ! foundAliasIn( oldRepo->alias(), collector.repos ) )
2179  {
2180  if ( oldRepo->enabled() )
2181  {
2182  // Currently enabled. If this was a user modification remember the state.
2183  const auto & last = service.repoStates().find( oldRepo->alias() );
2184  if ( last != service.repoStates().end() && ! last->second.enabled )
2185  {
2186  DBG << "Service removes user enabled repo " << oldRepo->alias() << endl;
2187  service.addRepoToEnable( oldRepo->alias() );
2188  serviceModified = true;
2189  }
2190  else
2191  DBG << "Service removes enabled repo " << oldRepo->alias() << endl;
2192  }
2193  else
2194  DBG << "Service removes disabled repo " << oldRepo->alias() << endl;
2195 
2196  removeRepository( *oldRepo );
2197  }
2198  }
2199 
2201  // create missing repositories and modify existing ones if needed...
2202  UrlCredentialExtractor urlCredentialExtractor( _options.rootDir ); // To collect any credentials stored in repo URLs
2203  for_( it, collector.repos.begin(), collector.repos.end() )
2204  {
2205  // User explicitly requested the repo being enabled?
2206  // User explicitly requested the repo being disabled?
2207  // And hopefully not both ;) If so, enable wins.
2208 
2209  TriBool toBeEnabled( indeterminate ); // indeterminate - follow the service request
2210  DBG << "Service request to " << (it->enabled()?"enable":"disable") << " service repo " << it->alias() << endl;
2211 
2212  if ( options_r.testFlag( RefreshService_restoreStatus ) )
2213  {
2214  DBG << "Opt RefreshService_restoreStatus " << it->alias() << endl;
2215  // this overrides any pending request!
2216  // Remove from enable request list.
2217  // NOTE: repoToDisable is handled differently.
2218  // It gets cleared on each refresh.
2219  service.delRepoToEnable( it->alias() );
2220  // toBeEnabled stays indeterminate!
2221  }
2222  else
2223  {
2224  if ( service.repoToEnableFind( it->alias() ) )
2225  {
2226  DBG << "User request to enable service repo " << it->alias() << endl;
2227  toBeEnabled = true;
2228  // Remove from enable request list.
2229  // NOTE: repoToDisable is handled differently.
2230  // It gets cleared on each refresh.
2231  service.delRepoToEnable( it->alias() );
2232  serviceModified = true;
2233  }
2234  else if ( service.repoToDisableFind( it->alias() ) )
2235  {
2236  DBG << "User request to disable service repo " << it->alias() << endl;
2237  toBeEnabled = false;
2238  }
2239  }
2240 
2241  RepoInfoList::iterator oldRepo( findAlias( it->alias(), oldRepos ) );
2242  if ( oldRepo == oldRepos.end() )
2243  {
2244  // Not found in oldRepos ==> a new repo to add
2245 
2246  // Make sure the service repo is created with the appropriate enablement
2247  if ( ! indeterminate(toBeEnabled) )
2248  it->setEnabled( ( bool ) toBeEnabled );
2249 
2250  DBG << "Service adds repo " << it->alias() << " " << (it->enabled()?"enabled":"disabled") << endl;
2251  addRepository( *it );
2252  }
2253  else
2254  {
2255  // ==> an exising repo to check
2256  bool oldRepoModified = false;
2257 
2258  if ( indeterminate(toBeEnabled) )
2259  {
2260  // No user request: check for an old user modificaton otherwise follow service request.
2261  // NOTE: Assert toBeEnabled is boolean afterwards!
2262  if ( oldRepo->enabled() == it->enabled() )
2263  toBeEnabled = it->enabled(); // service requests no change to the system
2264  else if (options_r.testFlag( RefreshService_restoreStatus ) )
2265  {
2266  toBeEnabled = it->enabled(); // RefreshService_restoreStatus forced
2267  DBG << "Opt RefreshService_restoreStatus " << it->alias() << " forces " << (toBeEnabled?"enabled":"disabled") << endl;
2268  }
2269  else
2270  {
2271  const auto & last = service.repoStates().find( oldRepo->alias() );
2272  if ( last == service.repoStates().end() || last->second.enabled != it->enabled() )
2273  toBeEnabled = it->enabled(); // service request has changed since last refresh -> follow
2274  else
2275  {
2276  toBeEnabled = oldRepo->enabled(); // service request unchaned since last refresh -> keep user modification
2277  DBG << "User modified service repo " << it->alias() << " may stay " << (toBeEnabled?"enabled":"disabled") << endl;
2278  }
2279  }
2280  }
2281 
2282  // changed enable?
2283  if ( toBeEnabled == oldRepo->enabled() )
2284  {
2285  DBG << "Service repo " << it->alias() << " stays " << (oldRepo->enabled()?"enabled":"disabled") << endl;
2286  }
2287  else if ( toBeEnabled )
2288  {
2289  DBG << "Service repo " << it->alias() << " gets enabled" << endl;
2290  oldRepo->setEnabled( true );
2291  oldRepoModified = true;
2292  }
2293  else
2294  {
2295  DBG << "Service repo " << it->alias() << " gets disabled" << endl;
2296  oldRepo->setEnabled( false );
2297  oldRepoModified = true;
2298  }
2299 
2300  // all other attributes follow the service request:
2301 
2302  // changed name (raw!)
2303  if ( oldRepo->rawName() != it->rawName() )
2304  {
2305  DBG << "Service repo " << it->alias() << " gets new NAME " << it->rawName() << endl;
2306  oldRepo->setName( it->rawName() );
2307  oldRepoModified = true;
2308  }
2309 
2310  // changed autorefresh
2311  if ( oldRepo->autorefresh() != it->autorefresh() )
2312  {
2313  DBG << "Service repo " << it->alias() << " gets new AUTOREFRESH " << it->autorefresh() << endl;
2314  oldRepo->setAutorefresh( it->autorefresh() );
2315  oldRepoModified = true;
2316  }
2317 
2318  // changed priority?
2319  if ( oldRepo->priority() != it->priority() )
2320  {
2321  DBG << "Service repo " << it->alias() << " gets new PRIORITY " << it->priority() << endl;
2322  oldRepo->setPriority( it->priority() );
2323  oldRepoModified = true;
2324  }
2325 
2326  // changed url?
2327  {
2328  RepoInfo::url_set newUrls( it->rawBaseUrls() );
2329  urlCredentialExtractor.extract( newUrls ); // Extract! to prevent passwds from disturbing the comparison below
2330  if ( oldRepo->rawBaseUrls() != newUrls )
2331  {
2332  DBG << "Service repo " << it->alias() << " gets new URLs " << newUrls << endl;
2333  oldRepo->setBaseUrls( std::move(newUrls) );
2334  oldRepoModified = true;
2335  }
2336  }
2337 
2338  // changed gpg check settings?
2339  // ATM only plugin services can set GPG values.
2340  if ( service.type() == ServiceType::PLUGIN )
2341  {
2342  TriBool ogpg[3]; // Gpg RepoGpg PkgGpg
2343  TriBool ngpg[3];
2344  oldRepo->getRawGpgChecks( ogpg[0], ogpg[1], ogpg[2] );
2345  it-> getRawGpgChecks( ngpg[0], ngpg[1], ngpg[2] );
2346 #define Z_CHKGPG(I,N) \
2347  if ( ! sameTriboolState( ogpg[I], ngpg[I] ) ) \
2348  { \
2349  DBG << "Service repo " << it->alias() << " gets new "#N"Check " << ngpg[I] << endl; \
2350  oldRepo->set##N##Check( ngpg[I] ); \
2351  oldRepoModified = true; \
2352  }
2353  Z_CHKGPG( 0, Gpg );
2354  Z_CHKGPG( 1, RepoGpg );
2355  Z_CHKGPG( 2, PkgGpg );
2356 #undef Z_CHKGPG
2357  }
2358 
2359  // save if modified:
2360  if ( oldRepoModified )
2361  {
2362  modifyRepository( oldRepo->alias(), *oldRepo );
2363  }
2364  }
2365  }
2366 
2367  // Unlike reposToEnable, reposToDisable is always cleared after refresh.
2368  if ( ! service.reposToDisableEmpty() )
2369  {
2370  service.clearReposToDisable();
2371  serviceModified = true;
2372  }
2373 
2374  // Remember original service request for next refresh
2375  if ( service.repoStates() != newRepoStates )
2376  {
2377  service.setRepoStates( std::move(newRepoStates) );
2378  serviceModified = true;
2379  }
2380 
2382  // save service if modified: (unless a plugin service)
2383  if ( service.type() != ServiceType::PLUGIN )
2384  {
2385  if ( service.ttl() )
2386  {
2387  service.setLrf( Date::now() ); // remember last refresh
2388  serviceModified = true; // or use a cookie file
2389  }
2390 
2391  if ( serviceModified )
2392  {
2393  // write out modified service file.
2394  modifyService( service.alias(), service );
2395  }
2396  }
2397 
2398  if ( uglyHack.first )
2399  {
2400  throw( uglyHack.second ); // intentionally not ZYPP_THROW
2401  }
2402  }
2403 
2405 
2406  void RepoManager::Impl::modifyService( const std::string & oldAlias, const ServiceInfo & newService )
2407  {
2408  MIL << "Going to modify service " << oldAlias << endl;
2409 
2410  // we need a writable copy to link it to the file where
2411  // it is saved if we modify it
2412  ServiceInfo service(newService);
2413 
2414  if ( service.type() == ServiceType::PLUGIN )
2415  {
2417  }
2418 
2419  const ServiceInfo & oldService = getService(oldAlias);
2420 
2421  Pathname location = oldService.filepath();
2422  if( location.empty() )
2423  {
2424  ZYPP_THROW(ServiceException( oldService, _("Can't figure out where the service is stored.") ));
2425  }
2426 
2427  // remember: there may multiple services being defined in one file:
2428  ServiceSet tmpSet;
2429  parser::ServiceFileReader( location, ServiceCollector(tmpSet) );
2430 
2431  filesystem::assert_dir(location.dirname());
2432  std::ofstream file(location.c_str());
2433  for_(it, tmpSet.begin(), tmpSet.end())
2434  {
2435  if( *it != oldAlias )
2436  it->dumpAsIniOn(file);
2437  }
2438  service.dumpAsIniOn(file);
2439  file.close();
2440  service.setFilepath(location);
2441 
2442  _services.erase(oldAlias);
2443  _services.insert(service);
2444  // check for credentials in Urls
2445  UrlCredentialExtractor( _options.rootDir ).collect( service.url() );
2446 
2447 
2448  // changed properties affecting also repositories
2449  if ( oldAlias != service.alias() // changed alias
2450  || oldService.enabled() != service.enabled() ) // changed enabled status
2451  {
2452  std::vector<RepoInfo> toModify;
2453  getRepositoriesInService(oldAlias, std::back_inserter(toModify));
2454  for_( it, toModify.begin(), toModify.end() )
2455  {
2456  if ( oldService.enabled() != service.enabled() )
2457  {
2458  if ( service.enabled() )
2459  {
2460  // reset to last refreshs state
2461  const auto & last = service.repoStates().find( it->alias() );
2462  if ( last != service.repoStates().end() )
2463  it->setEnabled( last->second.enabled );
2464  }
2465  else
2466  it->setEnabled( false );
2467  }
2468 
2469  if ( oldAlias != service.alias() )
2470  it->setService(service.alias());
2471 
2472  modifyRepository(it->alias(), *it);
2473  }
2474  }
2475 
2477  }
2478 
2480 
2482  {
2483  try
2484  {
2485  MediaSetAccess access(url);
2486  if ( access.doesFileExist("/repo/repoindex.xml") )
2487  return repo::ServiceType::RIS;
2488  }
2489  catch ( const media::MediaException &e )
2490  {
2491  ZYPP_CAUGHT(e);
2492  // TranslatorExplanation '%s' is an URL
2493  RepoException enew(str::form( _("Error trying to read from '%s'"), url.asString().c_str() ));
2494  enew.remember(e);
2495  ZYPP_THROW(enew);
2496  }
2497  catch ( const Exception &e )
2498  {
2499  ZYPP_CAUGHT(e);
2500  // TranslatorExplanation '%s' is an URL
2501  Exception enew(str::form( _("Unknown error reading from '%s'"), url.asString().c_str() ));
2502  enew.remember(e);
2503  ZYPP_THROW(enew);
2504  }
2505 
2506  return repo::ServiceType::NONE;
2507  }
2508 
2510  //
2511  // CLASS NAME : RepoManager
2512  //
2514 
2516  : _pimpl( new Impl(opt) )
2517  {}
2518 
2520  {}
2521 
2523  { return _pimpl->repoEmpty(); }
2524 
2526  { return _pimpl->repoSize(); }
2527 
2529  { return _pimpl->repoBegin(); }
2530 
2532  { return _pimpl->repoEnd(); }
2533 
2534  RepoInfo RepoManager::getRepo( const std::string & alias ) const
2535  { return _pimpl->getRepo( alias ); }
2536 
2537  bool RepoManager::hasRepo( const std::string & alias ) const
2538  { return _pimpl->hasRepo( alias ); }
2539 
2540  std::string RepoManager::makeStupidAlias( const Url & url_r )
2541  {
2542  std::string ret( url_r.getScheme() );
2543  if ( ret.empty() )
2544  ret = "repo-";
2545  else
2546  ret += "-";
2547 
2548  std::string host( url_r.getHost() );
2549  if ( ! host.empty() )
2550  {
2551  ret += host;
2552  ret += "-";
2553  }
2554 
2555  static Date::ValueType serial = Date::now();
2556  ret += Digest::digest( Digest::sha1(), str::hexstring( ++serial ) +url_r.asCompleteString() ).substr(0,8);
2557  return ret;
2558  }
2559 
2561  { return _pimpl->metadataStatus( info ); }
2562 
2564  { return _pimpl->checkIfToRefreshMetadata( info, url, policy ); }
2565 
2567  { return _pimpl->metadataPath( info ); }
2568 
2570  { return _pimpl->packagesPath( info ); }
2571 
2573  { return _pimpl->refreshMetadata( info, policy, progressrcv ); }
2574 
2575  void RepoManager::cleanMetadata( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv )
2576  { return _pimpl->cleanMetadata( info, progressrcv ); }
2577 
2578  void RepoManager::cleanPackages( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv )
2579  { return _pimpl->cleanPackages( info, progressrcv ); }
2580 
2582  { return _pimpl->cacheStatus( info ); }
2583 
2584  void RepoManager::buildCache( const RepoInfo &info, CacheBuildPolicy policy, const ProgressData::ReceiverFnc & progressrcv )
2585  { return _pimpl->buildCache( info, policy, progressrcv ); }
2586 
2587  void RepoManager::cleanCache( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv )
2588  { return _pimpl->cleanCache( info, progressrcv ); }
2589 
2590  bool RepoManager::isCached( const RepoInfo &info ) const
2591  { return _pimpl->isCached( info ); }
2592 
2593  void RepoManager::loadFromCache( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv )
2594  { return _pimpl->loadFromCache( info, progressrcv ); }
2595 
2597  { return _pimpl->cleanCacheDirGarbage( progressrcv ); }
2598 
2599  repo::RepoType RepoManager::probe( const Url & url, const Pathname & path ) const
2600  { return _pimpl->probe( url, path ); }
2601 
2603  { return _pimpl->probe( url ); }
2604 
2605  void RepoManager::addRepository( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv )
2606  { return _pimpl->addRepository( info, progressrcv ); }
2607 
2609  { return _pimpl->addRepositories( url, progressrcv ); }
2610 
2611  void RepoManager::removeRepository( const RepoInfo & info, const ProgressData::ReceiverFnc & progressrcv )
2612  { return _pimpl->removeRepository( info, progressrcv ); }
2613 
2614  void RepoManager::modifyRepository( const std::string &alias, const RepoInfo & newinfo, const ProgressData::ReceiverFnc & progressrcv )
2615  { return _pimpl->modifyRepository( alias, newinfo, progressrcv ); }
2616 
2617  RepoInfo RepoManager::getRepositoryInfo( const std::string &alias, const ProgressData::ReceiverFnc & progressrcv )
2618  { return _pimpl->getRepositoryInfo( alias, progressrcv ); }
2619 
2621  { return _pimpl->getRepositoryInfo( url, urlview, progressrcv ); }
2622 
2624  { return _pimpl->serviceEmpty(); }
2625 
2627  { return _pimpl->serviceSize(); }
2628 
2630  { return _pimpl->serviceBegin(); }
2631 
2633  { return _pimpl->serviceEnd(); }
2634 
2635  ServiceInfo RepoManager::getService( const std::string & alias ) const
2636  { return _pimpl->getService( alias ); }
2637 
2638  bool RepoManager::hasService( const std::string & alias ) const
2639  { return _pimpl->hasService( alias ); }
2640 
2642  { return _pimpl->probeService( url ); }
2643 
2644  void RepoManager::addService( const std::string & alias, const Url& url )
2645  { return _pimpl->addService( alias, url ); }
2646 
2647  void RepoManager::addService( const ServiceInfo & service )
2648  { return _pimpl->addService( service ); }
2649 
2650  void RepoManager::removeService( const std::string & alias )
2651  { return _pimpl->removeService( alias ); }
2652 
2653  void RepoManager::removeService( const ServiceInfo & service )
2654  { return _pimpl->removeService( service ); }
2655 
2657  { return _pimpl->refreshServices( options_r ); }
2658 
2659  void RepoManager::refreshService( const std::string & alias, const RefreshServiceOptions & options_r )
2660  { return _pimpl->refreshService( alias, options_r ); }
2661 
2662  void RepoManager::refreshService( const ServiceInfo & service, const RefreshServiceOptions & options_r )
2663  { return _pimpl->refreshService( service, options_r ); }
2664 
2665  void RepoManager::modifyService( const std::string & oldAlias, const ServiceInfo & service )
2666  { return _pimpl->modifyService( oldAlias, service ); }
2667 
2669 
2670  std::ostream & operator<<( std::ostream & str, const RepoManager & obj )
2671  { return str << *obj._pimpl; }
2672 
2674 } // namespace zypp
_mid
media::MediaAccessId _mid
Definition: RepoManager.cc:185
zypp::filesystem::PathInfo::mtime
time_t mtime() const
Definition: PathInfo.h:376
zypp::repo::ServiceRepos
Retrieval of repository list for a service.
Definition: ServiceRepos.h:25
zypp::repo::ServiceType
Service type enumeration.
Definition: ServiceType.h:26
zypp::RepoManager::Impl::refreshMetadata
void refreshMetadata(const RepoInfo &info, RawMetadataRefreshPolicy policy, OPT_PROGRESS)
Definition: RepoManager.cc:1086
Downloader.h
zypp::sat::Pool::instance
static Pool instance()
Singleton ctor.
Definition: Pool.h:55
ExternalProgram.h
zypp::filesystem::readdir
int readdir(std::list< std::string > &retlist_r, const Pathname &path_r, bool dots_r)
Return content of directory via retlist.
Definition: PathInfo.cc:584
zypp::ServiceInfo::noService
static const ServiceInfo noService
Represents an empty service.
Definition: ServiceInfo.h:61
zypp::ExternalProgram::Stderr_To_Stdout
Definition: ExternalProgram.h:73
zypp::ZConfig::repo_add_probe
bool repo_add_probe() const
Whether repository urls should be probed.
Definition: ZConfig.cc:1010
zypp::RepoStatus
Track changing files or directories.
Definition: RepoStatus.h:38
zypp::RepoManager::Impl::_reposX
RepoSet _reposX
Definition: RepoManager.cc:706
zypp::RepoManager::buildCache
void buildCache(const RepoInfo &info, CacheBuildPolicy policy=BuildIfNeeded, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Refresh local cache.
Definition: RepoManager.cc:2584
zypp::ServiceInfo::url
Url url() const
The service url.
Definition: ServiceInfo.cc:99
zypp::filesystem::assert_dir
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
Definition: PathInfo.cc:315
zypp::RepoManager::cleanPackages
void cleanPackages(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Clean local package cache.
Definition: RepoManager.cc:2578
_services
ServiceSet & _services
Definition: RepoManager.cc:450
zypp::RepoInfo::setBaseUrl
void setBaseUrl(const Url &url)
Clears current base URL list and adds url.
Definition: RepoInfo.cc:637
zypp::repo::yum::Downloader
Downloader for YUM (rpm-nmd) repositories Encapsulates all the knowledge of which files have to be do...
Definition: Downloader.h:40
zypp::Url::getScheme
std::string getScheme() const
Returns the scheme name of the URL.
Definition: Url.cc:528
zypp::ServiceInfo::setLrf
void setLrf(Date lrf_r)
Set date of last refresh.
Definition: ServiceInfo.cc:117
zypp::repo::RepoType::RPMMD_e
Definition: RepoType.h:37
zypp::RepoManager::Impl::generateNonExistingName
Pathname generateNonExistingName(const Pathname &dir, const std::string &basefilename) const
Generate a non existing filename in a directory, using a base name.
Definition: RepoManager.cc:759
zypp::str::hexstring
std::string hexstring(char n, int w=4)
Definition: String.h:321
TmpPath.h
PathInfo.h
zypp::readRepoFile
std::list< RepoInfo > readRepoFile(const Url &repo_file)
Parses repo_file and returns a list of RepoInfo objects corresponding to repositories found within th...
Definition: RepoManager.cc:457
zypp::RepoManager::refreshMetadata
void refreshMetadata(const RepoInfo &info, RawMetadataRefreshPolicy policy=RefreshIfNeeded, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Refresh local raw cache.
Definition: RepoManager.cc:2572
zypp::media::MediaException
Just inherits Exception to separate media exceptions.
Definition: MediaException.h:35
zypp::ProgressData::set
bool set(value_type val_r)
Set new counter value.
Definition: ProgressData.h:246
repos
RepoInfoList repos
Definition: RepoManager.cc:277
zypp::filesystem::PathInfo::isExist
bool isExist() const
Return whether valid stat info exists.
Definition: PathInfo.h:281
zypp::RepoInfo::setPackagesPath
void setPackagesPath(const Pathname &path)
set the path where the local packages are stored
Definition: RepoInfo.cc:659
zypp::RepoManagerOptions::rootDir
Pathname rootDir
remembers root_r value for later use
Definition: RepoManager.h:96
zypp::RepoManager::packagesPath
Pathname packagesPath(const RepoInfo &info) const
Path where the rpm packages are downloaded and kept.
Definition: RepoManager.cc:2569
ZYppFactory.h
zypp::RepoManager::Impl::_services
ServiceSet _services
Definition: RepoManager.cc:707
zypp::ServiceInfo::repoStates
const RepoStates & repoStates() const
Access the remembered repository states.
Definition: ServiceInfo.cc:161
zypp::RepoManager::Impl::clone
Impl * clone() const
clone for RWCOW_pointer
Definition: RepoManager.cc:714
zypp::RepoManagerOptions::knownServicesPath
Pathname knownServicesPath
Definition: RepoManager.h:84
zypp::ServiceInfo
Service data.
Definition: ServiceInfo.h:36
zypp::RepoManager::ServiceConstIterator
ServiceSet::const_iterator ServiceConstIterator
Definition: RepoManager.h:115
zypp::Exception
Base class for Exception.
Definition: Exception.h:145
zypp::RepoManager::Impl::generateFilename
std::string generateFilename(const ServiceInfo &info) const
Definition: RepoManager.cc:676
zypp::Digest::sha1
static const std::string & sha1()
sha1
Definition: Digest.cc:49
_root
const Pathname & _root
Definition: RepoManager.cc:143
zypp::RepoManager::Impl::cacheStatus
RepoStatus cacheStatus(const RepoInfo &info) const
Definition: RepoManager.cc:618
zypp::sat::Pool::reposErase
void reposErase(const std::string &alias_r)
Remove a Repository named alias_r.
Definition: Pool.h:112
zypp::filesystem::TmpPath::path
Pathname path() const
Definition: TmpPath.cc:146
zypp::Target::targetDistribution
std::string targetDistribution() const
This is register.target attribute of the installed base product.
Definition: Target.cc:102
OUTS
#define OUTS(X)
zypp::RepoManager::Impl::reposManip
RepoSet & reposManip()
Definition: RepoManager.cc:702
zypp::RepoManager::isCached
bool isCached(const RepoInfo &info) const
Whether a repository exists in cache.
Definition: RepoManager.cc:2590
zypp::callback::SendReport
Definition: Callback.h:236
zypp::RepoInfo
What is known about a repository.
Definition: RepoInfo.h:71
zypp::RepoInfo::urls_const_iterator
transform_iterator< repo::RepoVariablesUrlReplacer, url_set::const_iterator > urls_const_iterator
Definition: RepoInfo.h:105
zypp::repo::ServicePluginInformalException
Service plugin has trouble providing the metadata but this should not be treated as error.
Definition: RepoException.h:262
zypp::ServiceInfo::repoToDisableFind
bool repoToDisableFind(const std::string &alias_r) const
Whether alias_r is mentioned in ReposToDisable.
Definition: ServiceInfo.cc:145
zypp::MediaSetAccess::provideFileFromUrl
static ManagedFile provideFileFromUrl(const Url &file_url, ProvideFileOptions options=PROVIDE_DEFAULT)
Provides file from url.
Definition: MediaSetAccess.cc:192
zypp::RepoManager::Impl::_reposDirty
DefaultIntegral< bool, false > _reposDirty
Definition: RepoManager.cc:709
zypp::Date::day
static const ValueType day
Definition: Date.h:44
zypp::RepoManager::removeService
void removeService(const std::string &alias)
Removes service specified by its name.
Definition: RepoManager.cc:2650
zypp::ServiceInfo::addRepoToEnable
void addRepoToEnable(const std::string &alias_r)
Add alias_r to the set of ReposToEnable.
Definition: ServiceInfo.cc:127
zypp::env::ZYPP_PLUGIN_APPDATA_FORCE_COLLECT
bool ZYPP_PLUGIN_APPDATA_FORCE_COLLECT()
To trigger appdata refresh unconditionally.
Definition: RepoManager.cc:71
PL_
#define PL_(MSG1, MSG2, N)
Definition: Gettext.h:40
zypp::RepoStatus::empty
bool empty() const
Whether the status is empty (default constucted)
Definition: RepoStatus.cc:149
zypp::repo::ServiceAlreadyExistsException
Service already exists and some unique attribute can't be duplicated.
Definition: RepoException.h:223
MIL
#define MIL
Definition: Logger.h:79
zypp::MediaSetAccess::doesFileExist
bool doesFileExist(const Pathname &file, unsigned media_nr=1)
Checks if a file exists on the specified media, with user callbacks.
Definition: MediaSetAccess.cc:223
zypp::repo::RepoUnknownTypeException
thrown when it was impossible to determine this repo type.
Definition: RepoException.h:142
zypp::repo::RepoType::toEnum
Type toEnum() const
Definition: RepoType.h:48
zypp::RepoManager::cleanCacheDirGarbage
void cleanCacheDirGarbage(const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Remove any subdirectories of cache directories which no longer belong to any of known repositories.
Definition: RepoManager.cc:2596
zypp::repo::RepoInfoBase::enabled
bool enabled() const
If enabled is false, then this repository must be ignored as if does not exists, except when checking...
Definition: RepoInfoBase.cc:104
zypp::RepoManager::RepoConstIterator
RepoSet::const_iterator RepoConstIterator
Definition: RepoManager.h:120
HistoryLog.h
zypp::ProgressReportAdaptor
Definition: ZYppCallbacks.h:58
zypp::RepoManagerOptions
Repo manager settings.
Definition: RepoManager.h:53
zypp::RepoManager::removeRepository
void removeRepository(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Remove the best matching repository from known repos list.
Definition: RepoManager.cc:2611
zypp::filesystem::recursive_rmdir
int recursive_rmdir(const Pathname &path)
Like 'rm -r DIR'.
Definition: PathInfo.cc:408
zypp::RepoManager::Impl::getRepositoriesInService
void getRepositoriesInService(const std::string &alias, OutputIterator out) const
Definition: RepoManager.cc:689
zypp::repo::susetags::Downloader::status
RepoStatus status(MediaSetAccess &media) override
Status of the remote repository.
Definition: Downloader.cc:35
zypp::ServiceInfo::RepoStates
std::map< std::string, RepoState > RepoStates
Definition: ServiceInfo.h:185
zypp::RepoManager::Impl::metadataStatus
RepoStatus metadataStatus(const RepoInfo &info) const
Definition: RepoManager.cc:894
ZYPP_THROW
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:392
zypp::str::strToBool
bool strToBool(const C_Str &str, bool default_r)
Parse str into a bool depending on the default value.
Definition: String.h:426
zypp::RepoManager::RawMetadataRefreshPolicy
RawMetadataRefreshPolicy
Definition: RepoManager.h:128
zypp::RepoManager::MatchServiceAlias
Functor thats filter RepoInfo by service which it belongs to.
Definition: RepoManager.h:641
zypp::RepoManager::Impl::refreshServices
void refreshServices(const RefreshServiceOptions &options_r)
Definition: RepoManager.cc:2021
zypp::RepoInfo::noRepo
static const RepoInfo noRepo
Represents no Repository (one with an empty alias).
Definition: RepoInfo.h:80
zypp::filesystem::touch
int touch(const Pathname &path)
Change file's modification and access times.
Definition: PathInfo.cc:1182
zypp::repo::ServiceType::RIS
static const ServiceType RIS
Repository Index Service (RIS) (formerly known as 'Novell Update' (NU) service)
Definition: ServiceType.h:32
zypp::repo::RepoType::NONE_e
Definition: RepoType.h:36
zypp::Exception::addHistory
void addHistory(const std::string &msg_r)
Add some message text to the history.
Definition: Exception.cc:125
zypp::filesystem::Pathname::assertprefix
static Pathname assertprefix(const Pathname &root_r, const Pathname &path_r)
Return path_r prefixed with root_r, unless it is already prefixed.
Definition: Pathname.cc:235
zypp::RepoStatus::saveToCookieFile
void saveToCookieFile(const Pathname &path_r) const
Save the status information to a cookie file.
Definition: RepoStatus.cc:139
zypp::RepoManager::Impl::packagesPath
Pathname packagesPath(const RepoInfo &info) const
Definition: RepoManager.cc:593
zypp::ExternalProgram
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
Definition: ExternalProgram.h:59
zypp::repo::RepoInfoBase::setFilepath
void setFilepath(const Pathname &filename)
set the path to the .repo file
Definition: RepoInfoBase.cc:100
MediaManager.h
zypp::RepoManager::Impl::cleanCache
void cleanCache(const RepoInfo &info, OPT_PROGRESS)
Definition: RepoManager.cc:1567
zypp::repo::RepoType::NONE
static const RepoType NONE
Definition: RepoType.h:32
ServiceRepos.h
zypp::RepoManager::RepoSizeType
RepoSet::size_type RepoSizeType
Definition: RepoManager.h:121
zypp::RepoManager::Impl::serviceSize
ServiceSizeType serviceSize() const
Definition: RepoManager.cc:636
Target.h
report
callback::SendReport< DownloadProgressReport > * report
Definition: MediaCurl.cc:70
zypp::RepoManager::Impl::getRepo
RepoInfo getRepo(const std::string &alias) const
Definition: RepoManager.cc:583
zypp::filesystem::unlink
int unlink(const Pathname &path)
Like 'unlink'.
Definition: PathInfo.cc:648
zypp::ServiceInfo::dumpAsIniOn
virtual std::ostream & dumpAsIniOn(std::ostream &str) const
Writes ServiceInfo to stream in ".service" format.
Definition: ServiceInfo.cc:173
zypp::RepoManager::Impl::addRepository
void addRepository(const RepoInfo &info, OPT_PROGRESS)
Definition: RepoManager.cc:1615
Z_CHKGPG
#define Z_CHKGPG(I, N)
zypp::ServiceInfo::lrf
Date lrf() const
Date of last refresh (if known).
Definition: ServiceInfo.cc:116
zypp::RepoManager::ServiceSizeType
ServiceSet::size_type ServiceSizeType
Definition: RepoManager.h:116
zypp::repo::susetags::Downloader
Downloader for SUSETags (YaST2) repositories Encapsulates all the knowledge of which files have to be...
Definition: Downloader.h:34
zypp::RepoManager::loadFromCache
void loadFromCache(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Load resolvables into the pool.
Definition: RepoManager.cc:2593
zypp::RepoManager::Impl::loadFromCache
void loadFromCache(const RepoInfo &info, OPT_PROGRESS)
Definition: RepoManager.cc:1581
zypp::repo::RepoType::RPMPLAINDIR_e
Definition: RepoType.h:39
zypp::repo::RepoNotFoundException
thrown when it was impossible to match a repository
Definition: RepoException.h:116
zypp::ProgressData::name
void name(const std::string &name_r)
Set counter name.
Definition: ProgressData.h:222
zypp::repo::ServiceNoAliasException
Service without alias was used in an operation.
Definition: RepoException.h:200
zypp::RepoManager::Impl::removeRepository
void removeRepository(const RepoInfo &info, OPT_PROGRESS)
Definition: RepoManager.cc:1746
OPT_PROGRESS
#define OPT_PROGRESS
Definition: RepoManager.cc:61
zypp::RepoManager::getRepositoryInfo
RepoInfo getRepositoryInfo(const std::string &alias, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Find a matching repository info.
Definition: RepoManager.cc:2617
zypp::RepoManager::RepoManager
RepoManager(const RepoManagerOptions &options=RepoManagerOptions())
Definition: RepoManager.cc:2515
zypp::RepoManager::Impl::generateFilename
std::string generateFilename(const RepoInfo &info) const
Definition: RepoManager.cc:673
zypp::RepoManager::Impl::repos
const RepoSet & repos() const
Definition: RepoManager.cc:701
zypp::RepoManager::Impl::probeCache
repo::RepoType probeCache(const Pathname &path_r) const
Probe Metadata in a local cache directory.
Definition: RepoManager.cc:1501
zypp::media::MediaAccessId
unsigned int MediaAccessId
Media manager access Id type.
Definition: MediaSource.h:29
zypp::ServiceInfo::ttl
Date::Duration ttl() const
Sugested TTL between two metadata auto-refreshs.
Definition: ServiceInfo.cc:112
zypp::repo::RepoType::YAST2
static const RepoType YAST2
Definition: RepoType.h:30
zypp::repo::RepoNoAliasException
thrown when it was impossible to determine an alias for this repo.
Definition: RepoException.h:91
zypp::filesystem::PathInfo::userMayRX
bool userMayRX() const
Definition: PathInfo.h:350
zypp::RepoManager::Impl::_options
RepoManagerOptions _options
Definition: RepoManager.cc:705
zypp::RepoManager::Impl::repoSize
RepoSizeType repoSize() const
Definition: RepoManager.cc:576
zypp::RepoManager::serviceSize
ServiceSizeType serviceSize() const
Gets count of service in RepoManager (in specified location)
Definition: RepoManager.cc:2626
zypp::repo::RepoInvalidAliasException
Thrown when the repo alias is found to be invalid.
Definition: RepoException.h:103
zypp::RepoManager::Impl::refreshService
void refreshService(const std::string &alias, const RefreshServiceOptions &options_r)
Definition: RepoManager.cc:2039
zypp::RepoManager::Impl::addService
void addService(const ServiceInfo &service)
Definition: RepoManager.cc:1943
zypp::RepoManager::CacheBuildPolicy
CacheBuildPolicy
Definition: RepoManager.h:135
zypp::RepoManager::serviceBegin
ServiceConstIterator serviceBegin() const
Iterator to first service in internal storage.
Definition: RepoManager.cc:2629
zypp::ExternalProgram::Arguments
std::vector< std::string > Arguments
Definition: ExternalProgram.h:64
zypp::RepoManager::makeStupidAlias
static std::string makeStupidAlias(const Url &url_r=Url())
Some stupid string but suitable as alias for your url if nothing better is available.
Definition: RepoManager.cc:2540
LogTools.h
zypp::filesystem::exchange
int exchange(const Pathname &lpath, const Pathname &rpath)
Exchanges two files or directories.
Definition: PathInfo.cc:704
zypp::RepoManager::Impl::refreshService
void refreshService(const ServiceInfo &service, const RefreshServiceOptions &options_r)
Definition: RepoManager.cc:661
zypp::Exception::asUserString
std::string asUserString() const
Translated error message as string suitable for the user.
Definition: Exception.cc:82
zypp::Exception::remember
void remember(const Exception &old_r)
Store an other Exception as history.
Definition: Exception.cc:105
zypp::repo::operator<<
std::ostream & operator<<(std::ostream &str, const DeltaCandidates &obj)
Definition: DeltaCandidates.cc:107
zypp::RepoInfo::setMetadataPath
void setMetadataPath(const Pathname &path)
Set the path where the local metadata is stored.
Definition: RepoInfo.cc:656
zypp::RepoManager::getRepo
RepoInfo getRepo(const std::string &alias) const
Find RepoInfo by alias or return RepoInfo::noRepo.
Definition: RepoManager.cc:2534
zypp::Repository::systemRepoAlias
static const std::string & systemRepoAlias()
Reserved system repository alias @System .
Definition: Repository.cc:37
zypp::filesystem::PathInfo
Wrapper class for ::stat/::lstat.
Definition: PathInfo.h:220
zypp::ServiceInfo::repoToEnableFind
bool repoToEnableFind(const std::string &alias_r) const
Whether alias_r is mentioned in ReposToEnable.
Definition: ServiceInfo.cc:124
zypp::sat::SolvAttr::repositoryToolVersion
static const SolvAttr repositoryToolVersion
Definition: SolvAttr.h:174
zypp::RepoManagerOptions::repoSolvCachePath
Pathname repoSolvCachePath
Definition: RepoManager.h:81
zypp::ServiceInfo::reposToDisableEmpty
bool reposToDisableEmpty() const
Definition: ServiceInfo.cc:140
zypp::RepoManager::Impl::cleanCacheDirGarbage
void cleanCacheDirGarbage(OPT_PROGRESS)
Definition: RepoManager.cc:1520
zypp::Exception::asUserHistory
std::string asUserHistory() const
A single (multiline) string composed of asUserString and historyAsString.
Definition: Exception.cc:91
zypp::filesystem::TmpDir::makeSibling
static TmpDir makeSibling(const Pathname &sibling_r)
Provide a new empty temporary directory as sibling.
Definition: TmpPath.cc:295
zypp::ProgressData::val
value_type val() const
Definition: ProgressData.h:295
zypp::filesystem::TmpDir
Provide a new empty temporary directory and recursively delete it when no longer needed.
Definition: TmpPath.h:177
zypp::RepoInfo::setType
void setType(const repo::RepoType &t)
set the repository type
Definition: RepoInfo.cc:649
zypp::RepoManager::Impl::getRepositoryInfo
RepoInfo getRepositoryInfo(const std::string &alias, OPT_PROGRESS)
zypp::filesystem::Pathname::c_str
const char * c_str() const
String representation.
Definition: Pathname.h:110
zypp::repo::RepoType::YAST2_e
Definition: RepoType.h:38
zypp::RepoManager::cleanMetadata
void cleanMetadata(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Clean local metadata.
Definition: RepoManager.cc:2575
zypp::base::NonCopyable
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
zypp::HistoryLog
Writing the zypp history file.
Definition: HistoryLog.h:56
zypp::repo::RepoInfoBase::alias
std::string alias() const
unique identifier for this source.
Definition: RepoInfoBase.cc:111
zypp::repo::RepoType
Repository type enumeration.
Definition: RepoType.h:27
WAR
#define WAR
Definition: Logger.h:80
zypp::misc::testcase::TestcaseRepoType::Url
zypp::RepoManagerOptions::RepoManagerOptions
RepoManagerOptions(const Pathname &root_r=Pathname())
Default ctor following ZConfig global settings.
Definition: RepoManager.cc:472
zypp::filesystem::PathInfo::isFile
bool isFile() const
Definition: PathInfo.h:289
ServiceFileReader.h
zypp::RepoManager::Impl::checkIfToRefreshMetadata
RefreshCheckStatus checkIfToRefreshMetadata(const RepoInfo &info, const Url &url, RawMetadataRefreshPolicy policy)
Definition: RepoManager.cc:966
zypp::RepoManager::Impl::touchIndexFile
void touchIndexFile(const RepoInfo &info)
Definition: RepoManager.cc:929
zypp::RepoManager::Impl::serviceEmpty
bool serviceEmpty() const
Definition: RepoManager.cc:635
ZYppCallbacks.h
zypp::RepoManager::refreshService
void refreshService(const std::string &alias, const RefreshServiceOptions &options_r=RefreshServiceOptions())
Refresh specific service.
Definition: RepoManager.cc:2659
zypp::str::replaceAll
std::string & replaceAll(std::string &str_r, const std::string &from_r, const std::string &to_r)
Replace all occurrences of from_r with to_r in str_r (inplace).
Definition: String.cc:321
zypp::Date::Duration
time_t Duration
Definition: Date.h:39
zypp::RepoManager::addRepository
void addRepository(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Adds a repository to the list of known repositories.
Definition: RepoManager.cc:2605
zypp::RepoManager::metadataPath
Pathname metadataPath(const RepoInfo &info) const
Path where the metadata is downloaded and kept.
Definition: RepoManager.cc:2566
_
#define _(MSG)
Definition: Gettext.h:37
zypp::RepoManager::repoBegin
RepoConstIterator repoBegin() const
Definition: RepoManager.cc:2528
zypp::RepoManager::RefreshCheckStatus
RefreshCheckStatus
Possibly return state of checkIfRefreshMEtadata function.
Definition: RepoManager.h:196
zypp::str::form
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition: String.cc:35
zypp::ServiceInfo::delRepoToEnable
void delRepoToEnable(const std::string &alias_r)
Remove alias_r from the set of ReposToEnable.
Definition: ServiceInfo.cc:133
zypp::repo::RepoAlreadyExistsException
Repository already exists and some unique attribute can't be duplicated.
Definition: RepoException.h:129
zypp::ZConfig::instance
static ZConfig & instance()
Singleton ctor.
Definition: Resolver.cc:126
CredentialManager.h
zypp::RepoManager::Impl::repoBegin
RepoConstIterator repoBegin() const
Definition: RepoManager.cc:577
zypp::repo::ServiceType::PLUGIN
static const ServiceType PLUGIN
Plugin services are scripts installed on your system that provide the package manager with repositori...
Definition: ServiceType.h:43
zypp::RepoManager::Impl::hasRepo
bool hasRepo(const std::string &alias) const
Definition: RepoManager.cc:580
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
zypp::RepoManager::Impl::probe
repo::RepoType probe(const Url &url, const Pathname &path=Pathname()) const
Probe the metadata type of a repository located at url.
Definition: RepoManager.cc:1412
zypp::str::numstring
std::string numstring(char n, int w=0)
Definition: String.h:286
zypp::Url::asCompleteString
std::string asCompleteString() const
Returns a complete string representation of the Url object.
Definition: Url.cc:500
zypp::RepoInfo::baseUrlsBegin
urls_const_iterator baseUrlsBegin() const
iterator that points at begin of repository urls
Definition: RepoInfo.cc:728
zypp::ServiceInfo::rawUrl
Url rawUrl() const
The service raw url (no variables replaced)
Definition: ServiceInfo.cc:102
zypp::RepoManager::probe
repo::RepoType probe(const Url &url, const Pathname &path) const
Probe repo metadata type.
Definition: RepoManager.cc:2599
zypp::RepoManager::Impl::hasService
bool hasService(const std::string &alias) const
Definition: RepoManager.cc:640
zypp::RepoManager::Impl::Impl
Impl(const RepoManagerOptions &opt)
Definition: RepoManager.cc:523
Pool.h
zypp::repo::RepoInfoBase::label
std::string label() const
Label for use in messages for the user interface.
Definition: RepoInfoBase.cc:127
Regex.h
zypp::Digest::digest
std::string digest()
get hex string representation of the digest
Definition: Digest.cc:189
zypp::RepoManager::Impl::modifyService
void modifyService(const std::string &oldAlias, const ServiceInfo &newService)
Definition: RepoManager.cc:2406
zypp::sat::LookupRepoAttr
Lightweight repository attribute value lookup.
Definition: LookupAttr.h:257
zypp::RepoManager::Impl::getService
ServiceInfo getService(const std::string &alias) const
Definition: RepoManager.cc:643
zypp::str::Str
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
Definition: String.h:208
zypp::repo::RepoType::RPMMD
static const RepoType RPMMD
Definition: RepoType.h:29
zypp::RepoManagerOptions::makeTestSetup
static RepoManagerOptions makeTestSetup(const Pathname &root_r)
Test setup adjusting all paths to be located below one root_r directory.
Definition: RepoManager.cc:486
zypp::ExternalProgram::close
int close()
Wait for the progamm to complete.
Definition: ExternalProgram.cc:456
zypp::filesystem::PathInfo::asString
const std::string & asString() const
Return current Pathname as String.
Definition: PathInfo.h:248
PluginServices.h
zypp::RepoManager::Impl::addRepositories
void addRepositories(const Url &url, OPT_PROGRESS)
Definition: RepoManager.cc:1687
zypp::RepoManager::repoEmpty
bool repoEmpty() const
Definition: RepoManager.cc:2522
zypp::repo::PluginServices
Definition: PluginServices.h:28
zypp::RepoManagerOptions::pluginsPath
Pathname pluginsPath
Definition: RepoManager.h:85
targetDistro
std::string targetDistro
Definition: RepoManager.cc:278
zypp::repo::RepoInfoBase::filepath
Pathname filepath() const
File where this repo was read from.
Definition: RepoInfoBase.cc:134
zypp::RepoManager::serviceEnd
ServiceConstIterator serviceEnd() const
Iterator to place behind last service in internal storage.
Definition: RepoManager.cc:2632
zypp::RepoInfo::setProbedType
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:652
zypp::repo::RepoNoUrlException
thrown when it was impossible to determine one url for this repo.
Definition: RepoException.h:78
zypp::repo::ServiceNoUrlException
Service has no or invalid url defined.
Definition: RepoException.h:234
zypp::RepoManagerOptions::knownReposPath
Pathname knownReposPath
Definition: RepoManager.h:83
zypp::RepoManager::Impl::serviceEnd
ServiceConstIterator serviceEnd() const
Definition: RepoManager.cc:638
zypp::RepoManager::Impl::probeService
repo::ServiceType probeService(const Url &url) const
Definition: RepoManager.cc:2481
zypp::repo::yum::Downloader::status
RepoStatus status(MediaSetAccess &media_r) override
Status of the remote repository.
Definition: Downloader.cc:198
zypp::RepoInfo::url_set
std::list< Url > url_set
Definition: RepoInfo.h:103
zypp::parser::ServiceFileReader
Read service data from a .service file.
Definition: ServiceFileReader.h:43
zypp::media::ScopedDisableMediaChangeReport
Temporarily disable MediaChangeReport Sometimes helpful to suppress interactive messages connected to...
Definition: ZYppCallbacks.h:345
zypp::RepoManager::Impl
RepoManager implementation.
Definition: RepoManager.cc:520
zypp::RepoManager::Impl::init_knownRepositories
void init_knownRepositories()
Definition: RepoManager.cc:827
zypp::RepoManager::repoSize
RepoSizeType repoSize() const
Definition: RepoManager.cc:2525
zypp::asString
std::string asString(const DefaultIntegral< Tp, TInitial > &obj)
Definition: DefaultIntegral.h:98
zypp::RepoManager::metadataStatus
RepoStatus metadataStatus(const RepoInfo &info) const
Status of local metadata.
Definition: RepoManager.cc:2560
zypp::ProgressData::ReceiverFnc
function< bool(const ProgressData &)> ReceiverFnc
Most simple version of progress reporting The percentage in most cases.
Definition: ProgressData.h:139
zypp::repo::RepoType::RPMPLAINDIR
static const RepoType RPMPLAINDIR
Definition: RepoType.h:31
zypp::DefaultIntegral< bool, false >
zypp::RepoManager::RefreshServiceOptions
RefreshServiceFlags RefreshServiceOptions
Options tuning RefreshService.
Definition: RepoManager.h:150
zypp::RepoManager::Impl::serviceBegin
ServiceConstIterator serviceBegin() const
Definition: RepoManager.cc:637
zypp::RepoManager::RepoSet
std::set< RepoInfo > RepoSet
RepoInfo typedefs.
Definition: RepoManager.h:119
zypp::RepoStatus::fromCookieFile
static RepoStatus fromCookieFile(const Pathname &path)
Reads the status from a cookie file.
Definition: RepoStatus.cc:121
zypp::ServiceInfo::type
repo::ServiceType type() const
Service type.
Definition: ServiceInfo.cc:108
zypp::RepoManager::probeService
repo::ServiceType probeService(const Url &url) const
Probe the type or the service.
Definition: RepoManager.cc:2641
zypp::ServiceInfo::setProbedType
void setProbedType(const repo::ServiceType &t) const
Lazy init service type.
Definition: ServiceInfo.cc:110
zypp::RepoManager::cacheStatus
RepoStatus cacheStatus(const RepoInfo &info) const
Status of metadata cache.
Definition: RepoManager.cc:2581
zypp::repo::RepoNotCachedException
The repository cache is not built yet so you can't create the repostories from the cache.
Definition: RepoException.h:65
zypp::repo::ServiceType::NONE
static const ServiceType NONE
No service set.
Definition: ServiceType.h:34
zypp::RepoStatus::timestamp
Date timestamp() const
The time the data were changed the last time.
Definition: RepoStatus.cc:152
zypp::RepoManager::cleanCache
void cleanCache(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
clean local cache
Definition: RepoManager.cc:2587
Gettext.h
zypp::RepoManager::hasService
bool hasService(const std::string &alias) const
Return whether there is a known service for alias.
Definition: RepoManager.cc:2638
ZYPP_RETHROW
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
Definition: Exception.h:400
zypp::RepoManager::Impl::isCached
bool isCached(const RepoInfo &info) const
Definition: RepoManager.cc:615
zypp::AutoDispose
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition: AutoDispose.h:92
zypp::repo
Definition: DeltaCandidates.cc:28
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:147
zypp::RepoManagerOptions::repoRawCachePath
Pathname repoRawCachePath
Definition: RepoManager.h:80
zypp::RepoInfo::url
Url url() const
Pars pro toto: The first repository url.
Definition: RepoInfo.h:131
zypp::filesystem::Pathname::dirname
Pathname dirname() const
Return all but the last component od this path.
Definition: Pathname.h:124
zypp::Date
Store and operate on date (time_t).
Definition: Date.h:32
zypp::ProgressData::sendTo
void sendTo(const ReceiverFnc &fnc_r)
Set ReceiverFnc.
Definition: ProgressData.h:226
for_
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:28
RepoFileReader.h
zypp::RepoManager::serviceEmpty
bool serviceEmpty() const
Gets true if no service is in RepoManager (so no one in specified location)
Definition: RepoManager.cc:2623
zypp::RepoInfo::dumpAsIniOn
virtual std::ostream & dumpAsIniOn(std::ostream &str) const
Write this RepoInfo object into str in a .repo file format.
Definition: RepoInfo.cc:927
zypp::ProgressData::toMax
bool toMax()
Set counter value to current max value (unless no range).
Definition: ProgressData.h:273
zypp::ServiceInfo::clearReposToDisable
void clearReposToDisable()
Clear the set of ReposToDisable.
Definition: ServiceInfo.cc:157
zypp::RepoManager::~RepoManager
~RepoManager()
Dtor.
Definition: RepoManager.cc:2519
zypp::RepoManager::Impl::cleanPackages
void cleanPackages(const RepoInfo &info, OPT_PROGRESS)
Definition: RepoManager.cc:1238
zypp::RepoManager::Impl::repoEnd
RepoConstIterator repoEnd() const
Definition: RepoManager.cc:578
zypp::RepoInfo::baseUrls
url_set baseUrls() const
The complete set of repository urls.
Definition: RepoInfo.cc:710
zypp::RepoManager::addRepositories
void addRepositories(const Url &url, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Adds repositores from a repo file to the list of known repositories.
Definition: RepoManager.cc:2608
zypp::sat::updateSolvFileIndex
void updateSolvFileIndex(const Pathname &solvfile_r)
Create solv file content digest for zypper bash completion.
Definition: Pool.cc:285
zypp::iostr::copy
std::ostream & copy(std::istream &from_r, std::ostream &to_r)
Copy istream to ostream.
Definition: IOStream.h:50
zypp::filesystem::Pathname::empty
bool empty() const
Test for an empty path.
Definition: Pathname.h:114
Function.h
zypp::RepoManager::Impl::buildCache
void buildCache(const RepoInfo &info, CacheBuildPolicy policy, OPT_PROGRESS)
Definition: RepoManager.cc:1248
ServiceInfo.h
zypp::Repository::eraseFromPool
void eraseFromPool()
Remove this Repository from it's Pool.
Definition: Repository.cc:297
zypp::Date::now
static Date now()
Return the current time.
Definition: Date.h:78
zypp::externalprogram::ExternalDataSource::receiveLine
std::string receiveLine()
Read one line from the input stream.
Definition: ExternalDataSource.cc:115
zypp::filesystem::Pathname
Pathname.
Definition: Pathname.h:44
zypp::RepoManager::Impl::removeService
void removeService(const ServiceInfo &service)
Definition: RepoManager.cc:655
zypp::RepoManager::modifyRepository
void modifyRepository(const std::string &alias, const RepoInfo &newinfo, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Modify repository attributes.
Definition: RepoManager.cc:2614
zypp::Url::getHost
std::string getHost(EEncoding eflag=zypp::url::E_DECODED) const
Returns the hostname or IP from the URL authority.
Definition: Url.cc:583
ERR
#define ERR
Definition: Logger.h:81
zypp::JobReport::warning
static bool warning(const std::string &msg_r, const UserData &userData_r=UserData())
send warning text
Definition: ZYppCallbacks.h:826
zypp::RepoManager::Impl::removeService
void removeService(const std::string &alias)
Definition: RepoManager.cc:1965
zypp::RepoManager::Impl::setCacheStatus
void setCacheStatus(const RepoInfo &info, const RepoStatus &status)
Definition: RepoManager.cc:679
zypp::repo::ServicePluginImmutableException
Service plugin is immutable.
Definition: RepoException.h:273
zypp::RepoManager::Impl::~Impl
~Impl()
Definition: RepoManager.cc:530
zypp::repo::ServiceException
Base Exception for service handling.
Definition: RepoException.h:175
DBG
#define DBG
Definition: Logger.h:78
zypp::RepoManager::ServiceSet
std::set< ServiceInfo > ServiceSet
ServiceInfo typedefs.
Definition: RepoManager.h:111
zypp::sat::Pool::addRepoSolv
Repository addRepoSolv(const Pathname &file_r, const std::string &name_r)
Load Solvables from a solv-file into a Repository named name_r.
Definition: Pool.cc:185
zypp::ProgressData::toMin
bool toMin()
Set counter value to current min value.
Definition: ProgressData.h:269
zypp::Date::ValueType
time_t ValueType
Definition: Date.h:38
zypp::CombinedProgressData
Progress callback from another progress.
Definition: ProgressData.h:390
zypp::RepoManager::getService
ServiceInfo getService(const std::string &alias) const
Finds ServiceInfo by alias or return ServiceInfo::noService.
Definition: RepoManager.cc:2635
InputStream.h
zypp::str::Format
Convenient building of std::string with boost::format. Basically a boost::format autoconvertible to s...
Definition: String.h:249
_cmPtr
scoped_ptr< media::CredentialManager > _cmPtr
Definition: RepoManager.cc:144
zypp::repo::ServiceInvalidAliasException
Thrown when the repo alias is found to be invalid.
Definition: RepoException.h:212
Downloader.h
zypp::str::regex_match
bool regex_match(const std::string &s, smatch &matches, const regex &regex)
\relates regex \ingroup ZYPP_STR_REGEX \relates regex \ingroup ZYPP_STR_REGEX
Definition: Regex.h:70
zypp::repo::RepoException
Exception for repository handling.
Definition: RepoException.h:37
zypp::HistoryLog::removeRepository
void removeRepository(const RepoInfo &repo)
Log recently removed repository.
Definition: HistoryLog.cc:299
zypp::MediaSetAccess
Media access layer responsible for handling files distributed on a set of media with media change and...
Definition: MediaSetAccess.h:80
str
String related utilities and Regular expression matching.
ManagedFile.h
zypp::repo::RepoInfoBase::setAlias
void setAlias(const std::string &alias)
set the repository alias
Definition: RepoInfoBase.cc:94
zypp::RepoInfo::baseUrlsEnd
urls_const_iterator baseUrlsEnd() const
iterator that points at end of repository urls
Definition: RepoInfo.cc:731
zypp::AutoDispose::resetDispose
void resetDispose()
Set no dispose function.
Definition: AutoDispose.h:162
zypp::TriBool
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
Definition: String.h:30
zypp::RepoManager::addService
void addService(const std::string &alias, const Url &url)
Adds new service by it's alias and url.
Definition: RepoManager.cc:2644
ZYPP_CAUGHT
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition: Exception.h:396
zypp::url::ViewOption
Url::asString() view options.
Definition: UrlBase.h:39
zypp::ServiceInfo::setRepoStates
void setRepoStates(RepoStates newStates_r)
Remember a new set of repository states.
Definition: ServiceInfo.cc:162
zypp::RepoManager::Impl::addService
void addService(const std::string &alias, const Url &url)
Definition: RepoManager.cc:651
zypp::RepoManager::Impl::init_knownServices
void init_knownServices()
Definition: RepoManager.cc:774
MediaSetAccess.h
zypp::filesystem::Pathname::asString
const std::string & asString() const
String representation.
Definition: Pathname.h:91
zypp::RepoManagerOptions::repoCachePath
Pathname repoCachePath
Definition: RepoManager.h:79
url
Url url
Definition: MediaCurl.cc:66
zypp::RepoManager::Impl::repoEmpty
bool repoEmpty() const
Definition: RepoManager.cc:575
RepoException.h
zypp::Url
Url manipulation class.
Definition: Url.h:87
zypp::HistoryLog::modifyRepository
void modifyRepository(const RepoInfo &oldrepo, const RepoInfo &newrepo)
Log certain modifications to a repository.
Definition: HistoryLog.cc:310
zypp::Repository
Definition: Repository.h:39
zypp::RepoManager::Impl::operator<<
std::ostream & operator<<(std::ostream &str, const RepoManager::Impl &obj)
Definition: RepoManager.cc:720
zypp::RepoManager::hasRepo
bool hasRepo(const std::string &alias) const
Return whether there is a known repository for alias.
Definition: RepoManager.cc:2537
zypp::ZConfig::repo_refresh_delay
unsigned repo_refresh_delay() const
Amount of time in minutes that must pass before another refresh.
Definition: ZConfig.cc:1013
zypp::RepoManager::checkIfToRefreshMetadata
RefreshCheckStatus checkIfToRefreshMetadata(const RepoInfo &info, const Url &url, RawMetadataRefreshPolicy policy=RefreshIfNeeded)
Checks whether to refresh metadata for specified repository and url.
Definition: RepoManager.cc:2563
zypp::RepoManagerOptions::repoPackagesCachePath
Pathname repoPackagesCachePath
Definition: RepoManager.h:82
zypp::RepoManager::_pimpl
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: RepoManager.h:698
RepoManager.h
zypp::RepoManager
creates and provides information about known sources.
Definition: RepoManager.h:105
zypp::RepoManager::Impl::saveService
void saveService(ServiceInfo &service) const
Definition: RepoManager.cc:725
zypp::RepoManager::refreshServices
void refreshServices(const RefreshServiceOptions &options_r=RefreshServiceOptions())
Refreshes all enabled services.
Definition: RepoManager.cc:2656
zypp::RepoManager::modifyService
void modifyService(const std::string &oldAlias, const ServiceInfo &service)
Modifies service file (rewrites it with new values) and underlying repositories if needed.
Definition: RepoManager.cc:2665
zypp::RepoInfo::type
repo::RepoType type() const
Type of repository,.
Definition: RepoInfo.cc:683
zypp::ProgressData
Maintain [min,max] and counter (value) for progress counting.
Definition: ProgressData.h:130
zypp::HistoryLog::addRepository
void addRepository(const RepoInfo &repo)
Log a newly added repository.
Definition: HistoryLog.cc:287
zypp::RepoManager::repoEnd
RepoConstIterator repoEnd() const
Definition: RepoManager.cc:2531
zypp::RepoManager::Impl::metadataPath
Pathname metadataPath(const RepoInfo &info) const
Definition: RepoManager.cc:590
zypp::JobReport::error
static bool error(const std::string &msg_r, const UserData &userData_r=UserData())
send error text
Definition: ZYppCallbacks.h:830
DefaultIntegral.h
zypp::RepoInfo::path
Pathname path() const
Repository path.
Definition: RepoInfo.cc:716
zypp::RepoInfo::baseUrlsSize
urls_size_type baseUrlsSize() const
number of repository urls
Definition: RepoInfo.cc:734
zypp::RepoManager::Impl::modifyRepository
void modifyRepository(const std::string &alias, const RepoInfo &newinfo_r, OPT_PROGRESS)
Definition: RepoManager.cc:1835
zypp::ExternalProgram::command
const std::string & command() const
The command we're executing.
Definition: ExternalProgram.h:174
zypp::RepoManager::Impl::cleanMetadata
void cleanMetadata(const RepoInfo &info, OPT_PROGRESS)
Definition: RepoManager.cc:1228