libzypp 17.35.11
RepoManager.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
13#include <iostream>
14#include <zypp-core/Digest.h>
15#include <zypp-core/zyppng/pipelines/Lift>
20
21#undef ZYPP_BASE_LOGGER_LOGGROUP
22#define ZYPP_BASE_LOGGER_LOGGROUP "zypp::repomanager"
23
24using std::endl;
25using std::string;
26using namespace zypp::repo;
27
28#define OPT_PROGRESS const ProgressData::ReceiverFnc & = ProgressData::ReceiverFnc()
29
31namespace zypp
32{
39 {
40 public:
41 Impl( zyppng::SyncContextRef &&ctx, RepoManagerOptions &&opt) {
42 _ngMgr = zyppng::SyncRepoManager::create( std::move(ctx), std::move(opt) ).unwrap();
43 }
44
45 Impl(const Impl &) = delete;
46 Impl(Impl &&) = delete;
47 Impl &operator=(const Impl &) = delete;
48 Impl &operator=(Impl &&) = delete;
49
50 public:
52 return *_ngMgr;
53 }
54
56 return *_ngMgr;
57 }
58
59 private:
61
62 private:
63 friend Impl * rwcowClone<Impl>( const Impl * rhs );
65 Impl * clone() const
66 { return new Impl( zyppng::SyncContextRef(_ngMgr->zyppContext()), RepoManagerOptions(_ngMgr->options()) ); }
67 };
69
71 inline std::ostream & operator<<( std::ostream & str, const RepoManager::Impl & obj )
72 { return str << "RepoManager::Impl"; }
73
75 //
76 // CLASS NAME : RepoManager
77 //
79
81 : _pimpl( new Impl( zyppng::SyncContext::defaultContext(), std::move(opt)) )
82 {}
83
86
88 { return _pimpl->ngMgr().repoEmpty(); }
89
92
95
98
99 RepoInfo RepoManager::getRepo( const std::string & alias ) const
100 { return _pimpl->ngMgr().getRepo( alias ); }
101
102 bool RepoManager::hasRepo( const std::string & alias ) const
103 { return _pimpl->ngMgr().hasRepo( alias ); }
104
105 std::string RepoManager::makeStupidAlias( const Url & url_r )
106 {
107 std::string ret( url_r.getScheme() );
108 if ( ret.empty() )
109 ret = "repo-";
110 else
111 ret += "-";
112
113 std::string host( url_r.getHost() );
114 if ( ! host.empty() )
115 {
116 ret += host;
117 ret += "-";
118 }
119
120 static Date::ValueType serial = Date::now();
121 ret += Digest::digest( Digest::sha1(), str::hexstring( ++serial ) +url_r.asCompleteString() ).substr(0,8);
122 return ret;
123 }
124
126 { return _pimpl->ngMgr().metadataStatus( info ).unwrap(); }
127
130
132 { return _pimpl->ngMgr().metadataPath( info ).unwrap(); }
133
135 { return _pimpl->ngMgr().packagesPath( info ).unwrap(); }
136
138 {
139 // Suppress (interactive) media::MediaChangeReport if we in have multiple basurls (>1)
141 return _pimpl->ngMgr().refreshMetadata( info, policy, nullptr ).unwrap();
142 }
143
144 void RepoManager::cleanMetadata( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv )
145 { return _pimpl->ngMgr().cleanMetadata( info, nullptr ).unwrap(); }
146
147 void RepoManager::cleanPackages( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv )
148 { return _pimpl->ngMgr().cleanPackages( info, nullptr ).unwrap(); }
149
151 { return _pimpl->ngMgr().cacheStatus( info ).unwrap(); }
152
153 void RepoManager::buildCache( const RepoInfo &info, CacheBuildPolicy policy, const ProgressData::ReceiverFnc & progressrcv )
154 {
156 auto adapt = zyppng::ProgressObserverAdaptor( progressrcv, report );
157 return _pimpl->ngMgr().buildCache( info, policy, adapt.observer() ).unwrap();
158 }
159
160 void RepoManager::cleanCache( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv )
161 { return _pimpl->ngMgr().cleanCache( info, nullptr ).unwrap(); }
162
163 bool RepoManager::isCached( const RepoInfo &info ) const
164 { return _pimpl->ngMgr().isCached( info ).unwrap(); }
165
166 void RepoManager::loadFromCache( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv )
167 { return _pimpl->ngMgr().loadFromCache( info, nullptr ).unwrap(); }
168
170 { return _pimpl->ngMgr().cleanCacheDirGarbage( nullptr ).unwrap(); }
171
172 repo::RepoType RepoManager::probe( const Url & url, const Pathname & path ) const
173 { return _pimpl->ngMgr().probe( url, path ).unwrap(); }
174
176 { return _pimpl->ngMgr().probe( url ).unwrap(); }
177
178 void RepoManager::addRepository( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv )
179 {
181 auto adapt = zyppng::ProgressObserverAdaptor( progressrcv, report );
182 RepoInfo updatedRepo = _pimpl->ngMgr().addRepository( info, adapt.observer() ).unwrap();
183
184 // We should fix the API as we must inject those paths
185 // into the repoinfo in order to keep it usable.
186 RepoInfo & oinfo( const_cast<RepoInfo &>(info) );
187 oinfo.setFilepath( updatedRepo.filepath() );
188 oinfo.setMetadataPath( zyppng::rawcache_path_for_repoinfo( _pimpl->ngMgr().options(), updatedRepo ).unwrap() );
189 oinfo.setPackagesPath( zyppng::packagescache_path_for_repoinfo( _pimpl->ngMgr().options(), updatedRepo ).unwrap() );
190 }
191
192 void RepoManager::addRepositories( const Url &url, const ProgressData::ReceiverFnc & progressrcv )
193 { return _pimpl->ngMgr().addRepositories( url, nullptr ).unwrap(); }
194
195 void RepoManager::removeRepository( const RepoInfo & info, const ProgressData::ReceiverFnc & progressrcv )
196 {
198 auto adapt = zyppng::ProgressObserverAdaptor( progressrcv, report );
199 return _pimpl->ngMgr().removeRepository( info, adapt.observer() ).unwrap();
200 }
201
202 void RepoManager::modifyRepository( const std::string &alias, const RepoInfo & newinfo, const ProgressData::ReceiverFnc & progressrcv )
203 {
204 RepoInfo updated = _pimpl->ngMgr().modifyRepository( alias, newinfo, nullptr ).unwrap();
205 // We should fix the API as we must inject those paths
206 // into the repoinfo in order to keep it usable.
207 RepoInfo & oinfo( const_cast<RepoInfo &>(newinfo) );
208 oinfo.setFilepath( updated.filepath());
209 oinfo.setMetadataPath( zyppng::rawcache_path_for_repoinfo( _pimpl->ngMgr().options(), updated ).unwrap() );
211 }
212
213 RepoInfo RepoManager::getRepositoryInfo( const std::string &alias, const ProgressData::ReceiverFnc & progressrcv )
214 { return _pimpl->ngMgr().getRepositoryInfo( alias ).unwrap(); }
215
216 RepoInfo RepoManager::getRepositoryInfo( const Url & url, const url::ViewOption & urlview, const ProgressData::ReceiverFnc & progressrcv )
217 { return _pimpl->ngMgr().getRepositoryInfo( url, urlview ).unwrap(); }
218
220 { return _pimpl->ngMgr().serviceEmpty(); }
221
224
227
230
231 ServiceInfo RepoManager::getService( const std::string & alias ) const
232 { return _pimpl->ngMgr().getService( alias ); }
233
234 bool RepoManager::hasService( const std::string & alias ) const
235 { return _pimpl->ngMgr().hasService( alias ); }
236
238 { return _pimpl->ngMgr().probeService( url ).unwrap(); }
239
240 void RepoManager::addService( const std::string & alias, const Url& url )
241 { return _pimpl->ngMgr().addService( alias, url ).unwrap(); }
242
243 void RepoManager::addService( const ServiceInfo & service )
244 { return _pimpl->ngMgr().addService( service ).unwrap(); }
245
246 void RepoManager::removeService( const std::string & alias )
247 { return _pimpl->ngMgr().removeService( alias ).unwrap(); }
248
250 { return _pimpl->ngMgr().removeService( service ).unwrap(); }
251
253 { return _pimpl->ngMgr().refreshServices( options_r ).unwrap(); }
254
255 void RepoManager::refreshService( const std::string & alias, const RefreshServiceOptions & options_r )
256 { return _pimpl->ngMgr().refreshService( alias, options_r ).unwrap(); }
257
258 void RepoManager::refreshService( const ServiceInfo & service, const RefreshServiceOptions & options_r )
259 { return _pimpl->ngMgr().refreshService( service, options_r ).unwrap(); }
260
261 void RepoManager::modifyService( const std::string & oldAlias, const ServiceInfo & service )
262 { return _pimpl->ngMgr().modifyService( oldAlias, service ).unwrap(); }
263
265 { (void) _pimpl->ngMgr().refreshGeoIp( urls ); }
266
268
269 std::ostream & operator<<( std::ostream & str, const RepoManager & obj )
270 { return str << *obj._pimpl; }
271
272 std::list<RepoInfo> readRepoFile(const Url &repo_file)
273 {
275 }
276
278} // namespace zypp
time_t ValueType
Definition Date.h:38
static Date now()
Return the current time.
Definition Date.h:78
std::string digest()
get hex string representation of the digest
Definition Digest.cc:238
static const std::string & sha1()
sha1
Definition Digest.cc:44
function< bool(const ProgressData &)> ReceiverFnc
Most simple version of progress reporting The percentage in most cases.
What is known about a repository.
Definition RepoInfo.h:72
urls_size_type baseUrlsSize() const
number of repository urls
Definition RepoInfo.cc:653
void setPackagesPath(const Pathname &path)
set the path where the local packages are stored
Definition RepoInfo.cc:578
void setMetadataPath(const Pathname &path)
Set the path where the local metadata is stored.
Definition RepoInfo.cc:575
std::list< Url > url_set
Definition RepoInfo.h:108
creates and provides information about known sources.
Definition RepoManager.h:59
bool hasRepo(const std::string &alias) const
Return whether there is a known repository for alias.
void cleanCacheDirGarbage(const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Remove any subdirectories of cache directories which no longer belong to any of known repositories.
friend std::ostream & operator<<(std::ostream &str, const RepoManager &obj)
void cleanMetadata(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Clean local metadata.
bool serviceEmpty() const
Gets true if no service is in RepoManager (so no one in specified location)
bool hasService(const std::string &alias) const
Return whether there is a known service for alias.
ServiceSet::const_iterator ServiceConstIterator
Definition RepoManager.h:68
void addService(const std::string &alias, const Url &url)
Adds a new service by its alias and URL.
bool isCached(const RepoInfo &info) const
Whether a repository exists in cache.
void removeService(const std::string &alias)
Removes service specified by its name.
RepoInfo getRepo(const std::string &alias) const
Find RepoInfo by alias or return RepoInfo::noRepo.
repo::ServiceType probeService(const Url &url) const
Probe the type or the service.
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
void cleanCache(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
clean local cache
void refreshServices(const RefreshServiceOptions &options_r=RefreshServiceOptions())
Refreshes all enabled services.
void addRepository(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Adds a repository to the list of known repositories.
bool repoEmpty() const
Pathname metadataPath(const RepoInfo &info) const
Path where the metadata is downloaded and kept.
ServiceSet::size_type ServiceSizeType
Definition RepoManager.h:69
Pathname packagesPath(const RepoInfo &info) const
Path where the rpm packages are downloaded and kept.
RepoStatus cacheStatus(const RepoInfo &info) const
Status of metadata cache.
void addRepositories(const Url &url, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Adds repositores from a repo file to the list of known repositories.
void refreshMetadata(const RepoInfo &info, RawMetadataRefreshPolicy policy=RefreshIfNeeded, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Refresh local raw cache.
void refreshGeoIp(const RepoInfo::url_set &urls)
void refreshService(const std::string &alias, const RefreshServiceOptions &options_r=RefreshServiceOptions())
Refresh specific service.
ServiceConstIterator serviceEnd() const
Iterator to place behind last service in internal storage.
ServiceConstIterator serviceBegin() const
Iterator to first service in internal storage.
RepoSizeType repoSize() const
void modifyRepository(const std::string &alias, const RepoInfo &newinfo, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Modify repository attributes.
void removeRepository(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Remove the best matching repository from known repos list.
RepoInfo getRepositoryInfo(const std::string &alias, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Find a matching repository info.
ServiceSizeType serviceSize() const
Gets count of service in RepoManager (in specified location)
ServiceInfo getService(const std::string &alias) const
Finds ServiceInfo by alias or return ServiceInfo::noService.
RefreshCheckStatus checkIfToRefreshMetadata(const RepoInfo &info, const Url &url, RawMetadataRefreshPolicy policy=RefreshIfNeeded)
Checks whether to refresh metadata for specified repository and url.
RepoSet::size_type RepoSizeType
Definition RepoManager.h:74
RepoConstIterator repoBegin() const
void buildCache(const RepoInfo &info, CacheBuildPolicy policy=BuildIfNeeded, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Refresh local cache.
RepoManagerFlags::RefreshServiceFlags RefreshServiceOptions
Options tuning RefreshService.
Definition RepoManager.h:98
RepoManager(RepoManagerOptions options=RepoManagerOptions())
void loadFromCache(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Load resolvables into the pool.
void cleanPackages(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Clean local package cache.
RepoConstIterator repoEnd() const
RepoStatus metadataStatus(const RepoInfo &info) const
Status of local metadata.
void modifyService(const std::string &oldAlias, const ServiceInfo &service)
Modifies service file (rewrites it with new values) and underlying repositories if needed.
RepoSet::const_iterator RepoConstIterator
Definition RepoManager.h:73
static std::string makeStupidAlias(const Url &url_r=Url())
Some stupid string but suitable as alias for your url if nothing better is available.
repo::RepoType probe(const Url &url, const Pathname &path) const
Probe repo metadata type.
Track changing files or directories.
Definition RepoStatus.h:41
Service data.
Definition ServiceInfo.h:37
Url manipulation class.
Definition Url.h:92
std::string getScheme() const
Returns the scheme name of the URL.
Definition Url.cc:537
std::string asCompleteString() const
Returns a complete string representation of the Url object.
Definition Url.cc:509
std::string getHost(EEncoding eflag=zypp::url::E_DECODED) const
Returns the hostname or IP from the URL authority.
Definition Url.cc:592
void setFilepath(const Pathname &filename)
set the path to the .repo file
Pathname filepath() const
File where this repo was read from.
The RepoManager class Provides knowledge and methods to maintain repo settings and metadata for a giv...
Definition ZConfig.h:34
expected< RepoStatus > cacheStatus(const RepoInfo &info) const
expected< void > refreshServices(const RefreshServiceOptions &options_r)
RepoInfo getRepo(const std::string &alias) const
bool serviceEmpty() const
expected< void > refreshMetadata(const RepoInfo &info, RawMetadataRefreshPolicy policy, ProgressObserverRef myProgress=nullptr)
Refresh local raw cache.
expected< void > modifyService(const std::string &oldAlias, const ServiceInfo &newService)
ServiceConstIterator serviceBegin() const
RepoConstIterator repoBegin() const
expected< zypp::Pathname > metadataPath(const RepoInfo &info) const
expected< void > addService(const ServiceInfo &service)
expected< void > refreshGeoIp(const RepoInfo::url_set &urls)
expected< void > removeService(const std::string &alias)
expected< void > cleanPackages(const RepoInfo &info, ProgressObserverRef myProgress=nullptr, bool isAutoClean=false)
ServiceSizeType serviceSize() const
expected< RepoInfo > getRepositoryInfo(const std::string &alias)
expected< RepoInfo > modifyRepository(const std::string &alias, const RepoInfo &newinfo_r, ProgressObserverRef myProgress=nullptr)
expected< zypp::repo::RepoType > probe(const zypp::Url &url, const zypp::Pathname &path=zypp::Pathname()) const
Probe the metadata type of a repository located at url.
RepoSizeType repoSize() const
expected< void > cleanCacheDirGarbage(ProgressObserverRef myProgress=nullptr)
expected< RefreshCheckStatus > checkIfToRefreshMetadata(const RepoInfo &info, const zypp::Url &url, RawMetadataRefreshPolicy policy)
bool hasRepo(const std::string &alias) const
expected< RepoInfo > addRepository(const RepoInfo &info, ProgressObserverRef myProgress=nullptr)
RepoConstIterator repoEnd() const
expected< zypp::repo::ServiceType > probeService(const zypp::Url &url) const
bool hasService(const std::string &alias) const
expected< void > buildCache(const RepoInfo &info, CacheBuildPolicy policy, ProgressObserverRef myProgress=nullptr)
expected< zypp::Pathname > packagesPath(const RepoInfo &info) const
ServiceInfo getService(const std::string &alias) const
expected< void > addRepositories(const zypp::Url &url, ProgressObserverRef myProgress=nullptr)
static expected< std::shared_ptr< RepoManager< ZyppContextRefType > > > create(Args &&...args)
expected< void > cleanCache(const RepoInfo &info, ProgressObserverRef myProgress=nullptr)
expected< void > loadFromCache(const RepoInfo &info, ProgressObserverRef myProgress=nullptr)
expected< bool > isCached(const RepoInfo &info) const
expected< void > cleanMetadata(const RepoInfo &info, ProgressObserverRef myProgress=nullptr)
static expected< RepoStatus > metadataStatus(const RepoInfo &info, const RepoManagerOptions &options)
expected< void > removeRepository(const RepoInfo &info, ProgressObserverRef myProgress=nullptr)
expected< void > refreshService(const std::string &alias, const RefreshServiceOptions &options_r)
const RepoManagerOptions & options() const
ServiceConstIterator serviceEnd() const
bool repoEmpty() const
static SyncContextRef defaultContext()
Definition Arch.h:364
String related utilities and Regular expression matching.
RefreshCheckStatus
Possibly return state of RepoManager::checkIfToRefreshMetadata function.
std::string hexstring(char n, int w=4)
Definition String.h:324
Easy-to use interface to the ZYPP dependency resolver.
std::list< RepoInfo > readRepoFile(const Url &repo_file)
Parses repo_file and returns a list of RepoInfo objects corresponding to repositories found within th...
AsyncOpRef< expected< std::list< RepoInfo > > > readRepoFile(ContextRef ctx, zypp::Url repoFileUrl)
expected< zypp::Pathname > rawcache_path_for_repoinfo(const RepoManagerOptions &opt, const RepoInfo &info)
Calculates the raw cache path for a repository, this is usually /var/cache/zypp/alias.
RepoManagerRef< SyncContextRef > SyncRepoManagerRef
Definition repomanager.h:48
expected< zypp::Pathname > packagescache_path_for_repoinfo(const RepoManagerOptions &opt, const RepoInfo &info)
Calculates the packages cache path for a repository.
Repo manager settings.
RepoManager implementation.
Impl & operator=(const Impl &)=delete
Impl(zyppng::SyncContextRef &&ctx, RepoManagerOptions &&opt)
zyppng::SyncRepoManager & ngMgr()
zyppng::SyncRepoManagerRef _ngMgr
Impl(const Impl &)=delete
std::ostream & operator<<(std::ostream &str, const RepoManager::Impl &obj)
Stream output.
Impl(Impl &&)=delete
Impl * clone() const
clone for RWCOW_pointer
Impl & operator=(Impl &&)=delete
const zyppng::SyncRepoManager & ngMgr() const
Temporarily disable MediaChangeReport Sometimes helpful to suppress interactive messages connected to...
Repository type enumeration.
Definition RepoType.h:29
Service type enumeration.
Definition ServiceType.h:27
Url::asString() view options.
Definition UrlBase.h:40
#define ZYPP_LOCAL
Definition Globals.h:71