libzypp  17.32.4
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>
31 #include <utility>
32 #include <zypp-core/ui/ProgressData>
33 
35 namespace zypp
36 {
37 
51  std::list<RepoInfo> readRepoFile(const Url & repo_file);
52 
57  class RepoManager
58  {
59  friend std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
60 
61  public:
63  struct Impl;
64 
66  using ServiceSet = std::set<ServiceInfo>;
67  using ServiceConstIterator = ServiceSet::const_iterator;
69 
71  using RepoSet = std::set<RepoInfo>;
72  using RepoConstIterator = RepoSet::const_iterator;
74 
75  public:
78  ~RepoManager();
79 
81  {
85  };
86 
88  {
91  };
92 
95  {
98  };
99  ZYPP_DECLARE_FLAGS(RefreshServiceFlags,RefreshServiceBit);
100 
102  using RefreshServiceOptions = RefreshServiceFlags;
103 
104 
112  bool repoEmpty() const;
113  RepoSizeType repoSize() const;
115  RepoConstIterator repoEnd() const;
117 
119  std::list<RepoInfo> knownRepositories() const
120  { return std::list<RepoInfo>(repoBegin(),repoEnd()); }
121 
123  RepoInfo getRepo( const std::string & alias ) const;
125  RepoInfo getRepo( const RepoInfo & info_r ) const
126  { return getRepo( info_r.alias() ); }
127 
129  bool hasRepo( const std::string & alias ) const;
131  bool hasRepo( const RepoInfo & info_r ) const
132  { return hasRepo( info_r.alias() ); }
133 
137  static std::string makeStupidAlias( const Url & url_r = Url() );
139 
143  RepoStatus metadataStatus( const RepoInfo &info ) const;
144 
152  };
153 
209  const Url &url,
211 
222  Pathname metadataPath( const RepoInfo &info ) const;
223 
224 
235  Pathname packagesPath( const RepoInfo &info ) const;
236 
237 
252  void refreshMetadata( const RepoInfo &info,
254  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
255 
264  void cleanMetadata( const RepoInfo &info,
265  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
266 
275  void cleanPackages( const RepoInfo &info,
276  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
277 
281  RepoStatus cacheStatus( const RepoInfo &info ) const;
282 
301  void buildCache( const RepoInfo &info,
303  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
304 
317  void cleanCache( const RepoInfo &info,
318  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
319 
325  bool isCached( const RepoInfo &info ) const;
326 
327 
337  void loadFromCache( const RepoInfo &info,
338  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
339 
348 
356  repo::RepoType probe( const Url & url, const Pathname & path ) const;
360  repo::RepoType probe( const Url & url ) const;
361 
362 
377  void addRepository( const RepoInfo &info,
378  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
379 
392  void addRepositories( const Url &url,
393  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
399  void removeRepository( const RepoInfo & info,
400  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
401 
411  void modifyRepository( const std::string &alias,
412  const RepoInfo & newinfo,
413  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
415  void modifyRepository( const RepoInfo & newinfo,
416  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() )
417  { modifyRepository( newinfo.alias(), newinfo, progressrcv ); }
418 
432  RepoInfo getRepositoryInfo( const std::string &alias,
433  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
434 
454  RepoInfo getRepositoryInfo( const Url & url,
455  const url::ViewOption & urlview = url::ViewOption::DEFAULTS,
456  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
457 
458 
471  bool serviceEmpty() const;
472 
479 
486 
492 
495 
497  std::list<ServiceInfo> knownServices() const
498  { return std::list<ServiceInfo>(serviceBegin(),serviceEnd()); }
499 
506  ServiceInfo getService( const std::string & alias ) const;
507 
509  bool hasService( const std::string & alias ) const;
511 
515  repo::ServiceType probeService( const Url &url ) const;
516 
525  void addService( const std::string & alias, const Url& url );
526 
534  void addService( const ServiceInfo & service );
535 
544  void removeService( const std::string & alias );
546  void removeService( const ServiceInfo & service );
547 
548 
554  void refreshServices( const RefreshServiceOptions & options_r = RefreshServiceOptions() );
555 
564  void refreshService( const std::string & alias, const RefreshServiceOptions & options_r = RefreshServiceOptions() );
566  void refreshService( const ServiceInfo & service, const RefreshServiceOptions & options_r = RefreshServiceOptions() );
567 
584  void modifyService( const std::string & oldAlias, const ServiceInfo & service );
586  void modifyService( const ServiceInfo & service )
587  { modifyService( service.alias(), service ); }
588 
593  void refreshGeoIp ( const RepoInfo::url_set &urls );
594 
595  private:
600  {
601  public:
602  MatchServiceAlias( std::string alias_ ) : alias(std::move(alias_)) {}
603  bool operator()( const RepoInfo & info ) const
604  { return info.service() == alias; }
605  private:
606  std::string alias;
607  };
608 
609  public:
610 
643  template<typename OutputIterator>
644  void getRepositoriesInService( const std::string & alias,
645  OutputIterator out ) const
646  {
647  MatchServiceAlias filter(alias);
648 
649  std::copy( boost::make_filter_iterator( filter, repoBegin(), repoEnd() ),
650  boost::make_filter_iterator( filter, repoEnd(), repoEnd() ),
651  out);
652  }
653 
654  private:
657  };
658  ZYPP_DECLARE_OPERATORS_FOR_FLAGS(RepoManager::RefreshServiceFlags);
660 
662  std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
663 
666  { return makeIterable( repoBegin(), repoEnd() ); }
667 
670  { return makeIterable( serviceBegin(), serviceEnd() ); }
671 
673 } // namespace zypp
675 #endif // ZYPP2_REPOMANAGER_H
RefreshCheckStatus checkIfToRefreshMetadata(const RepoInfo &info, const Url &url, RawMetadataRefreshPolicy policy)
RefreshCheckStatus
Possibly return state of checkIfRefreshMEtadata function.
Definition: RepoManager.h:148
Service data.
Definition: ServiceInfo.h:36
RepoSet::size_type RepoSizeType
Definition: RepoManager.h:73
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:644
refresh is delayed due to settings
Definition: RepoManager.h:151
bool hasRepo(const std::string &alias) const
Return whether there is a known repository for alias.
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:638
repository not changed
Definition: RepoManager.h:150
void removeService(const std::string &alias)
Removes service specified by its name.
void cleanCache(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
clean local cache
ServiceInfo getService(const std::string &alias) const
Finds ServiceInfo by alias or return ServiceInfo::noService.
RepoSizeType repoSize() const
void refreshServices(const RefreshServiceOptions &options_r)
function< bool(const ProgressData &)> ReceiverFnc
Most simple version of progress reporting The percentage in most cases.
Definition: progressdata.h:140
Pathname metadataPath(const RepoInfo &info) const
Path where the metadata is downloaded and kept.
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:415
bool hasRepo(const RepoInfo &info_r) const
Definition: RepoManager.h:131
String related utilities and Regular expression matching.
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition: SerialNumber.cc:52
Definition: Arch.h:363
What is known about a repository.
Definition: RepoInfo.h:71
ZYPP_DECLARE_FLAGS(RefreshServiceFlags, RefreshServiceBit)
void addRepositories(const Url &url, OPT_PROGRESS)
RepoInfo getRepo(const std::string &alias) const
Find RepoInfo by alias or return RepoInfo::noRepo.
repo::ServiceType probeService(const Url &url) const
void buildCache(const RepoInfo &info, CacheBuildPolicy policy, OPT_PROGRESS)
Url::asString() view options.
Definition: UrlBase.h:39
repo::RepoType probe(const Url &url, const Pathname &path=Pathname()) const
Repo manager settings.
void loadFromCache(const RepoInfo &info, OPT_PROGRESS)
void cleanCacheDirGarbage(const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Remove any subdirectories of cache directories which no longer belong to any of known repositories...
void modifyRepository(const std::string &alias, const RepoInfo &newinfo, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Modify repository attributes.
RepoInfo getRepo(const RepoInfo &info_r) const
Definition: RepoManager.h:125
void addRepository(const RepoInfo &info, OPT_PROGRESS)
void cleanPackages(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Clean local package cache.
RepoInfo getRepositoryInfo(const std::string &alias, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Find a matching repository info.
std::set< ServiceInfo > ServiceSet
ServiceInfo typedefs.
Definition: RepoManager.h:66
void removeRepository(const RepoInfo &info, OPT_PROGRESS) override
std::string alias() const
unique identifier for this source.
void addService(const std::string &alias, const Url &url)
Adds a new service by its alias and URL.
bool serviceEmpty() const
Gets true if no service is in RepoManager (so no one in specified location)
Service type enumeration.
Definition: ServiceType.h:26
bool repoEmpty() const
MatchServiceAlias(std::string alias_)
Definition: RepoManager.h:602
ServiceSet::size_type ServiceSizeType
Definition: RepoManager.h:68
Iterable< RepoConstIterator > repos() const
Iterate the known repositories.
Definition: RepoManager.h:665
void modifyService(const std::string &oldAlias, const ServiceInfo &service)
Modifies service file (rewrites it with new values) and underlying repositories if needed...
bool isCached(const RepoInfo &info) const
Whether a repository exists in cache.
std::list< Url > url_set
Definition: RepoInfo.h:108
ServiceConstIterator serviceBegin() const
Iterator to first service in internal storage.
RefreshServiceBit
Flags for tuning RefreshService.
Definition: RepoManager.h:94
ServiceConstIterator serviceEnd() const
Iterator to place behind last service in internal storage.
std::ostream & copy(std::istream &from_r, std::ostream &to_r)
Copy istream to ostream.
Definition: IOStream.h:51
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: RepoManager.h:656
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:134
RefreshServiceFlags RefreshServiceOptions
Options tuning RefreshService.
Definition: RepoManager.h:102
void refreshMetadata(const RepoInfo &info, RawMetadataRefreshPolicy policy, OPT_PROGRESS)
bool operator()(const RepoInfo &info) const
Definition: RepoManager.h:603
std::list< RepoInfo > knownRepositories() const
List of known repositories.
Definition: RepoManager.h:119
RepoConstIterator repoBegin() const
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:599
std::set< RepoInfo > RepoSet
RepoInfo typedefs.
Definition: RepoManager.h:71
RepoSet::const_iterator RepoConstIterator
Definition: RepoManager.h:72
static const ViewOption DEFAULTS
Default combination of view options.
Definition: UrlBase.h:177
void modifyService(const ServiceInfo &service)
Definition: RepoManager.h:586
RepoStatus metadataStatus(const RepoInfo &info) const
Status of local metadata.
Track changing files or directories.
Definition: RepoStatus.h:40
ServiceSizeType serviceSize() const
Gets count of service in RepoManager (in specified location)
Force refresh even if TTL is not reached.
Definition: RepoManager.h:97
Iterable< ServiceConstIterator > services() const
Iterate the known services.
Definition: RepoManager.h:669
void refreshService(const std::string &alias, const RefreshServiceOptions &options_r)
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
SolvableIdType size_type
Definition: PoolMember.h:126
RepoConstIterator repoEnd() const
void refreshGeoIp(const RepoInfo::url_set &urls)
void cleanMetadata(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Clean local metadata.
Url manipulation class.
Definition: Url.h:91
RepoStatus cacheStatus(const RepoInfo &info) const
Status of metadata cache.
bool hasService(const std::string &alias) const
Return whether there is a known service for alias.
std::list< ServiceInfo > knownServices() const
List of known services.
Definition: RepoManager.h:497
RepoManager(RepoManagerOptions options=RepoManagerOptions())
Repository type enumeration.
Definition: RepoType.h:27
Force restoring repo enabled/disabled status.
Definition: RepoManager.h:96
ServiceSet::const_iterator ServiceConstIterator
Definition: RepoManager.h:67
Pathname packagesPath(const RepoInfo &info) const
Path where the rpm packages are downloaded and kept.