libzypp  13.10.6
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 
21 #include "zypp/Pathname.h"
22 #include "zypp/ZConfig.h"
23 #include "zypp/RepoInfo.h"
25 #include "zypp/repo/RepoType.h"
26 #include "zypp/repo/ServiceType.h"
27 #include "zypp/ServiceInfo.h"
28 #include "zypp/RepoStatus.h"
29 #include "zypp/ProgressData.h"
30 
32 namespace zypp
33 {
34 
46  std::list<RepoInfo> readRepoFile(const Url & repo_file);
47 
53  {
65  RepoManagerOptions( const Pathname & root_r = Pathname() );
66 
76  static RepoManagerOptions makeTestSetup( const Pathname & root_r );
77 
78  Pathname repoCachePath;
79  Pathname repoRawCachePath;
82  Pathname knownReposPath;
84  Pathname pluginsPath;
85  bool probe;
96  std::string servicesTargetDistro;
97 
99  Pathname rootDir;
100  };
101 
102 
103 
109  {
110  friend std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
111 
112  public:
114  class Impl;
115 
117  typedef std::set<ServiceInfo> ServiceSet;
118  typedef ServiceSet::const_iterator ServiceConstIterator;
120 
122  typedef std::set<RepoInfo> RepoSet;
123  typedef RepoSet::const_iterator RepoConstIterator;
125 
126  public:
127  RepoManager( const RepoManagerOptions &options = RepoManagerOptions() );
129  ~RepoManager();
130 
132  {
136  };
137 
139  {
142  };
143 
145  {
146 
147  };
148 
156  bool repoEmpty() const;
157  RepoSizeType repoSize() const;
159  RepoConstIterator repoEnd() const;
160 
162  std::list<RepoInfo> knownRepositories() const
163  { return std::list<RepoInfo>(repoBegin(),repoEnd()); }
164 
166  RepoInfo getRepo( const std::string & alias ) const;
168  RepoInfo getRepo( const RepoInfo & info_r ) const
169  { return getRepo( info_r.alias() ); }
170 
172  bool hasRepo( const std::string & alias ) const;
174  bool hasRepo( const RepoInfo & info_r ) const
175  { return hasRepo( info_r.alias() ); }
176 
180  static std::string makeStupidAlias( const Url & url_r = Url() );
182 
186  RepoStatus metadataStatus( const RepoInfo &info ) const;
187 
195  };
196 
252  const Url &url,
254 
265  Pathname metadataPath( const RepoInfo &info ) const;
266 
267 
278  Pathname packagesPath( const RepoInfo &info ) const;
279 
280 
295  void refreshMetadata( const RepoInfo &info,
297  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
298 
307  void cleanMetadata( const RepoInfo &info,
308  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
309 
318  void cleanPackages( const RepoInfo &info,
319  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
320 
324  RepoStatus cacheStatus( const RepoInfo &info ) const;
325 
344  void buildCache( const RepoInfo &info,
346  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
347 
360  void cleanCache( const RepoInfo &info,
361  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
362 
368  bool isCached( const RepoInfo &info ) const;
369 
370 
380  void loadFromCache( const RepoInfo &info,
381  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
382 
391 
399  repo::RepoType probe( const Url & url, const Pathname & path ) const;
403  repo::RepoType probe( const Url & url ) const;
404 
405 
420  void addRepository( const RepoInfo &info,
421  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
422 
435  void addRepositories( const Url &url,
436  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
442  void removeRepository( const RepoInfo & info,
443  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
444 
454  void modifyRepository( const std::string &alias,
455  const RepoInfo & newinfo,
456  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
458  void modifyRepository( const RepoInfo & newinfo,
459  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() )
460  { modifyRepository( newinfo.alias(), newinfo, progressrcv ); }
461 
475  RepoInfo getRepositoryInfo( const std::string &alias,
476  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
477 
497  RepoInfo getRepositoryInfo( const Url & url,
498  const url::ViewOption & urlview = url::ViewOption::DEFAULTS,
499  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
500 
501 
514  bool serviceEmpty() const;
515 
522 
529 
535 
537  std::list<ServiceInfo> knownServices() const
538  { return std::list<ServiceInfo>(serviceBegin(),serviceEnd()); }
539 
546  ServiceInfo getService( const std::string & alias ) const;
547 
549  bool hasService( const std::string & alias ) const;
551 
555  repo::ServiceType probeService( const Url &url ) const;
556 
565  void addService( const std::string & alias, const Url& url );
566 
574  void addService( const ServiceInfo & service );
575 
584  void removeService( const std::string & alias );
586  void removeService( const ServiceInfo & service );
587 
588 
594  void refreshServices();
595 
604  void refreshService( const std::string & alias );
606  void refreshService( const ServiceInfo & service );
607 
624  void modifyService( const std::string & oldAlias, const ServiceInfo & service );
626  void modifyService( const ServiceInfo & service )
627  { modifyService( service.alias(), service ); }
628 
629  private:
634  {
635  public:
636  MatchServiceAlias( const std::string & alias_ ) : alias(alias_) {}
637  bool operator()( const RepoInfo & info ) const
638  { return info.service() == alias; }
639  private:
640  std::string alias;
641  };
642 
643  public:
644 
677  template<typename OutputIterator>
678  void getRepositoriesInService( const std::string & alias,
679  OutputIterator out ) const
680  {
681  MatchServiceAlias filter(alias);
682 
683  std::copy( boost::make_filter_iterator( filter, repoBegin(), repoEnd() ),
684  boost::make_filter_iterator( filter, repoEnd(), repoEnd() ),
685  out);
686  }
687 
688  private:
691  };
693 
695  std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
696 
698 } // namespace zypp
700 #endif // ZYPP2_REPOMANAGER_H
RepoManager(const RepoManagerOptions &options=RepoManagerOptions())
void removeService(const std::string &alias)
Removes service specified by its name.
refresh is delayed due to settings
Definition: RepoManager.h:194
RepoManagerOptions(const Pathname &root_r=Pathname())
Default ctor following ZConfig global settings.
Definition: RepoManager.cc:375
std::string alias() const
unique identifier for this source.
void modifyService(const ServiceInfo &service)
Definition: RepoManager.h:626
void refreshServices()
Refreshes all enabled services.
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:690
void cleanCacheDirGarbage(const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Remove any subdirectories of cache directories which no longer belong to any of known repositories...
RepoStatus metadataStatus(const RepoInfo &info) const
Status of local metadata.
RefreshCheckStatus
Possibly return state of checkIfRefreshMEtadata function.
Definition: RepoManager.h:191
Pathname metadataPath(const RepoInfo &info) const
Path where the metadata is downloaded and kept.
RepoSet::size_type RepoSizeType
Definition: RepoManager.h:124
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.
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.
What is known about a repository.
Definition: RepoInfo.h:66
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:123
function< bool(const ProgressData &)> ReceiverFnc
Most simple version of progress reporting The percentage in most cases.
Definition: ProgressData.h:144
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:678
void modifyRepository(const std::string &alias, const RepoInfo &newinfo, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Modify repository attributes.
void refreshService(const std::string &alias)
Refresh specific service.
RepoSizeType repoSize() const
Repo manager settings.
Definition: RepoManager.h:52
RepoManager implementation.
Definition: RepoManager.cc:423
std::set< RepoInfo > RepoSet
RepoInfo typedefs.
Definition: RepoManager.h:122
static RepoManagerOptions makeTestSetup(const Pathname &root_r)
Test setup adjusting all paths to be located below one root_r directory.
Definition: RepoManager.cc:389
Pathname rootDir
remembers root_r value for later use
Definition: RepoManager.h:99
RepoInfo getRepo(const RepoInfo &info_r) const
Definition: RepoManager.h:168
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:120
RepoConstIterator repoEnd() const
bool hasRepo(const RepoInfo &info_r) const
Definition: RepoManager.h:174
MatchServiceAlias(const std::string &alias_)
Definition: RepoManager.h:636
Service type enumeration.
Definition: ServiceType.h:26
ServiceSet::const_iterator ServiceConstIterator
Definition: RepoManager.h:118
repo::ServiceType probeService(const Url &url) const
Probe the type or the service.
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:246
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:119
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:108
RepoStatus cacheStatus(const RepoInfo &info) const
Status of metadata cache.
bool operator()(const RepoInfo &info) const
Definition: RepoManager.h:637
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:354
RepoInfo getRepo(const std::string &alias) const
Find RepoInfo by alias or return RepoInfo::noRepo.
repository not changed
Definition: RepoManager.h:193
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:458
std::list< RepoInfo > knownRepositories() const
List of known repositories.
Definition: RepoManager.h:162
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:114
std::string servicesTargetDistro
Target distro ID to be used when refreshing repo index services.
Definition: RepoManager.h:96
Functor thats filter RepoInfo by service which it belongs to.
Definition: RepoManager.h:633
bool isCached(const RepoInfo &info) const
Whether a repository exists in cache.
Pathname repoPackagesCachePath
Definition: RepoManager.h:81
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)
Local facts about a repository This class represents the status of a repository on the system...
Definition: RepoStatus.h:37
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.
std::list< ServiceInfo > knownServices() const
List of known services.
Definition: RepoManager.h:537
bool repoEmpty() const
void addService(const std::string &alias, const Url &url)
Adds new service by it&#39;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.
RW_pointer supporting &#39;copy on write&#39; functionality.
Definition: PtrTypes.h:438
Repository type enumeration.
Definition: RepoType.h:27