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 { /////////////////////////////////////////////////////////////////
32 * Parses \a repo_file and returns a list of \ref RepoInfo objects
33 * corresponding to repositories found within the file.
35 * \param repo_file Valid URL of the repo file.
36 * \return found list<RepoInfo>
38 * \throws MediaException If the access to the url fails
39 * \throws ParseException If the file parsing fails
40 * \throws Exception On other errors.
42 std::list<RepoInfo> readRepoFile(const Url & repo_file);
45 * Repo manager settings.
46 * Settings default to ZYpp global settings.
48 struct RepoManagerOptions
52 Pathname repoCachePath;
53 Pathname repoRawCachePath;
54 Pathname repoPackagesCachePath;
55 Pathname knownReposPath;
60 * \short creates and provides information about known sources.
65 friend std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
72 RepoManager( const RepoManagerOptions &options = RepoManagerOptions() );
76 enum RawMetadataRefreshPolicy
80 RefreshIfNeededIgnoreDelay
95 * \short List known repositories.
97 * The known repositories are read from
98 * \ref RepoManagerOptions::knownReposPath passed on the Ctor.
99 * Which defaults to ZYpp global settings.
100 * \return found list<RepoInfo>
102 std::list<RepoInfo> knownRepositories() const;
105 * \short Status of local metadata
107 RepoStatus metadataStatus( const RepoInfo &info ) const;
110 * Possibly return state of checkIfRefreshMEtadata function
112 enum RefreshCheckStatus {
113 REFRESH_NEEDED, /**< refresh is needed */
114 REPO_UP_TO_DATE, /**< repository not changed */
115 REPO_CHECK_DELAYED /**< refresh is delayed due to settings */
119 * Checks whether to refresh metadata for specified repository and url.
121 * The need for refresh is evaluated according to the following conditions,
124 * <li>the refresh policy (refresh may be forced)
125 * <li>the repo.refresh.delay ZConfig value compared to the difference between
126 * cached index file timestamp and actual time
127 * <li>the timestamp of cached repo index file compared to the remote
128 * index file timestamp.
131 * This method checks the status against the specified url only. If more
132 * baseurls are defined for in the RepoInfo, each one must be check
133 * individually. Example:
138 * // try urls one by one
139 * for ( RepoInfo::urls_const_iterator it = info.baseUrlsBegin();
140 * it != info.baseUrlsEnd(); ++it )
144 * // check whether to refresh metadata
145 * // if the check fails for this url, it throws, so another url will be checked
146 * if (checkIfToRefreshMetadata(info, *it, policy)!=RepoInfo::REFRESH_NEEDED)
149 * // do the actual refresh
151 * catch (const Exception & e)
154 * ERR << *it << " doesn't look good. Trying another url." << endl;
158 * handle("No more URLs.");
165 * \return state of repository
166 * \see RefreshCheckStatus
167 * \throws RepoUnknownTypeException
168 * \throws repo::RepoNoAliasException if can't figure an alias
169 * \throws Exception on unknown error
172 RefreshCheckStatus checkIfToRefreshMetadata( const RepoInfo &info,
174 RawMetadataRefreshPolicy policy = RefreshIfNeeded);
177 * \short Path where the metadata is downloaded and kept
179 * Given a repoinfo, tells where \ref RepoManager will download
180 * and keep the raw metadata.
182 * \param info Repository information
184 * \throws repo::RepoNoAliasException if can't figure an alias
186 Pathname metadataPath( const RepoInfo &info ) const;
189 * \short Refresh local raw cache
191 * Will try to download the metadata
193 * In case of falure the metadata remains
196 * \throws repo::RepoNoUrlException if no urls are available.
197 * \throws repo::RepoNoAliasException if can't figure an alias
198 * \throws repo::RepoUnknownTypeException if the metadata is unknown
199 * \throws repo::RepoException if the repository is invalid
200 * (no valid metadata found at any of baseurls)
202 void refreshMetadata( const RepoInfo &info,
203 RawMetadataRefreshPolicy policy = RefreshIfNeeded,
204 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
207 * \short Clean local metadata
209 * Empty local metadata.
211 * \throws repo::RepoNoAliasException if can't figure an alias
212 * \throws Exception on unknown error.
214 void cleanMetadata( const RepoInfo &info,
215 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
218 * \short Clean local package cache
220 * Empty local directory with downloaded packages
222 * \throws repo::RepoNoAliasException if can't figure an alias
223 * \throws Exception on unknown error.
225 void cleanPackages( const RepoInfo &info,
226 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
229 * \short Status of metadata cache
231 RepoStatus cacheStatus( const RepoInfo &info ) const;
234 * \short Refresh local cache
236 * Will try to build the cache from local metadata.
238 * If the cache exists it will be overwriten.
240 * \note the local metadata must be valid.
242 * \throws repo::RepoNoAliasException if can't figure
243 * an alias to look in cache
244 * \throws repo::RepoMetadataException if the metadata
245 * is not enough to build a cache (empty, incorrect, or
247 * \throws repo::RepoUnknownTypeException
248 * \throws parser::ParseException if parser encounters an error.
249 * \throws Exception on unknown error.
251 void buildCache( const RepoInfo &info,
252 CacheBuildPolicy policy = BuildIfNeeded,
253 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
256 * \short clean local cache
258 * Clean the cached version of the metadata
260 * \note the local metadata must be valid.
262 * \throws repo::RepoNoAliasException if can't figure an alias to look in cache
263 * \throws cache::CacheRecordNotFoundException if the cache could not be
264 * cleaned because of repository record not found.
265 * \throws Exception on unknown error.
267 void cleanCache( const RepoInfo &info,
268 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
271 * Clean target system (rpm db) cache.
273 void cleanTargetCache(const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc());
276 * \short Whether a repository exists in cache
278 * \param RepoInfo to be checked.
280 bool isCached( const RepoInfo &info ) const;
284 * \short Load resolvables into the pool
286 * Creating from cache requires that the repository is
287 * refreshed (metadata downloaded) and cached
289 * \throws repo::RepoNoAliasException if can't figure an alias to look in cache
290 * \throw RepoNotCachedException When the source is not cached.
292 void loadFromCache( const RepoInfo &info,
293 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
295 * \short Probe repo metadata type.
297 * \todo FIXME Should this be private?
299 repo::RepoType probe( const Url &url ) const;
303 * \short Adds a repository to the list of known repositories.
307 * \throws repo::RepoAlreadyExistsException If the repo clash some
308 * unique attribute like alias
309 * \throws RepoUnknownType If repository type can't be determined
310 * \throws RepoException If the access to the url fails (while probing).
311 * \throws Exception On other errors.
313 void addRepository( const RepoInfo &info,
314 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
317 * \short Adds repositores from a repo file to the list of known repositories.
318 * \param url Url of the repo file
320 * \throws repo::RepoAlreadyExistsException If the repo clash some
321 * unique attribute like alias
323 * \throws RepoAlreadyExistsException
324 * \throws MediaException If the access to the url fails
325 * \throws ParseException If the file parsing fails
326 * \throws RepoUnknownType If repository type can't be determined
327 * \throws RepoException ON other repository related errors
328 * \throws Exception On other errors.
330 void addRepositories( const Url &url,
331 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
333 * \short Remove the best matching repository from known repos list
335 * \throws RepoNotFoundException If no repo match
337 void removeRepository( const RepoInfo & info,
338 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
341 * \short Modify repository attributes
343 * \throws RepoAlreadyExistsException if the alias specified in newinfo
344 * is already used by another repository
345 * \throws RepoNotFoundException If no repo match
346 * \throws ParseException If the file parsing fails
347 * \throws Exception On other errors.
349 void modifyRepository( const std::string &alias,
350 const RepoInfo & newinfo,
351 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
354 * \short Find a matching repository info
356 * \note if multiple repositories incorrectly share the
357 * same alias, the first one found will be returned.
359 * \param alias Repository alias
360 * \param progressrcv Progress reporting function
361 * \return RepoInfo of the found repository
362 * \throws RepoNotFoundException If no repo match the alias
363 * \throws ParseException If the file parsing fails
364 * \throws Exception On other errors.
366 RepoInfo getRepositoryInfo( const std::string &alias,
367 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
370 * \short Find repository info by URL.
372 * \param url URL to find.
373 * \param urlview url::ViewOption to influence URL matching.
374 * \param progressrcv Progress receiver function.
375 * \return RepoInfo of the found repository.
377 * \note if multpile repositories incorrectly share the
378 * same URL, the first one found will be returned.
380 * \note the string representation of the URLs are compared.
381 * The \a urlview can be used to influence which
382 parts of the URL are to be compared.
384 * \throws RepoNotFoundException If no repo match
385 * \throws ParseException If the file parsing fails
386 * \throws Exception On other errors.
388 RepoInfo getRepositoryInfo( const Url & url,
389 const url::ViewOption & urlview = url::ViewOption::DEFAULTS,
390 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
393 RepoStatus rawMetadataStatus( const RepoInfo &info );
394 void setCacheStatus( const std::string &alias, const RepoStatus &status );
397 * Update timestamp of repository index file for the specified repository \a info.
398 * Used in \ref checkIfToRefreshMetadata() for repo.refresh.delay feature.
400 void touchIndexFile(const RepoInfo & info);
405 /** Pointer to implementation */
406 RWCOW_pointer<Impl> _pimpl;
408 ///////////////////////////////////////////////////////////////////
410 /** \relates RepoManager Stream output */
411 std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
413 /////////////////////////////////////////////////////////////////
415 ///////////////////////////////////////////////////////////////////
416 #endif // ZYPP2_REPOMANAGER_H