1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/RepoManager.h
12 #ifndef ZYPP_REPOMANAGER_H
13 #define ZYPP_REPOMANAGER_H
18 #include "zypp/base/PtrTypes.h"
19 #include "zypp/Pathname.h"
20 #include "zypp/ZConfig.h"
21 #include "zypp/RepoInfo.h"
22 #include "zypp/repo/RepoException.h"
23 #include "zypp/repo/RepoType.h"
24 #include "zypp/RepoStatus.h"
25 #include "zypp/ProgressData.h"
27 ///////////////////////////////////////////////////////////////////
29 { /////////////////////////////////////////////////////////////////
30 class Service; //predef
33 * Parses \a repo_file and returns a list of \ref RepoInfo objects
34 * corresponding to repositories found within the file.
36 * \param repo_file Valid URL of the repo file.
37 * \return found list<RepoInfo>
39 * \throws MediaException If the access to the url fails
40 * \throws ParseException If the file parsing fails
41 * \throws Exception On other errors.
43 std::list<RepoInfo> readRepoFile(const Url & repo_file);
46 * Repo manager settings.
47 * Settings default to ZYpp global settings.
49 struct RepoManagerOptions
51 /** Default ctor following \ref ZConfig global settings.
52 * If an optional \c root_r directory is given, all paths will
53 * be prefixed accordingly.
55 * root_r\repoCachePath
58 * \repoPackagesCachePath
62 RepoManagerOptions( const Pathname & root_r = Pathname() );
64 /** Test setup adjusting all paths to be located below one \c root_r directory.
66 * root_r\ - repoCachePath
67 * \raw - repoRawCachePath
68 * \solv - repoSolvCachePath
69 * \packages - repoPackagesCachePath
70 * \repos.d - knownReposPath
73 static RepoManagerOptions makeTestSetup( const Pathname & root_r );
75 Pathname repoCachePath;
76 Pathname repoRawCachePath;
77 Pathname repoSolvCachePath;
78 Pathname repoPackagesCachePath;
79 Pathname knownReposPath;
80 Pathname knownServicesPath;
87 * \short creates and provides information about known sources.
92 friend std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
98 /** service typedefs */
99 typedef std::set<Service> ServiceSet;
100 typedef ServiceSet::const_iterator ServiceConstIterator;
101 typedef ServiceSet::size_type ServiceSizeType;
104 RepoManager( const RepoManagerOptions &options = RepoManagerOptions() );
108 enum RawMetadataRefreshPolicy
112 RefreshIfNeededIgnoreDelay
115 enum CacheBuildPolicy
121 enum RepoRemovePolicy
127 * \short List known repositories.
129 * The known repositories are read from
130 * \ref RepoManagerOptions::knownReposPath passed on the Ctor.
131 * Which defaults to ZYpp global settings.
132 * \return found list<RepoInfo>
134 std::list<RepoInfo> knownRepositories() const;
137 * \short Status of local metadata
139 RepoStatus metadataStatus( const RepoInfo &info ) const;
142 * Possibly return state of checkIfRefreshMEtadata function
144 enum RefreshCheckStatus {
145 REFRESH_NEEDED, /**< refresh is needed */
146 REPO_UP_TO_DATE, /**< repository not changed */
147 REPO_CHECK_DELAYED /**< refresh is delayed due to settings */
151 * Checks whether to refresh metadata for specified repository and url.
153 * The need for refresh is evaluated according to the following conditions,
156 * <li>the refresh policy (refresh may be forced)
157 * <li>the repo.refresh.delay ZConfig value compared to the difference between
158 * cached index file timestamp and actual time
159 * <li>the timestamp of cached repo index file compared to the remote
160 * index file timestamp.
163 * This method checks the status against the specified url only. If more
164 * baseurls are defined for in the RepoInfo, each one must be check
165 * individually. Example:
170 * // try urls one by one
171 * for ( RepoInfo::urls_const_iterator it = info.baseUrlsBegin();
172 * it != info.baseUrlsEnd(); ++it )
176 * // check whether to refresh metadata
177 * // if the check fails for this url, it throws, so another url will be checked
178 * if (checkIfToRefreshMetadata(info, *it, policy)!=RepoInfo::REFRESH_NEEDED)
181 * // do the actual refresh
183 * catch (const Exception & e)
186 * ERR << *it << " doesn't look good. Trying another url." << endl;
190 * handle("No more URLs.");
197 * \return state of repository
198 * \see RefreshCheckStatus
199 * \throws RepoUnknownTypeException
200 * \throws repo::RepoNoAliasException if can't figure an alias
201 * \throws Exception on unknown error
204 RefreshCheckStatus checkIfToRefreshMetadata( const RepoInfo &info,
206 RawMetadataRefreshPolicy policy = RefreshIfNeeded);
209 * \short Path where the metadata is downloaded and kept
211 * Given a repoinfo, tells where \ref RepoManager will download
212 * and keep the raw metadata.
214 * \param info Repository information
216 * \throws repo::RepoNoAliasException if can't figure an alias
218 Pathname metadataPath( const RepoInfo &info ) const;
222 * \short Path where the rpm packages are downloaded and kept
224 * Given a repoinfo, tells where \ref RepoProvidePackage will download
225 * and keep the .rpm files.
227 * \param info Repository information
229 * \throws repo::RepoNoAliasException if can't figure an alias
231 Pathname packagesPath( const RepoInfo &info ) const;
235 * \short Refresh local raw cache
237 * Will try to download the metadata
239 * In case of falure the metadata remains
242 * \throws repo::RepoNoUrlException if no urls are available.
243 * \throws repo::RepoNoAliasException if can't figure an alias
244 * \throws repo::RepoUnknownTypeException if the metadata is unknown
245 * \throws repo::RepoException if the repository is invalid
246 * (no valid metadata found at any of baseurls)
248 void refreshMetadata( const RepoInfo &info,
249 RawMetadataRefreshPolicy policy = RefreshIfNeeded,
250 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
253 * \short Clean local metadata
255 * Empty local metadata.
257 * \throws repo::RepoNoAliasException if can't figure an alias
258 * \throws Exception on unknown error.
260 void cleanMetadata( const RepoInfo &info,
261 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
264 * \short Clean local package cache
266 * Empty local directory with downloaded packages
268 * \throws repo::RepoNoAliasException if can't figure an alias
269 * \throws Exception on unknown error.
271 void cleanPackages( const RepoInfo &info,
272 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
275 * \short Status of metadata cache
277 RepoStatus cacheStatus( const RepoInfo &info ) const;
280 * \short Refresh local cache
282 * Will try to build the cache from local metadata.
284 * If the cache exists it will be overwriten.
286 * \note the local metadata must be valid.
288 * \throws repo::RepoNoAliasException if can't figure
289 * an alias to look in cache
290 * \throws repo::RepoMetadataException if the metadata
291 * is not enough to build a cache (empty, incorrect, or
293 * \throws repo::RepoUnknownTypeException
294 * \throws parser::ParseException if parser encounters an error.
295 * \throws Exception on unknown error.
297 void buildCache( const RepoInfo &info,
298 CacheBuildPolicy policy = BuildIfNeeded,
299 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
302 * \short clean local cache
304 * Clean the cached version of the metadata
306 * \note the local metadata must be valid.
308 * \throws repo::RepoNoAliasException if can't figure an alias to look in cache
309 * \throws cache::CacheRecordNotFoundException if the cache could not be
310 * cleaned because of repository record not found.
311 * \throws Exception on unknown error.
313 void cleanCache( const RepoInfo &info,
314 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
317 * \short Whether a repository exists in cache
319 * \param RepoInfo to be checked.
321 bool isCached( const RepoInfo &info ) const;
325 * \short Load resolvables into the pool
327 * Creating from cache requires that the repository is
328 * refreshed (metadata downloaded) and cached
330 * \throws repo::RepoNoAliasException if can't figure an alias to look in cache
331 * \throw RepoNotCachedException When the source is not cached.
333 void loadFromCache( const RepoInfo &info,
334 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
336 * \short Probe repo metadata type.
338 * \todo FIXME Should this be private?
340 repo::RepoType probe( const Url &url ) const;
344 * \short Adds a repository to the list of known repositories.
348 * \throws repo::RepoAlreadyExistsException If the repo clash some
349 * unique attribute like alias
350 * \throws RepoUnknownType If repository type can't be determined
351 * \throws RepoException If the access to the url fails (while probing).
352 * \throws Exception On other errors.
354 void addRepository( const RepoInfo &info,
355 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
358 * \short Adds repositores from a repo file to the list of known repositories.
359 * \param url Url of the repo file
361 * \throws repo::RepoAlreadyExistsException If the repo clash some
362 * unique attribute like alias
364 * \throws RepoAlreadyExistsException
365 * \throws MediaException If the access to the url fails
366 * \throws ParseException If the file parsing fails
367 * \throws RepoUnknownType If repository type can't be determined
368 * \throws RepoException ON other repository related errors
369 * \throws Exception On other errors.
371 void addRepositories( const Url &url,
372 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
374 * \short Remove the best matching repository from known repos list
376 * \throws RepoNotFoundException If no repo match
378 void removeRepository( const RepoInfo & info,
379 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
382 * \short Modify repository attributes
384 * \throws RepoAlreadyExistsException if the alias specified in newinfo
385 * is already used by another repository
386 * \throws RepoNotFoundException If no repo match
387 * \throws ParseException If the file parsing fails
388 * \throws Exception On other errors.
390 void modifyRepository( const std::string &alias,
391 const RepoInfo & newinfo,
392 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
395 * \short Find a matching repository info
397 * \note if multiple repositories incorrectly share the
398 * same alias, the first one found will be returned.
400 * \param alias Repository alias
401 * \param progressrcv Progress reporting function
402 * \return RepoInfo of the found repository
403 * \throws RepoNotFoundException If no repo match the alias
404 * \throws ParseException If the file parsing fails
405 * \throws Exception On other errors.
407 RepoInfo getRepositoryInfo( const std::string &alias,
408 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
411 * \short Find repository info by URL.
413 * \param url URL to find.
414 * \param urlview url::ViewOption to influence URL matching.
415 * \param progressrcv Progress receiver function.
416 * \return RepoInfo of the found repository.
418 * \note if multpile repositories incorrectly share the
419 * same URL, the first one found will be returned.
421 * \note the string representation of the URLs are compared.
422 * The \a urlview can be used to influence which
423 parts of the URL are to be compared.
425 * \throws RepoNotFoundException If no repo match
426 * \throws ParseException If the file parsing fails
427 * \throws Exception On other errors.
429 RepoInfo getRepositoryInfo( const Url & url,
430 const url::ViewOption & urlview = url::ViewOption::DEFAULTS,
431 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
433 void addService( const std::string& name, const Url& url );
435 void removeService( const std::string& name );
437 bool serviceEmpty() const;
439 ServiceSizeType serviceSize() const;
441 ServiceConstIterator serviceBegin() const;
443 ServiceConstIterator serviceEnd() const;
445 const Service& getService( const std::string& name ) const;
447 void refreshServices();
450 * modify service, except name change
451 * ( you need remove and add if you want change name )
453 void modifyService(const Service& service) const;
456 RepoStatus rawMetadataStatus( const RepoInfo &info );
457 void setCacheStatus( const RepoInfo &info, const RepoStatus &status );
460 * Update timestamp of repository index file for the specified repository \a info.
461 * Used in \ref checkIfToRefreshMetadata() for repo.refresh.delay feature.
463 void touchIndexFile(const RepoInfo & info);
468 /** Pointer to implementation */
469 RWCOW_pointer<Impl> _pimpl;
471 ///////////////////////////////////////////////////////////////////
473 /** \relates RepoManager Stream output */
474 std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
476 /////////////////////////////////////////////////////////////////
478 ///////////////////////////////////////////////////////////////////
479 #endif // ZYPP2_REPOMANAGER_H