libzypp  14.29.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 "zypp/base/InputStream.h"
22 #include "zypp/base/LogTools.h"
23 #include "zypp/base/Gettext.h"
24 #include "zypp/base/Function.h"
25 #include "zypp/base/Regex.h"
26 #include "zypp/PathInfo.h"
27 #include "zypp/TmpPath.h"
28 
29 #include "zypp/ServiceInfo.h"
31 #include "zypp/RepoManager.h"
32 
35 #include "zypp/MediaSetAccess.h"
36 #include "zypp/ExternalProgram.h"
37 #include "zypp/ManagedFile.h"
38 
41 #include "zypp/repo/ServiceRepos.h"
45 
46 #include "zypp/Target.h" // for Target::targetDistribution() for repo index services
47 #include "zypp/ZYppFactory.h" // to get the Target from ZYpp instance
48 #include "zypp/HistoryLog.h" // to write history :O)
49 
50 #include "zypp/ZYppCallbacks.h"
51 
52 #include "sat/Pool.h"
53 
54 using std::endl;
55 using std::string;
56 using namespace zypp::repo;
57 
58 #define OPT_PROGRESS const ProgressData::ReceiverFnc & = ProgressData::ReceiverFnc()
59 
61 namespace zypp
62 {
64  namespace
65  {
69  class MediaMounter
70  {
71  public:
73  MediaMounter( const Url & url_r )
74  {
75  media::MediaManager mediamanager;
76  _mid = mediamanager.open( url_r );
77  mediamanager.attach( _mid );
78  }
79 
81  ~MediaMounter()
82  {
83  media::MediaManager mediamanager;
84  mediamanager.release( _mid );
85  mediamanager.close( _mid );
86  }
87 
92  Pathname getPathName( const Pathname & path_r = Pathname() ) const
93  {
94  media::MediaManager mediamanager;
95  return mediamanager.localPath( _mid, path_r );
96  }
97 
98  private:
100  };
102 
104  template <class Iterator>
105  inline bool foundAliasIn( const std::string & alias_r, Iterator begin_r, Iterator end_r )
106  {
107  for_( it, begin_r, end_r )
108  if ( it->alias() == alias_r )
109  return true;
110  return false;
111  }
113  template <class Container>
114  inline bool foundAliasIn( const std::string & alias_r, const Container & cont_r )
115  { return foundAliasIn( alias_r, cont_r.begin(), cont_r.end() ); }
116 
118  template <class Iterator>
119  inline Iterator findAlias( const std::string & alias_r, Iterator begin_r, Iterator end_r )
120  {
121  for_( it, begin_r, end_r )
122  if ( it->alias() == alias_r )
123  return it;
124  return end_r;
125  }
127  template <class Container>
128  inline typename Container::iterator findAlias( const std::string & alias_r, Container & cont_r )
129  { return findAlias( alias_r, cont_r.begin(), cont_r.end() ); }
131  template <class Container>
132  inline typename Container::const_iterator findAlias( const std::string & alias_r, const Container & cont_r )
133  { return findAlias( alias_r, cont_r.begin(), cont_r.end() ); }
134 
135 
137  inline std::string filenameFromAlias( const std::string & alias_r, const std::string & stem_r )
138  {
139  std::string filename( alias_r );
140  // replace slashes with underscores
141  str::replaceAll( filename, "/", "_" );
142 
143  filename = Pathname(filename).extend("."+stem_r).asString();
144  MIL << "generating filename for " << stem_r << " [" << alias_r << "] : '" << filename << "'" << endl;
145  return filename;
146  }
147 
163  struct RepoCollector : private base::NonCopyable
164  {
165  RepoCollector()
166  {}
167 
168  RepoCollector(const std::string & targetDistro_)
169  : targetDistro(targetDistro_)
170  {}
171 
172  bool collect( const RepoInfo &repo )
173  {
174  // skip repositories meant for other distros than specified
175  if (!targetDistro.empty()
176  && !repo.targetDistribution().empty()
177  && repo.targetDistribution() != targetDistro)
178  {
179  MIL
180  << "Skipping repository meant for '" << repo.targetDistribution()
181  << "' distribution (current distro is '"
182  << targetDistro << "')." << endl;
183 
184  return true;
185  }
186 
187  repos.push_back(repo);
188  return true;
189  }
190 
191  RepoInfoList repos;
192  std::string targetDistro;
193  };
195 
201  std::list<RepoInfo> repositories_in_file( const Pathname & file )
202  {
203  MIL << "repo file: " << file << endl;
204  RepoCollector collector;
205  parser::RepoFileReader parser( file, bind( &RepoCollector::collect, &collector, _1 ) );
206  return std::move(collector.repos);
207  }
208 
210 
219  std::list<RepoInfo> repositories_in_dir( const Pathname &dir )
220  {
221  MIL << "directory " << dir << endl;
222  std::list<RepoInfo> repos;
223  bool nonroot( geteuid() != 0 );
224  if ( nonroot && ! PathInfo(dir).userMayRX() )
225  {
226  JobReport::warning( formatNAC(_("Cannot read repo directory ‘%1%’: Permission denied")) % dir );
227  }
228  else
229  {
230  std::list<Pathname> entries;
231  if ( filesystem::readdir( entries, dir, false ) != 0 )
232  {
233  // TranslatorExplanation '%s' is a pathname
234  ZYPP_THROW(Exception(str::form(_("Failed to read directory '%s'"), dir.c_str())));
235  }
236 
237  str::regex allowedRepoExt("^\\.repo(_[0-9]+)?$");
238  for ( std::list<Pathname>::const_iterator it = entries.begin(); it != entries.end(); ++it )
239  {
240  if ( str::regex_match(it->extension(), allowedRepoExt) )
241  {
242  if ( nonroot && ! PathInfo(*it).userMayR() )
243  {
244  JobReport::warning( formatNAC(_("Cannot read repo file ‘%1%’: Permission denied")) % *it );
245  }
246  else
247  {
248  const std::list<RepoInfo> & tmp( repositories_in_file( *it ) );
249  repos.insert( repos.end(), tmp.begin(), tmp.end() );
250  }
251  }
252  }
253  }
254  return repos;
255  }
256 
258 
259  inline void assert_alias( const RepoInfo & info )
260  {
261  if ( info.alias().empty() )
262  ZYPP_THROW( RepoNoAliasException( info ) );
263  // bnc #473834. Maybe we can match the alias against a regex to define
264  // and check for valid aliases
265  if ( info.alias()[0] == '.')
267  info, _("Repository alias cannot start with dot.")));
268  }
269 
270  inline void assert_alias( const ServiceInfo & info )
271  {
272  if ( info.alias().empty() )
274  // bnc #473834. Maybe we can match the alias against a regex to define
275  // and check for valid aliases
276  if ( info.alias()[0] == '.')
278  info, _("Service alias cannot start with dot.")));
279  }
280 
282 
283  inline void assert_urls( const RepoInfo & info )
284  {
285  if ( info.baseUrlsEmpty() )
286  ZYPP_THROW( RepoNoUrlException( info ) );
287  }
288 
289  inline void assert_url( const ServiceInfo & info )
290  {
291  if ( ! info.url().isValid() )
293  }
294 
296 
301  inline Pathname rawcache_path_for_repoinfo( const RepoManagerOptions &opt, const RepoInfo &info )
302  {
303  assert_alias(info);
304  return opt.repoRawCachePath / info.escaped_alias();
305  }
306 
315  inline Pathname rawproductdata_path_for_repoinfo( const RepoManagerOptions &opt, const RepoInfo &info )
316  {
317  assert_alias(info);
318  return opt.repoRawCachePath / info.escaped_alias() / info.path();
319  }
320 
324  inline Pathname packagescache_path_for_repoinfo( const RepoManagerOptions &opt, const RepoInfo &info )
325  {
326  assert_alias(info);
327  return opt.repoPackagesCachePath / info.escaped_alias();
328  }
329 
333  inline Pathname solv_path_for_repoinfo( const RepoManagerOptions &opt, const RepoInfo &info)
334  {
335  assert_alias(info);
336  return opt.repoSolvCachePath / info.escaped_alias();
337  }
338 
340 
342  class ServiceCollector
343  {
344  public:
345  typedef std::set<ServiceInfo> ServiceSet;
346 
347  ServiceCollector( ServiceSet & services_r )
348  : _services( services_r )
349  {}
350 
351  bool operator()( const ServiceInfo & service_r ) const
352  {
353  _services.insert( service_r );
354  return true;
355  }
356 
357  private:
358  ServiceSet & _services;
359  };
361 
362  } // namespace
364 
365  std::list<RepoInfo> readRepoFile( const Url & repo_file )
366  {
367  // no interface to download a specific file, using workaround:
369  Url url(repo_file);
370  Pathname path(url.getPathName());
371  url.setPathName ("/");
372  MediaSetAccess access(url);
373  Pathname local = access.provideFile(path);
374 
375  DBG << "reading repo file " << repo_file << ", local path: " << local << endl;
376 
377  return repositories_in_file(local);
378  }
379 
381  //
382  // class RepoManagerOptions
383  //
385 
386  RepoManagerOptions::RepoManagerOptions( const Pathname & root_r )
387  {
388  repoCachePath = Pathname::assertprefix( root_r, ZConfig::instance().repoCachePath() );
389  repoRawCachePath = Pathname::assertprefix( root_r, ZConfig::instance().repoMetadataPath() );
390  repoSolvCachePath = Pathname::assertprefix( root_r, ZConfig::instance().repoSolvfilesPath() );
391  repoPackagesCachePath = Pathname::assertprefix( root_r, ZConfig::instance().repoPackagesPath() );
392  knownReposPath = Pathname::assertprefix( root_r, ZConfig::instance().knownReposPath() );
393  knownServicesPath = Pathname::assertprefix( root_r, ZConfig::instance().knownServicesPath() );
394  pluginsPath = Pathname::assertprefix( root_r, ZConfig::instance().pluginsPath() );
395  probe = ZConfig::instance().repo_add_probe();
396 
397  rootDir = root_r;
398  }
399 
401  {
402  RepoManagerOptions ret;
403  ret.repoCachePath = root_r;
404  ret.repoRawCachePath = root_r/"raw";
405  ret.repoSolvCachePath = root_r/"solv";
406  ret.repoPackagesCachePath = root_r/"packages";
407  ret.knownReposPath = root_r/"repos.d";
408  ret.knownServicesPath = root_r/"services.d";
409  ret.pluginsPath = root_r/"plugins";
410  ret.rootDir = root_r;
411  return ret;
412  }
413 
414  std:: ostream & operator<<( std::ostream & str, const RepoManagerOptions & obj )
415  {
416 #define OUTS(X) str << " " #X "\t" << obj.X << endl
417  str << "RepoManagerOptions (" << obj.rootDir << ") {" << endl;
418  OUTS( repoRawCachePath );
419  OUTS( repoSolvCachePath );
420  OUTS( repoPackagesCachePath );
421  OUTS( knownReposPath );
422  OUTS( knownServicesPath );
423  OUTS( pluginsPath );
424  str << "}" << endl;
425 #undef OUTS
426  return str;
427  }
428 
435  {
436  public:
437  Impl( const RepoManagerOptions &opt )
438  : _options(opt)
439  {
440  init_knownServices();
441  init_knownRepositories();
442  }
443 
444  public:
445  bool repoEmpty() const { return _repos.empty(); }
446  RepoSizeType repoSize() const { return _repos.size(); }
447  RepoConstIterator repoBegin() const { return _repos.begin(); }
448  RepoConstIterator repoEnd() const { return _repos.end(); }
449 
450  bool hasRepo( const std::string & alias ) const
451  { return foundAliasIn( alias, _repos ); }
452 
453  RepoInfo getRepo( const std::string & alias ) const
454  {
455  RepoConstIterator it( findAlias( alias, _repos ) );
456  return it == _repos.end() ? RepoInfo::noRepo : *it;
457  }
458 
459  public:
460  Pathname metadataPath( const RepoInfo & info ) const
461  { return rawcache_path_for_repoinfo( _options, info ); }
462 
463  Pathname packagesPath( const RepoInfo & info ) const
464  { return packagescache_path_for_repoinfo( _options, info ); }
465 
466  RepoStatus metadataStatus( const RepoInfo & info ) const;
467 
468  RefreshCheckStatus checkIfToRefreshMetadata( const RepoInfo & info, const Url & url, RawMetadataRefreshPolicy policy );
469 
470  void refreshMetadata( const RepoInfo & info, RawMetadataRefreshPolicy policy, OPT_PROGRESS );
471 
472  void cleanMetadata( const RepoInfo & info, OPT_PROGRESS );
473 
474  void cleanPackages( const RepoInfo & info, OPT_PROGRESS );
475 
476  void buildCache( const RepoInfo & info, CacheBuildPolicy policy, OPT_PROGRESS );
477 
478  repo::RepoType probe( const Url & url, const Pathname & path = Pathname() ) const;
479 
480  void cleanCacheDirGarbage( OPT_PROGRESS );
481 
482  void cleanCache( const RepoInfo & info, OPT_PROGRESS );
483 
484  bool isCached( const RepoInfo & info ) const
485  { return PathInfo(solv_path_for_repoinfo( _options, info ) / "solv").isExist(); }
486 
487  RepoStatus cacheStatus( const RepoInfo & info ) const
488  { return RepoStatus::fromCookieFile(solv_path_for_repoinfo(_options, info) / "cookie"); }
489 
490  void loadFromCache( const RepoInfo & info, OPT_PROGRESS );
491 
492  void addRepository( const RepoInfo & info, OPT_PROGRESS );
493 
494  void addRepositories( const Url & url, OPT_PROGRESS );
495 
496  void removeRepository( const RepoInfo & info, OPT_PROGRESS );
497 
498  void modifyRepository( const std::string & alias, const RepoInfo & newinfo_r, OPT_PROGRESS );
499 
500  RepoInfo getRepositoryInfo( const std::string & alias, OPT_PROGRESS );
501  RepoInfo getRepositoryInfo( const Url & url, const url::ViewOption & urlview, OPT_PROGRESS );
502 
503  public:
504  bool serviceEmpty() const { return _services.empty(); }
505  ServiceSizeType serviceSize() const { return _services.size(); }
506  ServiceConstIterator serviceBegin() const { return _services.begin(); }
507  ServiceConstIterator serviceEnd() const { return _services.end(); }
508 
509  bool hasService( const std::string & alias ) const
510  { return foundAliasIn( alias, _services ); }
511 
512  ServiceInfo getService( const std::string & alias ) const
513  {
514  ServiceConstIterator it( findAlias( alias, _services ) );
515  return it == _services.end() ? ServiceInfo::noService : *it;
516  }
517 
518  public:
519  void addService( const ServiceInfo & service );
520  void addService( const std::string & alias, const Url & url )
521  { addService( ServiceInfo( alias, url ) ); }
522 
523  void removeService( const std::string & alias );
524  void removeService( const ServiceInfo & service )
525  { removeService( service.alias() ); }
526 
527  void refreshServices( const RefreshServiceOptions & options_r );
528 
529  void refreshService( const std::string & alias, const RefreshServiceOptions & options_r );
530  void refreshService( const ServiceInfo & service, const RefreshServiceOptions & options_r )
531  { refreshService( service.alias(), options_r ); }
532 
533  void modifyService( const std::string & oldAlias, const ServiceInfo & newService );
534 
535  repo::ServiceType probeService( const Url & url ) const;
536 
537  private:
538  void saveService( ServiceInfo & service ) const;
539 
540  Pathname generateNonExistingName( const Pathname & dir, const std::string & basefilename ) const;
541 
542  std::string generateFilename( const RepoInfo & info ) const
543  { return filenameFromAlias( info.alias(), "repo" ); }
544 
545  std::string generateFilename( const ServiceInfo & info ) const
546  { return filenameFromAlias( info.alias(), "service" ); }
547 
548  void setCacheStatus( const RepoInfo & info, const RepoStatus & status )
549  {
550  Pathname base = solv_path_for_repoinfo( _options, info );
552  status.saveToCookieFile( base / "cookie" );
553  }
554 
555  void touchIndexFile( const RepoInfo & info );
556 
557  template<typename OutputIterator>
558  void getRepositoriesInService( const std::string & alias, OutputIterator out ) const
559  {
560  MatchServiceAlias filter( alias );
561  std::copy( boost::make_filter_iterator( filter, _repos.begin(), _repos.end() ),
562  boost::make_filter_iterator( filter, _repos.end(), _repos.end() ),
563  out);
564  }
565 
566  private:
567  void init_knownServices();
568  void init_knownRepositories();
569 
570  private:
574 
575  private:
576  friend Impl * rwcowClone<Impl>( const Impl * rhs );
578  Impl * clone() const
579  { return new Impl( *this ); }
580  };
582 
584  inline std::ostream & operator<<( std::ostream & str, const RepoManager::Impl & obj )
585  { return str << "RepoManager::Impl"; }
586 
588 
590  {
591  filesystem::assert_dir( _options.knownServicesPath );
592  Pathname servfile = generateNonExistingName( _options.knownServicesPath,
593  generateFilename( service ) );
594  service.setFilepath( servfile );
595 
596  MIL << "saving service in " << servfile << endl;
597 
598  std::ofstream file( servfile.c_str() );
599  if ( !file )
600  {
601  // TranslatorExplanation '%s' is a filename
602  ZYPP_THROW( Exception(str::form( _("Can't open file '%s' for writing."), servfile.c_str() )));
603  }
604  service.dumpAsIniOn( file );
605  MIL << "done" << endl;
606  }
607 
623  Pathname RepoManager::Impl::generateNonExistingName( const Pathname & dir,
624  const std::string & basefilename ) const
625  {
626  std::string final_filename = basefilename;
627  int counter = 1;
628  while ( PathInfo(dir + final_filename).isExist() )
629  {
630  final_filename = basefilename + "_" + str::numstring(counter);
631  ++counter;
632  }
633  return dir + Pathname(final_filename);
634  }
635 
637 
639  {
640  Pathname dir = _options.knownServicesPath;
641  std::list<Pathname> entries;
642  if (PathInfo(dir).isExist())
643  {
644  if ( filesystem::readdir( entries, dir, false ) != 0 )
645  {
646  // TranslatorExplanation '%s' is a pathname
647  ZYPP_THROW(Exception(str::form(_("Failed to read directory '%s'"), dir.c_str())));
648  }
649 
650  //str::regex allowedServiceExt("^\\.service(_[0-9]+)?$");
651  for_(it, entries.begin(), entries.end() )
652  {
653  parser::ServiceFileReader(*it, ServiceCollector(_services));
654  }
655  }
656 
657  repo::PluginServices(_options.pluginsPath/"services", ServiceCollector(_services));
658  }
659 
661  namespace {
667  inline void cleanupNonRepoMetadtaFolders( const Pathname & cachePath_r,
668  const Pathname & defaultCachePath_r,
669  const std::list<std::string> & repoEscAliases_r )
670  {
671  if ( cachePath_r != defaultCachePath_r )
672  return;
673 
674  std::list<std::string> entries;
675  if ( filesystem::readdir( entries, cachePath_r, false ) == 0 )
676  {
677  entries.sort();
678  std::set<std::string> oldfiles;
679  set_difference( entries.begin(), entries.end(), repoEscAliases_r.begin(), repoEscAliases_r.end(),
680  std::inserter( oldfiles, oldfiles.end() ) );
681  for ( const std::string & old : oldfiles )
682  {
683  if ( old == Repository::systemRepoAlias() ) // don't remove the @System solv file
684  continue;
685  filesystem::recursive_rmdir( cachePath_r / old );
686  }
687  }
688  }
689  } // namespace
692  {
693  MIL << "start construct known repos" << endl;
694 
695  if ( PathInfo(_options.knownReposPath).isExist() )
696  {
697  std::list<std::string> repoEscAliases;
698  std::list<RepoInfo> orphanedRepos;
699  for ( RepoInfo & repoInfo : repositories_in_dir(_options.knownReposPath) )
700  {
701  // set the metadata path for the repo
702  repoInfo.setMetadataPath( rawcache_path_for_repoinfo(_options, repoInfo) );
703  // set the downloaded packages path for the repo
704  repoInfo.setPackagesPath( packagescache_path_for_repoinfo(_options, repoInfo) );
705  // remember it
706  _repos.insert( repoInfo );
707 
708  // detect orphaned repos belonging to a deleted service
709  const std::string & serviceAlias( repoInfo.service() );
710  if ( ! ( serviceAlias.empty() || hasService( serviceAlias ) ) )
711  {
712  WAR << "Schedule orphaned service repo for deletion: " << repoInfo << endl;
713  orphanedRepos.push_back( repoInfo );
714  continue; // don't remember it in repoEscAliases
715  }
716 
717  repoEscAliases.push_back(repoInfo.escaped_alias());
718  }
719 
720  // Cleanup orphanded service repos:
721  if ( ! orphanedRepos.empty() )
722  {
723  for ( auto & repoInfo : orphanedRepos )
724  {
725  MIL << "Delete orphaned service repo " << repoInfo.alias() << endl;
726  // translators: Cleanup a repository previously owned by a meanwhile unknown (deleted) service.
727  // %1% = service name
728  // %2% = repository name
729  JobReport::warning( formatNAC(_("Unknown service '%1%': Removing orphaned service repository '%2%'" ))
730  % repoInfo.service()
731  % repoInfo.alias() );
732  try {
733  removeRepository( repoInfo );
734  }
735  catch ( const Exception & caugth )
736  {
737  JobReport::error( caugth.asUserHistory() );
738  }
739  }
740  }
741 
742  // delete metadata folders without corresponding repo (e.g. old tmp directories)
743  //
744  // bnc#891515: Auto-cleanup only zypp.conf default locations. Otherwise
745  // we'd need somemagic file to identify zypp cache directories. Without this
746  // we may easily remove user data (zypper --pkg-cache-dir . download ...)
747  repoEscAliases.sort();
748  RepoManagerOptions defaultCache( _options.rootDir );
749  cleanupNonRepoMetadtaFolders( _options.repoRawCachePath, defaultCache.repoRawCachePath, repoEscAliases );
750  cleanupNonRepoMetadtaFolders( _options.repoSolvCachePath, defaultCache.repoSolvCachePath, repoEscAliases );
751  cleanupNonRepoMetadtaFolders( _options.repoPackagesCachePath, defaultCache.repoPackagesCachePath, repoEscAliases );
752  }
753  MIL << "end construct known repos" << endl;
754  }
755 
757 
759  {
760  Pathname mediarootpath = rawcache_path_for_repoinfo( _options, info );
761  Pathname productdatapath = rawproductdata_path_for_repoinfo( _options, info );
762 
763  RepoType repokind = info.type();
764  // If unknown, probe the local metadata
765  if ( repokind == RepoType::NONE )
766  repokind = probe( productdatapath.asUrl() );
767 
768  RepoStatus status;
769  switch ( repokind.toEnum() )
770  {
771  case RepoType::RPMMD_e :
772  status = RepoStatus( productdatapath/"repodata/repomd.xml");
773  break;
774 
775  case RepoType::YAST2_e :
776  status = RepoStatus( productdatapath/"content" ) && RepoStatus( mediarootpath/"media.1/media" );
777  break;
778 
780  status = RepoStatus::fromCookieFile( productdatapath/"cookie" );
781  break;
782 
783  case RepoType::NONE_e :
784  // Return default RepoStatus in case of RepoType::NONE
785  // indicating it should be created?
786  // ZYPP_THROW(RepoUnknownTypeException());
787  break;
788  }
789  return status;
790  }
791 
792 
794  {
795  Pathname productdatapath = rawproductdata_path_for_repoinfo( _options, info );
796 
797  RepoType repokind = info.type();
798  if ( repokind.toEnum() == RepoType::NONE_e )
799  // unknown, probe the local metadata
800  repokind = probe( productdatapath.asUrl() );
801  // if still unknown, just return
802  if (repokind == RepoType::NONE_e)
803  return;
804 
805  Pathname p;
806  switch ( repokind.toEnum() )
807  {
808  case RepoType::RPMMD_e :
809  p = Pathname(productdatapath + "/repodata/repomd.xml");
810  break;
811 
812  case RepoType::YAST2_e :
813  p = Pathname(productdatapath + "/content");
814  break;
815 
817  p = Pathname(productdatapath + "/cookie");
818  break;
819 
820  case RepoType::NONE_e :
821  default:
822  break;
823  }
824 
825  // touch the file, ignore error (they are logged anyway)
827  }
828 
829 
831  {
832  assert_alias(info);
833  try
834  {
835  MIL << "Going to try to check whether refresh is needed for " << url << endl;
836 
837  // first check old (cached) metadata
838  Pathname mediarootpath = rawcache_path_for_repoinfo( _options, info );
839  filesystem::assert_dir( mediarootpath );
840  RepoStatus oldstatus = metadataStatus( info );
841 
842  if ( oldstatus.empty() )
843  {
844  MIL << "No cached metadata, going to refresh" << endl;
845  return REFRESH_NEEDED;
846  }
847 
848  {
849  if ( url.schemeIsVolatile() )
850  {
851  MIL << "never refresh CD/DVD" << endl;
852  return REPO_UP_TO_DATE;
853  }
854  if ( url.schemeIsLocal() )
855  {
856  policy = RefreshIfNeededIgnoreDelay;
857  }
858  }
859 
860  // now we've got the old (cached) status, we can decide repo.refresh.delay
861  if (policy != RefreshForced && policy != RefreshIfNeededIgnoreDelay)
862  {
863  // difference in seconds
864  double diff = difftime(
866  (Date::ValueType)oldstatus.timestamp()) / 60;
867 
868  DBG << "oldstatus: " << (Date::ValueType)oldstatus.timestamp() << endl;
869  DBG << "current time: " << (Date::ValueType)Date::now() << endl;
870  DBG << "last refresh = " << diff << " minutes ago" << endl;
871 
872  if ( diff < ZConfig::instance().repo_refresh_delay() )
873  {
874  if ( diff < 0 )
875  {
876  WAR << "Repository '" << info.alias() << "' was refreshed in the future!" << endl;
877  }
878  else
879  {
880  MIL << "Repository '" << info.alias()
881  << "' has been refreshed less than repo.refresh.delay ("
883  << ") minutes ago. Advising to skip refresh" << endl;
884  return REPO_CHECK_DELAYED;
885  }
886  }
887  }
888 
889  repo::RepoType repokind = info.type();
890  // if unknown: probe it
891  if ( repokind == RepoType::NONE )
892  repokind = probe( url, info.path() );
893 
894  // retrieve newstatus
895  RepoStatus newstatus;
896  switch ( repokind.toEnum() )
897  {
898  case RepoType::RPMMD_e:
899  {
900  MediaSetAccess media( url );
901  newstatus = yum::Downloader( info, mediarootpath ).status( media );
902  }
903  break;
904 
905  case RepoType::YAST2_e:
906  {
907  MediaSetAccess media( url );
908  newstatus = susetags::Downloader( info, mediarootpath ).status( media );
909  }
910  break;
911 
913  newstatus = RepoStatus( MediaMounter(url).getPathName(info.path()) ); // dir status
914  break;
915 
916  default:
917  case RepoType::NONE_e:
919  break;
920  }
921 
922  // check status
923  bool refresh = false;
924  if ( oldstatus == newstatus )
925  {
926  MIL << "repo has not changed" << endl;
927  if ( policy == RefreshForced )
928  {
929  MIL << "refresh set to forced" << endl;
930  refresh = true;
931  }
932  }
933  else
934  {
935  MIL << "repo has changed, going to refresh" << endl;
936  refresh = true;
937  }
938 
939  if (!refresh)
940  touchIndexFile(info);
941 
942  return refresh ? REFRESH_NEEDED : REPO_UP_TO_DATE;
943 
944  }
945  catch ( const Exception &e )
946  {
947  ZYPP_CAUGHT(e);
948  ERR << "refresh check failed for " << url << endl;
949  ZYPP_RETHROW(e);
950  }
951 
952  return REFRESH_NEEDED; // default
953  }
954 
955 
957  {
958  assert_alias(info);
959  assert_urls(info);
960 
961  // we will throw this later if no URL checks out fine
962  RepoException rexception( info, _PL("Valid metadata not found at specified URL",
963  "Valid metadata not found at specified URLs",
964  info.baseUrlsSize() ) );
965 
966  // try urls one by one
967  for ( RepoInfo::urls_const_iterator it = info.baseUrlsBegin(); it != info.baseUrlsEnd(); ++it )
968  {
969  try
970  {
971  Url url(*it);
972 
973  // check whether to refresh metadata
974  // if the check fails for this url, it throws, so another url will be checked
975  if (checkIfToRefreshMetadata(info, url, policy)!=REFRESH_NEEDED)
976  return;
977 
978  MIL << "Going to refresh metadata from " << url << endl;
979 
980  repo::RepoType repokind = info.type();
981 
982  // if the type is unknown, try probing.
983  if ( repokind == RepoType::NONE )
984  {
985  // unknown, probe it
986  repokind = probe( *it, info.path() );
987 
988  if (repokind.toEnum() != RepoType::NONE_e)
989  {
990  // Adjust the probed type in RepoInfo
991  info.setProbedType( repokind ); // lazy init!
992  //save probed type only for repos in system
993  for_( it, repoBegin(), repoEnd() )
994  {
995  if ( info.alias() == (*it).alias() )
996  {
997  RepoInfo modifiedrepo = info;
998  modifiedrepo.setType( repokind );
999  modifyRepository( info.alias(), modifiedrepo );
1000  break;
1001  }
1002  }
1003  }
1004  }
1005 
1006  Pathname mediarootpath = rawcache_path_for_repoinfo( _options, info );
1007  if( filesystem::assert_dir(mediarootpath) )
1008  {
1009  Exception ex(str::form( _("Can't create %s"), mediarootpath.c_str()) );
1010  ZYPP_THROW(ex);
1011  }
1012 
1013  // create temp dir as sibling of mediarootpath
1014  filesystem::TmpDir tmpdir( filesystem::TmpDir::makeSibling( mediarootpath ) );
1015  if( tmpdir.path().empty() )
1016  {
1017  Exception ex(_("Can't create metadata cache directory."));
1018  ZYPP_THROW(ex);
1019  }
1020 
1021  if ( ( repokind.toEnum() == RepoType::RPMMD_e ) ||
1022  ( repokind.toEnum() == RepoType::YAST2_e ) )
1023  {
1024  MediaSetAccess media(url);
1025  shared_ptr<repo::Downloader> downloader_ptr;
1026 
1027  MIL << "Creating downloader for [ " << info.alias() << " ]" << endl;
1028 
1029  if ( repokind.toEnum() == RepoType::RPMMD_e )
1030  downloader_ptr.reset(new yum::Downloader(info, mediarootpath));
1031  else
1032  downloader_ptr.reset( new susetags::Downloader(info, mediarootpath) );
1033 
1040  for_( it, repoBegin(), repoEnd() )
1041  {
1042  Pathname cachepath(rawcache_path_for_repoinfo( _options, *it ));
1043  if ( PathInfo(cachepath).isExist() )
1044  downloader_ptr->addCachePath(cachepath);
1045  }
1046 
1047  downloader_ptr->download( media, tmpdir.path() );
1048  }
1049  else if ( repokind.toEnum() == RepoType::RPMPLAINDIR_e )
1050  {
1051  MediaMounter media( url );
1052  RepoStatus newstatus = RepoStatus( media.getPathName( info.path() ) ); // dir status
1053 
1054  Pathname productpath( tmpdir.path() / info.path() );
1055  filesystem::assert_dir( productpath );
1056  newstatus.saveToCookieFile( productpath/"cookie" );
1057  }
1058  else
1059  {
1061  }
1062 
1063  // ok we have the metadata, now exchange
1064  // the contents
1065  filesystem::exchange( tmpdir.path(), mediarootpath );
1066 
1067  // we are done.
1068  return;
1069  }
1070  catch ( const Exception &e )
1071  {
1072  ZYPP_CAUGHT(e);
1073  ERR << "Trying another url..." << endl;
1074 
1075  // remember the exception caught for the *first URL*
1076  // if all other URLs fail, the rexception will be thrown with the
1077  // cause of the problem of the first URL remembered
1078  if (it == info.baseUrlsBegin())
1079  rexception.remember(e);
1080  }
1081  } // for every url
1082  ERR << "No more urls..." << endl;
1083  ZYPP_THROW(rexception);
1084  }
1085 
1087 
1088  void RepoManager::Impl::cleanMetadata( const RepoInfo & info, const ProgressData::ReceiverFnc & progressfnc )
1089  {
1090  ProgressData progress(100);
1091  progress.sendTo(progressfnc);
1092 
1093  filesystem::recursive_rmdir(rawcache_path_for_repoinfo(_options, info));
1094  progress.toMax();
1095  }
1096 
1097 
1098  void RepoManager::Impl::cleanPackages( const RepoInfo & info, const ProgressData::ReceiverFnc & progressfnc )
1099  {
1100  ProgressData progress(100);
1101  progress.sendTo(progressfnc);
1102 
1103  filesystem::recursive_rmdir(packagescache_path_for_repoinfo(_options, info));
1104  progress.toMax();
1105  }
1106 
1107 
1108  void RepoManager::Impl::buildCache( const RepoInfo & info, CacheBuildPolicy policy, const ProgressData::ReceiverFnc & progressrcv )
1109  {
1110  assert_alias(info);
1111  Pathname mediarootpath = rawcache_path_for_repoinfo( _options, info );
1112  Pathname productdatapath = rawproductdata_path_for_repoinfo( _options, info );
1113 
1114  if( filesystem::assert_dir(_options.repoCachePath) )
1115  {
1116  Exception ex(str::form( _("Can't create %s"), _options.repoCachePath.c_str()) );
1117  ZYPP_THROW(ex);
1118  }
1119  RepoStatus raw_metadata_status = metadataStatus(info);
1120  if ( raw_metadata_status.empty() )
1121  {
1122  /* if there is no cache at this point, we refresh the raw
1123  in case this is the first time - if it's !autorefresh,
1124  we may still refresh */
1125  refreshMetadata(info, RefreshIfNeeded, progressrcv );
1126  raw_metadata_status = metadataStatus(info);
1127  }
1128 
1129  bool needs_cleaning = false;
1130  if ( isCached( info ) )
1131  {
1132  MIL << info.alias() << " is already cached." << endl;
1133  RepoStatus cache_status = cacheStatus(info);
1134 
1135  if ( cache_status == raw_metadata_status )
1136  {
1137  MIL << info.alias() << " cache is up to date with metadata." << endl;
1138  if ( policy == BuildIfNeeded ) {
1139  return;
1140  }
1141  else {
1142  MIL << info.alias() << " cache rebuild is forced" << endl;
1143  }
1144  }
1145 
1146  needs_cleaning = true;
1147  }
1148 
1149  ProgressData progress(100);
1151  progress.sendTo( ProgressReportAdaptor( progressrcv, report ) );
1152  progress.name(str::form(_("Building repository '%s' cache"), info.label().c_str()));
1153  progress.toMin();
1154 
1155  if (needs_cleaning)
1156  {
1157  cleanCache(info);
1158  }
1159 
1160  MIL << info.alias() << " building cache..." << info.type() << endl;
1161 
1162  Pathname base = solv_path_for_repoinfo( _options, info);
1163 
1164  if( filesystem::assert_dir(base) )
1165  {
1166  Exception ex(str::form( _("Can't create %s"), base.c_str()) );
1167  ZYPP_THROW(ex);
1168  }
1169 
1170  if( ! PathInfo(base).userMayW() )
1171  {
1172  Exception ex(str::form( _("Can't create cache at %s - no writing permissions."), base.c_str()) );
1173  ZYPP_THROW(ex);
1174  }
1175  Pathname solvfile = base / "solv";
1176 
1177  // do we have type?
1178  repo::RepoType repokind = info.type();
1179 
1180  // if the type is unknown, try probing.
1181  switch ( repokind.toEnum() )
1182  {
1183  case RepoType::NONE_e:
1184  // unknown, probe the local metadata
1185  repokind = probe( productdatapath.asUrl() );
1186  break;
1187  default:
1188  break;
1189  }
1190 
1191  MIL << "repo type is " << repokind << endl;
1192 
1193  switch ( repokind.toEnum() )
1194  {
1195  case RepoType::RPMMD_e :
1196  case RepoType::YAST2_e :
1198  {
1199  // Take care we unlink the solvfile on exception
1200  ManagedFile guard( solvfile, filesystem::unlink );
1201  scoped_ptr<MediaMounter> forPlainDirs;
1202 
1204  cmd.push_back( "repo2solv" );
1205  // repo2solv expects -o as 1st arg!
1206  cmd.push_back( "-o" );
1207  cmd.push_back( solvfile.asString() );
1208  cmd.push_back( "-X" ); // autogenerate pattern from pattern-package
1209 
1210  if ( repokind == RepoType::RPMPLAINDIR )
1211  {
1212  forPlainDirs.reset( new MediaMounter( *info.baseUrlsBegin() ) );
1213  // recusive for plaindir as 2nd arg!
1214  cmd.push_back( "-R" );
1215  // FIXME this does only work form dir: URLs
1216  cmd.push_back( forPlainDirs->getPathName( info.path() ).c_str() );
1217  }
1218  else
1219  cmd.push_back( productdatapath.asString() );
1220 
1222  std::string errdetail;
1223 
1224  for ( std::string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() ) {
1225  WAR << " " << output;
1226  if ( errdetail.empty() ) {
1227  errdetail = prog.command();
1228  errdetail += '\n';
1229  }
1230  errdetail += output;
1231  }
1232 
1233  int ret = prog.close();
1234  if ( ret != 0 )
1235  {
1236  RepoException ex(str::form( _("Failed to cache repo (%d)."), ret ));
1237  ex.remember( errdetail );
1238  ZYPP_THROW(ex);
1239  }
1240 
1241  // We keep it.
1242  guard.resetDispose();
1243  }
1244  break;
1245  default:
1246  ZYPP_THROW(RepoUnknownTypeException( info, _("Unhandled repository type") ));
1247  break;
1248  }
1249  // update timestamp and checksum
1250  setCacheStatus(info, raw_metadata_status);
1251  MIL << "Commit cache.." << endl;
1252  progress.toMax();
1253  }
1254 
1256 
1257  repo::RepoType RepoManager::Impl::probe( const Url & url, const Pathname & path ) const
1258  {
1259  MIL << "going to probe the repo type at " << url << " (" << path << ")" << endl;
1260 
1261  if ( url.getScheme() == "dir" && ! PathInfo( url.getPathName()/path ).isDir() )
1262  {
1263  // Handle non existing local directory in advance, as
1264  // MediaSetAccess does not support it.
1265  MIL << "Probed type NONE (not exists) at " << url << " (" << path << ")" << endl;
1266  return repo::RepoType::NONE;
1267  }
1268 
1269  // prepare exception to be thrown if the type could not be determined
1270  // due to a media exception. We can't throw right away, because of some
1271  // problems with proxy servers returning an incorrect error
1272  // on ftp file-not-found(bnc #335906). Instead we'll check another types
1273  // before throwing.
1274 
1275  // TranslatorExplanation '%s' is an URL
1276  RepoException enew(str::form( _("Error trying to read from '%s'"), url.asString().c_str() ));
1277  bool gotMediaException = false;
1278  try
1279  {
1280  MediaSetAccess access(url);
1281  try
1282  {
1283  if ( access.doesFileExist(path/"/repodata/repomd.xml") )
1284  {
1285  MIL << "Probed type RPMMD at " << url << " (" << path << ")" << endl;
1286  return repo::RepoType::RPMMD;
1287  }
1288  }
1289  catch ( const media::MediaException &e )
1290  {
1291  ZYPP_CAUGHT(e);
1292  DBG << "problem checking for repodata/repomd.xml file" << endl;
1293  enew.remember(e);
1294  gotMediaException = true;
1295  }
1296 
1297  try
1298  {
1299  if ( access.doesFileExist(path/"/content") )
1300  {
1301  MIL << "Probed type YAST2 at " << url << " (" << path << ")" << endl;
1302  return repo::RepoType::YAST2;
1303  }
1304  }
1305  catch ( const media::MediaException &e )
1306  {
1307  ZYPP_CAUGHT(e);
1308  DBG << "problem checking for content file" << endl;
1309  enew.remember(e);
1310  gotMediaException = true;
1311  }
1312 
1313  // if it is a non-downloading URL denoting a directory
1314  if ( ! url.schemeIsDownloading() )
1315  {
1316  MediaMounter media( url );
1317  if ( PathInfo(media.getPathName()/path).isDir() )
1318  {
1319  // allow empty dirs for now
1320  MIL << "Probed type RPMPLAINDIR at " << url << " (" << path << ")" << endl;
1322  }
1323  }
1324  }
1325  catch ( const Exception &e )
1326  {
1327  ZYPP_CAUGHT(e);
1328  // TranslatorExplanation '%s' is an URL
1329  Exception enew(str::form( _("Unknown error reading from '%s'"), url.asString().c_str() ));
1330  enew.remember(e);
1331  ZYPP_THROW(enew);
1332  }
1333 
1334  if (gotMediaException)
1335  ZYPP_THROW(enew);
1336 
1337  MIL << "Probed type NONE at " << url << " (" << path << ")" << endl;
1338  return repo::RepoType::NONE;
1339  }
1340 
1342 
1344  {
1345  MIL << "Going to clean up garbage in cache dirs" << endl;
1346 
1347  ProgressData progress(300);
1348  progress.sendTo(progressrcv);
1349  progress.toMin();
1350 
1351  std::list<Pathname> cachedirs;
1352  cachedirs.push_back(_options.repoRawCachePath);
1353  cachedirs.push_back(_options.repoPackagesCachePath);
1354  cachedirs.push_back(_options.repoSolvCachePath);
1355 
1356  for_( dir, cachedirs.begin(), cachedirs.end() )
1357  {
1358  if ( PathInfo(*dir).isExist() )
1359  {
1360  std::list<Pathname> entries;
1361  if ( filesystem::readdir( entries, *dir, false ) != 0 )
1362  // TranslatorExplanation '%s' is a pathname
1363  ZYPP_THROW(Exception(str::form(_("Failed to read directory '%s'"), dir->c_str())));
1364 
1365  unsigned sdircount = entries.size();
1366  unsigned sdircurrent = 1;
1367  for_( subdir, entries.begin(), entries.end() )
1368  {
1369  // if it does not belong known repo, make it disappear
1370  bool found = false;
1371  for_( r, repoBegin(), repoEnd() )
1372  if ( subdir->basename() == r->escaped_alias() )
1373  { found = true; break; }
1374 
1375  if ( ! found && ( Date::now()-PathInfo(*subdir).mtime() > Date::day ) )
1376  filesystem::recursive_rmdir( *subdir );
1377 
1378  progress.set( progress.val() + sdircurrent * 100 / sdircount );
1379  ++sdircurrent;
1380  }
1381  }
1382  else
1383  progress.set( progress.val() + 100 );
1384  }
1385  progress.toMax();
1386  }
1387 
1389 
1390  void RepoManager::Impl::cleanCache( const RepoInfo & info, const ProgressData::ReceiverFnc & progressrcv )
1391  {
1392  ProgressData progress(100);
1393  progress.sendTo(progressrcv);
1394  progress.toMin();
1395 
1396  MIL << "Removing raw metadata cache for " << info.alias() << endl;
1397  filesystem::recursive_rmdir(solv_path_for_repoinfo(_options, info));
1398 
1399  progress.toMax();
1400  }
1401 
1403 
1404  void RepoManager::Impl::loadFromCache( const RepoInfo & info, const ProgressData::ReceiverFnc & progressrcv )
1405  {
1406  assert_alias(info);
1407  Pathname solvfile = solv_path_for_repoinfo(_options, info) / "solv";
1408 
1409  if ( ! PathInfo(solvfile).isExist() )
1411 
1412  sat::Pool::instance().reposErase( info.alias() );
1413  try
1414  {
1415  Repository repo = sat::Pool::instance().addRepoSolv( solvfile, info );
1416  // test toolversion in order to rebuild solv file in case
1417  // it was written by an old libsolv-tool parser.
1418  //
1419  // Known version strings used:
1420  // - <no string>
1421  // - "1.0"
1422  //
1424  if ( toolversion.begin().asString().empty() )
1425  {
1426  repo.eraseFromPool();
1427  ZYPP_THROW(Exception("Solv-file was created by old parser."));
1428  }
1429  // else: up-to-date (or even newer).
1430  }
1431  catch ( const Exception & exp )
1432  {
1433  ZYPP_CAUGHT( exp );
1434  MIL << "Try to handle exception by rebuilding the solv-file" << endl;
1435  cleanCache( info, progressrcv );
1436  buildCache( info, BuildIfNeeded, progressrcv );
1437 
1438  sat::Pool::instance().addRepoSolv( solvfile, info );
1439  }
1440  }
1441 
1443 
1444  void RepoManager::Impl::addRepository( const RepoInfo & info, const ProgressData::ReceiverFnc & progressrcv )
1445  {
1446  assert_alias(info);
1447 
1448  ProgressData progress(100);
1450  progress.sendTo( ProgressReportAdaptor( progressrcv, report ) );
1451  progress.name(str::form(_("Adding repository '%s'"), info.label().c_str()));
1452  progress.toMin();
1453 
1454  MIL << "Try adding repo " << info << endl;
1455 
1456  RepoInfo tosave = info;
1457  if ( _repos.find(tosave) != _repos.end() )
1459 
1460  // check the first url for now
1461  if ( _options.probe )
1462  {
1463  DBG << "unknown repository type, probing" << endl;
1464 
1465  RepoType probedtype;
1466  probedtype = probe( *tosave.baseUrlsBegin(), info.path() );
1467  if ( tosave.baseUrlsSize() > 0 )
1468  {
1469  if ( probedtype == RepoType::NONE )
1471  else
1472  tosave.setType(probedtype);
1473  }
1474  }
1475 
1476  progress.set(50);
1477 
1478  // assert the directory exists
1479  filesystem::assert_dir(_options.knownReposPath);
1480 
1481  Pathname repofile = generateNonExistingName(
1482  _options.knownReposPath, generateFilename(tosave));
1483  // now we have a filename that does not exists
1484  MIL << "Saving repo in " << repofile << endl;
1485 
1486  std::ofstream file(repofile.c_str());
1487  if (!file)
1488  {
1489  // TranslatorExplanation '%s' is a filename
1490  ZYPP_THROW( Exception(str::form( _("Can't open file '%s' for writing."), repofile.c_str() )));
1491  }
1492 
1493  tosave.dumpAsIniOn(file);
1494  tosave.setFilepath(repofile);
1495  tosave.setMetadataPath( metadataPath( tosave ) );
1496  tosave.setPackagesPath( packagesPath( tosave ) );
1497  {
1498  // We chould fix the API as we must injet those paths
1499  // into the repoinfo in order to keep it usable.
1500  RepoInfo & oinfo( const_cast<RepoInfo &>(info) );
1501  oinfo.setMetadataPath( metadataPath( tosave ) );
1502  oinfo.setPackagesPath( packagesPath( tosave ) );
1503  }
1504  _repos.insert(tosave);
1505 
1506  progress.set(90);
1507 
1508  // check for credentials in Urls
1509  bool havePasswords = false;
1510  for_( urlit, tosave.baseUrlsBegin(), tosave.baseUrlsEnd() )
1511  if ( urlit->hasCredentialsInAuthority() )
1512  {
1513  havePasswords = true;
1514  break;
1515  }
1516  // save the credentials
1517  if ( havePasswords )
1518  {
1520  media::CredManagerOptions(_options.rootDir) );
1521 
1522  for_(urlit, tosave.baseUrlsBegin(), tosave.baseUrlsEnd())
1523  if (urlit->hasCredentialsInAuthority())
1525  cm.saveInUser(media::AuthData(*urlit));
1526  }
1527 
1528  HistoryLog().addRepository(tosave);
1529 
1530  progress.toMax();
1531  MIL << "done" << endl;
1532  }
1533 
1534 
1536  {
1537  std::list<RepoInfo> repos = readRepoFile(url);
1538  for ( std::list<RepoInfo>::const_iterator it = repos.begin();
1539  it != repos.end();
1540  ++it )
1541  {
1542  // look if the alias is in the known repos.
1543  for_ ( kit, repoBegin(), repoEnd() )
1544  {
1545  if ( (*it).alias() == (*kit).alias() )
1546  {
1547  ERR << "To be added repo " << (*it).alias() << " conflicts with existing repo " << (*kit).alias() << endl;
1549  }
1550  }
1551  }
1552 
1553  std::string filename = Pathname(url.getPathName()).basename();
1554 
1555  if ( filename == Pathname() )
1556  {
1557  // TranslatorExplanation '%s' is an URL
1558  ZYPP_THROW(RepoException(str::form( _("Invalid repo file name at '%s'"), url.asString().c_str() )));
1559  }
1560 
1561  // assert the directory exists
1562  filesystem::assert_dir(_options.knownReposPath);
1563 
1564  Pathname repofile = generateNonExistingName(_options.knownReposPath, filename);
1565  // now we have a filename that does not exists
1566  MIL << "Saving " << repos.size() << " repo" << ( repos.size() ? "s" : "" ) << " in " << repofile << endl;
1567 
1568  std::ofstream file(repofile.c_str());
1569  if (!file)
1570  {
1571  // TranslatorExplanation '%s' is a filename
1572  ZYPP_THROW( Exception(str::form( _("Can't open file '%s' for writing."), repofile.c_str() )));
1573  }
1574 
1575  for ( std::list<RepoInfo>::iterator it = repos.begin();
1576  it != repos.end();
1577  ++it )
1578  {
1579  MIL << "Saving " << (*it).alias() << endl;
1580  it->setFilepath(repofile.asString());
1581  it->dumpAsIniOn(file);
1582  _repos.insert(*it);
1583 
1584  HistoryLog(_options.rootDir).addRepository(*it);
1585  }
1586 
1587  MIL << "done" << endl;
1588  }
1589 
1591 
1593  {
1594  ProgressData progress;
1596  progress.sendTo( ProgressReportAdaptor( progressrcv, report ) );
1597  progress.name(str::form(_("Removing repository '%s'"), info.label().c_str()));
1598 
1599  MIL << "Going to delete repo " << info.alias() << endl;
1600 
1601  for_( it, repoBegin(), repoEnd() )
1602  {
1603  // they can be the same only if the provided is empty, that means
1604  // the provided repo has no alias
1605  // then skip
1606  if ( (!info.alias().empty()) && ( info.alias() != (*it).alias() ) )
1607  continue;
1608 
1609  // TODO match by url
1610 
1611  // we have a matcing repository, now we need to know
1612  // where it does come from.
1613  RepoInfo todelete = *it;
1614  if (todelete.filepath().empty())
1615  {
1616  ZYPP_THROW(RepoException( todelete, _("Can't figure out where the repo is stored.") ));
1617  }
1618  else
1619  {
1620  // figure how many repos are there in the file:
1621  std::list<RepoInfo> filerepos = repositories_in_file(todelete.filepath());
1622  if ( (filerepos.size() == 1) && ( filerepos.front().alias() == todelete.alias() ) )
1623  {
1624  // easy, only this one, just delete the file
1625  if ( filesystem::unlink(todelete.filepath()) != 0 )
1626  {
1627  // TranslatorExplanation '%s' is a filename
1628  ZYPP_THROW(RepoException( todelete, str::form( _("Can't delete '%s'"), todelete.filepath().c_str() )));
1629  }
1630  MIL << todelete.alias() << " successfully deleted." << endl;
1631  }
1632  else
1633  {
1634  // there are more repos in the same file
1635  // write them back except the deleted one.
1636  //TmpFile tmp;
1637  //std::ofstream file(tmp.path().c_str());
1638 
1639  // assert the directory exists
1640  filesystem::assert_dir(todelete.filepath().dirname());
1641 
1642  std::ofstream file(todelete.filepath().c_str());
1643  if (!file)
1644  {
1645  // TranslatorExplanation '%s' is a filename
1646  ZYPP_THROW( Exception(str::form( _("Can't open file '%s' for writing."), todelete.filepath().c_str() )));
1647  }
1648  for ( std::list<RepoInfo>::const_iterator fit = filerepos.begin();
1649  fit != filerepos.end();
1650  ++fit )
1651  {
1652  if ( (*fit).alias() != todelete.alias() )
1653  (*fit).dumpAsIniOn(file);
1654  }
1655  }
1656 
1657  CombinedProgressData cSubprogrcv(progress, 20);
1658  CombinedProgressData mSubprogrcv(progress, 40);
1659  CombinedProgressData pSubprogrcv(progress, 40);
1660  // now delete it from cache
1661  if ( isCached(todelete) )
1662  cleanCache( todelete, cSubprogrcv);
1663  // now delete metadata (#301037)
1664  cleanMetadata( todelete, mSubprogrcv );
1665  cleanPackages( todelete, pSubprogrcv );
1666  _repos.erase(todelete);
1667  MIL << todelete.alias() << " successfully deleted." << endl;
1668  HistoryLog(_options.rootDir).removeRepository(todelete);
1669  return;
1670  } // else filepath is empty
1671 
1672  }
1673  // should not be reached on a sucess workflow
1675  }
1676 
1678 
1679  void RepoManager::Impl::modifyRepository( const std::string & alias, const RepoInfo & newinfo_r, const ProgressData::ReceiverFnc & progressrcv )
1680  {
1681  RepoInfo toedit = getRepositoryInfo(alias);
1682  RepoInfo newinfo( newinfo_r ); // need writable copy to upadte housekeeping data
1683 
1684  // check if the new alias already exists when renaming the repo
1685  if ( alias != newinfo.alias() && hasRepo( newinfo.alias() ) )
1686  {
1688  }
1689 
1690  if (toedit.filepath().empty())
1691  {
1692  ZYPP_THROW(RepoException( toedit, _("Can't figure out where the repo is stored.") ));
1693  }
1694  else
1695  {
1696  // figure how many repos are there in the file:
1697  std::list<RepoInfo> filerepos = repositories_in_file(toedit.filepath());
1698 
1699  // there are more repos in the same file
1700  // write them back except the deleted one.
1701  //TmpFile tmp;
1702  //std::ofstream file(tmp.path().c_str());
1703 
1704  // assert the directory exists
1705  filesystem::assert_dir(toedit.filepath().dirname());
1706 
1707  std::ofstream file(toedit.filepath().c_str());
1708  if (!file)
1709  {
1710  // TranslatorExplanation '%s' is a filename
1711  ZYPP_THROW( Exception(str::form( _("Can't open file '%s' for writing."), toedit.filepath().c_str() )));
1712  }
1713  for ( std::list<RepoInfo>::const_iterator fit = filerepos.begin();
1714  fit != filerepos.end();
1715  ++fit )
1716  {
1717  // if the alias is different, dump the original
1718  // if it is the same, dump the provided one
1719  if ( (*fit).alias() != toedit.alias() )
1720  (*fit).dumpAsIniOn(file);
1721  else
1722  newinfo.dumpAsIniOn(file);
1723  }
1724 
1725  newinfo.setFilepath(toedit.filepath());
1726  _repos.erase(toedit);
1727  _repos.insert(newinfo);
1728  HistoryLog(_options.rootDir).modifyRepository(toedit, newinfo);
1729  MIL << "repo " << alias << " modified" << endl;
1730  }
1731  }
1732 
1734 
1735  RepoInfo RepoManager::Impl::getRepositoryInfo( const std::string & alias, const ProgressData::ReceiverFnc & progressrcv )
1736  {
1737  RepoConstIterator it( findAlias( alias, _repos ) );
1738  if ( it != _repos.end() )
1739  return *it;
1740  RepoInfo info;
1741  info.setAlias( alias );
1743  }
1744 
1745 
1746  RepoInfo RepoManager::Impl::getRepositoryInfo( const Url & url, const url::ViewOption & urlview, const ProgressData::ReceiverFnc & progressrcv )
1747  {
1748  for_( it, repoBegin(), repoEnd() )
1749  {
1750  for_( urlit, (*it).baseUrlsBegin(), (*it).baseUrlsEnd() )
1751  {
1752  if ( (*urlit).asString(urlview) == url.asString(urlview) )
1753  return *it;
1754  }
1755  }
1756  RepoInfo info;
1757  info.setBaseUrl( url );
1759  }
1760 
1762  //
1763  // Services
1764  //
1766 
1768  {
1769  assert_alias( service );
1770 
1771  // check if service already exists
1772  if ( hasService( service.alias() ) )
1774 
1775  // Writable ServiceInfo is needed to save the location
1776  // of the .service file. Finaly insert into the service list.
1777  ServiceInfo toSave( service );
1778  saveService( toSave );
1779  _services.insert( toSave );
1780 
1781  // check for credentials in Url (username:password, not ?credentials param)
1782  if ( toSave.url().hasCredentialsInAuthority() )
1783  {
1785  media::CredManagerOptions(_options.rootDir) );
1786 
1788  cm.saveInUser(media::AuthData(toSave.url()));
1789  }
1790 
1791  MIL << "added service " << toSave.alias() << endl;
1792  }
1793 
1795 
1796  void RepoManager::Impl::removeService( const std::string & alias )
1797  {
1798  MIL << "Going to delete service " << alias << endl;
1799 
1800  const ServiceInfo & service = getService( alias );
1801 
1802  Pathname location = service.filepath();
1803  if( location.empty() )
1804  {
1805  ZYPP_THROW(ServiceException( service, _("Can't figure out where the service is stored.") ));
1806  }
1807 
1808  ServiceSet tmpSet;
1809  parser::ServiceFileReader( location, ServiceCollector(tmpSet) );
1810 
1811  // only one service definition in the file
1812  if ( tmpSet.size() == 1 )
1813  {
1814  if ( filesystem::unlink(location) != 0 )
1815  {
1816  // TranslatorExplanation '%s' is a filename
1817  ZYPP_THROW(ServiceException( service, str::form( _("Can't delete '%s'"), location.c_str() ) ));
1818  }
1819  MIL << alias << " successfully deleted." << endl;
1820  }
1821  else
1822  {
1823  filesystem::assert_dir(location.dirname());
1824 
1825  std::ofstream file(location.c_str());
1826  if( !file )
1827  {
1828  // TranslatorExplanation '%s' is a filename
1829  ZYPP_THROW( Exception(str::form( _("Can't open file '%s' for writing."), location.c_str() )));
1830  }
1831 
1832  for_(it, tmpSet.begin(), tmpSet.end())
1833  {
1834  if( it->alias() != alias )
1835  it->dumpAsIniOn(file);
1836  }
1837 
1838  MIL << alias << " successfully deleted from file " << location << endl;
1839  }
1840 
1841  // now remove all repositories added by this service
1842  RepoCollector rcollector;
1843  getRepositoriesInService( alias,
1844  boost::make_function_output_iterator( bind( &RepoCollector::collect, &rcollector, _1 ) ) );
1845  // cannot do this directly in getRepositoriesInService - would invalidate iterators
1846  for_(rit, rcollector.repos.begin(), rcollector.repos.end())
1847  removeRepository(*rit);
1848  }
1849 
1851 
1853  {
1854  // copy the set of services since refreshService
1855  // can eventually invalidate the iterator
1856  ServiceSet services( serviceBegin(), serviceEnd() );
1857  for_( it, services.begin(), services.end() )
1858  {
1859  if ( !it->enabled() )
1860  continue;
1861 
1862  try {
1863  refreshService(*it, options_r);
1864  }
1865  catch ( const repo::ServicePluginInformalException & e )
1866  { ;/* ignore ServicePluginInformalException */ }
1867  }
1868  }
1869 
1870  void RepoManager::Impl::refreshService( const std::string & alias, const RefreshServiceOptions & options_r )
1871  {
1872  ServiceInfo service( getService( alias ) );
1873  assert_alias( service );
1874  assert_url( service );
1875  // NOTE: It might be necessary to modify and rewrite the service info.
1876  // Either when probing the type, or when adjusting the repositories
1877  // enable/disable state.:
1878  bool serviceModified = false;
1879  MIL << "Going to refresh service '" << service.alias() << "', url: "<< service.url() << ", opts: " << options_r << endl;
1880 
1882 
1883  // if the type is unknown, try probing.
1884  if ( service.type() == repo::ServiceType::NONE )
1885  {
1886  repo::ServiceType type = probeService( service.url() );
1887  if ( type != ServiceType::NONE )
1888  {
1889  service.setProbedType( type ); // lazy init!
1890  serviceModified = true;
1891  }
1892  }
1893 
1894  // get target distro identifier
1895  std::string servicesTargetDistro = _options.servicesTargetDistro;
1896  if ( servicesTargetDistro.empty() )
1897  {
1898  servicesTargetDistro = Target::targetDistribution( Pathname() );
1899  }
1900  DBG << "ServicesTargetDistro: " << servicesTargetDistro << endl;
1901 
1902  // parse it
1903  RepoCollector collector(servicesTargetDistro);
1904  // FIXME Ugly hack: ServiceRepos may throw ServicePluginInformalException
1905  // which is actually a notification. Using an exception for this
1906  // instead of signal/callback is bad. Needs to be fixed here, in refreshServices()
1907  // and in zypper.
1908  std::pair<DefaultIntegral<bool,false>, repo::ServicePluginInformalException> uglyHack;
1909  try {
1910  ServiceRepos repos(service, bind( &RepoCollector::collect, &collector, _1 ));
1911  }
1912  catch ( const repo::ServicePluginInformalException & e )
1913  {
1914  /* ignore ServicePluginInformalException and throw later */
1915  uglyHack.first = true;
1916  uglyHack.second = e;
1917  }
1918 
1920  // On the fly remember the new repo states as defined the reopoindex.xml.
1921  // Move into ServiceInfo later.
1922  ServiceInfo::RepoStates newRepoStates;
1923 
1924  // set service alias and base url for all collected repositories
1925  for_( it, collector.repos.begin(), collector.repos.end() )
1926  {
1927  // First of all: Prepend service alias:
1928  it->setAlias( str::form( "%s:%s", service.alias().c_str(), it->alias().c_str() ) );
1929  // set refrence to the parent service
1930  it->setService( service.alias() );
1931 
1932  // remember the new parsed repo state
1933  newRepoStates[it->alias()] = *it;
1934 
1935  // if the repo url was not set by the repoindex parser, set service's url
1936  Url url;
1937  if ( it->baseUrlsEmpty() )
1938  url = service.url();
1939  else
1940  {
1941  // service repo can contain only one URL now, so no need to iterate.
1942  url = *it->baseUrlsBegin();
1943  }
1944 
1945  // libzypp currently has problem with separate url + path handling
1946  // so just append the path to the baseurl
1947  if ( !it->path().empty() )
1948  {
1949  Pathname path(url.getPathName());
1950  path /= it->path();
1951  url.setPathName( path.asString() );
1952  it->setPath("");
1953  }
1954 
1955  // save the url
1956  it->setBaseUrl( url );
1957  }
1958 
1960  // Now compare collected repos with the ones in the system...
1961  //
1962  RepoInfoList oldRepos;
1963  getRepositoriesInService( service.alias(), std::back_inserter( oldRepos ) );
1964 
1966  // find old repositories to remove...
1967  for_( oldRepo, oldRepos.begin(), oldRepos.end() )
1968  {
1969  if ( ! foundAliasIn( oldRepo->alias(), collector.repos ) )
1970  {
1971  if ( oldRepo->enabled() )
1972  {
1973  // Currently enabled. If this was a user modification remember the state.
1974  const auto & last = service.repoStates().find( oldRepo->alias() );
1975  if ( last != service.repoStates().end() && ! last->second.enabled )
1976  {
1977  DBG << "Service removes user enabled repo " << oldRepo->alias() << endl;
1978  service.addRepoToEnable( oldRepo->alias() );
1979  serviceModified = true;
1980  }
1981  else
1982  DBG << "Service removes enabled repo " << oldRepo->alias() << endl;
1983  }
1984  else
1985  DBG << "Service removes disabled repo " << oldRepo->alias() << endl;
1986 
1987  removeRepository( *oldRepo );
1988  }
1989  }
1990 
1992  // create missing repositories and modify exising ones if needed...
1993  for_( it, collector.repos.begin(), collector.repos.end() )
1994  {
1995  // User explicitly requested the repo being enabled?
1996  // User explicitly requested the repo being disabled?
1997  // And hopefully not both ;) If so, enable wins.
1998 
1999  TriBool toBeEnabled( indeterminate ); // indeterminate - follow the service request
2000  DBG << "Service request to " << (it->enabled()?"enable":"disable") << " service repo " << it->alias() << endl;
2001 
2002  if ( options_r.testFlag( RefreshService_restoreStatus ) )
2003  {
2004  DBG << "Opt RefreshService_restoreStatus " << it->alias() << endl;
2005  // this overrides any pending request!
2006  // Remove from enable request list.
2007  // NOTE: repoToDisable is handled differently.
2008  // It gets cleared on each refresh.
2009  service.delRepoToEnable( it->alias() );
2010  // toBeEnabled stays indeterminate!
2011  }
2012  else
2013  {
2014  if ( service.repoToEnableFind( it->alias() ) )
2015  {
2016  DBG << "User request to enable service repo " << it->alias() << endl;
2017  toBeEnabled = true;
2018  // Remove from enable request list.
2019  // NOTE: repoToDisable is handled differently.
2020  // It gets cleared on each refresh.
2021  service.delRepoToEnable( it->alias() );
2022  serviceModified = true;
2023  }
2024  else if ( service.repoToDisableFind( it->alias() ) )
2025  {
2026  DBG << "User request to disable service repo " << it->alias() << endl;
2027  toBeEnabled = false;
2028  }
2029  }
2030 
2031  RepoInfoList::iterator oldRepo( findAlias( it->alias(), oldRepos ) );
2032  if ( oldRepo == oldRepos.end() )
2033  {
2034  // Not found in oldRepos ==> a new repo to add
2035 
2036  // Make sure the service repo is created with the appropriate enablement
2037  if ( ! indeterminate(toBeEnabled) )
2038  it->setEnabled( toBeEnabled );
2039 
2040  DBG << "Service adds repo " << it->alias() << " " << (it->enabled()?"enabled":"disabled") << endl;
2041  addRepository( *it );
2042  }
2043  else
2044  {
2045  // ==> an exising repo to check
2046  bool oldRepoModified = false;
2047 
2048  if ( indeterminate(toBeEnabled) )
2049  {
2050  // No user request: check for an old user modificaton otherwise follow service request.
2051  // NOTE: Assert toBeEnabled is boolean afterwards!
2052  if ( oldRepo->enabled() == it->enabled() )
2053  toBeEnabled = it->enabled(); // service requests no change to the system
2054  else if (options_r.testFlag( RefreshService_restoreStatus ) )
2055  {
2056  toBeEnabled = it->enabled(); // RefreshService_restoreStatus forced
2057  DBG << "Opt RefreshService_restoreStatus " << it->alias() << " forces " << (toBeEnabled?"enabled":"disabled") << endl;
2058  }
2059  else
2060  {
2061  const auto & last = service.repoStates().find( oldRepo->alias() );
2062  if ( last == service.repoStates().end() || last->second.enabled != it->enabled() )
2063  toBeEnabled = it->enabled(); // service request has changed since last refresh -> follow
2064  else
2065  {
2066  toBeEnabled = oldRepo->enabled(); // service request unchaned since last refresh -> keep user modification
2067  DBG << "User modified service repo " << it->alias() << " may stay " << (toBeEnabled?"enabled":"disabled") << endl;
2068  }
2069  }
2070  }
2071 
2072  // changed enable?
2073  if ( toBeEnabled == oldRepo->enabled() )
2074  {
2075  DBG << "Service repo " << it->alias() << " stays " << (oldRepo->enabled()?"enabled":"disabled") << endl;
2076  }
2077  else if ( toBeEnabled )
2078  {
2079  DBG << "Service repo " << it->alias() << " gets enabled" << endl;
2080  oldRepo->setEnabled( true );
2081  oldRepoModified = true;
2082  }
2083  else
2084  {
2085  DBG << "Service repo " << it->alias() << " gets disabled" << endl;
2086  oldRepo->setEnabled( false );
2087  oldRepoModified = true;
2088  }
2089 
2090  // all other attributes follow the service request:
2091 
2092  // changed autorefresh
2093  if ( oldRepo->autorefresh() != it->autorefresh() )
2094  {
2095  DBG << "Service repo " << it->alias() << " gets new AUTOREFRESH " << it->autorefresh() << endl;
2096  oldRepo->setAutorefresh( it->autorefresh() );
2097  oldRepoModified = true;
2098  }
2099 
2100  // changed priority?
2101  if ( oldRepo->priority() != it->priority() )
2102  {
2103  DBG << "Service repo " << it->alias() << " gets new PRIORITY " << it->priority() << endl;
2104  oldRepo->setPriority( it->priority() );
2105  oldRepoModified = true;
2106  }
2107 
2108  // changed url?
2109  // service repo can contain only one URL now, so no need to iterate.
2110  if ( oldRepo->url() != it->url() )
2111  {
2112  DBG << "Service repo " << it->alias() << " gets new URL " << it->url() << endl;
2113  oldRepo->setBaseUrl( it->url() );
2114  oldRepoModified = true;
2115  }
2116 
2117  // save if modified:
2118  if ( oldRepoModified )
2119  {
2120  modifyRepository( oldRepo->alias(), *oldRepo );
2121  }
2122  }
2123  }
2124 
2125  // Unlike reposToEnable, reposToDisable is always cleared after refresh.
2126  if ( ! service.reposToDisableEmpty() )
2127  {
2128  service.clearReposToDisable();
2129  serviceModified = true;
2130  }
2131 
2132  // Remember original service request for next refresh
2133  if ( service.repoStates() != newRepoStates )
2134  {
2135  service.setRepoStates( std::move(newRepoStates) );
2136  serviceModified = true;
2137  }
2138 
2140  // save service if modified: (unless a plugin service)
2141  if ( serviceModified && service.type() != ServiceType::PLUGIN )
2142  {
2143  // write out modified service file.
2144  modifyService( service.alias(), service );
2145  }
2146 
2147  if ( uglyHack.first )
2148  {
2149  throw( uglyHack.second ); // intentionally not ZYPP_THROW
2150  }
2151  }
2152 
2154 
2155  void RepoManager::Impl::modifyService( const std::string & oldAlias, const ServiceInfo & newService )
2156  {
2157  MIL << "Going to modify service " << oldAlias << endl;
2158 
2159  // we need a writable copy to link it to the file where
2160  // it is saved if we modify it
2161  ServiceInfo service(newService);
2162 
2163  if ( service.type() == ServiceType::PLUGIN )
2164  {
2166  }
2167 
2168  const ServiceInfo & oldService = getService(oldAlias);
2169 
2170  Pathname location = oldService.filepath();
2171  if( location.empty() )
2172  {
2173  ZYPP_THROW(ServiceException( oldService, _("Can't figure out where the service is stored.") ));
2174  }
2175 
2176  // remember: there may multiple services being defined in one file:
2177  ServiceSet tmpSet;
2178  parser::ServiceFileReader( location, ServiceCollector(tmpSet) );
2179 
2180  filesystem::assert_dir(location.dirname());
2181  std::ofstream file(location.c_str());
2182  for_(it, tmpSet.begin(), tmpSet.end())
2183  {
2184  if( *it != oldAlias )
2185  it->dumpAsIniOn(file);
2186  }
2187  service.dumpAsIniOn(file);
2188  file.close();
2189  service.setFilepath(location);
2190 
2191  _services.erase(oldAlias);
2192  _services.insert(service);
2193 
2194  // changed properties affecting also repositories
2195  if ( oldAlias != service.alias() // changed alias
2196  || oldService.enabled() != service.enabled() ) // changed enabled status
2197  {
2198  std::vector<RepoInfo> toModify;
2199  getRepositoriesInService(oldAlias, std::back_inserter(toModify));
2200  for_( it, toModify.begin(), toModify.end() )
2201  {
2202  if ( oldService.enabled() != service.enabled() )
2203  {
2204  if ( service.enabled() )
2205  {
2206  // reset to last refreshs state
2207  const auto & last = service.repoStates().find( it->alias() );
2208  if ( last != service.repoStates().end() )
2209  it->setEnabled( last->second.enabled );
2210  }
2211  else
2212  it->setEnabled( false );
2213  }
2214 
2215  if ( oldAlias != service.alias() )
2216  it->setService(service.alias());
2217 
2218  modifyRepository(it->alias(), *it);
2219  }
2220  }
2221 
2223  }
2224 
2226 
2228  {
2229  try
2230  {
2231  MediaSetAccess access(url);
2232  if ( access.doesFileExist("/repo/repoindex.xml") )
2233  return repo::ServiceType::RIS;
2234  }
2235  catch ( const media::MediaException &e )
2236  {
2237  ZYPP_CAUGHT(e);
2238  // TranslatorExplanation '%s' is an URL
2239  RepoException enew(str::form( _("Error trying to read from '%s'"), url.asString().c_str() ));
2240  enew.remember(e);
2241  ZYPP_THROW(enew);
2242  }
2243  catch ( const Exception &e )
2244  {
2245  ZYPP_CAUGHT(e);
2246  // TranslatorExplanation '%s' is an URL
2247  Exception enew(str::form( _("Unknown error reading from '%s'"), url.asString().c_str() ));
2248  enew.remember(e);
2249  ZYPP_THROW(enew);
2250  }
2251 
2252  return repo::ServiceType::NONE;
2253  }
2254 
2256  //
2257  // CLASS NAME : RepoManager
2258  //
2260 
2262  : _pimpl( new Impl(opt) )
2263  {}
2264 
2266  {}
2267 
2269  { return _pimpl->repoEmpty(); }
2270 
2272  { return _pimpl->repoSize(); }
2273 
2275  { return _pimpl->repoBegin(); }
2276 
2278  { return _pimpl->repoEnd(); }
2279 
2280  RepoInfo RepoManager::getRepo( const std::string & alias ) const
2281  { return _pimpl->getRepo( alias ); }
2282 
2283  bool RepoManager::hasRepo( const std::string & alias ) const
2284  { return _pimpl->hasRepo( alias ); }
2285 
2286  std::string RepoManager::makeStupidAlias( const Url & url_r )
2287  {
2288  std::string ret( url_r.getScheme() );
2289  if ( ret.empty() )
2290  ret = "repo-";
2291  else
2292  ret += "-";
2293 
2294  std::string host( url_r.getHost() );
2295  if ( ! host.empty() )
2296  {
2297  ret += host;
2298  ret += "-";
2299  }
2300 
2301  static Date::ValueType serial = Date::now();
2302  ret += Digest::digest( Digest::sha1(), str::hexstring( ++serial ) +url_r.asCompleteString() ).substr(0,8);
2303  return ret;
2304  }
2305 
2307  { return _pimpl->metadataStatus( info ); }
2308 
2310  { return _pimpl->checkIfToRefreshMetadata( info, url, policy ); }
2311 
2312  Pathname RepoManager::metadataPath( const RepoInfo &info ) const
2313  { return _pimpl->metadataPath( info ); }
2314 
2315  Pathname RepoManager::packagesPath( const RepoInfo &info ) const
2316  { return _pimpl->packagesPath( info ); }
2317 
2319  { return _pimpl->refreshMetadata( info, policy, progressrcv ); }
2320 
2321  void RepoManager::cleanMetadata( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv )
2322  { return _pimpl->cleanMetadata( info, progressrcv ); }
2323 
2324  void RepoManager::cleanPackages( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv )
2325  { return _pimpl->cleanPackages( info, progressrcv ); }
2326 
2328  { return _pimpl->cacheStatus( info ); }
2329 
2330  void RepoManager::buildCache( const RepoInfo &info, CacheBuildPolicy policy, const ProgressData::ReceiverFnc & progressrcv )
2331  { return _pimpl->buildCache( info, policy, progressrcv ); }
2332 
2333  void RepoManager::cleanCache( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv )
2334  { return _pimpl->cleanCache( info, progressrcv ); }
2335 
2336  bool RepoManager::isCached( const RepoInfo &info ) const
2337  { return _pimpl->isCached( info ); }
2338 
2339  void RepoManager::loadFromCache( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv )
2340  { return _pimpl->loadFromCache( info, progressrcv ); }
2341 
2343  { return _pimpl->cleanCacheDirGarbage( progressrcv ); }
2344 
2345  repo::RepoType RepoManager::probe( const Url & url, const Pathname & path ) const
2346  { return _pimpl->probe( url, path ); }
2347 
2349  { return _pimpl->probe( url ); }
2350 
2351  void RepoManager::addRepository( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv )
2352  { return _pimpl->addRepository( info, progressrcv ); }
2353 
2354  void RepoManager::addRepositories( const Url &url, const ProgressData::ReceiverFnc & progressrcv )
2355  { return _pimpl->addRepositories( url, progressrcv ); }
2356 
2357  void RepoManager::removeRepository( const RepoInfo & info, const ProgressData::ReceiverFnc & progressrcv )
2358  { return _pimpl->removeRepository( info, progressrcv ); }
2359 
2360  void RepoManager::modifyRepository( const std::string &alias, const RepoInfo & newinfo, const ProgressData::ReceiverFnc & progressrcv )
2361  { return _pimpl->modifyRepository( alias, newinfo, progressrcv ); }
2362 
2363  RepoInfo RepoManager::getRepositoryInfo( const std::string &alias, const ProgressData::ReceiverFnc & progressrcv )
2364  { return _pimpl->getRepositoryInfo( alias, progressrcv ); }
2365 
2366  RepoInfo RepoManager::getRepositoryInfo( const Url & url, const url::ViewOption & urlview, const ProgressData::ReceiverFnc & progressrcv )
2367  { return _pimpl->getRepositoryInfo( url, urlview, progressrcv ); }
2368 
2370  { return _pimpl->serviceEmpty(); }
2371 
2373  { return _pimpl->serviceSize(); }
2374 
2376  { return _pimpl->serviceBegin(); }
2377 
2379  { return _pimpl->serviceEnd(); }
2380 
2381  ServiceInfo RepoManager::getService( const std::string & alias ) const
2382  { return _pimpl->getService( alias ); }
2383 
2384  bool RepoManager::hasService( const std::string & alias ) const
2385  { return _pimpl->hasService( alias ); }
2386 
2388  { return _pimpl->probeService( url ); }
2389 
2390  void RepoManager::addService( const std::string & alias, const Url& url )
2391  { return _pimpl->addService( alias, url ); }
2392 
2393  void RepoManager::addService( const ServiceInfo & service )
2394  { return _pimpl->addService( service ); }
2395 
2396  void RepoManager::removeService( const std::string & alias )
2397  { return _pimpl->removeService( alias ); }
2398 
2399  void RepoManager::removeService( const ServiceInfo & service )
2400  { return _pimpl->removeService( service ); }
2401 
2403  { return _pimpl->refreshServices( options_r ); }
2404 
2405  void RepoManager::refreshService( const std::string & alias, const RefreshServiceOptions & options_r )
2406  { return _pimpl->refreshService( alias, options_r ); }
2407 
2408  void RepoManager::refreshService( const ServiceInfo & service, const RefreshServiceOptions & options_r )
2409  { return _pimpl->refreshService( service, options_r ); }
2410 
2411  void RepoManager::modifyService( const std::string & oldAlias, const ServiceInfo & service )
2412  { return _pimpl->modifyService( oldAlias, service ); }
2413 
2415 
2416  std::ostream & operator<<( std::ostream & str, const RepoManager & obj )
2417  { return str << *obj._pimpl; }
2418 
2420 } // namespace zypp
void saveToCookieFile(const Pathname &path_r) const
Save the status information to a cookie file.
Definition: RepoStatus.cc:126
Pathname packagesPath(const RepoInfo &info) const
Definition: RepoManager.cc:463
RepoManager(const RepoManagerOptions &options=RepoManagerOptions())
static const ValueType day
Definition: Date.h:43
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
Definition: PathInfo.cc:324
void removeService(const std::string &alias)
Removes service specified by its name.
thrown when it was impossible to match a repository
Thrown when the repo alias is found to be invalid.
Interface to gettext.
RepoManagerOptions(const Pathname &root_r=Pathname())
Default ctor following ZConfig global settings.
Definition: RepoManager.cc:386
#define MIL
Definition: Logger.h:47
bool hasService(const std::string &alias) const
Definition: RepoManager.cc:509
std::string alias() const
unique identifier for this source.
static const std::string & sha1()
sha1
Definition: Digest.cc:46
int exchange(const Pathname &lpath, const Pathname &rpath)
Exchanges two files or directories.
Definition: PathInfo.cc:688
RepoStatus status(MediaSetAccess &media)
Status of the remote repository.
Definition: Downloader.cc:42
void setCacheStatus(const RepoInfo &info, const RepoStatus &status)
Definition: RepoManager.cc:548
std::string generateFilename(const ServiceInfo &info) const
Definition: RepoManager.cc:545
thrown when it was impossible to determine this repo type.
std::string digest()
get hex string representation of the digest
Definition: Digest.cc:174
Retrieval of repository list for a service.
Definition: ServiceRepos.h:26
virtual std::ostream & dumpAsIniOn(std::ostream &str) const
Write this RepoInfo object into str in a .repo file format.
Definition: RepoInfo.cc:488
void refreshServices(const RefreshServiceOptions &options_r)
bool serviceEmpty() const
Gets true if no service is in RepoManager (so no one in specified location)
void modifyService(const std::string &oldAlias, const ServiceInfo &service)
Modifies service file (rewrites it with new values) and underlying repositories if needed...
Read service data from a .service file.
void sendTo(const ReceiverFnc &fnc_r)
Set ReceiverFnc.
Definition: ProgressData.h:226
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:320
Date timestamp() const
The time the data were changed the last time.
Definition: RepoStatus.cc:139
ServiceConstIterator serviceBegin() const
Definition: RepoManager.cc:506
static ZConfig & instance()
Singleton ctor.
Definition: ZConfig.cc:655
Pathname path() const
Definition: TmpPath.cc:146
static TmpDir makeSibling(const Pathname &sibling_r)
Provide a new empty temporary directory as sibling.
Definition: TmpPath.cc:287
#define OPT_PROGRESS
Definition: RepoManager.cc:58
void refreshService(const std::string &alias, const RefreshServiceOptions &options_r)
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: RepoManager.h:697
void cleanCacheDirGarbage(const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Remove any subdirectories of cache directories which no longer belong to any of known repositories...
RepoConstIterator repoBegin() const
Definition: RepoManager.cc:447
Pathname filepath() const
File where this repo was read from.
void resetDispose()
Set no dispose function.
Definition: AutoDispose.h:162
bool isCached(const RepoInfo &info) const
Definition: RepoManager.cc:484
void refreshServices(const RefreshServiceOptions &options_r=RefreshServiceOptions())
Refreshes all enabled services.
RepoStatus metadataStatus(const RepoInfo &info) const
Status of local metadata.
std::string getPathName(EEncoding eflag=zypp::url::E_DECODED) const
Returns the path name from the URL.
Definition: Url.cc:598
#define _PL(MSG1, MSG2, N)
Return translated text (plural form).
Definition: Gettext.h:24
bool empty() const
Test for an empty path.
Definition: Pathname.h:113
std::string getHost(EEncoding eflag=zypp::url::E_DECODED) const
Returns the hostname or IP from the URL authority.
Definition: Url.cc:582
RefreshCheckStatus
Possibly return state of checkIfRefreshMEtadata function.
Definition: RepoManager.h:198
Pathname metadataPath(const RepoInfo &info) const
Path where the metadata is downloaded and kept.
const std::string & command() const
The command we're executing.
urls_const_iterator baseUrlsBegin() const
iterator that points at begin of repository urls
Definition: RepoInfo.cc:307
RepoSet::size_type RepoSizeType
Definition: RepoManager.h:125
bool empty() const
Whether the status is empty (default constucted)
Definition: RepoStatus.cc:136
void loadFromCache(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Load resolvables into the pool.
ServiceConstIterator serviceEnd() const
Iterator to place behind last service in internal storage.
repo::RepoType probe(const Url &url, const Pathname &path) const
Probe repo metadata type.
std::string generateFilename(const RepoInfo &info) const
Definition: RepoManager.cc:542
RepoConstIterator repoBegin() const
void refreshMetadata(const RepoInfo &info, RawMetadataRefreshPolicy policy=RefreshIfNeeded, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Refresh local raw cache.
Pathname packagesPath(const RepoInfo &info) const
Path where the rpm packages are downloaded and kept.
void addService(const std::string &alias, const Url &url)
Definition: RepoManager.cc:520
void touchIndexFile(const RepoInfo &info)
Definition: RepoManager.cc:793
void setAlias(const std::string &alias)
set the repository alias
Definition: RepoInfoBase.cc:94
String related utilities and Regular expression matching.
void addRepoToEnable(const std::string &alias_r)
Add alias_r to the set of ReposToEnable.
Definition: ServiceInfo.cc:125
void removeRepository(const RepoInfo &info, OPT_PROGRESS)
RefreshServiceFlags RefreshServiceOptions
Options tuning RefreshService.
Definition: RepoManager.h:153
void modifyService(const std::string &oldAlias, const ServiceInfo &newService)
bool toMax()
Set counter value to current max value (unless no range).
Definition: ProgressData.h:273
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:246
void refreshService(const std::string &alias, const RefreshServiceOptions &options_r=RefreshServiceOptions())
Refresh specific service.
bool doesFileExist(const Pathname &file, unsigned media_nr=1)
Checks if a file exists on the specified media, with user callbacks.
void setFilepath(const Pathname &filename)
set the path to the .repo file
Definition: Arch.h:330
What is known about a repository.
Definition: RepoInfo.h:66
Service plugin has trouble providing the metadata but this should not be treated as error...
void removeRepository(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Remove the best matching repository from known repos list.
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:27
const RepoStates & repoStates() const
Access the remembered repository states.
Definition: ServiceInfo.cc:165
void setBaseUrl(const Url &url)
Clears current base URL list and adds url.
Definition: RepoInfo.cc:234
bool enabled() const
If enabled is false, then this repository must be ignored as if does not exists, except when checking...
std::string targetDistro
Definition: RepoManager.cc:192
void reposErase(const std::string &alias_r)
Remove a Repository named alias_r.
Definition: Pool.h:99
Service already exists and some unique attribute can't be duplicated.
void refreshService(const ServiceInfo &service, const RefreshServiceOptions &options_r)
Definition: RepoManager.cc:530
bool repo_add_probe() const
Whether repository urls should be probed.
Definition: ZConfig.cc:821
urls_const_iterator baseUrlsEnd() const
iterator that points at end of repository urls
Definition: RepoInfo.cc:314
std::string targetDistribution() const
This is register.target attribute of the installed base product.
Definition: Target.cc:114
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition: String.cc:34
static RepoStatus fromCookieFile(const Pathname &path)
Reads the status from a cookie file.
Definition: RepoStatus.cc:108
Service without alias was used in an operation.
RepoStatus metadataStatus(const RepoInfo &info) const
Definition: RepoManager.cc:758
RepoSet::const_iterator RepoConstIterator
Definition: RepoManager.h:124
function< bool(const ProgressData &)> ReceiverFnc
Most simple version of progress reporting The percentage in most cases.
Definition: ProgressData.h:139
Url::asString() view options.
Definition: UrlBase.h:39
void cleanMetadata(const RepoInfo &info, OPT_PROGRESS)
#define ERR
Definition: Logger.h:49
unsigned int MediaAccessId
Media manager access Id type.
Definition: MediaSource.h:29
void modifyRepository(const std::string &alias, const RepoInfo &newinfo, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Modify repository attributes.
std::vector< std::string > Arguments
RepoManagerOptions _options
Definition: RepoManager.cc:571
std::string asString() const
Returns a default string representation of the Url object.
Definition: Url.cc:491
ServiceInfo getService(const std::string &alias) const
Definition: RepoManager.cc:512
RepoSizeType repoSize() const
Repo manager settings.
Definition: RepoManager.h:53
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
Definition: TriBool.h:39
void remember(const Exception &old_r)
Store an other Exception as history.
Definition: Exception.cc:89
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:304
void removeService(const ServiceInfo &service)
Definition: RepoManager.cc:524
transform_iterator< repo::RepoVariablesUrlReplacer, url_set::const_iterator > urls_const_iterator
Definition: RepoInfo.h:96
Progress callback from another progress.
Definition: ProgressData.h:390
std::map< std::string, RepoState > RepoStates
Definition: ServiceInfo.h:165
std::string label() const
Label for use in messages for the user interface.
void addRepository(const RepoInfo &info, OPT_PROGRESS)
static const ServiceType RIS
Repository Index Service (RIS) (formerly known as 'Novell Update' (NU) service)
Definition: ServiceType.h:32
RepoManager implementation.
Definition: RepoManager.cc:434
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
Definition: Exception.h:328
void setPathName(const std::string &path, EEncoding eflag=zypp::url::E_DECODED)
Set the path name.
Definition: Url.cc:758
std::set< RepoInfo > RepoSet
RepoInfo typedefs.
Definition: RepoManager.h:123
bool toMin()
Set counter value to current min value.
Definition: ProgressData.h:269
RepoInfo getRepositoryInfo(const std::string &alias, OPT_PROGRESS)
Downloader for SUSETags (YaST2) repositories Encapsulates all the knowledge of which files have to be...
Definition: Downloader.h:34
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
static Pool instance()
Singleton ctor.
Definition: Pool.h:52
bool serviceEmpty() const
Definition: RepoManager.cc:504
static RepoManagerOptions makeTestSetup(const Pathname &root_r)
Test setup adjusting all paths to be located below one root_r directory.
Definition: RepoManager.cc:400
Pathname rootDir
remembers root_r value for later use
Definition: RepoManager.h:100
void removeRepository(const RepoInfo &repo)
Log recently removed repository.
Definition: HistoryLog.cc:257
Provide a new empty temporary directory and recursively delete it when no longer needed.
Definition: TmpPath.h:170
format formatNAC(const std::string &string_r)
A formater with (N)o (A)rgument (C)heck.
Definition: String.h:36
void clearReposToDisable()
Clear the set of ReposToDisable.
Definition: ServiceInfo.cc:162
Lightweight repository attribute value lookup.
Definition: LookupAttr.h:260
std::string asCompleteString() const
Returns a complete string representation of the Url object.
Definition: Url.cc:499
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:120
RepoConstIterator repoEnd() const
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
void cleanCacheDirGarbage(OPT_PROGRESS)
int unlink(const Pathname &path)
Like 'unlink'.
Definition: PathInfo.cc:660
thrown when it was impossible to determine one url for this repo.
Definition: RepoException.h:78
Just inherits Exception to separate media exceptions.
static const ServiceType NONE
No service set.
Definition: ServiceType.h:34
static const SolvAttr repositoryToolVersion
Definition: SolvAttr.h:172
Service type enumeration.
Definition: ServiceType.h:26
void modifyRepository(const std::string &alias, const RepoInfo &newinfo_r, OPT_PROGRESS)
ServiceSet::const_iterator ServiceConstIterator
Definition: RepoManager.h:119
void setRepoStates(RepoStates newStates_r)
Remember a new set of repository states.
Definition: ServiceInfo.cc:168
std::ostream & operator<<(std::ostream &str, const DeltaCandidates &obj)
repo::ServiceType probeService(const Url &url) const
Probe the type or the service.
int recursive_rmdir(const Pathname &path)
Like 'rm -r DIR'.
Definition: PathInfo.cc:417
#define WAR
Definition: Logger.h:48
#define OUTS(X)
void setMetadataPath(const Pathname &path)
set the path where the local metadata is stored
Definition: RepoInfo.cc:250
void setType(const repo::RepoType &t)
set the repository type
Definition: RepoInfo.cc:243
Maintain [min,max] and counter (value) for progress counting.
Definition: ProgressData.h:130
RepoInfoList repos
Definition: RepoManager.cc:191
RepoStatus cacheStatus(const RepoInfo &info) const
Definition: RepoManager.cc:487
static bool error(const MessageString &msg_r, const UserData &userData_r=UserData())
send error text
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:623
void addRepository(const RepoInfo &repo)
Log a newly added repository.
Definition: HistoryLog.cc:245
zypp::Url url
Definition: MediaCurl.cc:193
RepoInfo getRepo(const std::string &alias) const
Definition: RepoManager.cc:453
Writing the zypp history fileReference counted signleton for writhing the zypp history file...
Definition: HistoryLog.h:55
static bool schemeIsVolatile(const std::string &scheme_r)
cd dvd
Definition: Url.cc:468
void addRepository(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Adds a repository to the list of known repositories.
RepoInfo getRepositoryInfo(const std::string &alias, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Find a matching repository info.
#define _(MSG)
Return translated text.
Definition: Gettext.h:21
static const ServiceType PLUGIN
Plugin services are scripts installed on your system that provide the package manager with repositori...
Definition: ServiceType.h:43
Base Exception for service handling.
std::string receiveLine()
Read one line from the input stream.
void delRepoToEnable(const std::string &alias_r)
Remove alias_r from the set of ReposToEnable.
Definition: ServiceInfo.cc:131
static std::string makeStupidAlias(const Url &url_r=Url())
Some stupid string but suitable as alias for your url if nothing better is available.
RefreshCheckStatus checkIfToRefreshMetadata(const RepoInfo &info, const Url &url, RawMetadataRefreshPolicy policy=RefreshIfNeeded)
Checks whether to refresh metadata for specified repository and url.
void cleanCache(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
clean local cache
void cleanCache(const RepoInfo &info, OPT_PROGRESS)
std::string numstring(char n, int w=0)
Definition: String.h:266
ServiceSet::size_type ServiceSizeType
Definition: RepoManager.h:120
Class for handling media authentication data.
Definition: MediaUserAuth.h:30
bool reposToDisableEmpty() const
Definition: ServiceInfo.cc:138
static const RepoType NONE
Definition: RepoType.h:32
int touch(const Pathname &path)
Change file's modification and access times.
Definition: PathInfo.cc:1134
ServiceInfo getService(const std::string &alias) const
Finds ServiceInfo by alias or return ServiceInfo::noService.
void getRepositoriesInService(const std::string &alias, OutputIterator out) const
Definition: RepoManager.cc:558
void setPackagesPath(const Pathname &path)
set the path where the local packages are stored
Definition: RepoInfo.cc:253
bool repoEmpty() const
Definition: RepoManager.cc:445
std::ostream & copy(std::istream &from_r, std::ostream &to_r)
Copy istream to ostream.
Definition: IOStream.h:50
int close()
Wait for the progamm to complete.
bool hasRepo(const std::string &alias) const
Return whether there is a known repository for alias.
static const RepoType RPMMD
Definition: RepoType.h:29
creates and provides information about known sources.
Definition: RepoManager.h:109
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition: Exception.h:324
RepoStatus cacheStatus(const RepoInfo &info) const
Status of metadata cache.
repo::RepoType type() const
Type of repository,.
Definition: RepoInfo.cc:277
int readdir(std::list< std::string > &retlist_r, const Pathname &path_r, bool dots_r)
Return content of directory via retlist.
Definition: PathInfo.cc:599
RepoSizeType repoSize() const
Definition: RepoManager.cc:446
void addService(const ServiceInfo &service)
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:365
RepoInfo getRepo(const std::string &alias) const
Find RepoInfo by alias or return RepoInfo::noRepo.
static const RepoType YAST2
Definition: RepoType.h:30
ServiceSet & _services
Definition: RepoManager.cc:358
thrown when it was impossible to determine an alias for this repo.
Definition: RepoException.h:91
RepoStatus status(MediaSetAccess &media)
Status of the remote repository.
Definition: Downloader.cc:36
void buildCache(const RepoInfo &info, CacheBuildPolicy policy=BuildIfNeeded, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Refresh local cache.
Base class for Exception.
Definition: Exception.h:143
void addRepositories(const Url &url, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Adds repositores from a repo file to the list of known repositories.
std::set< ServiceInfo > ServiceSet
ServiceInfo typedefs.
Definition: RepoManager.h:115
Type toEnum() const
Definition: RepoType.h:48
Exception for repository handling.
Definition: RepoException.h:37
void saveService(ServiceInfo &service) const
Definition: RepoManager.cc:589
Impl(const RepoManagerOptions &opt)
Definition: RepoManager.cc:437
media::MediaAccessId _mid
Definition: RepoManager.cc:99
static Date now()
Return the current time.
Definition: Date.h:77
repo::RepoType probe(const Url &url, const Pathname &path=Pathname()) const
callback::SendReport< DownloadProgressReport > * report
Definition: MediaCurl.cc:178
value_type val() const
Definition: ProgressData.h:295
ServiceConstIterator serviceEnd() const
Definition: RepoManager.cc:507
Functor thats filter RepoInfo by service which it belongs to.
Definition: RepoManager.h:640
bool isCached(const RepoInfo &info) const
Whether a repository exists in cache.
bool hasRepo(const std::string &alias) const
Definition: RepoManager.cc:450
Reference counted access to a _Tp object calling a custom Dispose function when the last AutoDispose ...
Definition: AutoDispose.h:92
The repository cache is not built yet so you can't create the repostories from the cache...
Definition: RepoException.h:65
time_t ValueType
Definition: Date.h:38
void eraseFromPool()
Remove this Repository from it's Pool.
Definition: Repository.cc:297
Pathname repoPackagesCachePath
Definition: RepoManager.h:82
std::string asUserHistory() const
A single (multiline) string composed of asUserString and historyAsString.
Definition: Exception.cc:75
static const ServiceInfo noService
Represents an empty service.
Definition: ServiceInfo.h:58
RepoConstIterator repoEnd() const
Definition: RepoManager.cc:448
bool hasService(const std::string &alias) const
Return whether there is a known service for alias.
void removeService(const std::string &alias)
void buildCache(const RepoInfo &info, CacheBuildPolicy policy, OPT_PROGRESS)
bool repoToDisableFind(const std::string &alias_r) const
Whether alias_r is mentioned in ReposToDisable.
Definition: ServiceInfo.cc:150
static const RepoInfo noRepo
Represents no Repository (one with an empty alias).
Definition: RepoInfo.h:75
bool regex_match(const std::string &s, smatch &matches, const regex &regex)
regex ZYPP_STR_REGEX regex ZYPP_STR_REGEX
Definition: Regex.h:70
Thrown when the repo alias is found to be invalid.
ServiceSizeType serviceSize() const
Gets count of service in RepoManager (in specified location)
static const RepoType RPMPLAINDIR
Definition: RepoType.h:31
static const std::string & systemRepoAlias()
Reserved system repository alias .
Definition: Repository.cc:37
bool repoToEnableFind(const std::string &alias_r) const
Whether alias_r is mentioned in ReposToEnable.
Definition: ServiceInfo.cc:122
ServiceSizeType serviceSize() const
Definition: RepoManager.cc:505
Track changing files or directories.
Definition: RepoStatus.h:38
void cleanPackages(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Clean local package cache.
unsigned repo_refresh_delay() const
Amount of time in minutes that must pass before another refresh.
Definition: ZConfig.cc:824
Repository already exists and some unique attribute can't be duplicated.
ServiceConstIterator serviceBegin() const
Iterator to first service in internal storage.
bool set(value_type val_r)
Set new counter value.
Definition: ProgressData.h:246
std::string getScheme() const
Returns the scheme name of the URL.
Definition: Url.cc:527
Url url() const
Gets url to service.
Definition: ServiceInfo.cc:99
static bool schemeIsDownloading(const std::string &scheme_r)
http https ftp sftp tftp
Definition: Url.cc:474
void modifyRepository(const RepoInfo &oldrepo, const RepoInfo &newrepo)
Log certain modifications to a repository.
Definition: HistoryLog.cc:268
std::ostream & operator<<(std::ostream &str, const RepoManager::Impl &obj)
Definition: RepoManager.cc:584
Impl * clone() const
clone for RWCOW_pointer
Definition: RepoManager.cc:578
urls_size_type baseUrlsSize() const
number of repository urls
Definition: RepoInfo.cc:321
static bool warning(const MessageString &msg_r, const UserData &userData_r=UserData())
send warning text
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:145
std::string asString() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: LookupAttr.cc:613
void name(const std::string &name_r)
Set counter name.
Definition: ProgressData.h:222
Downloader for YUM (rpm-nmd) repositories Encapsulates all the knowledge of which files have to be do...
Definition: Downloader.h:41
Pathname metadataPath(const RepoInfo &info) const
Definition: RepoManager.cc:460
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
void setProbedType(const repo::ServiceType &t) const
Definition: ServiceInfo.cc:107
void cleanPackages(const RepoInfo &info, OPT_PROGRESS)
Pathname provideFile(const OnMediaLocation &resource, ProvideFileOptions options=PROVIDE_DEFAULT, const Pathname &deltafile=Pathname())
Provides a file from a media location.
bool repoEmpty() const
void loadFromCache(const RepoInfo &info, OPT_PROGRESS)
std::string hexstring(char n, int w=4)
Definition: String.h:301
void addService(const std::string &alias, const Url &url)
Adds new service by it's alias and url.
void refreshMetadata(const RepoInfo &info, RawMetadataRefreshPolicy policy, OPT_PROGRESS)
Definition: RepoManager.cc:956
Service has no or invalid url defined.
static bool schemeIsLocal(const std::string &scheme_r)
hd cd dvd dir file iso
Definition: Url.cc:456
Url manipulation class.
Definition: Url.h:87
void addRepositories(const Url &url, OPT_PROGRESS)
Media access layer responsible for handling files distributed on a set of media with media change and...
void cleanMetadata(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Clean local metadata.
void saveInUser(const AuthData &cred)
Saves given cred to user's credentials file.
Pathname path() const
Repository path.
Definition: RepoInfo.cc:298
#define DBG
Definition: Logger.h:46
bool hasCredentialsInAuthority() const
Returns true if username and password are encoded in the authority component.
Definition: Url.h:371
virtual std::ostream & dumpAsIniOn(std::ostream &str) const
Writes ServiceInfo to stream in ".service" format.
Definition: ServiceInfo.cc:179
repo::ServiceType type() const
Definition: ServiceInfo.cc:102
iterator begin() const
Iterator to the begin of query results.
Definition: LookupAttr.cc:236
Repository type enumeration.
Definition: RepoType.h:27
RefreshCheckStatus checkIfToRefreshMetadata(const RepoInfo &info, const Url &url, RawMetadataRefreshPolicy policy)
Definition: RepoManager.cc:830
repo::ServiceType probeService(const Url &url) const