libzypp  15.3.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/ProgressData.h"
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 
79  Pathname repoCachePath;
80  Pathname repoRawCachePath;
83  Pathname knownReposPath;
85  Pathname pluginsPath;
86  bool probe;
93  std::string servicesTargetDistro;
94 
96  Pathname rootDir;
97  };
98 
99 
100 
106  {
107  friend std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
108 
109  public:
111  class 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  {
145  };
146  ZYPP_DECLARE_FLAGS(RefreshServiceFlags,RefreshServiceBit);
147 
149  typedef RefreshServiceFlags RefreshServiceOptions;
150 
151 
159  bool repoEmpty() const;
160  RepoSizeType repoSize() const;
161  RepoConstIterator repoBegin() const;
162  RepoConstIterator repoEnd() const;
163 
165  std::list<RepoInfo> knownRepositories() const
166  { return std::list<RepoInfo>(repoBegin(),repoEnd()); }
167 
169  RepoInfo getRepo( const std::string & alias ) const;
171  RepoInfo getRepo( const RepoInfo & info_r ) const
172  { return getRepo( info_r.alias() ); }
173 
175  bool hasRepo( const std::string & alias ) const;
177  bool hasRepo( const RepoInfo & info_r ) const
178  { return hasRepo( info_r.alias() ); }
179 
183  static std::string makeStupidAlias( const Url & url_r = Url() );
185 
189  RepoStatus metadataStatus( const RepoInfo &info ) const;
190 
198  };
199 
255  const Url &url,
257 
268  Pathname metadataPath( const RepoInfo &info ) const;
269 
270 
281  Pathname packagesPath( const RepoInfo &info ) const;
282 
283 
298  void refreshMetadata( const RepoInfo &info,
300  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
301 
310  void cleanMetadata( const RepoInfo &info,
311  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
312 
321  void cleanPackages( const RepoInfo &info,
322  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
323 
327  RepoStatus cacheStatus( const RepoInfo &info ) const;
328 
347  void buildCache( const RepoInfo &info,
349  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
350 
363  void cleanCache( const RepoInfo &info,
364  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
365 
371  bool isCached( const RepoInfo &info ) const;
372 
373 
383  void loadFromCache( const RepoInfo &info,
384  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
385 
394 
402  repo::RepoType probe( const Url & url, const Pathname & path ) const;
406  repo::RepoType probe( const Url & url ) const;
407 
408 
423  void addRepository( const RepoInfo &info,
424  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
425 
438  void addRepositories( const Url &url,
439  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
445  void removeRepository( const RepoInfo & info,
446  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
447 
457  void modifyRepository( const std::string &alias,
458  const RepoInfo & newinfo,
459  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
461  void modifyRepository( const RepoInfo & newinfo,
462  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() )
463  { modifyRepository( newinfo.alias(), newinfo, progressrcv ); }
464 
478  RepoInfo getRepositoryInfo( const std::string &alias,
479  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
480 
500  RepoInfo getRepositoryInfo( const Url & url,
501  const url::ViewOption & urlview = url::ViewOption::DEFAULTS,
502  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
503 
504 
517  bool serviceEmpty() const;
518 
524  ServiceSizeType serviceSize() const;
525 
531  ServiceConstIterator serviceBegin() const;
532 
537  ServiceConstIterator serviceEnd() const;
538 
540  std::list<ServiceInfo> knownServices() const
541  { return std::list<ServiceInfo>(serviceBegin(),serviceEnd()); }
542 
549  ServiceInfo getService( const std::string & alias ) const;
550 
552  bool hasService( const std::string & alias ) const;
554 
558  repo::ServiceType probeService( const Url &url ) const;
559 
568  void addService( const std::string & alias, const Url& url );
569 
577  void addService( const ServiceInfo & service );
578 
587  void removeService( const std::string & alias );
589  void removeService( const ServiceInfo & service );
590 
591 
597  void refreshServices( const RefreshServiceOptions & options_r = RefreshServiceOptions() );
598 
607  void refreshService( const std::string & alias, const RefreshServiceOptions & options_r = RefreshServiceOptions() );
609  void refreshService( const ServiceInfo & service, const RefreshServiceOptions & options_r = RefreshServiceOptions() );
610 
627  void modifyService( const std::string & oldAlias, const ServiceInfo & service );
629  void modifyService( const ServiceInfo & service )
630  { modifyService( service.alias(), service ); }
631 
632  private:
637  {
638  public:
639  MatchServiceAlias( const std::string & alias_ ) : alias(alias_) {}
640  bool operator()( const RepoInfo & info ) const
641  { return info.service() == alias; }
642  private:
643  std::string alias;
644  };
645 
646  public:
647 
680  template<typename OutputIterator>
681  void getRepositoriesInService( const std::string & alias,
682  OutputIterator out ) const
683  {
684  MatchServiceAlias filter(alias);
685 
686  std::copy( boost::make_filter_iterator( filter, repoBegin(), repoEnd() ),
687  boost::make_filter_iterator( filter, repoEnd(), repoEnd() ),
688  out);
689  }
690 
691  private:
694  };
695  ZYPP_DECLARE_OPERATORS_FOR_FLAGS(RepoManager::RefreshServiceFlags);
697 
699  std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
700 
702 } // namespace zypp
704 #endif // ZYPP2_REPOMANAGER_H
RepoManager(const RepoManagerOptions &options=RepoManagerOptions())
void removeService(const std::string &alias)
Removes service specified by its name.
Service data.
Definition: ServiceInfo.h:35
refresh is delayed due to settings
Definition: RepoManager.h:197
RepoManagerOptions(const Pathname &root_r=Pathname())
Default ctor following ZConfig global settings.
Definition: RepoManager.cc:387
std::string alias() const
unique identifier for this source.
void modifyService(const ServiceInfo &service)
Definition: RepoManager.h:629
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...
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: RepoManager.h:693
void cleanCacheDirGarbage(const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Remove any subdirectories of cache directories which no longer belong to any of known repositories...
void refreshServices(const RefreshServiceOptions &options_r=RefreshServiceOptions())
Refreshes all enabled services.
RepoStatus metadataStatus(const RepoInfo &info) const
Status of local metadata.
RefreshCheckStatus
Possibly return state of checkIfRefreshMEtadata function.
Definition: RepoManager.h:194
Pathname metadataPath(const RepoInfo &info) const
Path where the metadata is downloaded and kept.
RepoSet::size_type RepoSizeType
Definition: RepoManager.h:121
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.
ZYPP_DECLARE_OPERATORS_FOR_FLAGS(DiskUsageCounter::MountPoint::HintFlags)
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.
String related utilities and Regular expression matching.
RefreshServiceFlags RefreshServiceOptions
Options tuning RefreshService.
Definition: RepoManager.h:149
void refreshService(const std::string &alias, const RefreshServiceOptions &options_r=RefreshServiceOptions())
Refresh specific service.
What is known about a repository.
Definition: RepoInfo.h:71
void removeRepository(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Remove the best matching repository from known repos list.
RepoSet::const_iterator RepoConstIterator
Definition: RepoManager.h:120
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 getRepositoriesInService(const std::string &alias, OutputIterator out) const
fill to output iterator repositories in service name.
Definition: RepoManager.h:681
void modifyRepository(const std::string &alias, const RepoInfo &newinfo, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Modify repository attributes.
RefreshServiceBit
Flags for tuning RefreshService.
Definition: RepoManager.h:142
RepoSizeType repoSize() const
Repo manager settings.
Definition: RepoManager.h:53
RepoManager implementation.
Definition: RepoManager.cc:435
std::set< RepoInfo > RepoSet
RepoInfo typedefs.
Definition: RepoManager.h:119
static RepoManagerOptions makeTestSetup(const Pathname &root_r)
Test setup adjusting all paths to be located below one root_r directory.
Definition: RepoManager.cc:401
Pathname rootDir
remembers root_r value for later use
Definition: RepoManager.h:96
RepoInfo getRepo(const RepoInfo &info_r) const
Definition: RepoManager.h:171
RepoConstIterator repoEnd() const
bool hasRepo(const RepoInfo &info_r) const
Definition: RepoManager.h:177
MatchServiceAlias(const std::string &alias_)
Definition: RepoManager.h:639
Service type enumeration.
Definition: ServiceType.h:26
ServiceSet::const_iterator ServiceConstIterator
Definition: RepoManager.h:115
repo::ServiceType probeService(const Url &url) const
Probe the type or the service.
ZYPP_DECLARE_FLAGS(RefreshServiceFlags, RefreshServiceBit)
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:392
zypp::Url url
Definition: MediaCurl.cc:193
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.
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
ServiceSet::size_type ServiceSizeType
Definition: RepoManager.h:116
SolvableIdType size_type
Definition: PoolMember.h:99
ServiceInfo getService(const std::string &alias) const
Finds ServiceInfo by alias or return ServiceInfo::noService.
std::ostream & copy(std::istream &from_r, std::ostream &to_r)
Copy istream to ostream.
Definition: IOStream.h:50
bool hasRepo(const std::string &alias) const
Return whether there is a known repository for alias.
creates and provides information about known sources.
Definition: RepoManager.h:105
RepoStatus cacheStatus(const RepoInfo &info) const
Status of metadata cache.
bool operator()(const RepoInfo &info) const
Definition: RepoManager.h:640
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:366
RepoInfo getRepo(const std::string &alias) const
Find RepoInfo by alias or return RepoInfo::noRepo.
repository not changed
Definition: RepoManager.h:196
void buildCache(const RepoInfo &info, CacheBuildPolicy policy=BuildIfNeeded, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Refresh local cache.
void modifyRepository(const RepoInfo &newinfo, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Definition: RepoManager.h:461
std::list< RepoInfo > knownRepositories() const
List of known repositories.
Definition: RepoManager.h:165
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:111
std::string servicesTargetDistro
Target distro ID to be used when refreshing repo index services.
Definition: RepoManager.h:93
Force restoring repo enabled/disabled staus.
Definition: RepoManager.h:144
Functor thats filter RepoInfo by service which it belongs to.
Definition: RepoManager.h:636
bool isCached(const RepoInfo &info) const
Whether a repository exists in cache.
Pathname repoPackagesCachePath
Definition: RepoManager.h:82
bool hasService(const std::string &alias) const
Return whether there is a known service for alias.
static const ViewOption DEFAULTS
Default combination of view options.
Definition: UrlBase.h:177
friend std::ostream & operator<<(std::ostream &str, const RepoManager &obj)
ServiceSizeType serviceSize() const
Gets count of service in RepoManager (in specified location)
Track changing files or directories.
Definition: RepoStatus.h:38
void cleanPackages(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Clean local package cache.
ServiceConstIterator serviceBegin() const
Iterator to first service in internal storage.
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
std::list< ServiceInfo > knownServices() const
List of known services.
Definition: RepoManager.h:540
bool repoEmpty() const
void addService(const std::string &alias, const Url &url)
Adds new service by it's alias and url.
Url manipulation class.
Definition: Url.h:87
void cleanMetadata(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Clean local metadata.
Repository type enumeration.
Definition: RepoType.h:27