libzypp  17.31.31
RepoManager.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_REPOMANAGER_H
13 #define ZYPP_REPOMANAGER_H
14 
15 #include <iosfwd>
16 #include <list>
17 
18 #include <zypp/base/PtrTypes.h>
19 #include <zypp/base/Iterator.h>
20 #include <zypp/base/Flags.h>
21 
22 #include <zypp/Pathname.h>
23 #include <zypp/ZConfig.h>
24 #include <zypp/RepoInfo.h>
26 #include <zypp/repo/RepoType.h>
27 #include <zypp/repo/ServiceType.h>
28 #include <zypp/ServiceInfo.h>
29 #include <zypp/RepoStatus.h>
30 #include <zypp-core/ui/ProgressData>
31 
33 namespace zypp
34 {
35 
49  std::list<RepoInfo> readRepoFile(const Url & repo_file);
50 
56  {
68  RepoManagerOptions( const Pathname & root_r = Pathname() );
69 
79  static RepoManagerOptions makeTestSetup( const Pathname & root_r );
80 
88  bool probe;
95  std::string servicesTargetDistro;
96 
99  };
100 
101 
102 
107  class RepoManager
108  {
109  friend std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
110 
111  public:
113  struct Impl;
114 
116  typedef std::set<ServiceInfo> ServiceSet;
117  typedef ServiceSet::const_iterator ServiceConstIterator;
119 
121  typedef std::set<RepoInfo> RepoSet;
122  typedef RepoSet::const_iterator RepoConstIterator;
124 
125  public:
126  RepoManager( const RepoManagerOptions &options = RepoManagerOptions() );
128  ~RepoManager();
129 
131  {
135  };
136 
138  {
141  };
142 
145  {
148  };
149  ZYPP_DECLARE_FLAGS(RefreshServiceFlags,RefreshServiceBit);
150 
152  typedef RefreshServiceFlags RefreshServiceOptions;
153 
154 
162  bool repoEmpty() const;
163  RepoSizeType repoSize() const;
165  RepoConstIterator repoEnd() const;
167 
169  std::list<RepoInfo> knownRepositories() const
170  { return std::list<RepoInfo>(repoBegin(),repoEnd()); }
171 
173  RepoInfo getRepo( const std::string & alias ) const;
175  RepoInfo getRepo( const RepoInfo & info_r ) const
176  { return getRepo( info_r.alias() ); }
177 
179  bool hasRepo( const std::string & alias ) const;
181  bool hasRepo( const RepoInfo & info_r ) const
182  { return hasRepo( info_r.alias() ); }
183 
187  static std::string makeStupidAlias( const Url & url_r = Url() );
189 
193  RepoStatus metadataStatus( const RepoInfo &info ) const;
194 
202  };
203 
259  const Url &url,
261 
272  Pathname metadataPath( const RepoInfo &info ) const;
273 
274 
285  Pathname packagesPath( const RepoInfo &info ) const;
286 
287 
302  void refreshMetadata( const RepoInfo &info,
304  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
305 
314  void cleanMetadata( const RepoInfo &info,
315  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
316 
325  void cleanPackages( const RepoInfo &info,
326  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
327 
331  RepoStatus cacheStatus( const RepoInfo &info ) const;
332 
351  void buildCache( const RepoInfo &info,
353  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
354 
367  void cleanCache( const RepoInfo &info,
368  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
369 
375  bool isCached( const RepoInfo &info ) const;
376 
377 
387  void loadFromCache( const RepoInfo &info,
388  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
389 
398 
406  repo::RepoType probe( const Url & url, const Pathname & path ) const;
410  repo::RepoType probe( const Url & url ) const;
411 
412 
427  void addRepository( const RepoInfo &info,
428  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
429 
442  void addRepositories( const Url &url,
443  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
449  void removeRepository( const RepoInfo & info,
450  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
451 
461  void modifyRepository( const std::string &alias,
462  const RepoInfo & newinfo,
463  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
465  void modifyRepository( const RepoInfo & newinfo,
466  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() )
467  { modifyRepository( newinfo.alias(), newinfo, progressrcv ); }
468 
482  RepoInfo getRepositoryInfo( const std::string &alias,
483  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
484 
504  RepoInfo getRepositoryInfo( const Url & url,
505  const url::ViewOption & urlview = url::ViewOption::DEFAULTS,
506  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
507 
508 
521  bool serviceEmpty() const;
522 
529 
536 
542 
545 
547  std::list<ServiceInfo> knownServices() const
548  { return std::list<ServiceInfo>(serviceBegin(),serviceEnd()); }
549 
556  ServiceInfo getService( const std::string & alias ) const;
557 
559  bool hasService( const std::string & alias ) const;
561 
565  repo::ServiceType probeService( const Url &url ) const;
566 
575  void addService( const std::string & alias, const Url& url );
576 
584  void addService( const ServiceInfo & service );
585 
594  void removeService( const std::string & alias );
596  void removeService( const ServiceInfo & service );
597 
598 
604  void refreshServices( const RefreshServiceOptions & options_r = RefreshServiceOptions() );
605 
614  void refreshService( const std::string & alias, const RefreshServiceOptions & options_r = RefreshServiceOptions() );
616  void refreshService( const ServiceInfo & service, const RefreshServiceOptions & options_r = RefreshServiceOptions() );
617 
634  void modifyService( const std::string & oldAlias, const ServiceInfo & service );
636  void modifyService( const ServiceInfo & service )
637  { modifyService( service.alias(), service ); }
638 
643  void refreshGeoIp ( const RepoInfo::url_set &urls );
644 
645  private:
650  {
651  public:
652  MatchServiceAlias( const std::string & alias_ ) : alias(alias_) {}
653  bool operator()( const RepoInfo & info ) const
654  { return info.service() == alias; }
655  private:
656  std::string alias;
657  };
658 
659  public:
660 
693  template<typename OutputIterator>
694  void getRepositoriesInService( const std::string & alias,
695  OutputIterator out ) const
696  {
697  MatchServiceAlias filter(alias);
698 
699  std::copy( boost::make_filter_iterator( filter, repoBegin(), repoEnd() ),
700  boost::make_filter_iterator( filter, repoEnd(), repoEnd() ),
701  out);
702  }
703 
704  private:
707  };
708  ZYPP_DECLARE_OPERATORS_FOR_FLAGS(RepoManager::RefreshServiceFlags);
710 
712  std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
713 
716  { return makeIterable( repoBegin(), repoEnd() ); }
717 
720  { return makeIterable( serviceBegin(), serviceEnd() ); }
721 
723 } // namespace zypp
725 #endif // ZYPP2_REPOMANAGER_H
RefreshCheckStatus checkIfToRefreshMetadata(const RepoInfo &info, const Url &url, RawMetadataRefreshPolicy policy)
RefreshCheckStatus
Possibly return state of checkIfRefreshMEtadata function.
Definition: RepoManager.h:198
Service data.
Definition: ServiceInfo.h:36
RepoManagerOptions(const Pathname &root_r=Pathname())
Default ctor following ZConfig global settings.
Definition: RepoManager.cc:486
constexpr std::string_view Url("url")
void getRepositoriesInService(const std::string &alias, OutputIterator out) const
fill to output iterator repositories in service name.
Definition: RepoManager.h:694
refresh is delayed due to settings
Definition: RepoManager.h:201
bool hasRepo(const std::string &alias) const
Definition: RepoManager.cc:595
std::string service() const
Gets name of the service to which this repository belongs or empty string if it has been added manual...
Definition: RepoInfo.cc:725
repository not changed
Definition: RepoManager.h:200
void removeService(const std::string &alias)
ServiceInfo getService(const std::string &alias) const
Definition: RepoManager.cc:658
RepoSizeType repoSize() const
Definition: RepoManager.cc:591
void refreshServices(const RefreshServiceOptions &options_r)
Pathname metadataPath(const RepoInfo &info) const
Definition: RepoManager.cc:605
friend std::ostream & operator<<(std::ostream &str, const RepoManager &obj)
ZYPP_DECLARE_OPERATORS_FOR_FLAGS(DiskUsageCounter::MountPoint::HintFlags)
void modifyRepository(const RepoInfo &newinfo, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Definition: RepoManager.h:465
bool hasRepo(const RepoInfo &info_r) const
Definition: RepoManager.h:181
String related utilities and Regular expression matching.
RefreshServiceFlags RefreshServiceOptions
Options tuning RefreshService.
Definition: RepoManager.h:152
std::list< Url > url_set
Definition: RepoInfo.h:103
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition: SerialNumber.cc:52
What is known about a repository.
Definition: RepoInfo.h:71
ServiceSet::size_type ServiceSizeType
Definition: RepoManager.h:118
RepoInfo getRepositoryInfo(const std::string &alias, OPT_PROGRESS)
ZYPP_DECLARE_FLAGS(RefreshServiceFlags, RefreshServiceBit)
void addRepositories(const Url &url, OPT_PROGRESS)
RepoInfo getRepo(const std::string &alias) const
Definition: RepoManager.cc:598
void cleanPackages(const RepoInfo &info, OPT_PROGRESS, bool isAutoClean=false)
repo::ServiceType probeService(const Url &url) const
function< bool(const ProgressData &)> ReceiverFnc
Most simple version of progress reporting The percentage in most cases.
Definition: progressdata.h:140
void buildCache(const RepoInfo &info, CacheBuildPolicy policy, OPT_PROGRESS)
Url::asString() view options.
Definition: UrlBase.h:39
void modifyService(const std::string &oldAlias, const ServiceInfo &newService)
repo::RepoType probe(const Url &url, const Pathname &path=Pathname()) const
Repo manager settings.
Definition: RepoManager.h:55
void loadFromCache(const RepoInfo &info, OPT_PROGRESS)
std::set< ServiceInfo > ServiceSet
ServiceInfo typedefs.
Definition: RepoManager.h:113
RepoInfo getRepo(const RepoInfo &info_r) const
Definition: RepoManager.h:175
void addRepository(const RepoInfo &info, OPT_PROGRESS)
static RepoManagerOptions makeTestSetup(const Pathname &root_r)
Test setup adjusting all paths to be located below one root_r directory.
Definition: RepoManager.cc:500
Pathname rootDir
remembers root_r value for later use
Definition: RepoManager.h:98
std::string alias() const
unique identifier for this source.
bool serviceEmpty() const
Definition: RepoManager.cc:650
std::set< RepoInfo > RepoSet
RepoInfo typedefs.
Definition: RepoManager.h:121
MatchServiceAlias(const std::string &alias_)
Definition: RepoManager.h:652
Service type enumeration.
Definition: ServiceType.h:26
void cleanMetadata(const RepoInfo &info, OPT_PROGRESS)
bool repoEmpty() const
Definition: RepoManager.cc:590
const RepoSet & repos() const
Iterate the known repositories.
Definition: RepoManager.cc:718
bool isCached(const RepoInfo &info) const
Definition: RepoManager.cc:630
ServiceSet::const_iterator ServiceConstIterator
Definition: RepoManager.h:117
ServiceConstIterator serviceBegin() const
Definition: RepoManager.cc:652
RefreshServiceBit
Flags for tuning RefreshService.
Definition: RepoManager.h:144
SolvableIdType size_type
Definition: PoolMember.h:126
ServiceConstIterator serviceEnd() const
Definition: RepoManager.cc:653
std::ostream & copy(std::istream &from_r, std::ostream &to_r)
Copy istream to ostream.
Definition: IOStream.h:50
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: RepoManager.h:706
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:469
void refreshMetadata(const RepoInfo &info, RawMetadataRefreshPolicy policy, OPT_PROGRESS)
bool operator()(const RepoInfo &info) const
Definition: RepoManager.h:653
RepoSet::size_type RepoSizeType
Definition: RepoManager.h:123
std::list< RepoInfo > knownRepositories() const
List of known repositories.
Definition: RepoManager.h:169
RepoConstIterator repoBegin() const
Definition: RepoManager.cc:592
std::string servicesTargetDistro
Target distro ID to be used when refreshing repo index services.
Definition: RepoManager.h:95
static std::string makeStupidAlias(const Url &url_r=Url())
Some stupid string but suitable as alias for your url if nothing better is available.
Functor thats filter RepoInfo by service which it belongs to.
Definition: RepoManager.h:649
Pathname repoPackagesCachePath
Definition: RepoManager.h:84
void removeRepository(const RepoInfo &info, OPT_PROGRESS)
static const ViewOption DEFAULTS
Default combination of view options.
Definition: UrlBase.h:177
void modifyService(const ServiceInfo &service)
Definition: RepoManager.h:636
RepoStatus metadataStatus(const RepoInfo &info) const
Track changing files or directories.
Definition: RepoStatus.h:40
void modifyRepository(const std::string &alias, const RepoInfo &newinfo_r, OPT_PROGRESS)
ServiceSizeType serviceSize() const
Definition: RepoManager.cc:651
Force refresh even if TTL is not reached.
Definition: RepoManager.h:147
Iterable< ServiceConstIterator > services() const
Iterate the known services.
Definition: RepoManager.h:719
void refreshService(const std::string &alias, const RefreshServiceOptions &options_r)
void addService(const ServiceInfo &service)
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
RepoManager(const RepoManagerOptions &options=RepoManagerOptions())
RepoConstIterator repoEnd() const
Definition: RepoManager.cc:593
void refreshGeoIp(const RepoInfo::url_set &urls)
void cleanCacheDirGarbage(OPT_PROGRESS)
Url manipulation class.
Definition: Url.h:91
RepoStatus cacheStatus(const RepoInfo &info) const
Definition: RepoManager.cc:633
bool hasService(const std::string &alias) const
Definition: RepoManager.cc:655
void cleanCache(const RepoInfo &info, OPT_PROGRESS)
std::list< ServiceInfo > knownServices() const
List of known services.
Definition: RepoManager.h:547
RepoSet::const_iterator RepoConstIterator
Definition: RepoManager.h:122
Repository type enumeration.
Definition: RepoType.h:27
Force restoring repo enabled/disabled status.
Definition: RepoManager.h:146
Pathname packagesPath(const RepoInfo &info) const
Definition: RepoManager.cc:608