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
50 /** Default ctor following \ref ZConfig global settings. */
53 /** Test setup adjusting all paths to be located below one \c root_r directory.
55 * root_r\ - repoCachePath
56 * \raw - repoRawCachePath
57 * \solv - repoSolvCachePath
58 * \packages - repoPackagesCachePath
59 * \repos.d - knownReposPath
62 static RepoManagerOptions makeTestSetup( const Pathname & root_r );
64 Pathname repoCachePath;
65 Pathname repoRawCachePath;
66 Pathname repoSolvCachePath;
67 Pathname repoPackagesCachePath;
68 Pathname knownReposPath;
75 * \short creates and provides information about known sources.
80 friend std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
87 RepoManager( const RepoManagerOptions &options = RepoManagerOptions() );
91 enum RawMetadataRefreshPolicy
95 RefreshIfNeededIgnoreDelay
104 enum RepoRemovePolicy
110 * \short List known repositories.
112 * The known repositories are read from
113 * \ref RepoManagerOptions::knownReposPath passed on the Ctor.
114 * Which defaults to ZYpp global settings.
115 * \return found list<RepoInfo>
117 std::list<RepoInfo> knownRepositories() const;
120 * \short Status of local metadata
122 RepoStatus metadataStatus( const RepoInfo &info ) const;
125 * Possibly return state of checkIfRefreshMEtadata function
127 enum RefreshCheckStatus {
128 REFRESH_NEEDED, /**< refresh is needed */
129 REPO_UP_TO_DATE, /**< repository not changed */
130 REPO_CHECK_DELAYED /**< refresh is delayed due to settings */
134 * Checks whether to refresh metadata for specified repository and url.
136 * The need for refresh is evaluated according to the following conditions,
139 * <li>the refresh policy (refresh may be forced)
140 * <li>the repo.refresh.delay ZConfig value compared to the difference between
141 * cached index file timestamp and actual time
142 * <li>the timestamp of cached repo index file compared to the remote
143 * index file timestamp.
146 * This method checks the status against the specified url only. If more
147 * baseurls are defined for in the RepoInfo, each one must be check
148 * individually. Example:
153 * // try urls one by one
154 * for ( RepoInfo::urls_const_iterator it = info.baseUrlsBegin();
155 * it != info.baseUrlsEnd(); ++it )
159 * // check whether to refresh metadata
160 * // if the check fails for this url, it throws, so another url will be checked
161 * if (checkIfToRefreshMetadata(info, *it, policy)!=RepoInfo::REFRESH_NEEDED)
164 * // do the actual refresh
166 * catch (const Exception & e)
169 * ERR << *it << " doesn't look good. Trying another url." << endl;
173 * handle("No more URLs.");
180 * \return state of repository
181 * \see RefreshCheckStatus
182 * \throws RepoUnknownTypeException
183 * \throws repo::RepoNoAliasException if can't figure an alias
184 * \throws Exception on unknown error
187 RefreshCheckStatus checkIfToRefreshMetadata( const RepoInfo &info,
189 RawMetadataRefreshPolicy policy = RefreshIfNeeded);
192 * \short Path where the metadata is downloaded and kept
194 * Given a repoinfo, tells where \ref RepoManager will download
195 * and keep the raw metadata.
197 * \param info Repository information
199 * \throws repo::RepoNoAliasException if can't figure an alias
201 Pathname metadataPath( const RepoInfo &info ) const;
204 * \short Refresh local raw cache
206 * Will try to download the metadata
208 * In case of falure the metadata remains
211 * \throws repo::RepoNoUrlException if no urls are available.
212 * \throws repo::RepoNoAliasException if can't figure an alias
213 * \throws repo::RepoUnknownTypeException if the metadata is unknown
214 * \throws repo::RepoException if the repository is invalid
215 * (no valid metadata found at any of baseurls)
217 void refreshMetadata( const RepoInfo &info,
218 RawMetadataRefreshPolicy policy = RefreshIfNeeded,
219 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
222 * \short Clean local metadata
224 * Empty local metadata.
226 * \throws repo::RepoNoAliasException if can't figure an alias
227 * \throws Exception on unknown error.
229 void cleanMetadata( const RepoInfo &info,
230 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
233 * \short Clean local package cache
235 * Empty local directory with downloaded packages
237 * \throws repo::RepoNoAliasException if can't figure an alias
238 * \throws Exception on unknown error.
240 void cleanPackages( const RepoInfo &info,
241 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
244 * \short Status of metadata cache
246 RepoStatus cacheStatus( const RepoInfo &info ) const;
249 * \short Refresh local cache
251 * Will try to build the cache from local metadata.
253 * If the cache exists it will be overwriten.
255 * \note the local metadata must be valid.
257 * \throws repo::RepoNoAliasException if can't figure
258 * an alias to look in cache
259 * \throws repo::RepoMetadataException if the metadata
260 * is not enough to build a cache (empty, incorrect, or
262 * \throws repo::RepoUnknownTypeException
263 * \throws parser::ParseException if parser encounters an error.
264 * \throws Exception on unknown error.
266 void buildCache( const RepoInfo &info,
267 CacheBuildPolicy policy = BuildIfNeeded,
268 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
271 * \short clean local cache
273 * Clean the cached version of the metadata
275 * \note the local metadata must be valid.
277 * \throws repo::RepoNoAliasException if can't figure an alias to look in cache
278 * \throws cache::CacheRecordNotFoundException if the cache could not be
279 * cleaned because of repository record not found.
280 * \throws Exception on unknown error.
282 void cleanCache( const RepoInfo &info,
283 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
286 * \short Whether a repository exists in cache
288 * \param RepoInfo to be checked.
290 bool isCached( const RepoInfo &info ) const;
294 * \short Load resolvables into the pool
296 * Creating from cache requires that the repository is
297 * refreshed (metadata downloaded) and cached
299 * \throws repo::RepoNoAliasException if can't figure an alias to look in cache
300 * \throw RepoNotCachedException When the source is not cached.
302 void loadFromCache( const RepoInfo &info,
303 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
305 * \short Probe repo metadata type.
307 * \todo FIXME Should this be private?
309 repo::RepoType probe( const Url &url ) const;
313 * \short Adds a repository to the list of known repositories.
317 * \throws repo::RepoAlreadyExistsException If the repo clash some
318 * unique attribute like alias
319 * \throws RepoUnknownType If repository type can't be determined
320 * \throws RepoException If the access to the url fails (while probing).
321 * \throws Exception On other errors.
323 void addRepository( const RepoInfo &info,
324 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
327 * \short Adds repositores from a repo file to the list of known repositories.
328 * \param url Url of the repo file
330 * \throws repo::RepoAlreadyExistsException If the repo clash some
331 * unique attribute like alias
333 * \throws RepoAlreadyExistsException
334 * \throws MediaException If the access to the url fails
335 * \throws ParseException If the file parsing fails
336 * \throws RepoUnknownType If repository type can't be determined
337 * \throws RepoException ON other repository related errors
338 * \throws Exception On other errors.
340 void addRepositories( const Url &url,
341 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
343 * \short Remove the best matching repository from known repos list
345 * \throws RepoNotFoundException If no repo match
347 void removeRepository( const RepoInfo & info,
348 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
351 * \short Modify repository attributes
353 * \throws RepoAlreadyExistsException if the alias specified in newinfo
354 * is already used by another repository
355 * \throws RepoNotFoundException If no repo match
356 * \throws ParseException If the file parsing fails
357 * \throws Exception On other errors.
359 void modifyRepository( const std::string &alias,
360 const RepoInfo & newinfo,
361 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
364 * \short Find a matching repository info
366 * \note if multiple repositories incorrectly share the
367 * same alias, the first one found will be returned.
369 * \param alias Repository alias
370 * \param progressrcv Progress reporting function
371 * \return RepoInfo of the found repository
372 * \throws RepoNotFoundException If no repo match the alias
373 * \throws ParseException If the file parsing fails
374 * \throws Exception On other errors.
376 RepoInfo getRepositoryInfo( const std::string &alias,
377 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
380 * \short Find repository info by URL.
382 * \param url URL to find.
383 * \param urlview url::ViewOption to influence URL matching.
384 * \param progressrcv Progress receiver function.
385 * \return RepoInfo of the found repository.
387 * \note if multpile repositories incorrectly share the
388 * same URL, the first one found will be returned.
390 * \note the string representation of the URLs are compared.
391 * The \a urlview can be used to influence which
392 parts of the URL are to be compared.
394 * \throws RepoNotFoundException If no repo match
395 * \throws ParseException If the file parsing fails
396 * \throws Exception On other errors.
398 RepoInfo getRepositoryInfo( const Url & url,
399 const url::ViewOption & urlview = url::ViewOption::DEFAULTS,
400 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
403 RepoStatus rawMetadataStatus( const RepoInfo &info );
404 void setCacheStatus( const RepoInfo &info, const RepoStatus &status );
407 * Update timestamp of repository index file for the specified repository \a info.
408 * Used in \ref checkIfToRefreshMetadata() for repo.refresh.delay feature.
410 void touchIndexFile(const RepoInfo & info);
415 /** Pointer to implementation */
416 RWCOW_pointer<Impl> _pimpl;
418 ///////////////////////////////////////////////////////////////////
420 /** \relates RepoManager Stream output */
421 std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
423 /////////////////////////////////////////////////////////////////
425 ///////////////////////////////////////////////////////////////////
426 #endif // ZYPP2_REPOMANAGER_H