libzypp 17.37.17
RepoManager.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12
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 };
68
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
91 { return _pimpl->ngMgr().repoSize(); }
92
94 { return _pimpl->ngMgr().repoBegin(); }
95
97 { return _pimpl->ngMgr().repoEnd(); }
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
129 { return _pimpl->ngMgr().checkIfToRefreshMetadata( info, origin, policy ).unwrap(); }
130
132 { return _pimpl->ngMgr().checkIfToRefreshMetadata( info, url, policy ).unwrap(); }
133
135 { return _pimpl->ngMgr().metadataPath( info ).unwrap(); }
136
138 { return _pimpl->ngMgr().packagesPath( info ).unwrap(); }
139
141 {
142 // Suppress (interactive) media::MediaChangeReport if we have fallback URLs
144 return _pimpl->ngMgr().refreshMetadata( info, policy, nullptr ).unwrap();
145 }
146
147 void RepoManager::cleanMetadata( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv )
148 { return _pimpl->ngMgr().cleanMetadata( info, nullptr ).unwrap(); }
149
150 void RepoManager::cleanPackages( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv )
151 { return _pimpl->ngMgr().cleanPackages( info, nullptr ).unwrap(); }
152
154 { return _pimpl->ngMgr().cacheStatus( info ).unwrap(); }
155
156 void RepoManager::buildCache( const RepoInfo &info, CacheBuildPolicy policy, const ProgressData::ReceiverFnc & progressrcv )
157 {
159 auto adapt = zyppng::ProgressObserverAdaptor( progressrcv, report );
160 return _pimpl->ngMgr().buildCache( info, policy, adapt.observer() ).unwrap();
161 }
162
163 void RepoManager::cleanCache( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv )
164 { return _pimpl->ngMgr().cleanCache( info, nullptr ).unwrap(); }
165
166 bool RepoManager::isCached( const RepoInfo &info ) const
167 { return _pimpl->ngMgr().isCached( info ).unwrap(); }
168
169 void RepoManager::loadFromCache( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv )
170 { return _pimpl->ngMgr().loadFromCache( info, nullptr ).unwrap(); }
171
173 { return _pimpl->ngMgr().cleanCacheDirGarbage( nullptr ).unwrap(); }
174
175 repo::RepoType RepoManager::probe( const Url & url, const Pathname & path ) const
176 { return _pimpl->ngMgr().probe( {url}, path ).unwrap(); }
177
179 { return _pimpl->ngMgr().probe( {url} ).unwrap(); }
180
181 void RepoManager::addRepository( const RepoInfo &info, const TriBool & forcedProbe, const ProgressData::ReceiverFnc & progressrcv )
182 {
184 auto adapt = zyppng::ProgressObserverAdaptor( progressrcv, report );
185 RepoInfo updatedRepo = _pimpl->ngMgr().addRepository( info, adapt.observer(), forcedProbe ).unwrap();
186
187 // We should fix the API as we must inject those paths
188 // into the repoinfo in order to keep it usable.
189 RepoInfo & oinfo( const_cast<RepoInfo &>(info) );
190 oinfo.setFilepath( updatedRepo.filepath() );
191 oinfo.setMetadataPath( zyppng::rawcache_path_for_repoinfo( _pimpl->ngMgr().options(), updatedRepo ).unwrap() );
192 oinfo.setPackagesPath( zyppng::packagescache_path_for_repoinfo( _pimpl->ngMgr().options(), updatedRepo ).unwrap() );
193 }
194
195 void RepoManager::addRepository( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv )
196 { addRepository( info, indeterminate, progressrcv ); }
197
199 { return _pimpl->ngMgr().addRepositories( url, nullptr ).unwrap(); }
200
201 void RepoManager::removeRepository( const RepoInfo & info, const ProgressData::ReceiverFnc & progressrcv )
202 {
204 auto adapt = zyppng::ProgressObserverAdaptor( progressrcv, report );
205 return _pimpl->ngMgr().removeRepository( info, adapt.observer() ).unwrap();
206 }
207
208 void RepoManager::modifyRepository( const std::string &alias, const RepoInfo & newinfo, const ProgressData::ReceiverFnc & progressrcv )
209 {
210 RepoInfo updated = _pimpl->ngMgr().modifyRepository( alias, newinfo, nullptr ).unwrap();
211 // We should fix the API as we must inject those paths
212 // into the repoinfo in order to keep it usable.
213 RepoInfo & oinfo( const_cast<RepoInfo &>(newinfo) );
214 oinfo.setFilepath( updated.filepath());
215 oinfo.setMetadataPath( zyppng::rawcache_path_for_repoinfo( _pimpl->ngMgr().options(), updated ).unwrap() );
216 oinfo.setPackagesPath( zyppng::packagescache_path_for_repoinfo( _pimpl->ngMgr().options(), updated ).unwrap() );
217 }
218
219 RepoInfo RepoManager::getRepositoryInfo( const std::string &alias, const ProgressData::ReceiverFnc & progressrcv )
220 { return _pimpl->ngMgr().getRepositoryInfo( alias ).unwrap(); }
221
223 { return _pimpl->ngMgr().getRepositoryInfo( url, urlview ).unwrap(); }
224
226 { return _pimpl->ngMgr().serviceEmpty(); }
227
229 { return _pimpl->ngMgr().serviceSize(); }
230
232 { return _pimpl->ngMgr().serviceBegin(); }
233
235 { return _pimpl->ngMgr().serviceEnd(); }
236
237 ServiceInfo RepoManager::getService( const std::string & alias ) const
238 { return _pimpl->ngMgr().getService( alias ); }
239
240 bool RepoManager::hasService( const std::string & alias ) const
241 { return _pimpl->ngMgr().hasService( alias ); }
242
244 { return _pimpl->ngMgr().probeService( url ).unwrap(); }
245
246 void RepoManager::addService( const std::string & alias, const Url& url )
247 { return _pimpl->ngMgr().addService( alias, url ).unwrap(); }
248
249 void RepoManager::addService( const ServiceInfo & service )
250 { return _pimpl->ngMgr().addService( service ).unwrap(); }
251
252 void RepoManager::removeService( const std::string & alias )
253 { return _pimpl->ngMgr().removeService( alias ).unwrap(); }
254
256 { return _pimpl->ngMgr().removeService( service ).unwrap(); }
257
259 { return _pimpl->ngMgr().refreshServices( options_r ).unwrap(); }
260
261 void RepoManager::refreshService( const std::string & alias, const RefreshServiceOptions & options_r )
262 { return _pimpl->ngMgr().refreshService( alias, options_r ).unwrap(); }
263
264 void RepoManager::refreshService( const ServiceInfo & service, const RefreshServiceOptions & options_r )
265 { return _pimpl->ngMgr().refreshService( service, options_r ).unwrap(); }
266
267 void RepoManager::modifyService( const std::string & oldAlias, const ServiceInfo & service )
268 { return _pimpl->ngMgr().modifyService( oldAlias, service ).unwrap(); }
269
271 { (void) _pimpl->ngMgr().refreshGeoIp( urls ); }
272
274
275 std::ostream & operator<<( std::ostream & str, const RepoManager & obj )
276 { return str << *obj._pimpl; }
277
278 std::list<RepoInfo> readRepoFile(const Url &repo_file)
279 {
281 }
282
284} // 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: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:697
void setPackagesPath(const Pathname &path)
set the path where the local packages are stored
Definition RepoInfo.cc:720
void setMetadataPath(const Pathname &path)
Set the path where the local metadata is stored.
Definition RepoInfo.cc:717
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:551
std::string asCompleteString() const
Returns a complete string representation of the Url object.
Definition Url.cc:523
std::string getHost(EEncoding eflag=zypp::url::E_DECODED) const
Returns the hostname or IP from the URL authority.
Definition Url.cc:606
void setFilepath(const Pathname &filename)
set the path to the .repo file
Pathname filepath() const
File where this repo was read from.
static expected< std::shared_ptr< RepoManager< SyncContextRef > > > create(Args &&...args)
static SyncContextRef defaultContext()
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
Definition String.h:31
Definition Arch.h:364
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...
AsyncOpRef< expected< std::list< RepoInfo > > > readRepoFile(ContextRef ctx, zypp::Url repoFileUrl)
RepoManager< SyncContextRef > SyncRepoManager
Definition repomanager.h:48
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:49
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.
friend Impl * rwcowClone(const Impl *rhs)
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:41
#define ZYPP_LOCAL
Definition Globals.h:71