libzypp  17.31.0
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 
47  std::list<RepoInfo> readRepoFile(const Url & repo_file);
48 
54  {
66  RepoManagerOptions( const Pathname & root_r = Pathname() );
67 
77  static RepoManagerOptions makeTestSetup( const Pathname & root_r );
78 
86  bool probe;
93  std::string servicesTargetDistro;
94 
97  };
98 
99 
100 
105  class RepoManager
106  {
107  friend std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
108 
109  public:
111  struct Impl;
112 
114  typedef std::set<ServiceInfo> ServiceSet;
115  typedef ServiceSet::const_iterator ServiceConstIterator;
117 
119  typedef std::set<RepoInfo> RepoSet;
120  typedef RepoSet::const_iterator RepoConstIterator;
122 
123  public:
124  RepoManager( const RepoManagerOptions &options = RepoManagerOptions() );
126  ~RepoManager();
127 
129  {
133  };
134 
136  {
139  };
140 
143  {
146  };
147  ZYPP_DECLARE_FLAGS(RefreshServiceFlags,RefreshServiceBit);
148 
150  typedef RefreshServiceFlags RefreshServiceOptions;
151 
152 
160  bool repoEmpty() const;
161  RepoSizeType repoSize() const;
163  RepoConstIterator repoEnd() const;
165 
167  std::list<RepoInfo> knownRepositories() const
168  { return std::list<RepoInfo>(repoBegin(),repoEnd()); }
169 
171  RepoInfo getRepo( const std::string & alias ) const;
173  RepoInfo getRepo( const RepoInfo & info_r ) const
174  { return getRepo( info_r.alias() ); }
175 
177  bool hasRepo( const std::string & alias ) const;
179  bool hasRepo( const RepoInfo & info_r ) const
180  { return hasRepo( info_r.alias() ); }
181 
185  static std::string makeStupidAlias( const Url & url_r = Url() );
187 
191  RepoStatus metadataStatus( const RepoInfo &info ) const;
192 
200  };
201 
257  const Url &url,
259 
270  Pathname metadataPath( const RepoInfo &info ) const;
271 
272 
283  Pathname packagesPath( const RepoInfo &info ) const;
284 
285 
300  void refreshMetadata( const RepoInfo &info,
302  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
303 
312  void cleanMetadata( const RepoInfo &info,
313  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
314 
323  void cleanPackages( const RepoInfo &info,
324  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
325 
329  RepoStatus cacheStatus( const RepoInfo &info ) const;
330 
349  void buildCache( const RepoInfo &info,
351  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
352 
365  void cleanCache( const RepoInfo &info,
366  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
367 
373  bool isCached( const RepoInfo &info ) const;
374 
375 
385  void loadFromCache( const RepoInfo &info,
386  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
387 
396 
404  repo::RepoType probe( const Url & url, const Pathname & path ) const;
408  repo::RepoType probe( const Url & url ) const;
409 
410 
425  void addRepository( const RepoInfo &info,
426  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
427 
440  void addRepositories( const Url &url,
441  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
447  void removeRepository( const RepoInfo & info,
448  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
449 
459  void modifyRepository( const std::string &alias,
460  const RepoInfo & newinfo,
461  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
463  void modifyRepository( const RepoInfo & newinfo,
464  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() )
465  { modifyRepository( newinfo.alias(), newinfo, progressrcv ); }
466 
480  RepoInfo getRepositoryInfo( const std::string &alias,
481  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
482 
502  RepoInfo getRepositoryInfo( const Url & url,
503  const url::ViewOption & urlview = url::ViewOption::DEFAULTS,
504  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
505 
506 
519  bool serviceEmpty() const;
520 
527 
534 
540 
543 
545  std::list<ServiceInfo> knownServices() const
546  { return std::list<ServiceInfo>(serviceBegin(),serviceEnd()); }
547 
554  ServiceInfo getService( const std::string & alias ) const;
555 
557  bool hasService( const std::string & alias ) const;
559 
563  repo::ServiceType probeService( const Url &url ) const;
564 
573  void addService( const std::string & alias, const Url& url );
574 
582  void addService( const ServiceInfo & service );
583 
592  void removeService( const std::string & alias );
594  void removeService( const ServiceInfo & service );
595 
596 
602  void refreshServices( const RefreshServiceOptions & options_r = RefreshServiceOptions() );
603 
612  void refreshService( const std::string & alias, const RefreshServiceOptions & options_r = RefreshServiceOptions() );
614  void refreshService( const ServiceInfo & service, const RefreshServiceOptions & options_r = RefreshServiceOptions() );
615 
632  void modifyService( const std::string & oldAlias, const ServiceInfo & service );
634  void modifyService( const ServiceInfo & service )
635  { modifyService( service.alias(), service ); }
636 
637  private:
642  {
643  public:
644  MatchServiceAlias( const std::string & alias_ ) : alias(alias_) {}
645  bool operator()( const RepoInfo & info ) const
646  { return info.service() == alias; }
647  private:
648  std::string alias;
649  };
650 
651  public:
652 
685  template<typename OutputIterator>
686  void getRepositoriesInService( const std::string & alias,
687  OutputIterator out ) const
688  {
689  MatchServiceAlias filter(alias);
690 
691  std::copy( boost::make_filter_iterator( filter, repoBegin(), repoEnd() ),
692  boost::make_filter_iterator( filter, repoEnd(), repoEnd() ),
693  out);
694  }
695 
696  private:
699  };
700  ZYPP_DECLARE_OPERATORS_FOR_FLAGS(RepoManager::RefreshServiceFlags);
702 
704  std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
705 
708  { return makeIterable( repoBegin(), repoEnd() ); }
709 
712  { return makeIterable( serviceBegin(), serviceEnd() ); }
713 
715 } // namespace zypp
717 #endif // ZYPP2_REPOMANAGER_H
RefreshCheckStatus checkIfToRefreshMetadata(const RepoInfo &info, const Url &url, RawMetadataRefreshPolicy policy)
RefreshCheckStatus
Possibly return state of checkIfRefreshMEtadata function.
Definition: RepoManager.h:196
Service data.
Definition: ServiceInfo.h:36
RepoManagerOptions(const Pathname &root_r=Pathname())
Default ctor following ZConfig global settings.
Definition: RepoManager.cc:474
void getRepositoriesInService(const std::string &alias, OutputIterator out) const
fill to output iterator repositories in service name.
Definition: RepoManager.h:686
refresh is delayed due to settings
Definition: RepoManager.h:199
bool hasRepo(const std::string &alias) const
Definition: RepoManager.cc:583
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:724
repository not changed
Definition: RepoManager.h:198
void removeService(const std::string &alias)
ServiceInfo getService(const std::string &alias) const
Definition: RepoManager.cc:646
RepoSizeType repoSize() const
Definition: RepoManager.cc:579
void refreshServices(const RefreshServiceOptions &options_r)
Pathname metadataPath(const RepoInfo &info) const
Definition: RepoManager.cc:593
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:463
bool hasRepo(const RepoInfo &info_r) const
Definition: RepoManager.h:179
String related utilities and Regular expression matching.
RefreshServiceFlags RefreshServiceOptions
Options tuning RefreshService.
Definition: RepoManager.h:150
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:116
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:586
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:139
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:53
void loadFromCache(const RepoInfo &info, OPT_PROGRESS)
std::set< ServiceInfo > ServiceSet
ServiceInfo typedefs.
Definition: RepoManager.h:111
RepoInfo getRepo(const RepoInfo &info_r) const
Definition: RepoManager.h:173
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:488
Pathname rootDir
remembers root_r value for later use
Definition: RepoManager.h:96
std::string alias() const
unique identifier for this source.
bool serviceEmpty() const
Definition: RepoManager.cc:638
std::set< RepoInfo > RepoSet
RepoInfo typedefs.
Definition: RepoManager.h:119
MatchServiceAlias(const std::string &alias_)
Definition: RepoManager.h:644
Service type enumeration.
Definition: ServiceType.h:26
void cleanMetadata(const RepoInfo &info, OPT_PROGRESS)
bool repoEmpty() const
Definition: RepoManager.cc:578
const RepoSet & repos() const
Iterate the known repositories.
Definition: RepoManager.cc:704
bool isCached(const RepoInfo &info) const
Definition: RepoManager.cc:618
ServiceSet::const_iterator ServiceConstIterator
Definition: RepoManager.h:115
ServiceConstIterator serviceBegin() const
Definition: RepoManager.cc:640
RefreshServiceBit
Flags for tuning RefreshService.
Definition: RepoManager.h:142
SolvableIdType size_type
Definition: PoolMember.h:126
ServiceConstIterator serviceEnd() const
Definition: RepoManager.cc:641
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:698
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:459
void refreshMetadata(const RepoInfo &info, RawMetadataRefreshPolicy policy, OPT_PROGRESS)
bool operator()(const RepoInfo &info) const
Definition: RepoManager.h:645
RepoSet::size_type RepoSizeType
Definition: RepoManager.h:121
std::list< RepoInfo > knownRepositories() const
List of known repositories.
Definition: RepoManager.h:167
RepoConstIterator repoBegin() const
Definition: RepoManager.cc:580
std::string servicesTargetDistro
Target distro ID to be used when refreshing repo index services.
Definition: RepoManager.h:93
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:641
Pathname repoPackagesCachePath
Definition: RepoManager.h:82
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:634
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:639
Force refresh even if TTL is not reached.
Definition: RepoManager.h:145
void cleanPackages(const RepoInfo &info, OPT_PROGRESS)
Iterable< ServiceConstIterator > services() const
Iterate the known services.
Definition: RepoManager.h:711
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:581
void cleanCacheDirGarbage(OPT_PROGRESS)
Url manipulation class.
Definition: Url.h:91
RepoStatus cacheStatus(const RepoInfo &info) const
Definition: RepoManager.cc:621
bool hasService(const std::string &alias) const
Definition: RepoManager.cc:643
void cleanCache(const RepoInfo &info, OPT_PROGRESS)
std::list< ServiceInfo > knownServices() const
List of known services.
Definition: RepoManager.h:545
RepoSet::const_iterator RepoConstIterator
Definition: RepoManager.h:120
Repository type enumeration.
Definition: RepoType.h:27
Force restoring repo enabled/disabled status.
Definition: RepoManager.h:144
Pathname packagesPath(const RepoInfo &info) const
Definition: RepoManager.cc:596