libzypp 17.38.3
RepoManager.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12
13#include "RepoManager.h"
14
15#include <iostream>
16#include <zypp-core/Digest.h>
17#include <zypp-core/ng/pipelines/Lift>
19#include <zypp/ng/context.h>
22
23#undef ZYPP_BASE_LOGGER_LOGGROUP
24#define ZYPP_BASE_LOGGER_LOGGROUP "zypp::repomanager"
25
26using std::endl;
27using std::string;
28using namespace zypp::repo;
29
30#define OPT_PROGRESS const ProgressData::ReceiverFnc & = ProgressData::ReceiverFnc()
31
33namespace zypp
34{
41 {
42 public:
43 Impl( zyppng::ContextRef &&ctx, RepoManagerOptions &&opt) {
44 _ngMgr = zyppng::RepoManager::create( std::move(ctx), std::move(opt) ).unwrap();
45 }
46
47 Impl(const Impl &) = delete;
48 Impl(Impl &&) = delete;
49 Impl &operator=(const Impl &) = delete;
50 Impl &operator=(Impl &&) = delete;
51
52 public:
53 const zyppng::RepoManager &ngMgr() const {
54 return *_ngMgr;
55 }
56
58 return *_ngMgr;
59 }
60
61 private:
62 zyppng::RepoManagerRef _ngMgr;
63
64 private:
65 friend Impl * rwcowClone<Impl>( const Impl * rhs );
67 Impl * clone() const
68 { return new Impl( zyppng::ContextRef(_ngMgr->zyppContext()), RepoManagerOptions(_ngMgr->options()) ); }
69 };
70
71
73 inline std::ostream & operator<<( std::ostream & str, const RepoManager::Impl & obj )
74 { return str << "RepoManager::Impl"; }
75
77 //
78 // CLASS NAME : RepoManager
79 //
81
83 : _pimpl( new Impl( zyppng::Context::defaultContext(), std::move(opt)) )
84 {}
85
88
90 { return _pimpl->ngMgr().repoEmpty(); }
91
93 { return _pimpl->ngMgr().repoSize(); }
94
96 { return _pimpl->ngMgr().repoBegin(); }
97
99 { return _pimpl->ngMgr().repoEnd(); }
100
101 RepoInfo RepoManager::getRepo( const std::string & alias ) const
102 { return _pimpl->ngMgr().getRepo( alias ); }
103
104 bool RepoManager::hasRepo( const std::string & alias ) const
105 { return _pimpl->ngMgr().hasRepo( alias ); }
106
107 std::string RepoManager::makeStupidAlias( const Url & url_r )
108 {
109 std::string ret( url_r.getScheme() );
110 if ( ret.empty() )
111 ret = "repo-";
112 else
113 ret += "-";
114
115 std::string host( url_r.getHost() );
116 if ( ! host.empty() )
117 {
118 ret += host;
119 ret += "-";
120 }
121
122 static Date::ValueType serial = Date::now();
123 ret += Digest::digest( Digest::sha1(), str::hexstring( ++serial ) +url_r.asCompleteString() ).substr(0,8);
124 return ret;
125 }
126
128 { return _pimpl->ngMgr().metadataStatus( info ).unwrap(); }
129
131 { return _pimpl->ngMgr().checkIfToRefreshMetadata( info, origin, policy ).unwrap(); }
132
134 { return _pimpl->ngMgr().checkIfToRefreshMetadata( info, url, policy ).unwrap(); }
135
137 { return _pimpl->ngMgr().metadataPath( info ).unwrap(); }
138
140 { return _pimpl->ngMgr().packagesPath( info ).unwrap(); }
141
143 {
144 // Suppress (interactive) media::MediaChangeReport if we have fallback URLs
146 return _pimpl->ngMgr().refreshMetadata( info, policy, nullptr ).unwrap();
147 }
148
149 void RepoManager::cleanMetadata( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv )
150 { return _pimpl->ngMgr().cleanMetadata( info, nullptr ).unwrap(); }
151
152 void RepoManager::cleanPackages( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv )
153 { return _pimpl->ngMgr().cleanPackages( info, nullptr ).unwrap(); }
154
156 { return _pimpl->ngMgr().cacheStatus( info ).unwrap(); }
157
158 void RepoManager::buildCache( const RepoInfo &info, CacheBuildPolicy policy, const ProgressData::ReceiverFnc & progressrcv )
159 {
161 auto adapt = zyppng::ProgressObserverAdaptor( progressrcv, report );
162 return _pimpl->ngMgr().buildCache( info, policy, adapt.observer() ).unwrap();
163 }
164
165 void RepoManager::cleanCache( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv )
166 { return _pimpl->ngMgr().cleanCache( info, nullptr ).unwrap(); }
167
168 bool RepoManager::isCached( const RepoInfo &info ) const
169 { return _pimpl->ngMgr().isCached( info ).unwrap(); }
170
171 void RepoManager::loadFromCache( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv )
172 { return _pimpl->ngMgr().loadFromCache( info, nullptr ).unwrap(); }
173
175 { return _pimpl->ngMgr().cleanCacheDirGarbage( nullptr ).unwrap(); }
176
177 repo::RepoType RepoManager::probe( const Url & url, const Pathname & path ) const
178 { return _pimpl->ngMgr().probe( {url}, path ).unwrap(); }
179
181 { return _pimpl->ngMgr().probe( {url} ).unwrap(); }
182
183 void RepoManager::addRepository( const RepoInfo &info, const TriBool & forcedProbe, const ProgressData::ReceiverFnc & progressrcv )
184 {
186 auto adapt = zyppng::ProgressObserverAdaptor( progressrcv, report );
187 RepoInfo updatedRepo = _pimpl->ngMgr().addRepository( info, adapt.observer(), forcedProbe ).unwrap();
188
189 // We should fix the API as we must inject those paths
190 // into the repoinfo in order to keep it usable.
191 RepoInfo & oinfo( const_cast<RepoInfo &>(info) );
192 oinfo.setFilepath( updatedRepo.filepath() );
193 oinfo.setMetadataPath( zyppng::rawcache_path_for_repoinfo( _pimpl->ngMgr().options(), updatedRepo ).unwrap() );
194 oinfo.setPackagesPath( zyppng::packagescache_path_for_repoinfo( _pimpl->ngMgr().options(), updatedRepo ).unwrap() );
195 }
196
197 void RepoManager::addRepository( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv )
198 { addRepository( info, indeterminate, progressrcv ); }
199
201 { return _pimpl->ngMgr().addRepositories( url, nullptr ).unwrap(); }
202
203 void RepoManager::removeRepository( const RepoInfo & info, const ProgressData::ReceiverFnc & progressrcv )
204 {
206 auto adapt = zyppng::ProgressObserverAdaptor( progressrcv, report );
207 return _pimpl->ngMgr().removeRepository( info, adapt.observer() ).unwrap();
208 }
209
210 void RepoManager::modifyRepository( const std::string &alias, const RepoInfo & newinfo, const ProgressData::ReceiverFnc & progressrcv )
211 {
212 RepoInfo updated = _pimpl->ngMgr().modifyRepository( alias, newinfo, nullptr ).unwrap();
213 // We should fix the API as we must inject those paths
214 // into the repoinfo in order to keep it usable.
215 RepoInfo & oinfo( const_cast<RepoInfo &>(newinfo) );
216 oinfo.setFilepath( updated.filepath());
217 oinfo.setMetadataPath( zyppng::rawcache_path_for_repoinfo( _pimpl->ngMgr().options(), updated ).unwrap() );
218 oinfo.setPackagesPath( zyppng::packagescache_path_for_repoinfo( _pimpl->ngMgr().options(), updated ).unwrap() );
219 }
220
221 RepoInfo RepoManager::getRepositoryInfo( const std::string &alias, const ProgressData::ReceiverFnc & progressrcv )
222 { return _pimpl->ngMgr().getRepositoryInfo( alias ).unwrap(); }
223
225 { return _pimpl->ngMgr().getRepositoryInfo( url, urlview ).unwrap(); }
226
228 { return _pimpl->ngMgr().serviceEmpty(); }
229
231 { return _pimpl->ngMgr().serviceSize(); }
232
234 { return _pimpl->ngMgr().serviceBegin(); }
235
237 { return _pimpl->ngMgr().serviceEnd(); }
238
239 ServiceInfo RepoManager::getService( const std::string & alias ) const
240 { return _pimpl->ngMgr().getService( alias ); }
241
242 bool RepoManager::hasService( const std::string & alias ) const
243 { return _pimpl->ngMgr().hasService( alias ); }
244
246 { return _pimpl->ngMgr().probeService( url ).unwrap(); }
247
248 void RepoManager::addService( const std::string & alias, const Url& url )
249 { return _pimpl->ngMgr().addService( alias, url ).unwrap(); }
250
251 void RepoManager::addService( const ServiceInfo & service )
252 { return _pimpl->ngMgr().addService( service ).unwrap(); }
253
254 void RepoManager::removeService( const std::string & alias )
255 { return _pimpl->ngMgr().removeService( alias ).unwrap(); }
256
258 { return _pimpl->ngMgr().removeService( service ).unwrap(); }
259
261 { return _pimpl->ngMgr().refreshServices( options_r ).unwrap(); }
262
263 void RepoManager::refreshService( const std::string & alias, const RefreshServiceOptions & options_r )
264 { return _pimpl->ngMgr().refreshService( alias, options_r ).unwrap(); }
265
266 void RepoManager::refreshService( const ServiceInfo & service, const RefreshServiceOptions & options_r )
267 { return _pimpl->ngMgr().refreshService( service, options_r ).unwrap(); }
268
269 void RepoManager::modifyService( const std::string & oldAlias, const ServiceInfo & service )
270 { return _pimpl->ngMgr().modifyService( oldAlias, service ).unwrap(); }
271
273 { (void) _pimpl->ngMgr().refreshGeoIp( urls ); }
274
276
277 std::ostream & operator<<( std::ostream & str, const RepoManager & obj )
278 { return str << *obj._pimpl; }
279
280 std::list<RepoInfo> readRepoFile(const Url &repo_file)
281 {
283 }
284
286} // namespace zypp
#define ZYPP_LOCAL
Definition Globals.h:71
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:239
static const std::string & sha1()
sha1
Definition Digest.cc:45
bool hasFallbackUrls() const
Whether this set contains more than one Url in total (authorities or mirrors).
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
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
MirroredOriginSet repoOrigins() const
The repodata origins.
Definition RepoInfo.cc:733
void setPackagesPath(const Pathname &path)
set the path where the local packages are stored
Definition RepoInfo.cc:756
void setMetadataPath(const Pathname &path)
Set the path where the local metadata is stored.
Definition RepoInfo.cc:753
std::list< Url > url_set
Definition RepoInfo.h:108
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:69
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.
RepoManagerFlags::RawMetadataRefreshPolicy RawMetadataRefreshPolicy
Definition RepoManager.h:82
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:70
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.
RepoManagerFlags::CacheBuildPolicy CacheBuildPolicy
Definition RepoManager.h:87
ServiceConstIterator serviceBegin() const
Iterator to first service in internal storage.
RepoManagerFlags::RefreshCheckStatus RefreshCheckStatus
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:75
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:99
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:74
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:93
std::string getScheme() const
Returns the scheme name of the URL.
Definition Url.cc:560
std::string asCompleteString() const
Returns a complete string representation of the Url object.
Definition Url.cc:532
std::string getHost(EEncoding eflag=zypp::url::E_DECODED) const
Returns the hostname or IP from the URL authority.
Definition Url.cc:615
void setFilepath(const Pathname &filename)
set the path to the .repo file
Pathname filepath() const
File where this repo was read from.
static ContextRef defaultContext()
Definition context.cc:26
The RepoManager class Provides knowledge and methods to maintain repo settings and metadata for a giv...
static expected< std::shared_ptr< RepoManager > > create(Args &&...args)
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
Definition String.h:31
Definition ansi.h:855
String related utilities and Regular expression matching.
std::string hexstring(char n, int w=4)
Definition String.h:325
Url details namespace.
Definition UrlBase.cc:58
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...
MaybeAwaitable< 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.
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(const Impl &)=delete
std::ostream & operator<<(std::ostream &str, const RepoManager::Impl &obj)
Stream output.
friend Impl * rwcowClone(const Impl *rhs)
zyppng::RepoManager & ngMgr()
Impl(Impl &&)=delete
Impl * clone() const
clone for RWCOW_pointer
zyppng::RepoManagerRef _ngMgr
const zyppng::RepoManager & ngMgr() const
Impl(zyppng::ContextRef &&ctx, RepoManagerOptions &&opt)
Impl & operator=(Impl &&)=delete
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:41